public void SetNtpConfigurationDnsFromDHCPTest() { NetworkInterface ni = null; RunTest <NTPInformation>( // Backup action new Backup <NTPInformation>(() => { NTPInformation originalInformation = GetNTP(); string reason = null; Assert((originalInformation != null) && originalInformation.IsValidNTPInformation(false, out reason), reason == null ? "Failed to get original NTP configuration" : reason, "Check that original NTP configuration returned from the DUT"); ni = TurnOnDhcpIpv4(); return(originalInformation); }), // Main action () => { NTPInformation testInformation = new NTPInformation(); testInformation.FromDHCP = true; SetNTP(testInformation); double timeout = ((double)_operationDelay) / 1000; BeginStep(string.Format("Wait {0} seconds to allow the DUT to interact with DHCP server", timeout.ToString("0.000"))); Sleep(_operationDelay); StepPassed(); NTPInformation actualInformation = GetNTP(); string reason = null; Assert((actualInformation != null) && actualInformation.IsValidNTPInformation(false, out reason), reason == null ? "Failed to get current NTP configuration" : reason, "Check that current NTP configuration returned from the DUT"); BeginStep("Check current NTP configuration"); bool bAllEquals; bool bEquals = (actualInformation.FromDHCP == testInformation.FromDHCP); LogStepEvent(string.Format("FromDHCP: expected - {0}, actual - {1}", testInformation.FromDHCP, actualInformation.FromDHCP)); bAllEquals = bEquals; string actualIpDescription; actualIpDescription = DeviceManagementNetworkTestSuite.DumpNetworkHostArray(actualInformation.NTPManual); string expectedAddress = "No Network Hosts"; if (actualInformation.NTPManual != null && actualInformation.NTPManual.Count() > 0) { bEquals = false; } else { bEquals = true; } LogStepEvent(string.Format("NTPManual: expected - {0}, actual - {1}", expectedAddress, actualIpDescription)); bAllEquals = bAllEquals && bEquals; /*************************************************/ actualIpDescription = DeviceManagementNetworkTestSuite.DumpNetworkHostArray(actualInformation.NTPFromDHCP); if (actualInformation.NTPFromDHCP == null) { bEquals = false; } else { bEquals = (actualInformation.NTPFromDHCP.Length > 0); } string expectedDescription = "List of NTP servers"; LogStepEvent(string.Format("NTPFromDHCP: expected - {0}, actual - {1}", expectedDescription, actualIpDescription)); bAllEquals = bAllEquals && bEquals; /*********************************************************/ if (!bAllEquals) { throw new AssertException("Current NTP configuration differs from configuration was set"); } StepPassed(); }, // Restore action (originalInformation) => { // if DHCP was ON, it has not been changed if (!ni.IPv4.Config.DHCP) { // restore network interface configuration RestoreNetworkInterface(ni.token, ni); } SetNTP(originalInformation, "Restore NTP configuration"); } ); }
public void SetNtpIpv6ConfigurationTest() { NetworkInterface ni = null; RunTest <NTPInformation>( new Backup <NTPInformation>(() => { NTPInformation originalInformation = GetNTP(); Assert(originalInformation != null, "The DUT did not return NTP configuration", "Check that DUT returned NTP information"); ni = TurnOffDhcpIpv6(); return(originalInformation); }), () => { NTPInformation testInformation = new NTPInformation(); testInformation.FromDHCP = false; testInformation.NTPManual = new NetworkHost[] { new NetworkHost() }; testInformation.NTPManual[0].Type = NetworkHostType.IPv6; testInformation.NTPManual[0].IPv6Address = _environmentSettings.NtpIpv6; SetNTP(testInformation); NTPInformation currentInformation = GetNTP(); Assert(currentInformation != null, "The DUT did not return NTP configuration", "Check that DUT returned NTP information"); BeginStep("Validate current NTP configuration"); bool bAllEquals; bool bEquals = (currentInformation.FromDHCP == testInformation.FromDHCP); LogStepEvent(string.Format("FromDHCP: expected - {0}, actual - {1}", testInformation.FromDHCP, currentInformation.FromDHCP)); bAllEquals = bEquals; string actualIpDescription; actualIpDescription = DeviceManagementNetworkTestSuite.DumpNetworkHostArray(currentInformation.NTPManual); NetworkHostType type = testInformation.NTPManual[0].Type; string expectedAddress = testInformation.NTPManual[0].IPv6Address; if ( currentInformation.NTPManual.Where( A => A.Type == type && A.IPv6Address == expectedAddress).Count() > 0) { bEquals = true; } else { bEquals = false; } string expectedDescription = string.Format("{0} should be presented", testInformation.NTPManual[0].IPv6Address); LogStepEvent(string.Format("NTPManual: expected - {0}, actual - {1}", expectedDescription, actualIpDescription)); bAllEquals = bAllEquals && bEquals; actualIpDescription = DeviceManagementNetworkTestSuite.DumpNetworkHostArray(currentInformation.NTPFromDHCP); if (currentInformation.NTPFromDHCP == null) { bEquals = true; } else { bEquals = (currentInformation.NTPFromDHCP.Length == 0); } expectedDescription = "No NTPFromDHCP"; LogStepEvent(string.Format("NTPFromDHCP: expected - {0}, actual - {1}", expectedDescription, actualIpDescription)); bAllEquals = bAllEquals && bEquals; if (!bAllEquals) { throw new AssertException( "Current NTP configuration differs from configuration set in previous step"); } StepPassed(); }, (originalInformation) => { SetNTP(originalInformation, "Restore NTP configuration"); if (ni.IPv6.Config.DHCP != IPv6DHCPConfiguration.Off) { RestoreNetworkInterface(ni.token, ni); } } ); }