mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
refactor test cases: use testNG instead of junit, as testNG can group test cases and pass parameter to test case
This commit is contained in:
parent
877e16029c
commit
4b2d9f4415
@ -51,11 +51,11 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
<version>4.2.2</version>
|
<version>4.2.2</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
@ -72,10 +72,22 @@
|
|||||||
<artifactId>javax.inject</artifactId>
|
<artifactId>javax.inject</artifactId>
|
||||||
<version>1</version>
|
<version>1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
<version>6.1.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>install</defaultGoal>
|
<defaultGoal>install</defaultGoal>
|
||||||
<testSourceDirectory>test</testSourceDirectory>
|
<testSourceDirectory>${project.basedir}/test</testSourceDirectory>
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>${project.basedir}/test/resource</directory>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
|||||||
@ -0,0 +1,68 @@
|
|||||||
|
package org.apache.cloudstack.storage.test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||||
|
private String hostGateway;
|
||||||
|
private String hostCidr;
|
||||||
|
private String hostIp;
|
||||||
|
private String hostGuid;
|
||||||
|
private String templateUrl;
|
||||||
|
private String localStorageUuid;
|
||||||
|
private Transaction txn;
|
||||||
|
|
||||||
|
@BeforeMethod(alwaysRun = true)
|
||||||
|
protected void injectDB(Method testMethod) throws Exception {
|
||||||
|
txn = Transaction.open(testMethod.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterMethod(alwaysRun = true)
|
||||||
|
protected void closeDB(Method testMethod) throws Exception {
|
||||||
|
if (txn != null) {
|
||||||
|
txn.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeMethod(alwaysRun = true)
|
||||||
|
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr", "devcloud-host-ip", "template-url", "devcloud-local-storage-uuid"})
|
||||||
|
protected void setup(String hostuuid, String gateway, String cidr, String hostIp, String templateUrl, String localStorageUuid) {
|
||||||
|
this.hostGuid = hostuuid;
|
||||||
|
this.hostGateway = gateway;
|
||||||
|
this.hostCidr = cidr;
|
||||||
|
this.hostIp = hostIp;
|
||||||
|
this.templateUrl = templateUrl;
|
||||||
|
this.localStorageUuid = localStorageUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getHostGuid() {
|
||||||
|
return this.hostGuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getHostGateway() {
|
||||||
|
return this.hostGateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getHostCidr() {
|
||||||
|
return this.hostCidr;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getHostIp() {
|
||||||
|
return this.hostIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getTemplateUrl() {
|
||||||
|
return this.templateUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getLocalStorageUuid() {
|
||||||
|
return this.localStorageUuid;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cloudstack.storage.test;
|
package org.apache.cloudstack.storage.test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -27,12 +28,16 @@ import org.apache.cloudstack.storage.to.ImageDataStoreTO;
|
|||||||
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
||||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||||
import org.apache.cloudstack.storage.to.TemplateTO;
|
import org.apache.cloudstack.storage.to.TemplateTO;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.cloud.agent.AgentManager;
|
import com.cloud.agent.AgentManager;
|
||||||
import com.cloud.agent.api.ReadyCommand;
|
import com.cloud.agent.api.ReadyCommand;
|
||||||
@ -52,10 +57,11 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
|||||||
import com.cloud.org.Cluster.ClusterType;
|
import com.cloud.org.Cluster.ClusterType;
|
||||||
import com.cloud.org.Managed.ManagedState;
|
import com.cloud.org.Managed.ManagedState;
|
||||||
import com.cloud.resource.ResourceState;
|
import com.cloud.resource.ResourceState;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||||
@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
|
public class DirectAgentTest extends CloudStackTestNGBase {
|
||||||
public class DirectAgentTest {
|
|
||||||
@Inject
|
@Inject
|
||||||
AgentManager agentMgr;
|
AgentManager agentMgr;
|
||||||
@Inject
|
@Inject
|
||||||
@ -69,10 +75,10 @@ public class DirectAgentTest {
|
|||||||
private long dcId;
|
private long dcId;
|
||||||
private long clusterId;
|
private long clusterId;
|
||||||
private long hostId;
|
private long hostId;
|
||||||
private String hostGuid = "9d4c9db8-32f7-25c3-0435-eab4bf3adcea";
|
|
||||||
@Before
|
@Test(priority = -1)
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
HostVO host = hostDao.findByGuid(hostGuid);
|
HostVO host = hostDao.findByGuid(this.getHostGuid());
|
||||||
if (host != null) {
|
if (host != null) {
|
||||||
hostId = host.getId();
|
hostId = host.getId();
|
||||||
dcId = host.getDataCenterId();
|
dcId = host.getDataCenterId();
|
||||||
@ -86,7 +92,7 @@ public class DirectAgentTest {
|
|||||||
dcId = dc.getId();
|
dcId = dc.getId();
|
||||||
//create pod
|
//create pod
|
||||||
|
|
||||||
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "192.168.56.1", "192.168.56.0/24", 8, "test");
|
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
|
||||||
pod = podDao.persist(pod);
|
pod = podDao.persist(pod);
|
||||||
//create xen cluster
|
//create xen cluster
|
||||||
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
|
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
|
||||||
@ -97,12 +103,11 @@ public class DirectAgentTest {
|
|||||||
clusterId = cluster.getId();
|
clusterId = cluster.getId();
|
||||||
//create xen host
|
//create xen host
|
||||||
|
|
||||||
//TODO: this hardcode host uuid in devcloud
|
host = new HostVO(this.getHostGuid());
|
||||||
host = new HostVO(hostGuid);
|
|
||||||
host.setName("devcloud xen host");
|
host.setName("devcloud xen host");
|
||||||
host.setType(Host.Type.Routing);
|
host.setType(Host.Type.Routing);
|
||||||
host.setHypervisorType(HypervisorType.XenServer);
|
host.setHypervisorType(HypervisorType.XenServer);
|
||||||
host.setPrivateIpAddress("192.168.56.10");
|
host.setPrivateIpAddress(this.getHostIp());
|
||||||
host.setDataCenterId(dc.getId());
|
host.setDataCenterId(dc.getId());
|
||||||
host.setVersion("6.0.1");
|
host.setVersion("6.0.1");
|
||||||
host.setAvailable(true);
|
host.setAvailable(true);
|
||||||
@ -133,14 +138,14 @@ public class DirectAgentTest {
|
|||||||
public void testDownloadTemplate() {
|
public void testDownloadTemplate() {
|
||||||
ImageOnPrimayDataStoreTO image = Mockito.mock(ImageOnPrimayDataStoreTO.class);
|
ImageOnPrimayDataStoreTO image = Mockito.mock(ImageOnPrimayDataStoreTO.class);
|
||||||
PrimaryDataStoreTO primaryStore = Mockito.mock(PrimaryDataStoreTO.class);
|
PrimaryDataStoreTO primaryStore = Mockito.mock(PrimaryDataStoreTO.class);
|
||||||
Mockito.when(primaryStore.getUuid()).thenReturn("9f3f9262-3f77-09cc-2df7-0d8475676260");
|
Mockito.when(primaryStore.getUuid()).thenReturn(this.getLocalStorageUuid());
|
||||||
Mockito.when(image.getPrimaryDataStore()).thenReturn(primaryStore);
|
Mockito.when(image.getPrimaryDataStore()).thenReturn(primaryStore);
|
||||||
|
|
||||||
ImageDataStoreTO imageStore = Mockito.mock(ImageDataStoreTO.class);
|
ImageDataStoreTO imageStore = Mockito.mock(ImageDataStoreTO.class);
|
||||||
Mockito.when(imageStore.getType()).thenReturn("http");
|
Mockito.when(imageStore.getType()).thenReturn("http");
|
||||||
|
|
||||||
TemplateTO template = Mockito.mock(TemplateTO.class);
|
TemplateTO template = Mockito.mock(TemplateTO.class);
|
||||||
Mockito.when(template.getPath()).thenReturn("http://download.cloud.com/templates/devcloud/defaulttemplates/5/ce5b212e-215a-3461-94fb-814a635b2215.vhd");
|
Mockito.when(template.getPath()).thenReturn(this.getTemplateUrl());
|
||||||
Mockito.when(template.getImageDataStore()).thenReturn(imageStore);
|
Mockito.when(template.getImageDataStore()).thenReturn(imageStore);
|
||||||
|
|
||||||
Mockito.when(image.getTemplate()).thenReturn(template);
|
Mockito.when(image.getTemplate()).thenReturn(template);
|
||||||
|
|||||||
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.cloudstack.storage.test;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
|
|
||||||
public class Future2<T> {
|
|
||||||
|
|
||||||
private Callable<T> callable;
|
|
||||||
private Callable<T> success;
|
|
||||||
private Callable<T> failed;
|
|
||||||
private ExecutorService executor = Executors.newFixedThreadPool(2);
|
|
||||||
private Future<T> f;
|
|
||||||
|
|
||||||
public class Func<T> implements Callable<T> {
|
|
||||||
private Callable<T> f;
|
|
||||||
private Callable<T> fs;
|
|
||||||
public T func() throws Exception {
|
|
||||||
return f.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T success() throws Exception {
|
|
||||||
return fs.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Func (Callable<T> f, Callable<T> s) {
|
|
||||||
this.f = f;
|
|
||||||
this.fs = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T call() throws Exception {
|
|
||||||
func();
|
|
||||||
success();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public Future2 (Callable<T> callable) {
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSuccess(Callable<T> s) {
|
|
||||||
this.success = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void go() {
|
|
||||||
Func<T> ft = new Func<T>(this.callable, this.success);
|
|
||||||
f = executor.submit(ft);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T get() {
|
|
||||||
try {
|
|
||||||
return this.f.get();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return null;
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
|
||||||
this.executor.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Callable<String> fun = new Callable<String> () {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String call() throws Exception {
|
|
||||||
System.out.println("execing");
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
Future2<String> f2 = new Future2<String>(fun);
|
|
||||||
f2.onSuccess(new Callable<String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String call() throws Exception {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
System.out.println("success");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
f2.go();
|
|
||||||
//f2.get();
|
|
||||||
f2.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.cloudstack.storage.test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class SimpleTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
try {
|
|
||||||
URI u = new URI("http://myproxy.domain.com:3128");
|
|
||||||
System.out.print(u.getHost());
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -40,13 +40,15 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||||
@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
|
public class TestHttp extends AbstractTestNGSpringContextTests {
|
||||||
public class TestHttp {
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpclient() {
|
@Parameters("template-url")
|
||||||
HttpHead method = new HttpHead("http://download.cloud.com/templates/devcloud/defaulttemplates/5/ce5b212e-215a-3461-94fb-814a635b2215.vhd");
|
public void testHttpclient(String templateUrl) {
|
||||||
|
HttpHead method = new HttpHead(templateUrl);
|
||||||
DefaultHttpClient client = new DefaultHttpClient();
|
DefaultHttpClient client = new DefaultHttpClient();
|
||||||
|
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
@ -60,7 +62,7 @@ public class TestHttp {
|
|||||||
localFile.createNewFile();
|
localFile.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpGet getMethod = new HttpGet("http://download.cloud.com/templates/devcloud/defaulttemplates/5/ce5b212e-215a-3461-94fb-814a635b2215.vhd");
|
HttpGet getMethod = new HttpGet(templateUrl);
|
||||||
response = client.execute(getMethod);
|
response = client.execute(getMethod);
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package org.apache.cloudstack.storage.test;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||||
|
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||||
|
public class TestNG extends AbstractTestNGSpringContextTests {
|
||||||
|
@Test
|
||||||
|
@DB
|
||||||
|
public void test1() {
|
||||||
|
Assert.assertEquals("", "192.168.56.2");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package org.apache.cloudstack.storage.test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.testng.IMethodInstance;
|
||||||
|
import org.testng.IMethodInterceptor;
|
||||||
|
import org.testng.ITestContext;
|
||||||
|
import org.testng.ITestNGMethod;
|
||||||
|
import org.testng.internal.ConstructorOrMethod;
|
||||||
|
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
|
public class TestNGAop implements IMethodInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IMethodInstance> intercept(List<IMethodInstance> methods,
|
||||||
|
ITestContext context) {
|
||||||
|
for (IMethodInstance methodIns : methods) {
|
||||||
|
ITestNGMethod method = methodIns.getMethod();
|
||||||
|
ConstructorOrMethod meth = method.getConstructorOrMethod();
|
||||||
|
Method m = meth.getMethod();
|
||||||
|
if (m != null) {
|
||||||
|
DB db = m.getAnnotation(DB.class);
|
||||||
|
if (db != null) {
|
||||||
|
Transaction txn = Transaction.open(m.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -105,7 +105,7 @@ import com.cloud.utils.db.DB;
|
|||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
|
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||||
public class volumeServiceTest {
|
public class volumeServiceTest {
|
||||||
@Inject
|
@Inject
|
||||||
ImageDataStoreProviderManager imageProviderMgr;
|
ImageDataStoreProviderManager imageProviderMgr;
|
||||||
@ -158,7 +158,7 @@ public class volumeServiceTest {
|
|||||||
HostVO host = new HostVO(UUID.randomUUID().toString());
|
HostVO host = new HostVO(UUID.randomUUID().toString());
|
||||||
host.setName("devcloud xen host");
|
host.setName("devcloud xen host");
|
||||||
host.setType(Host.Type.Routing);
|
host.setType(Host.Type.Routing);
|
||||||
host.setPrivateIpAddress("192.168.56.10");
|
host.setPrivateIpAddress("192.168.56.2");
|
||||||
host.setDataCenterId(dc.getId());
|
host.setDataCenterId(dc.getId());
|
||||||
host.setVersion("6.0.1");
|
host.setVersion("6.0.1");
|
||||||
host.setAvailable(true);
|
host.setAvailable(true);
|
||||||
|
|||||||
22
engine/storage/integration-test/test/resource/testng.xml
Normal file
22
engine/storage/integration-test/test/resource/testng.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
||||||
|
<suite thread-count="1" verbose="1" name="storage test" annotations="JDK" parallel="methods">
|
||||||
|
<!--describe your test environment-->
|
||||||
|
<parameter name="devcloud-host-ip" value="192.168.56.2"/>
|
||||||
|
<parameter name="devcloud-host-gateway" value="192.168.56.1"/>
|
||||||
|
<parameter name="devcloud-host-cidr" value="192.168.56.0/24"/>
|
||||||
|
<parameter name="template-url" value="http://192.168.56.1/ce5b212e-215a-3461-94fb-814a635b2215.vhd"/>
|
||||||
|
<parameter name="primary-storage-want-to-add" value="nfs://192.168.56.2/opt/storage/primarynfs"/>
|
||||||
|
<parameter name="devcloud-local-storage-uuid" value="cd10cac1-4772-92e5-5da6-c2bc16b1ce1b"/>
|
||||||
|
<parameter name="devcloud-host-uuid" value="759ee4c9-a15a-297b-67c6-ac267d8aa429"/>
|
||||||
|
|
||||||
|
<listeners>
|
||||||
|
<listener class-name="org.apache.cloudstack.storage.test.TestNGAop" />
|
||||||
|
</listeners>
|
||||||
|
|
||||||
|
<test name="integration-tests">
|
||||||
|
<packages>
|
||||||
|
<package name="org.apache.cloudstack.storage.test"/>
|
||||||
|
</packages>
|
||||||
|
</test>
|
||||||
|
</suite>
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package org.apache.cloudstack.storage.command;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Command;
|
||||||
|
|
||||||
|
public class CreatePrimaryDataStoreCmd extends Command implements StorageSubSystemCommand {
|
||||||
|
private final PrimaryDataStoreTO dataStore;
|
||||||
|
public CreatePrimaryDataStoreCmd(PrimaryDataStoreTO dataStore) {
|
||||||
|
this.dataStore = dataStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrimaryDataStoreTO getDataStore() {
|
||||||
|
return this.dataStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean executeInSequence() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ public class NfsValidator implements ProtocolValidator {
|
|||||||
params.put("path", hostPath);
|
params.put("path", hostPath);
|
||||||
params.put("user", userInfo);
|
params.put("user", userInfo);
|
||||||
params.put("port", String.valueOf(port));
|
params.put("port", String.valueOf(port));
|
||||||
|
params.put("uuid", UUID.fromString(storageHost + hostPath).toString());
|
||||||
|
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new CloudRuntimeException("invalid url: " + e.toString());
|
throw new CloudRuntimeException("invalid url: " + e.toString());
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class PrimaryDataStoreVO implements Identity {
|
|||||||
private String uuid = null;
|
private String uuid = null;
|
||||||
|
|
||||||
@Column(name = "pool_type", updatable = false, nullable = false, length = 32)
|
@Column(name = "pool_type", updatable = false, nullable = false, length = 32)
|
||||||
private String protocol;
|
private String poolType;
|
||||||
|
|
||||||
@Column(name = GenericDao.CREATED_COLUMN)
|
@Column(name = GenericDao.CREATED_COLUMN)
|
||||||
Date created;
|
Date created;
|
||||||
@ -123,11 +123,11 @@ public class PrimaryDataStoreVO implements Identity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPoolType() {
|
public String getPoolType() {
|
||||||
return protocol;
|
return poolType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoolType(String protocol) {
|
public void setPoolType(String protocol) {
|
||||||
this.protocol = protocol;
|
this.poolType = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
@ -262,6 +262,6 @@ public class PrimaryDataStoreVO implements Identity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringBuilder("Pool[").append(id).append("|").append(protocol).append("]").toString();
|
return new StringBuilder("Pool[").append(id).append("|").append(poolType).append("]").toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,21 +51,25 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void attachCluster() {
|
||||||
|
//send down createStoragePool command to all the hosts in the cluster
|
||||||
|
AttachPrimaryDataStoreCmd cmd = new AttachPrimaryDataStoreCmd(this.dataStore);
|
||||||
|
for (EndPoint ep : dataStore.getEndPoints()) {
|
||||||
|
ep.sendMessage(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean attachCluster(ClusterScope scope) {
|
public boolean attachCluster(ClusterScope scope) {
|
||||||
|
attachCluster();
|
||||||
|
|
||||||
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(this.dataStore.getId());
|
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(this.dataStore.getId());
|
||||||
dataStoreVO.setDataCenterId(scope.getZoneId());
|
dataStoreVO.setDataCenterId(scope.getZoneId());
|
||||||
dataStoreVO.setPodId(scope.getPodId());
|
dataStoreVO.setPodId(scope.getPodId());
|
||||||
dataStoreVO.setClusterId(scope.getScopeId());
|
dataStoreVO.setClusterId(scope.getScopeId());
|
||||||
dataStoreVO.setStatus(DataStoreStatus.Up);
|
dataStoreVO.setStatus(DataStoreStatus.Up);
|
||||||
dataStoreDao.update(dataStoreVO.getId(), dataStoreVO);
|
dataStoreDao.update(dataStoreVO.getId(), dataStoreVO);
|
||||||
|
return true;
|
||||||
//send down createStoragePool command to all the hosts in the cluster
|
|
||||||
AttachPrimaryDataStoreCmd cmd = new AttachPrimaryDataStoreCmd(this.dataStore);
|
|
||||||
for (EndPoint ep : dataStore.getEndPoints()) {
|
|
||||||
ep.sendMessage(cmd);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,8 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cloudstack.storage.datastore.lifecycle;
|
package org.apache.cloudstack.storage.datastore.lifecycle;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.storage.EndPoint;
|
||||||
|
import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd;
|
||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
|
||||||
public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStoreLifeCycleImpl {
|
public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStoreLifeCycleImpl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,5 +35,22 @@ public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStore
|
|||||||
super(dataStoreDao);
|
super(dataStoreDao);
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attachCluster() {
|
||||||
|
//send one time is enough, as xenserver is clustered
|
||||||
|
AttachPrimaryDataStoreCmd cmd = new AttachPrimaryDataStoreCmd(this.dataStore);
|
||||||
|
String result = null;
|
||||||
|
for (EndPoint ep : dataStore.getEndPoints()) {
|
||||||
|
Answer answer = ep.sendMessage(cmd);
|
||||||
|
if (answer.getResult()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
result = answer.getDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new CloudRuntimeException("AttachPrimaryDataStoreCmd failed: " + result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,6 +125,7 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
|
|||||||
dataStoreVO.setPort(Integer.parseInt(dsInfos.get("port")));
|
dataStoreVO.setPort(Integer.parseInt(dsInfos.get("port")));
|
||||||
dataStoreVO.setKey(key);
|
dataStoreVO.setKey(key);
|
||||||
dataStoreVO.setName(dsInfos.get("name"));
|
dataStoreVO.setName(dsInfos.get("name"));
|
||||||
|
dataStoreVO.setUuid(dsInfos.get("uuid"));
|
||||||
dataStoreVO = dataStoreDao.persist(dataStoreVO);
|
dataStoreVO = dataStoreDao.persist(dataStoreVO);
|
||||||
|
|
||||||
DefaultPrimaryDataStore dataStore = (DefaultPrimaryDataStore)configurator.getDataStore(dataStoreVO.getId());
|
DefaultPrimaryDataStore dataStore = (DefaultPrimaryDataStore)configurator.getDataStore(dataStoreVO.getId());
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreAnswer;
|
|||||||
import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd;
|
import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd;
|
||||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
|
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
|
||||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
|
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
|
||||||
|
import org.apache.cloudstack.storage.command.CreatePrimaryDataStoreCmd;
|
||||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||||
import org.apache.cloudstack.storage.to.ImageDataStoreTO;
|
import org.apache.cloudstack.storage.to.ImageDataStoreTO;
|
||||||
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
||||||
@ -56,10 +57,14 @@ import com.cloud.agent.api.Command;
|
|||||||
import com.cloud.agent.api.ModifyStoragePoolAnswer;
|
import com.cloud.agent.api.ModifyStoragePoolAnswer;
|
||||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
|
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
|
||||||
import com.cloud.agent.api.to.StorageFilerTO;
|
import com.cloud.agent.api.to.StorageFilerTO;
|
||||||
|
import com.cloud.hypervisor.xen.resource.CitrixResourceBase.SRType;
|
||||||
|
import com.cloud.storage.Storage.StoragePoolType;
|
||||||
import com.cloud.storage.template.TemplateInfo;
|
import com.cloud.storage.template.TemplateInfo;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.xensource.xenapi.Connection;
|
import com.xensource.xenapi.Connection;
|
||||||
|
import com.xensource.xenapi.Host;
|
||||||
import com.xensource.xenapi.PBD;
|
import com.xensource.xenapi.PBD;
|
||||||
|
import com.xensource.xenapi.Pool;
|
||||||
import com.xensource.xenapi.SR;
|
import com.xensource.xenapi.SR;
|
||||||
import com.xensource.xenapi.Types;
|
import com.xensource.xenapi.Types;
|
||||||
import com.xensource.xenapi.Types.BadServerResponse;
|
import com.xensource.xenapi.Types.BadServerResponse;
|
||||||
@ -79,13 +84,212 @@ public class XenServerStorageResource {
|
|||||||
return this.execute((CopyTemplateToPrimaryStorageCmd)command);
|
return this.execute((CopyTemplateToPrimaryStorageCmd)command);
|
||||||
} else if (command instanceof AttachPrimaryDataStoreCmd) {
|
} else if (command instanceof AttachPrimaryDataStoreCmd) {
|
||||||
return this.execute((AttachPrimaryDataStoreCmd)command);
|
return this.execute((AttachPrimaryDataStoreCmd)command);
|
||||||
|
} else if (command instanceof CreatePrimaryDataStoreCmd) {
|
||||||
|
return execute((CreatePrimaryDataStoreCmd) command);
|
||||||
}
|
}
|
||||||
return new Answer((Command)command, false, "not implemented yet");
|
return new Answer((Command)command, false, "not implemented yet");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
protected SR getNfsSR(Connection conn, PrimaryDataStoreTO pool) {
|
||||||
|
Map<String, String> deviceConfig = new HashMap<String, String>();
|
||||||
|
try {
|
||||||
|
String server = pool.getHost();
|
||||||
|
String serverpath = pool.getPath();
|
||||||
|
serverpath = serverpath.replace("//", "/");
|
||||||
|
Set<SR> srs = SR.getAll(conn);
|
||||||
|
for (SR sr : srs) {
|
||||||
|
if (!SRType.NFS.equals(sr.getType(conn))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<PBD> pbds = sr.getPBDs(conn);
|
||||||
|
if (pbds.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PBD pbd = pbds.iterator().next();
|
||||||
|
|
||||||
|
Map<String, String> dc = pbd.getDeviceConfig(conn);
|
||||||
|
|
||||||
|
if (dc == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dc.get("server") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dc.get("serverpath") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
|
||||||
|
throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:"
|
||||||
|
+ dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + _host.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
deviceConfig.put("server", server);
|
||||||
|
deviceConfig.put("serverpath", serverpath);
|
||||||
|
Host host = Host.getByUuid(conn, _host.uuid);
|
||||||
|
SR sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), Long.toString(pool.getId()), SRType.NFS.toString(), "user", true,
|
||||||
|
new HashMap<String, String>());
|
||||||
|
sr.scan(conn);
|
||||||
|
return sr;
|
||||||
|
} catch (XenAPIException e) {
|
||||||
|
throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
|
||||||
|
} catch (XmlRpcException e) {
|
||||||
|
throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SR getIscsiSR(Connection conn, PrimaryDataStoreTO pool) {
|
||||||
|
synchronized (pool.getUuid().intern()) {
|
||||||
|
Map<String, String> deviceConfig = new HashMap<String, String>();
|
||||||
|
try {
|
||||||
|
String target = pool.getHost();
|
||||||
|
String path = pool.getPath();
|
||||||
|
if (path.endsWith("/")) {
|
||||||
|
path = path.substring(0, path.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String tmp[] = path.split("/");
|
||||||
|
if (tmp.length != 3) {
|
||||||
|
String msg = "Wrong iscsi path " + pool.getPath() + " it should be /targetIQN/LUN";
|
||||||
|
s_logger.warn(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
String targetiqn = tmp[1].trim();
|
||||||
|
String lunid = tmp[2].trim();
|
||||||
|
String scsiid = "";
|
||||||
|
|
||||||
|
Set<SR> srs = SR.getByNameLabel(conn, pool.getUuid());
|
||||||
|
for (SR sr : srs) {
|
||||||
|
if (!SRType.LVMOISCSI.equals(sr.getType(conn))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Set<PBD> pbds = sr.getPBDs(conn);
|
||||||
|
if (pbds.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PBD pbd = pbds.iterator().next();
|
||||||
|
Map<String, String> dc = pbd.getDeviceConfig(conn);
|
||||||
|
if (dc == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (dc.get("target") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (dc.get("targetIQN") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (dc.get("lunid") == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (target.equals(dc.get("target")) && targetiqn.equals(dc.get("targetIQN")) && lunid.equals(dc.get("lunid"))) {
|
||||||
|
throw new CloudRuntimeException("There is a SR using the same configuration target:" + dc.get("target") + ", targetIQN:"
|
||||||
|
+ dc.get("targetIQN") + ", lunid:" + dc.get("lunid") + " for pool " + pool.getUuid() + "on host:" + _host.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviceConfig.put("target", target);
|
||||||
|
deviceConfig.put("targetIQN", targetiqn);
|
||||||
|
|
||||||
|
Host host = Host.getByUuid(conn, _host.uuid);
|
||||||
|
Map<String, String> smConfig = new HashMap<String, String>();
|
||||||
|
String type = SRType.LVMOISCSI.toString();
|
||||||
|
String poolId = Long.toString(pool.getId());
|
||||||
|
SR sr = null;
|
||||||
|
try {
|
||||||
|
sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), poolId, type, "user", true,
|
||||||
|
smConfig);
|
||||||
|
} catch (XenAPIException e) {
|
||||||
|
String errmsg = e.toString();
|
||||||
|
if (errmsg.contains("SR_BACKEND_FAILURE_107")) {
|
||||||
|
String lun[] = errmsg.split("<LUN>");
|
||||||
|
boolean found = false;
|
||||||
|
for (int i = 1; i < lun.length; i++) {
|
||||||
|
int blunindex = lun[i].indexOf("<LUNid>") + 7;
|
||||||
|
int elunindex = lun[i].indexOf("</LUNid>");
|
||||||
|
String ilun = lun[i].substring(blunindex, elunindex);
|
||||||
|
ilun = ilun.trim();
|
||||||
|
if (ilun.equals(lunid)) {
|
||||||
|
int bscsiindex = lun[i].indexOf("<SCSIid>") + 8;
|
||||||
|
int escsiindex = lun[i].indexOf("</SCSIid>");
|
||||||
|
scsiid = lun[i].substring(bscsiindex, escsiindex);
|
||||||
|
scsiid = scsiid.trim();
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
String msg = "can not find LUN " + lunid + " in " + errmsg;
|
||||||
|
s_logger.warn(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString();
|
||||||
|
s_logger.warn(msg, e);
|
||||||
|
throw new CloudRuntimeException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviceConfig.put("SCSIid", scsiid);
|
||||||
|
|
||||||
|
String result = SR.probe(conn, host, deviceConfig, type , smConfig);
|
||||||
|
String pooluuid = null;
|
||||||
|
if( result.indexOf("<UUID>") != -1) {
|
||||||
|
pooluuid = result.substring(result.indexOf("<UUID>") + 6, result.indexOf("</UUID>")).trim();
|
||||||
|
}
|
||||||
|
if( pooluuid == null || pooluuid.length() != 36) {
|
||||||
|
sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), poolId, type, "user", true,
|
||||||
|
smConfig);
|
||||||
|
} else {
|
||||||
|
sr = SR.introduce(conn, pooluuid, pool.getUuid(), poolId,
|
||||||
|
type, "user", true, smConfig);
|
||||||
|
Pool.Record pRec = XenServerConnectionPool.getPoolRecord(conn);
|
||||||
|
PBD.Record rec = new PBD.Record();
|
||||||
|
rec.deviceConfig = deviceConfig;
|
||||||
|
rec.host = pRec.master;
|
||||||
|
rec.SR = sr;
|
||||||
|
PBD pbd = PBD.create(conn, rec);
|
||||||
|
pbd.plug(conn);
|
||||||
|
}
|
||||||
|
sr.scan(conn);
|
||||||
|
return sr;
|
||||||
|
} catch (XenAPIException e) {
|
||||||
|
String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString();
|
||||||
|
s_logger.warn(msg, e);
|
||||||
|
throw new CloudRuntimeException(msg, e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.getMessage();
|
||||||
|
s_logger.warn(msg, e);
|
||||||
|
throw new CloudRuntimeException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
protected Answer execute(CreatePrimaryDataStoreCmd cmd) {
|
||||||
|
Connection conn = hypervisorResource.getConnection();
|
||||||
|
PrimaryDataStoreTO dataStore = cmd.getDataStore();
|
||||||
|
try {
|
||||||
|
if (dataStore.getType() == StoragePoolType.NetworkFilesystem.toString()) {
|
||||||
|
//getNfsSR(conn, dataStore);
|
||||||
|
} else if (dataStore.getType() == StoragePoolType.IscsiLUN.toString()) {
|
||||||
|
//getIscsiSR(conn, dataStore);
|
||||||
|
} else if (dataStore.getType() == StoragePoolType.PreSetup.toString()) {
|
||||||
|
} else {
|
||||||
|
//return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
|
||||||
|
}
|
||||||
|
return new Answer(cmd, true, "success");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// String msg = "Catch Exception " + e.getClass().getName() + ", create StoragePool failed due to " + e.toString() + " on host:" + _host.uuid + " pool: " + pool.getHost() + pool.getPath();
|
||||||
|
//s_logger.warn(msg, e);
|
||||||
|
return new Answer(cmd, false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private long getTemplateSize(Connection conn, String url) {
|
private long getTemplateSize(Connection conn, String url) {
|
||||||
String size = hypervisorResource.callHostPlugin(conn, "storagePlugin", "getTemplateSize", "srcUrl", url);
|
String size = hypervisorResource.callHostPlugin(conn, "storagePlugin", "getTemplateSize", "srcUrl", url);
|
||||||
if (size == "" || size == null) {
|
if (size.equalsIgnoreCase("") || size == null) {
|
||||||
throw new CloudRuntimeException("Can't get template size");
|
throw new CloudRuntimeException("Can't get template size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
import os, sys, time
|
import os, sys, time
|
||||||
import XenAPIPlugin
|
import XenAPIPlugin
|
||||||
sys.path.extend(["/usr/lib/xcp/sm/", "/usr/local/sbin/", "/sbin/"])
|
sys.path.extend(["/opt/xensource/sm/", "/usr/lib/xcp/sm/", "/usr/local/sbin/", "/sbin/"])
|
||||||
import util
|
import util
|
||||||
import base64
|
import base64
|
||||||
import socket
|
import socket
|
||||||
|
|||||||
@ -64,4 +64,4 @@ cloud-prepare-upgrade.sh=..,0755,/usr/lib/xcp/bin
|
|||||||
getRouterStatus.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
getRouterStatus.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||||
bumpUpPriority.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
bumpUpPriority.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||||
getDomRVersion.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
getDomRVersion.sh=../../../../network/domr/,0755,/usr/lib/xcp/bin
|
||||||
storagePlugin=.,0755,/usr/lib/xcp/plugins
|
storagePlugin=..,0755,/usr/lib/xcp/plugins
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user