AutonomiccsSystemVmsGuru implements VirtualMachineGuru, InitializingBean { protected void configureNicGatewayAndManagementNetwork(DeployDestination dest, StringBuilder buf, NicProfile nic) { if (nic.isDefaultNic()) { buf.append(" gateway=").append(nic.getIPv4Gateway()); } if (nic.getTrafficType() == TrafficType.Management) { String mgmt_cidr = configurationDao.getValue(Config.ManagementNetwork.key()); if (NetUtils.isValidCIDR(mgmt_cidr)) { buf.append(" mgmtcidr=").append(mgmt_cidr); } buf.append(" localgw=").append(dest.getPod().getGateway()); } }  @Override void afterPropertiesSet(); @Override boolean finalizeCommandsOnStart(Commands arg0, VirtualMachineProfile arg1); @Override boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void finalizeExpunge(VirtualMachine vm); @Override boolean finalizeStart(VirtualMachineProfile arg0, long arg1, Commands arg2, ReservationContext arg3); @Override void finalizeStop(VirtualMachineProfile arg0, Answer arg1); @Override boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void prepareStop(VirtualMachineProfile arg0);  }
@Test public void configureNicGatewayAndManagementNetworkTestBufferEmpty() throws Exception { StringBuilder buf = new StringBuilder(); configureTestConfigureNicGatewayAndManagementNetwork(false, TrafficType.Guest); spy.configureNicGatewayAndManagementNetwork(dest, buf, nic); Assert.assertEquals(StringUtils.EMPTY, buf.toString()); }
@Test @PrepareForTest(NetUtils.class) public void configureNicGatewayAndManagementNetworkTestTrafficManagementAndIsNotValidCIDR() throws Exception { StringBuilder buf = new StringBuilder(); PowerMockito.mockStatic(NetUtils.class); PowerMockito.doReturn(false).when(NetUtils.class, "isValidCIDR", Mockito.anyString()); configureTestConfigureNicGatewayAndManagementNetwork(true, TrafficType.Management); spy.configureNicGatewayAndManagementNetwork(dest, buf, nic); Assert.assertEquals(" gateway=IPv4Gateway localgw=localgw", buf.toString()); }
@Test @PrepareForTest(NetUtils.class) public void configureNicGatewayAndManagementNetworkTestIsValidCidrAndTrafficTypeManagement() throws Exception { StringBuilder buf = new StringBuilder(); PowerMockito.mockStatic(NetUtils.class); PowerMockito.doReturn(true).when(NetUtils.class, "isValidCIDR", Mockito.anyString()); configureTestConfigureNicGatewayAndManagementNetwork(true, TrafficType.Management); spy.configureNicGatewayAndManagementNetwork(dest, buf, nic); Assert.assertEquals(" gateway=IPv4Gateway mgmtcidr=mgmt_cidr localgw=localgw", buf.toString()); }
@Test public void configureNicGatewayAndManagementNetworkTestTrafficTypeNotManagement() { StringBuilder buf = new StringBuilder(); configureTestConfigureNicGatewayAndManagementNetwork(true, TrafficType.Guest); spy.configureNicGatewayAndManagementNetwork(dest, buf, nic); Assert.assertEquals(" gateway=IPv4Gateway", buf.toString()); }
@Test public void configureNicGatewayAndManagementNetworkTestNotDefaultNicAndTrafficManagement() { StringBuilder buf = new StringBuilder(); configureTestConfigureNicGatewayAndManagementNetwork(false, TrafficType.Management); spy.configureNicGatewayAndManagementNetwork(dest, buf, nic); Assert.assertEquals(" localgw=localgw", buf.toString()); }
@Test @PrepareForTest(NetUtils.class) public void configureNicGatewayAndManagementNetworkTestTrafficManagementAndIsValidCIDR() throws Exception { StringBuilder buf = new StringBuilder(); PowerMockito.mockStatic(NetUtils.class); PowerMockito.doReturn(true).when(NetUtils.class, "isValidCIDR", Mockito.anyString()); configureTestConfigureNicGatewayAndManagementNetwork(false, TrafficType.Management); spy.configureNicGatewayAndManagementNetwork(dest, buf, nic); Assert.assertEquals(" mgmtcidr=mgmt_cidr localgw=localgw", buf.toString()); }