public boolean isNetworkInSync() { return reportConfigurationsOnHost().isNetworkInSync(); }
private NetworkInSyncWithVdsNetworkInterface createTestedInstance(boolean isDefaultRouteNetwork, DnsResolverConfiguration reportedDnsResolverConfiguration) { return new NetworkInSyncWithVdsNetworkInterface(iface, network, networkQos, testedNetworkAttachment, reportedDnsResolverConfiguration, cluster, isDefaultRouteNetwork); }
private void addDnsConfiguration(ReportedConfigurations result) { if (isDefaultRouteNetwork) { List<NameServer> nameServersOfHost = getNameServers(reportedDnsResolverConfiguration); List<NameServer> expectedNameServers = getExpectedNameServers(); result.add(DNS_CONFIGURATION, addressesAsString(nameServersOfHost), addressesAsString(expectedNameServers), nameServersOfHost.containsAll(expectedNameServers)); } }
private boolean isIpv4NetworkSubnetInSync() { return getsSubnetUtilsInstance().equalSubnet(iface.getIpv4Subnet(), getIpv4PrimaryAddress().getNetmask()); }
isNetworkMtuInSync()); result.add(ReportedConfigurationType.BRIDGED, iface.isBridged(), network.isVmNetwork()); result.add(ReportedConfigurationType.VLAN, iface.getVlanId(), network.getVlanId()); cluster.getRequiredSwitchTypeForCluster()); addReportedIpv4Configuration(result); result.add(OUT_AVERAGE_LINK_SHARE, getOutAverageLinkshare(ifaceQos), getOutAverageLinkshare(hostNetworkQos)); result.add(OUT_AVERAGE_UPPER_LIMIT, getOutAverageUpperlimit(ifaceQos), getOutAverageUpperlimit(hostNetworkQos)); result.add(OUT_AVERAGE_REAL_TIME, getOutAverageRealtime(ifaceQos), getOutAverageRealtime(hostNetworkQos)); addDnsConfiguration(result);
private void addReportedIpv4Configuration(ReportedConfigurations result) { if (!isIpv4PrimaryAddressExist()) { return; } Ipv4BootProtocol definedIpv4BootProtocol = getIpv4PrimaryAddress().getBootProtocol(); result.add(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol(), definedIpv4BootProtocol); if (definedIpv4BootProtocol == Ipv4BootProtocol.STATIC_IP && iface.getIpv4BootProtocol() == definedIpv4BootProtocol) { result.add(ReportedConfigurationType.IPV4_NETMASK, iface.getIpv4Subnet(), getIpv4PrimaryAddress().getNetmask(), isIpv4NetworkSubnetInSync()); result.add(ReportedConfigurationType.IPV4_ADDRESS, iface.getIpv4Address(), getIpv4PrimaryAddress().getAddress()); result.add(ReportedConfigurationType.IPV4_GATEWAY, iface.getIpv4Gateway(), getIpv4PrimaryAddress().getGateway(), isIpv4GatewayInSync()); } }
private void addReportedIpv6Configuration(ReportedConfigurations result) { if (!isIpv6PrimaryAddressExist()) { return; } Ipv6BootProtocol definedIpv6BootProtocol = getIpv6PrimaryAddress().getBootProtocol(); result.add(ReportedConfigurationType.IPV6_BOOT_PROTOCOL, iface.getIpv6BootProtocol(), definedIpv6BootProtocol); if (definedIpv6BootProtocol == Ipv6BootProtocol.STATIC_IP && iface.getIpv6BootProtocol() == definedIpv6BootProtocol) { result.add(ReportedConfigurationType.IPV6_PREFIX, iface.getIpv6Prefix(), getIpv6PrimaryAddress().getPrefix(), isIpv6PrefixInSync()); result.add(ReportedConfigurationType.IPV6_ADDRESS, iface.getIpv6Address(), getIpv6PrimaryAddress().getAddress()); result.add(ReportedConfigurationType.IPV6_GATEWAY, iface.getIpv6Gateway(), getIpv6PrimaryAddress().getGateway(), isIpv6GatewayInSync()); } }
networkQos.setOutAverageRealtime(1); ReportedConfigurations reportedConfigurations = testedInstanceWithSameNonQosValues.reportConfigurationsOnHost(); assertThat(createTestedInstanceWithSameNonQosValues().isNetworkInSync(), is(false)); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList();
private boolean isIpv4PrimaryAddressExist() { IpConfiguration networkDataCenterIpConfigurationDefinition = getIpConfigurationOfNetworkAttachment(); return networkDataCenterIpConfigurationDefinition != null && networkDataCenterIpConfigurationDefinition.hasIpv4PrimaryAddressSet(); }
private boolean isIpv6GatewayInSync() { String gatewayDesiredValue = getIpv6PrimaryAddress().getGateway(); String gatewayActualValue = iface.getIpv6Gateway(); return Objects.equals(gatewayDesiredValue, gatewayActualValue); }
private List<NameServer> getExpectedNameServers() { List<NameServer> nameServersOfNetworkAttachment = getNameServers(networkAttachment.getDnsResolverConfiguration()); List<NameServer> nameServersOfNetwork = getNameServers(network.getDnsResolverConfiguration()); return nameServersOfNetworkAttachment.isEmpty() ? nameServersOfNetwork : nameServersOfNetworkAttachment; }
private boolean isIpv4GatewayInSync() { String gatewayDesiredValue = getIpv4PrimaryAddress().getGateway(); String gatewayActualValue = iface.getIpv4Gateway(); return Objects.equals(gatewayDesiredValue, gatewayActualValue); }
private boolean isIpv6PrimaryAddressExist() { IpConfiguration ipConfiguration = getIpConfigurationOfNetworkAttachment(); return ipConfiguration != null && ipConfiguration.hasIpv6PrimaryAddressSet(); }
private boolean isIpv6PrefixInSync() { return Objects.equals(iface.getIpv6Prefix(), getIpv6PrimaryAddress().getPrefix()); }
@Test public void testReportConfigurationsOnHostWhenSwitchTypeIsOutOfSync() { cluster.setRequiredSwitchTypeForCluster(SwitchType.OVS); ReportedConfigurations reportedConfigurations = createTestedInstance().reportConfigurationsOnHost(); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); ReportedConfiguration expectedReportedConfiguration = new ReportedConfiguration(ReportedConfigurationType.SWITCH_TYPE, SwitchType.LEGACY, SwitchType.OVS, false); assertThat(reportedConfigurationList.contains(expectedReportedConfiguration), is(true)); }
@SuppressWarnings("ConstantConditions") private IPv4Address getIpv4PrimaryAddress() { return getIpConfigurationOfNetworkAttachment().getIpv4PrimaryAddress(); }
@Test public void testReportConfigurationsOnHost() { NetworkInSyncWithVdsNetworkInterface testedInstanceWithSameNonQosValues = createTestedInstanceWithSameNonQosValues(); ifaceQos.setOutAverageLinkshare(1); ifaceQos.setOutAverageUpperlimit(1); ifaceQos.setOutAverageRealtime(1); ReportedConfigurations reportedConfigurations = testedInstanceWithSameNonQosValues.reportConfigurationsOnHost(); assertThat(reportedConfigurations.isNetworkInSync(), is(false)); List<ReportedConfiguration> reportedConfigurationList = reportedConfigurations.getReportedConfigurationList(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( combineReportedConfigurations(createBasicReportedConfigurations(), reportQos(false)), defaultRouteReportedConfiguration(false) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
@SuppressWarnings("ConstantConditions") private IpV6Address getIpv6PrimaryAddress() { return getIpConfigurationOfNetworkAttachment().getIpv6PrimaryAddress(); }
@Test public void testReportConfigurationsOnHostWhenIpv4BootProtocolNotStatic() { initIpv4ConfigurationBootProtocolAddress(Ipv4BootProtocol.NONE, false); initIpv4ConfigurationBootProtocolNetmask(Ipv4BootProtocol.NONE, false); initIpv4ConfigurationBootProtocolGateway(Ipv4BootProtocol.NONE, false); NetworkInSyncWithVdsNetworkInterface testedInstanceWithSameNonQosValues = createTestedInstanceWithSameNonQosValues(); List<ReportedConfiguration> reportedConfigurationList = testedInstanceWithSameNonQosValues.reportConfigurationsOnHost().getReportedConfigurationList(); IPv4Address primaryAddress = this.testedNetworkAttachment.getIpConfiguration().getIpv4PrimaryAddress(); List<ReportedConfiguration> expectedReportedConfigurations = addReportedConfigurations( createBasicAndQosReportedConfigurations(), defaultRouteReportedConfiguration(false), new ReportedConfiguration(ReportedConfigurationType.IPV4_BOOT_PROTOCOL, iface.getIpv4BootProtocol().name(), primaryAddress.getBootProtocol().name(), true) ); assertThat(reportedConfigurationList.containsAll(expectedReportedConfigurations), is(true)); assertThat(reportedConfigurationList.size(), is(expectedReportedConfigurations.size())); }
@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())); }