private static VdsNetworkInterface createVdsNetworkInterfaceWithStaticIp(String ip) { VdsNetworkInterface networkInterface = new VdsNetworkInterface(); networkInterface.setIpv4Address(ip); networkInterface.setIpv4BootProtocol(Ipv4BootProtocol.STATIC_IP); return networkInterface; }
private void initIpv4ConfigurationStaticBootProtocol(Ipv4BootProtocol networkBootProtocol) { initIpv4Configuration(); ipv4Address.setBootProtocol(networkBootProtocol); iface.setIpv4BootProtocol(networkBootProtocol); }
entity.setVdsName(rs.getString("vds_name")); entity.setId(getGuidDefaultEmpty(rs, "id")); entity.setIpv4BootProtocol(Ipv4BootProtocol.forValue(rs.getInt("boot_protocol"))); entity.setIpv6BootProtocol(Ipv6BootProtocol.forValue(rs.getInt("ipv6_boot_protocol"))); entity.setReportedSwitchType(SwitchType.parse(rs.getString("reported_switch_type")));
@Test public void testIsNetworkInSyncWhenIpv4BootProtocolDifferent() { initIpv4ConfigurationBootProtocol(false); iface.setIpv4BootProtocol(Ipv4BootProtocol.forValue( (IPV4_BOOT_PROTOCOL.getValue() + 1) % Ipv4BootProtocol.values().length)); assertThat(createTestedInstance().isNetworkInSync(), is(false)); }
@Test public void testIsNetworkInSyncWhenIpv4StaticBootProtocolNetmaskDifferent() { initIpv4ConfigurationBootProtocolNetmask(IPV4_BOOT_PROTOCOL, false); iface.setIpv4BootProtocol(Ipv4BootProtocol.forValue( (IPV4_BOOT_PROTOCOL.getValue() + 1) % Ipv4BootProtocol.values().length)); assertThat(createTestedInstance().isNetworkInSync(), is(false)); }
@Test public void testIsNetworkInSyncWhenIpv4StaticBootProtocolAddressDifferent() { initIpv4ConfigurationBootProtocolAddress(IPV4_BOOT_PROTOCOL, false); iface.setIpv4BootProtocol(Ipv4BootProtocol.forValue( (IPV4_BOOT_PROTOCOL.getValue() + 1) % Ipv4BootProtocol.values().length)); assertThat(createTestedInstance().isNetworkInSync(), is(false)); }
private void testDnsResolverConfiguration(DnsResolverConfiguration vdsDnsResolver, DnsResolverConfiguration networkDnsResolver, DnsResolverConfiguration attachmentDnsResolver, boolean expectedInSync) { iface.setIpv4DefaultRoute(true); //cannot use initIpv4ConfigurationBootProtocol because of 'randomized tests' technique. iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); network.setDnsResolverConfiguration(networkDnsResolver); testedNetworkAttachment.setDnsResolverConfiguration(attachmentDnsResolver); assertThat(createTestedInstance(true, vdsDnsResolver).isNetworkInSync(), is(expectedInSync)); }
@Test public void testDnsResolverConfigurationInSyncWithHostWhenDhcpIsUsed() { iface.setIpv4DefaultRoute(false); network.setDnsResolverConfiguration(sampleDnsResolverConfiguration2); testedNetworkAttachment.setDnsResolverConfiguration(null); iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); assertThat(createTestedInstance(true, sampleDnsResolverConfiguration).isNetworkInSync(), is(false)); }
private void initIpv4ConfigurationBootProtocol(boolean sameBootProtocol) { initIpv4Configuration(); ipv4Address.setBootProtocol(IPV4_BOOT_PROTOCOL); Ipv4BootProtocol ifaceBootProtocol = sameBootProtocol ? IPV4_BOOT_PROTOCOL : Ipv4BootProtocol.forValue((IPV4_BOOT_PROTOCOL.getValue() + 1) % Ipv4BootProtocol.values().length); iface.setIpv4BootProtocol(ifaceBootProtocol); }
@Test public void testReportConfigurationsOnHostWhenDefaultRouteDiffers() { //cannot use initIpv4ConfigurationBootProtocol because of 'randomized tests' technique. iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); //network has default route role NetworkInSyncWithVdsNetworkInterface testedInstance = createTestedInstanceWithSameNonQosValues(true); ReportedConfigurations reportedConfigurations = testedInstance.reportConfigurationsOnHost(); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( combineReportedConfigurations(createBasicReportedConfigurations(), reportQos(true)), new ReportedConfiguration(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol().name(), /*ipv4Address*/address.getBootProtocol().name(), true), new ReportedConfiguration(ReportedConfigurationType.DNS_CONFIGURATION, addressesAsString(sampleDnsResolverConfiguration.getNameServers()), "192.168.1.1,2001:0db8:85a3:0000:0000:8a2e:0370:7334", true), new ReportedConfiguration(ReportedConfigurationType.DEFAULT_ROUTE, false, true, false) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
public static VdsNetworkInterface getMaster() { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(MASTER_GUID); entity.setName(MASTER_NAME); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity.setBonded(true); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); return setUpStatistics(entity, MASTER_GUID); }
@Test public void testReportConfigurationsOnHostWhenDnsConfigurationResolverOutOfSync() { iface.setIpv4DefaultRoute(true); //cannot use initIpv4ConfigurationBootProtocol because of 'randomized tests' technique. iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); network.setDnsResolverConfiguration(sampleDnsResolverConfiguration2); ReportedConfigurations reportedConfigurations = createTestedInstanceWithSameNonQosValues(true).reportConfigurationsOnHost(); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( combineReportedConfigurations(createBasicReportedConfigurations(), reportQos(true)), new ReportedConfiguration(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol().name(), /*ipv4Address*/address.getBootProtocol().name(), true), new ReportedConfiguration(ReportedConfigurationType.DNS_CONFIGURATION, addressesAsString(sampleDnsResolverConfiguration.getNameServers()), addressesAsString(network.getDnsResolverConfiguration().getNameServers()), false), new ReportedConfiguration(ReportedConfigurationType.DEFAULT_ROUTE, true, true, true) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
public static VdsNetworkInterface getSlave() { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(SLAVE_GUID); entity.setName(SLAVE_NAME); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity.setBondName(MASTER_NAME); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); return setUpStatistics(entity, SLAVE_GUID); }
public static VdsNetworkInterface getEntitySpecific(int index) { VdsNetworkInterface entity = new VdsNetworkInterface(); entity.setId(GUIDS[index]); entity.setName(NAMES[index]); entity.setNetworkName(NETWORK_NAME); entity.setSpeed(NIC_SPEED); entity = setUpStatistics(entity, GUIDS[index]); entity.getStatistics().setStatus(NIC_STATUS); entity.setIpv4BootProtocol(IPV4_BOOT_PROTOCOL); entity.setIpv6BootProtocol(IPV6_BOOT_PROTOCOL); return entity; }
private static void mapIpv4FromModel(HostNic model, VdsNetworkInterface entity) { if (model.isSetIp()) { if (model.getIp().isSetAddress()) { entity.setIpv4Address(model.getIp().getAddress()); } if (model.getIp().isSetGateway()) { entity.setIpv4Gateway(model.getIp().getGateway()); } if (model.getIp().isSetNetmask()) { entity.setIpv4Subnet(model.getIp().getNetmask()); } } if (model.isSetBootProtocol()) { Ipv4BootProtocol ipv4BootProtocol = Ipv4BootProtocolMapper.map(model.getBootProtocol()); if (ipv4BootProtocol != null) { entity.setIpv4BootProtocol(ipv4BootProtocol); } } }
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); existingVdsInterface = dao.get(FixturesTool.VDS_NETWORK_INTERFACE); newQos = new HostNetworkQos(); newQos.setOutAverageLinkshare(30); newQos.setOutAverageUpperlimit(30); newQos.setOutAverageRealtime(30); newVdsInterface = new VdsNetworkInterface(); newVdsInterface.setStatistics(new VdsNetworkStatistics()); newVdsInterface.setId(Guid.newGuid()); newVdsInterface.setName("eth77"); newVdsInterface.setNetworkName("enginet"); newVdsInterface.setSpeed(1000); newVdsInterface.setType(3); newVdsInterface.setMacAddress("01:C0:81:21:71:17"); newVdsInterface.setIpv4BootProtocol(Ipv4BootProtocol.STATIC_IP); newVdsInterface.setIpv4Address("192.168.122.177"); newVdsInterface.setIpv4Subnet("255.255.255.0"); newVdsInterface.setIpv4Gateway("192.168.122.1"); newVdsInterface.setIpv6BootProtocol(Ipv6BootProtocol.AUTOCONF); newVdsInterface.setIpv6Address("ipv6 address"); newVdsInterface.setIpv6Prefix(666); newVdsInterface.setIpv6Gateway("ipv6 gateway"); newVdsInterface.setMtu(1500); newVdsInterface.setQos(newQos); newVdsStatistics = newVdsInterface.getStatistics(); }