use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.
the class NuageVspGuestNetworkGuruTest method testReserve.
@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, URISyntaxException {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(network.getAccountId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
final DataCenterVO dataCenter = mock(DataCenterVO.class);
when(_dataCenterDao.findById(NETWORK_ID)).thenReturn(dataCenter);
final AccountVO networksAccount = mock(AccountVO.class);
when(networksAccount.getId()).thenReturn(NETWORK_ID);
when(networksAccount.getUuid()).thenReturn("aaaa-abbbb");
when(networksAccount.getType()).thenReturn(Account.ACCOUNT_TYPE_NORMAL);
when(_accountDao.findById(NETWORK_ID)).thenReturn(networksAccount);
final DomainVO networksDomain = mock(DomainVO.class);
when(networksDomain.getId()).thenReturn(NETWORK_ID);
when(networksDomain.getUuid()).thenReturn("aaaaa-bbbbb");
when(_domainDao.findById(NETWORK_ID)).thenReturn(networksDomain);
final NicVO nicvo = mock(NicVO.class);
when(nicvo.getId()).thenReturn(NETWORK_ID);
when(nicvo.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
when(nicvo.getUuid()).thenReturn("aaaa-fffff");
when(nicvo.getNetworkId()).thenReturn(NETWORK_ID);
when(nicvo.getInstanceId()).thenReturn(NETWORK_ID);
when(_nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
when(_nicDao.findDefaultNicForVM(NETWORK_ID)).thenReturn(nicvo);
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getId()).thenReturn(NETWORK_ID);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
when(vmProfile.getType()).thenReturn(VirtualMachine.Type.User);
when(vmProfile.getInstanceName()).thenReturn("");
when(vmProfile.getUuid()).thenReturn("aaaa-bbbbb");
when(vmProfile.getVirtualMachine()).thenReturn(vm);
NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getUuid()).thenReturn("aaa-bbbb");
when(nicProfile.getId()).thenReturn(NETWORK_ID);
when(nicProfile.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
final NetworkOfferingVO ntwkoffering = mock(NetworkOfferingVO.class);
when(ntwkoffering.getId()).thenReturn(NETWORK_ID);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffering);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_ipAddressDao.findByVmIdAndNetworkId(NETWORK_ID, NETWORK_ID)).thenReturn(null);
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
final ReservationContext reservationContext = mock(ReservationContext.class);
when(reservationContext.getAccount()).thenReturn(networksAccount);
when(reservationContext.getDomain()).thenReturn(networksDomain);
_nuageVspGuestNetworkGuru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), reservationContext);
}
use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.
the class NetworkOrchestratorTest method testDontRemoveDhcpServiceFromDomainRouter.
@Test
public void testDontRemoveDhcpServiceFromDomainRouter() {
// make local mocks
VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
NicVO nic = mock(NicVO.class);
NetworkVO network = mock(NetworkVO.class);
// make sure that release dhcp won't be called
when(vm.getType()).thenReturn(Type.DomainRouter);
when(network.getGuruName()).thenReturn(guruName);
when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
testOrchastrator.removeNic(vm, nic);
verify(nic, times(1)).setState(Nic.State.Deallocating);
verify(testOrchastrator._networkModel, never()).getElementImplementingProvider(dhcpProvider);
verify(testOrchastrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
verify(testOrchastrator._networksDao, times(1)).findById(nic.getNetworkId());
}
use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.
the class NetworkOrchestratorTest method testDontRemoveDhcpServiceWhenNotProvided.
@Test
public void testDontRemoveDhcpServiceWhenNotProvided() {
// make local mocks
VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
NicVO nic = mock(NicVO.class);
NetworkVO network = mock(NetworkVO.class);
// make sure that release dhcp will *not* be called
when(vm.getType()).thenReturn(Type.User);
when(testOrchastrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(false);
when(network.getGuruName()).thenReturn(guruName);
when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
testOrchastrator.removeNic(vm, nic);
verify(nic, times(1)).setState(Nic.State.Deallocating);
verify(testOrchastrator._networkModel, never()).getElementImplementingProvider(dhcpProvider);
verify(testOrchastrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
verify(testOrchastrator._networksDao, times(1)).findById(nic.getNetworkId());
}
use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.
the class ElasticLoadBalancerManagerImplTest method testFinalizeStartWhenCmdsAnswerIsNull.
@Test
public void testFinalizeStartWhenCmdsAnswerIsNull() throws Exception {
VirtualMachineProfile profileMock = mock(VirtualMachineProfile.class);
long hostId = 1L;
Commands cmds = mock(Commands.class);
when(cmds.getAnswer("checkSsh")).thenReturn(null);
ReservationContext context = mock(ReservationContext.class);
boolean expected = false;
boolean actual = elasticLoadBalancerManagerImpl.finalizeStart(profileMock, hostId, cmds, context);
assertEquals(expected, actual);
}
use of com.cloud.vm.VirtualMachineProfile in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testReserve.
@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, URISyntaxException, InsufficientAddressCapacityException {
final NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
final NicProfile nic = mock(NicProfile.class);
when(nic.getMacAddress()).thenReturn("macaddress");
when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
final DeployDestination dest = mock(DeployDestination.class);
final DataCenterVO dc = mock(DataCenterVO.class);
when(dest.getDataCenter()).thenReturn(dc);
when(dcdao.findById((long) anyInt())).thenReturn(dc);
final HostVO brocadeHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
when(brocadeHost.getId()).thenReturn(NETWORK_ID);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
final Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
final AssociateMacToNetworkAnswer answer = mock(AssociateMacToNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
guru.reserve(nic, network, vmProfile, dest, res);
verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Aggregations