/// <summary> /// Test Command: ReadChassisLogWithTimestamp. The test case verifies: /// The command returns completion code success; /// Verifies all the entries with in the time stamp /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool ReadChassisLogWithTimestamp() { CmTestLog.Start(); bool testPassed = true; ChassisLogResponse cmLogReponse = null; ChassisLogResponse CMLogReponseWithTime = null; CmTestLog.Info("!!!!!!!!! Starting execution of ReadChassisLogWithTimestampTest !!!!!!!!!"); cmLogReponse = this.Channel.ReadChassisLog(); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, cmLogReponse.completionCode, "Received for read chassis log"); // Make sure log entries should not be more than 50 testPassed &= ChassisManagerTestHelper.IsTrue(cmLogReponse.logEntries.Count <= CmConstants.LogEntries, string.Format("Received {0} log entries", cmLogReponse.logEntries.Count)); DateTime invalidStart = DateTime.Now.AddDays(1); DateTime invalidEnd = DateTime.Now.AddDays(2); CMLogReponseWithTime = this.Channel.ReadChassisLogWithTimestamp(invalidStart, invalidEnd); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, CMLogReponseWithTime.completionCode, "Received success for ReadChassisLogWithTimestamp"); testPassed &= ChassisManagerTestHelper.IsTrue(CMLogReponseWithTime.logEntries.Count == 0, "Received zero entries for invalid timestamp"); //need to clear the chassis log so the response is not too big ChassisResponse response = this.Channel.ClearChassisLog(); //Add couple more calls this.Channel.SetChassisAttentionLEDOn(); this.Channel.SetChassisAttentionLEDOff(); cmLogReponse = this.Channel.ReadChassisLog(); DateTime start = DateTime.Now.AddDays(-1); DateTime end = DateTime.Now.AddDays(1); CMLogReponseWithTime = this.Channel.ReadChassisLogWithTimestamp(start, end); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, CMLogReponseWithTime.completionCode, "Received success for ReadChassisLogWithTimestamp"); testPassed &= ChassisManagerTestHelper.IsTrue(cmLogReponse.logEntries[1].eventTime > start, "Log entires start time"); testPassed &= ChassisManagerTestHelper.IsTrue(cmLogReponse.logEntries[cmLogReponse.logEntries.Count - 1].eventTime < end, "Log entires end time"); int logSize = CMLogReponseWithTime.logEntries.Count; if (!CMLogReponseWithTime.logEntries[logSize - 1].eventDescription.Contains("SetChassisAttentionLEDOn")) { CmTestLog.Failure("!!!Failed to read the CM logs with a time range."); return(false); } //This will require that the CM doesn't receive any other user commands. if (!CMLogReponseWithTime.logEntries[0].eventDescription.Contains("ReadChassisLog")) { CmTestLog.Failure("!!!Failed to read the CM logs with a time range."); return(false); } CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Test Command: ClearChassisLog. Test case verifies: /// The command returns completion code success for WcsAdmin; /// Bad Request for WcsOperator and WcsUser /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> // [TFS WorkItem:2585] ClearChassisLog: Verify ONLY users from WcsCmAdmin are able to execute the command public bool ClearChassisLogByAllUsers() { CmTestLog.Start(); bool testPassed = true; // Loop through different user types and ReadChassisLogWithTimestamp foreach (WCSSecurityRole roleId in Enum.GetValues(typeof(WCSSecurityRole))) { try { // Use different user context this.TestChannelContext = this.ListTestChannelContexts[(int)roleId]; CmTestLog.Info(string.Format("Trying to ClearChassisLog with user type {0} ", roleId.ToString())); ChassisResponse clearChassisLog = this.TestChannelContext.ClearChassisLog(); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, clearChassisLog.completionCode, "Received ClearChassisLog for user " + roleId.ToString()); } catch (Exception ex) { // Check error is due to permission HTTP 400 bad request if (ex.Message.Contains("400") && roleId == WCSSecurityRole.WcsCmUser) { ChassisManagerTestHelper.IsTrue(true, "ClearChassisLog returned Bad Request for user " + roleId.ToString()); } else { ChassisManagerTestHelper.IsTrue(false, "Exception: " + ex.Message); testPassed = false; } } } CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Test Command: ReadChassisLog /// The test case verifies: All users can execute command /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool ReadChassisLogTest() { CmTestLog.Start(); bool allPassed = true; string currentApi = "ReadChassisLog"; try { // Verify all users can execute command : WorkItem(2580) bool userPassed; foreach (WCSSecurityRole TestUser in Enum.GetValues(typeof(WCSSecurityRole))) { CmTestLog.Info("Calling " + currentApi + " for user type " + TestUser); userPassed = true; VerifyReadChassisLog(ref userPassed, TestUser); ChassisManagerTestHelper.IsTrue(userPassed, currentApi + ": Command executed for user " + TestUser); allPassed &= userPassed; } ChassisManagerTestHelper.IsTrue(allPassed, currentApi + ": All users can execute the command"); } catch (Exception ex) { ChassisManagerTestHelper.IsTrue(false, ex.Message); ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Chassis Manager service started"); allPassed = false; } CmTestLog.End(allPassed); return(allPassed); }
/// <summary> /// Test Command: SetNextBoot, GetNextBoot. The test case verifies: /// The command returns a success completion code on server blades; /// The command works with all blade types (except unknown type); /// When set to non-persistent, the blade will lose its next boot value after restart. /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool SetGetNextBootTest() { CmTestLog.Start(); // get all server blade locations int[] serverLocations; if (!GetBladeLocations(blade => blade.bladeType.Equals(CmConstants.ServerBladeType), out serverLocations) || serverLocations.Length == 0) { CmTestLog.Failure("Cannot find any server blade"); CmTestLog.End(false); return(false); } // pick up a random server blade int bladeId = serverLocations.RandomOrDefault(); CmTestLog.Info(string.Format("Pick up a random server blade# {0} for test", bladeId)); // make sure the blade is powered on if (!SetPowerState(PowerState.ON, bladeId)) { CmTestLog.Failure("Cannot power on Blade# " + bladeId); CmTestLog.End(false); return(false); } bool allPassed = true; foreach (BladeBootType bootType in Enum.GetValues(typeof(BladeBootType))) { if (bootType == BladeBootType.Unknown) { continue; } //// set next boot to persistent CmTestLog.Info(string.Format("Trying to set next boot to Type {0} with persistent", bootType)); BootResponse response = Channel.SetNextBoot(bladeId, bootType, false, true, 0); allPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Set persistent boot type"); // get next boot and verify CmTestLog.Info("Trying to get the next boot"); response = Channel.GetNextBoot(bladeId); allPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Get next boot value"); allPassed &= ChassisManagerTestHelper.AreEqual(bootType, response.nextBoot, "The boot type matches what it was set to"); //// set to non persistent CmTestLog.Info(string.Format("Trying to set next boot to Type {0} with non-persistent", bootType)); response = Channel.SetNextBoot(bladeId, bootType, false, false, 1); allPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Set non-persistent boot type"); // get next boot and verify CmTestLog.Info("Trying to get the next boot"); response = Channel.GetNextBoot(bladeId); allPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Get next boot value"); allPassed &= ChassisManagerTestHelper.AreEqual(bootType, response.nextBoot, "The boot type matches what it was set to"); // make sure it loses its value after restart if (!(bootType == BladeBootType.ForcePxe || bootType == BladeBootType.NoOverride)) { CmTestLog.Info("Trying to restart the blade and get next boot value again"); Channel.SetBladeActivePowerCycle(bladeId, 0); Thread.Sleep(TimeSpan.FromMinutes(1)); response = Channel.GetNextBoot(bladeId); allPassed &= ChassisManagerTestHelper.IsTrue(bootType == response.nextBoot, "The blade loses its next boot value after power cycle"); } } // end of the test CmTestLog.End(allPassed); return(allPassed); }
private void VerifyReadChassisLog(ref bool chassisPassed, WCSSecurityRole user) { string currentApi = "ReadChassisLog"; string logParentDirectory = @"\\" + defaultCMName + @"\c$\"; string[] userLogPaths = new string[] { null, null }; ChassisLogResponse chassisLog = new ChassisLogResponse(); CmTestLog.Info("TestChannelContext user " + (int)user); this.TestChannelContext = this.ListTestChannelContexts[(int)user]; chassisLog = this.TestChannelContext.ReadChassisLog(); chassisPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, chassisLog.completionCode, currentApi + ": Completion Code success for user " + user.ToString()); if (StartStopCmService("stop")) { CmTestLog.Success(currentApi + ": Stopped Chassis Manager Service"); } else { CmTestLog.Failure(currentApi + ": Unable to stop Chassis Manager Service. Will not check log entry contents"); chassisPassed = false; return; } // Check Log entries are populated in ChassisLogResponse and not greater than 50 entries if (chassisLog.logEntries.Count < 1) { CmTestLog.Failure(currentApi + ": Command does not return Log Entries"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Stopped Chassis Manager Service"); return; } else if (chassisLog.logEntries.Count > 50) { CmTestLog.Failure(currentApi + ": Command returns more than 50 Log Entries"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Stopped Chassis Manager Service"); return; } else { CmTestLog.Success(currentApi + ": Command returns between 1 and 50 Log Entries"); } IntPtr token = IntPtr.Zero; // Impersonate remote user bool successLogon = LogonUser(defaultAdminUserName, defaultCMName, defaultAdminPassword, (int)DwLogonType.NewCredentials, (int)DwLogonProvider.WinNT50, ref token); if (successLogon) { using (WindowsImpersonationContext context = WindowsIdentity.Impersonate(token)) { // Verify that User Logs exist to compare log entries with ChassisLogResponse if (!Directory.Exists(logParentDirectory)) { CmTestLog.Failure(currentApi + ": Directory to User Log files does not exist"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Stopped Chassis Manager Service"); return; } foreach (string filePath in Directory.GetFiles(logParentDirectory)) { Match fileMatch00 = Regex.Match(filePath, @"ChassisManagerUserLog00\.svclog"); Match fileMatch01 = Regex.Match(filePath, @"ChassisManagerUserLog01\.svclog"); if (fileMatch00.Success) { userLogPaths[0] = filePath; } else if (fileMatch01.Success) { userLogPaths[1] = filePath; } } if (userLogPaths[0] == null && userLogPaths[1] == null) { CmTestLog.Failure(currentApi + ": Could not find user logs"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Started Chassis Manager Service"); return; } // Compare and match log entries in ChassisLogResponse to User Logs in Chassis Manager int entryCount = 0; bool allEntriesPassed = true; foreach (LogEntry entry in chassisLog.logEntries) { if (entry.eventDescription == null && entry.eventTime == null) { CmTestLog.Failure(currentApi + string.Format(": Log Entry {0} returns no data for either eventDescription or eventTime or both", entryCount)); allEntriesPassed = false; entryCount++; continue; } // Find log entry in either UserLog00 or UserLog01 int userLogCount = 0; bool userLogEntryFound = false; string propertyValue; foreach (string userLogPath in userLogPaths) { if (userLogPath == null) { CmTestLog.Info(currentApi + string.Format(": User Log {0} does not exist", userLogCount)); userLogCount++; continue; } XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader userLogReader = XmlReader.Create(userLogPath, xmlSettings); try { while (!userLogEntryFound) { while (userLogReader.Read()) { if (userLogReader.Name == "ApplicationData") { break; } } if (userLogReader.Name != "ApplicationData") { userLogReader.Close(); break; } // Read User Log Entry and condition both strings for comparison propertyValue = userLogReader.ReadElementContentAsString(); propertyValue = propertyValue.Replace(@"\", ""); propertyValue = propertyValue.Replace(@"(", ""); propertyValue = propertyValue.Replace(@")", ""); entry.eventDescription = entry.eventDescription.Replace(@"\", ""); entry.eventDescription = entry.eventDescription.Replace(@"(", ""); entry.eventDescription = entry.eventDescription.Replace(@")", ""); Match eventTimeMatch = Regex.Match(propertyValue, entry.eventTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); Match eventDescriptionMatch = Regex.Match(propertyValue, entry.eventDescription); if (eventTimeMatch.Success && eventDescriptionMatch.Success) { CmTestLog.Success(currentApi + string.Format(": Found eventTime match and eventDescription match for entry {0} in user log {1}", entryCount, userLogCount)); userLogEntryFound = true; } } } catch (Exception exc) { if (exc.Message.Contains(@"Not enough )'s")) { CmTestLog.Info(currentApi + string.Format(": Entry {0} throwing exception 'Not enough )'s' in User Log {1}", entryCount, userLogCount)); userLogCount++; continue; } else { throw new Exception(exc.Message); } } if (!userLogEntryFound) { CmTestLog.Info(currentApi + string.Format(": User Log {0} does not contain entry {1}", userLogCount, entryCount)); userLogReader.Close(); userLogCount++; continue; } userLogReader.Close(); userLogCount++; } if (!userLogEntryFound) { CmTestLog.Failure(currentApi + string.Format(": Entry {0} was not found in either user logs", entryCount)); allEntriesPassed = false; entryCount++; continue; } chassisPassed &= allEntriesPassed; entryCount++; } ChassisManagerTestHelper.IsTrue(allEntriesPassed, currentApi + string.Format(": All Log Entries passed", entryCount)); // Revert back to original user context.Undo(); } } else { CmTestLog.Failure("UserLogon: User failed to be created"); chassisPassed = false; } ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Started Chassis Manager Service"); }
/// <summary> /// Test: User Logs /// The test case verifies: /// User Log exists /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool UserLogsTest() { CmTestLog.Start(); bool allPassed = true; string currentTest = "UserLogs"; try { string logParentDirectory = @"\\" + defaultCMName + @"\c$\"; bool foundUserLog = false; IntPtr token = IntPtr.Zero; // Impersonate remote user bool successLogon = LogonUser(defaultAdminUserName, defaultCMName, defaultAdminPassword, (int)DwLogonType.NewCredentials, (int)DwLogonProvider.WinNT50, ref token); if (successLogon) { using (WindowsImpersonationContext context = WindowsIdentity.Impersonate(token)) { // Verify presence of User Log : WorkItem(2271) if (!Directory.Exists(logParentDirectory)) { CmTestLog.Failure(currentTest + ": Directory to User Log files does not exist"); return(false); } foreach (string filePath in Directory.GetFiles(logParentDirectory)) { Match fileMatch = Regex.Match(filePath, @"ChassisManagerUserLog0[01]\.svclog"); if (fileMatch.Success) { CmTestLog.Success(currentTest + ": Verified presence of User Log " + filePath); foundUserLog = true; break; } } allPassed &= foundUserLog; // Revert back to original user context.Undo(); } } else { CmTestLog.Failure("UserLogon: User failed to be created"); return(false); } } catch (Exception ex) { ChassisManagerTestHelper.IsTrue(false, "Exception: " + ex.Message); allPassed = false; } CmTestLog.End(allPassed); return(allPassed); }