public void GetNtpConfigurationTest() { RunTest(() => { NTPInformation ntpInformation = GetNTP(); Assert(ntpInformation != null, "NTP information not returned", "Check that DUT returned NTP information"); string reason = string.Empty; bool valid = ntpInformation.IsValidNTPInformation(false, out reason); Assert(valid, reason, "Validate NTP information"); }); }
public void SetInvalidIpv4NtpConfigurationTest() { RunTest <NetworkInterface>( new Backup <NetworkInterface>( () => { NetworkInterface ni = TurnOffDhcpIpv4(); return(ni); }), () => { NTPInformation testInformation = new NTPInformation(); testInformation.FromDHCP = false; testInformation.NTPManual = new NetworkHost[] { new NetworkHost() }; testInformation.NTPManual[0].Type = NetworkHostType.IPv4; testInformation.NTPManual[0].IPv4Address = "10.1.1"; RunStep(() => Client.SetNTP(testInformation.FromDHCP, testInformation.NTPManual), "Set NTP configuration - negative test", "Sender/InvalidArgVal/InvalidIPv4Address", true); DoRequestDelay(); NTPInformation currentInformation = GetNTP(); Assert(currentInformation != null, "The DUT did not return NTP configuration", "Check that NTP information returned from the DUT"); string reason; bool bValidConfiguration = currentInformation.IsValidNTPInformation(false, out reason); Assert(bValidConfiguration, reason, "Validate NTP configuration"); bool bFound = (currentInformation.NTPManual != null) && (currentInformation.NTPManual.Where(IP => IP.IPv4Address == "10.1.1"). FirstOrDefault() != null); Assert(!bFound, "The DUT returned invalid NTP Manual IP address", "Check if invalid address was not set"); }, (ni) => { if (ni.IPv4.Config.DHCP) { RestoreNetworkInterface(ni.token, ni); } }); }
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"); } ); }