We can directly load xenserver resource in unit test now, that means directly sending commands to hypervisor host in unit test is possible, storage integration test is in a final stage

This commit is contained in:
Edison Su 2012-12-05 17:52:24 -08:00
parent 0836bb8ec9
commit 1b91641397
10 changed files with 218 additions and 10 deletions

View File

@ -37,4 +37,5 @@ public interface PrimaryDataStoreInfo {
public String getUuid();
public State getManagedState();
public String getName();
public String getType();
}

View File

@ -44,6 +44,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-hypervisor-xen</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>

View File

@ -18,7 +18,7 @@ public class ChildTestConfiguration extends TestConfiguration {
@Bean
public AgentManager agentMgr() {
return Mockito.mock(AgentManager.class);
return new DirectAgentManagerSimpleImpl();
}
/* @Override
@Bean

View File

@ -18,10 +18,14 @@
*/
package org.apache.cloudstack.storage.test;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.StartupCommandProcessor;
@ -35,11 +39,16 @@ import com.cloud.exception.ConnectionException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.Status.Event;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.xen.resource.XcpOssResource;
import com.cloud.resource.ServerResource;
public class DirectAgentManagerImpl implements AgentManager {
public class DirectAgentManagerSimpleImpl implements AgentManager {
private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class);
private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
@Inject
HostDao hostDao;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub
@ -70,10 +79,43 @@ public class DirectAgentManagerImpl implements AgentManager {
return null;
}
protected void loadResource(Long hostId) {
HostVO host = hostDao.findById(hostId);
Map<String, Object> params = new HashMap<String, Object>();
params.put("guid", host.getGuid());
params.put("ipaddress", host.getPrivateIpAddress());
params.put("username", "root");
params.put("password", "password");
params.put("zone", String.valueOf(host.getDataCenterId()));
params.put("pod", String.valueOf(host.getPodId()));
ServerResource resource = null;
if (host.getHypervisorType() == HypervisorType.XenServer) {
resource = new XcpOssResource();
}
try {
resource.configure(host.getName(), params);
hostResourcesMap.put(hostId, resource);
} catch (ConfigurationException e) {
logger.debug("Failed to load resource:" + e.toString());
}
}
@Override
public Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException {
// TODO Auto-generated method stub
return null;
public synchronized Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException {
ServerResource resource = hostResourcesMap.get(hostId);
if (resource == null) {
loadResource(hostId);
resource = hostResourcesMap.get(hostId);
}
if (resource == null) {
return null;
}
Answer answer = resource.executeRequest(cmd);
return answer;
}
@Override

View File

@ -0,0 +1,125 @@
/*
* 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.UUID;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Cluster.ClusterType;
import com.cloud.org.Managed.ManagedState;
import com.cloud.resource.ResourceState;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
public class DirectAgentTest {
@Inject
AgentManager agentMgr;
@Inject
HostDao hostDao;
@Inject
HostPodDao podDao;
@Inject
ClusterDao clusterDao;
@Inject
DataCenterDao dcDao;
private long dcId;
private long clusterId;
private long hostId;
private String hostGuid = "759ee4c9-a15a-297b-67c6-ac267d8aa429";
@Before
public void setUp() {
HostVO host = hostDao.findByGuid(hostGuid);
if (host != null) {
hostId = host.getId();
dcId = host.getDataCenterId();
clusterId = host.getClusterId();
return;
}
//create data center
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24",
null, null, NetworkType.Basic, null, null, true, true);
dc = dcDao.persist(dc);
dcId = dc.getId();
//create pod
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "192.168.56.1", "192.168.56.0/24", 8, "test");
pod = podDao.persist(pod);
//create xen cluster
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
cluster.setHypervisorType(HypervisorType.XenServer.toString());
cluster.setClusterType(ClusterType.CloudManaged);
cluster.setManagedState(ManagedState.Managed);
cluster = clusterDao.persist(cluster);
clusterId = cluster.getId();
//create xen host
//TODO: this hardcode host uuid in devcloud
host = new HostVO(hostGuid);
host.setName("devcloud xen host");
host.setType(Host.Type.Routing);
host.setHypervisorType(HypervisorType.XenServer);
host.setPrivateIpAddress("192.168.56.2");
host.setDataCenterId(dc.getId());
host.setVersion("6.0.1");
host.setAvailable(true);
host.setSetup(true);
host.setLastPinged(0);
host.setResourceState(ResourceState.Enabled);
host.setClusterId(cluster.getId());
host = hostDao.persist(host);
hostId = host.getId();
}
@Test
public void testInitResource() {
ReadyCommand cmd = new ReadyCommand(dcId);
try {
agentMgr.send(hostId, cmd);
} catch (AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -293,8 +293,7 @@ public class volumeServiceTest {
DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class);
//assertNotNull(provider.dataStoreDao);
DefaultPrimaryDataStore dpdsi = new DefaultPrimaryDataStore(null, null, null);
ComponentInject.inject(dpdsi);
DefaultPrimaryDataStore dpdsi = DefaultPrimaryDataStore.createDataStore(null, null, null);
//assertNotNull(dpdsi.volumeDao);
}

View File

@ -147,7 +147,6 @@ public class PrimaryDataStoreEntityImpl implements StorageEntity {
@Override
public StoragePoolType getPoolType() {
// TODO Auto-generated method stub
return null;
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@ -168,4 +169,28 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
// TODO Auto-generated method stub
return true;
}
@Override
public String getUuid() {
// TODO Auto-generated method stub
return null;
}
@Override
public State getManagedState() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getType() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -140,4 +140,16 @@ public class VolumeObject implements VolumeInfo {
// TODO Auto-generated method stub
return null;
}
@Override
public Date getUpdatedDate() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getOwner() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -139,7 +139,6 @@ public class VolumeServiceImpl implements VolumeService {
try {
dataStore.installTemplate(templateOnPrimaryStoreObj);
templateOnPrimaryStoreObj.updateStatus(Status.CREATED);
} catch (Exception e) {
templateOnPrimaryStoreObj.updateStatus(Status.ABANDONED);
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationFailed);