NetworkOrchestrator extends ManagerBase implements NetworkOrchestrationService, Listener, Configurable { @Override public void removeNic(final VirtualMachineProfile vm, final Nic nic) { removeNic(vm, _nicDao.findById(nic.getId())); } protected  NetworkOrchestrator(); List<NetworkGuru> getNetworkGurus(); void setNetworkGurus(final List<NetworkGuru> networkGurus); List<NetworkElement> getNetworkElements(); void setNetworkElements(final List<NetworkElement> networkElements); List<IpDeployer> getIpDeployers(); void setIpDeployers(final List<IpDeployer> ipDeployers); List<DhcpServiceProvider> getDhcpProviders(); void setDhcpProviders(final List<DhcpServiceProvider> dhcpProviders); @Override @DB boolean configure(final String name, final Map<String, Object> params); @Override boolean start(); @Override boolean stop(); @Override List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final DeploymentPlan plan, final String name, final String displayText, final boolean isDefault); @Override @DB List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final Network predefined, final DeploymentPlan plan, final String name,
                                                final String displayText, final boolean errorIfAlreadySetup, final Long domainId, final ACLType aclType, final Boolean subdomainAccess, final Long vpcId,
                                                final Boolean isDisplayNetworkEnabled); @Override @DB void allocate(final VirtualMachineProfile vm, final LinkedHashMap<? extends Network, List<? extends NicProfile>> networks); @DB @Override Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm); @Override @DB Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context); @Override void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering); @Override void prepare(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context); @Override NicProfile prepareNic(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context, final long nicId, final Network network); @Override void prepareNicForMigration(final VirtualMachineProfile vm, final DeployDestination dest); @Override void prepareAllNicsForMigration(final VirtualMachineProfile vm, final DeployDestination dest); @Override void commitNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst); @Override void rollbackNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst); @Override @DB void release(final VirtualMachineProfile vmProfile, final boolean forced); @Override @DB void releaseNic(final VirtualMachineProfile vmProfile, final Nic nic); @Override void cleanupNics(final VirtualMachineProfile vm); @Override void removeNic(final VirtualMachineProfile vm, final Nic nic); boolean isDhcpAccrossMultipleSubnetsSupported(final DhcpServiceProvider dhcpServiceProvider); @DB @Override void removeDhcpServiceInSubnet(final Nic nic); @Override void expungeNics(final VirtualMachineProfile vm); @Override @DB Network createGuestNetwork(final long networkOfferingId, final String name, final String displayText, final String gateway, final String cidr, String vlanId,
                                      String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk, final long zoneId, final ACLType aclType, Boolean subdomainAccess,
                                      final Long vpcId, final String ip6Gateway, final String ip6Cidr, final Boolean isDisplayNetworkEnabled, final String isolatedPvlan); @Override @DB boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements); @Override boolean shutdownNetworkElementsAndResources(final ReservationContext context, final boolean cleanupElements, final Network network); @Override @DB boolean destroyNetwork(final long networkId, final ReservationContext context, final boolean forced); @Override boolean resourceCountNeedsUpdate(final NetworkOffering ntwkOff, final ACLType aclType); @Override boolean startNetwork(final long networkId, final DeployDestination dest, final ReservationContext context); @Override boolean restartNetwork(final Long networkId, final Account callerAccount, final User callerUser, final boolean cleanup); @Override NetworkProfile convertNetworkToNetworkProfile(final long networkId); @Override UserDataServiceProvider getPasswordResetProvider(final Network network); @Override UserDataServiceProvider getSSHKeyResetProvider(final Network network); @Override DhcpServiceProvider getDhcpServiceProvider(final Network network); @Override List<? extends Nic> listVmNics(final long vmId, final Long nicId, final Long networkId); @DB @Override boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest); @Override boolean processAnswers(final long agentId, final long seq, final Answer[] answers); @Override boolean processCommands(final long agentId, final long seq, final Command[] commands); @Override AgentControlAnswer processControlCommand(final long agentId, final AgentControlCommand cmd); @Override void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance); @Override boolean processDisconnect(final long agentId, final Status state); @Override boolean isRecurring(); @Override int getTimeout(); @Override boolean processTimeout(final long agentId, final long seq); @Override Map<String, String> finalizeServicesAndProvidersForNetwork(final NetworkOffering offering, final Long physicalNetworkId); @Override boolean setupDns(final Network network, final Provider provider); @Override NicProfile createNicForVm(final Network network, final NicProfile requested, final ReservationContext context, final VirtualMachineProfile vmProfile, final boolean prepare); @Override List<NicProfile> getNicProfiles(final VirtualMachine vm); @Override List<Provider> getProvidersForServiceInNetwork(final Network network, final Service service); @Override StaticNatServiceProvider getStaticNatProviderForNetwork(final Network network); @Override LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(final Network network, final Scheme lbScheme); @Override boolean isNetworkInlineMode(final Network network); @Override boolean isSecondaryIpSetForNic(final long nicId); @Override NicVO savePlaceholderNic(final Network network, final String ip4Address, final String ip6Address, final Type vmType); @Override String getConfigComponentName(); @Override ConfigKey<?>[] getConfigKeys(); static final ConfigKey<Integer> NetworkGcWait; static final ConfigKey<Integer> NetworkGcInterval; }
@Test public void testRemoveDhcpServiceWithNic() { VirtualMachineProfile vm = mock(VirtualMachineProfile.class); NicVO nic = mock(NicVO.class); NetworkVO network = mock(NetworkVO.class); when(vm.getType()).thenReturn(Type.User); when(testOrchastrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(true); when(network.getTrafficType()).thenReturn(TrafficType.Guest); when(network.getGuestType()).thenReturn(GuestType.Shared); when(testOrchastrator._nicDao.listByNetworkIdTypeAndGatewayAndBroadcastUri(nic.getNetworkId(), VirtualMachine.Type.User, nic.getIPv4Gateway(), nic.getBroadcastUri())).thenReturn(new ArrayList<NicVO>()); 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, times(2)).getElementImplementingProvider(dhcpProvider); verify(testOrchastrator._ntwkSrvcDao, times(2)).getProviderForServiceInNetwork(network.getId(), Service.Dhcp); verify(testOrchastrator._networksDao, times(2)).findById(nic.getNetworkId()); }
@Test public void testDontRemoveDhcpServiceFromDomainRouter() { VirtualMachineProfile vm = mock(VirtualMachineProfile.class); NicVO nic = mock(NicVO.class); NetworkVO network = mock(NetworkVO.class); 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()); }
@Test public void testDontRemoveDhcpServiceWhenNotProvided() { VirtualMachineProfile vm = mock(VirtualMachineProfile.class); NicVO nic = mock(NicVO.class); NetworkVO network = mock(NetworkVO.class); 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()); }