use of com.cloud.user.AccountVO in project cloudstack by apache.
the class HypervisorTemplateAdapterTest method testEmitDeleteEventUuid.
@Test
public void testEmitDeleteEventUuid() throws InterruptedException, ExecutionException, EventBusException {
//All the mocks required for this test to work.
ImageStoreEntity store = mock(ImageStoreEntity.class);
when(store.getId()).thenReturn(1l);
when(store.getDataCenterId()).thenReturn(1l);
when(store.getName()).thenReturn("Test Store");
TemplateDataStoreVO dataStoreVO = mock(TemplateDataStoreVO.class);
when(dataStoreVO.getDownloadState()).thenReturn(Status.DOWNLOADED);
TemplateInfo info = mock(TemplateInfo.class);
when(info.getDataStore()).thenReturn(store);
VMTemplateVO template = mock(VMTemplateVO.class);
when(template.getId()).thenReturn(1l);
when(template.getName()).thenReturn("Test Template");
when(template.getFormat()).thenReturn(ImageFormat.QCOW2);
when(template.getAccountId()).thenReturn(1l);
//TODO possibly return this from method for comparison, if things work how i want
when(template.getUuid()).thenReturn("Test UUID");
TemplateProfile profile = mock(TemplateProfile.class);
when(profile.getTemplate()).thenReturn(template);
when(profile.getZoneId()).thenReturn(1l);
TemplateApiResult result = mock(TemplateApiResult.class);
when(result.isSuccess()).thenReturn(true);
when(result.isFailed()).thenReturn(false);
@SuppressWarnings("unchecked") AsyncCallFuture<TemplateApiResult> future = mock(AsyncCallFuture.class);
when(future.get()).thenReturn(result);
AccountVO acct = mock(AccountVO.class);
when(acct.getId()).thenReturn(1l);
when(acct.getDomainId()).thenReturn(1l);
when(_templateMgr.getImageStoreByTemplate(anyLong(), anyLong())).thenReturn(Collections.singletonList((DataStore) store));
when(_templateStoreDao.listByTemplateStore(anyLong(), anyLong())).thenReturn(Collections.singletonList(dataStoreVO));
when(_dataFactory.getTemplate(anyLong(), any(DataStore.class))).thenReturn(info);
when(_dataFactory.listTemplateOnCache(anyLong())).thenReturn(Collections.singletonList(info));
when(_templateService.deleteTemplateAsync(any(TemplateInfo.class))).thenReturn(future);
when(_accountDao.findById(anyLong())).thenReturn(acct);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(acct);
//Test actually begins here.
setupUsageUtils();
_adapter.delete(profile);
Assert.assertNotNull(usageEvents);
Assert.assertNotNull(events);
Assert.assertEquals(1, events.size());
Event event = events.get(0);
Assert.assertNotNull(event);
Assert.assertNotNull(event.getResourceType());
Assert.assertEquals(VirtualMachineTemplate.class.getName(), event.getResourceType());
Assert.assertNotNull(event.getResourceUUID());
Assert.assertEquals("Test UUID", event.getResourceUUID());
Assert.assertEquals(EventTypes.EVENT_TEMPLATE_DELETE, event.getEventType());
cleanupUsageUtils();
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class TemplateManagerImplTest method setUp.
@Before
public void setUp() {
ComponentContext.initComponentsLifeCycle();
AccountVO account = new AccountVO("admin", 1L, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class FirstFitPlannerTest method initializeForTest.
private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDeployment plan, ExcludeList avoids) {
DataCenterVO mockDc = mock(DataCenterVO.class);
VMInstanceVO vm = mock(VMInstanceVO.class);
UserVmVO userVm = mock(UserVmVO.class);
ServiceOfferingVO offering = mock(ServiceOfferingVO.class);
AccountVO account = mock(AccountVO.class);
when(account.getId()).thenReturn(accountId);
when(account.getAccountId()).thenReturn(accountId);
when(vmProfile.getOwner()).thenReturn(account);
when(vmProfile.getVirtualMachine()).thenReturn(vm);
when(vmProfile.getId()).thenReturn(12L);
when(vmDao.findById(12L)).thenReturn(userVm);
when(userVm.getAccountId()).thenReturn(accountId);
when(vm.getDataCenterId()).thenReturn(dataCenterId);
when(dcDao.findById(1L)).thenReturn(mockDc);
when(avoids.shouldAvoid(mockDc)).thenReturn(false);
when(plan.getDataCenterId()).thenReturn(dataCenterId);
when(plan.getClusterId()).thenReturn(null);
when(plan.getPodId()).thenReturn(null);
// Mock offering details.
when(vmProfile.getServiceOffering()).thenReturn(offering);
when(offering.getId()).thenReturn(offeringId);
when(vmProfile.getServiceOfferingId()).thenReturn(offeringId);
when(offering.getCpu()).thenReturn(noOfCpusInOffering);
when(offering.getSpeed()).thenReturn(cpuSpeedInOffering);
when(offering.getRamSize()).thenReturn(ramInOffering);
List<Long> clustersWithEnoughCapacity = new ArrayList<Long>();
clustersWithEnoughCapacity.add(1L);
clustersWithEnoughCapacity.add(2L);
clustersWithEnoughCapacity.add(3L);
clustersWithEnoughCapacity.add(4L);
clustersWithEnoughCapacity.add(5L);
clustersWithEnoughCapacity.add(6L);
when(capacityDao.listClustersInZoneOrPodByHostCapacities(dataCenterId, noOfCpusInOffering * cpuSpeedInOffering, ramInOffering * 1024L * 1024L, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersWithEnoughCapacity);
Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
clusterCapacityMap.put(1L, 2048D);
clusterCapacityMap.put(2L, 2048D);
clusterCapacityMap.put(3L, 2048D);
clusterCapacityMap.put(4L, 2048D);
clusterCapacityMap.put(5L, 2048D);
clusterCapacityMap.put(6L, 2048D);
Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity = new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersOrderedByCapacity);
List<Long> disabledClusters = new ArrayList<Long>();
List<Long> clustersWithDisabledPods = new ArrayList<Long>();
when(clusterDao.listDisabledClusters(dataCenterId, null)).thenReturn(disabledClusters);
when(clusterDao.listClustersWithDisabledPods(dataCenterId)).thenReturn(clustersWithDisabledPods);
List<Long> hostList0 = new ArrayList<Long>();
List<Long> hostList1 = new ArrayList<Long>();
List<Long> hostList2 = new ArrayList<Long>();
List<Long> hostList3 = new ArrayList<Long>();
List<Long> hostList4 = new ArrayList<Long>();
List<Long> hostList5 = new ArrayList<Long>();
List<Long> hostList6 = new ArrayList<Long>();
hostList0.add(new Long(1));
hostList1.add(new Long(10));
hostList2.add(new Long(11));
hostList3.add(new Long(12));
hostList4.add(new Long(13));
hostList5.add(new Long(14));
hostList6.add(new Long(15));
String[] implicitHostTags = { "GPU" };
int ramInBytes = ramInOffering * 1024 * 1024;
when(serviceOfferingDetailsDao.findDetail(Matchers.anyLong(), anyString())).thenReturn(null);
when(hostGpuGroupsDao.listHostIds()).thenReturn(hostList0);
when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(1), Host.Type.Routing.toString())).thenReturn(hostList1);
when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(2), Host.Type.Routing.toString())).thenReturn(hostList2);
when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(3), Host.Type.Routing.toString())).thenReturn(hostList3);
when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(4), Host.Type.Routing.toString())).thenReturn(hostList4);
when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(5), Host.Type.Routing.toString())).thenReturn(hostList5);
when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(6), Host.Type.Routing.toString())).thenReturn(hostList6);
when(hostTagsDao.getDistinctImplicitHostTags(hostList1, implicitHostTags)).thenReturn(Arrays.asList("abc", "pqr", "xyz"));
when(hostTagsDao.getDistinctImplicitHostTags(hostList2, implicitHostTags)).thenReturn(Arrays.asList("abc", "123", "pqr", "456", "xyz"));
when(hostTagsDao.getDistinctImplicitHostTags(hostList3, implicitHostTags)).thenReturn(Arrays.asList("abc", "pqr"));
when(hostTagsDao.getDistinctImplicitHostTags(hostList4, implicitHostTags)).thenReturn(Arrays.asList("abc"));
when(hostTagsDao.getDistinctImplicitHostTags(hostList5, implicitHostTags)).thenReturn(Arrays.asList("abc", "pqr", "xyz"));
when(hostTagsDao.getDistinctImplicitHostTags(hostList6, implicitHostTags)).thenReturn(Arrays.asList("abc", "123", "pqr", "xyz"));
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class UserVmManagerTest method testMoveVmToUser1.
// Test Move VM b/w accounts where caller is not ROOT/Domain admin
@Test(expected = InvalidParameterValueException.class)
public void testMoveVmToUser1() throws Exception {
AssignVMCmd cmd = new AssignVMCmd();
Class<?> _class = cmd.getClass();
Field virtualmachineIdField = _class.getDeclaredField("virtualMachineId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
Field accountNameField = _class.getDeclaredField("accountName");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "account");
Field domainIdField = _class.getDeclaredField("domainId");
domainIdField.setAccessible(true);
domainIdField.set(cmd, 1L);
// caller is of type 0
Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.moveVMToUser(cmd);
} finally {
CallContext.unregister();
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class UserVmManagerTest method testUpdateVmNicIpFailure2.
// vm is stopped in isolated network in advanced zone
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure2() throws Exception {
UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
Class<?> _class = cmd.getClass();
Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
List<Service> services = new ArrayList<Service>();
services.add(Service.Dhcp);
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Stopped);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
when(_networkMock.getDataCenterId()).thenReturn(3L);
when(_networkMock.getGuestType()).thenReturn(GuestType.Isolated);
when(_dcDao.findById(anyLong())).thenReturn(_dcMock);
when(_dcMock.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_ipAddrMgr.allocateGuestIP(Mockito.eq(_networkMock), anyString())).thenReturn(null);
Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
Aggregations