/// <summary> /// This method returns list of populated Psu slots for CM /// </summary> /// <param name="testName"></param> /// <returns>Returns list of Psus if CM has any; returns null otherwise.</returns> protected int[] GetPsuLocations([CallerMemberName] string testName = null) { ChassisInfoResponse chassisInfoResponse = this.Channel.GetChassisInfo(false, true, false, true); if (chassisInfoResponse.completionCode != CompletionCode.Success) { CmTestLog.Failure("Failed to get Psu info using GetChassisInfo", testName); return(null); } else { CmTestLog.Success("Successfully received Psu info using GetChassisInfo", testName); } string testingLes = ConfigurationManager.AppSettings["LesOrNonLesPsus"].ToString(); int[] psuLocations = chassisInfoResponse .psuCollections .Where(psu => psu.state.Equals(PowerState.ON)) .Select(psu => (int)psu.id) .ToArray(); if (testingLes == "1") { psuLocations = chassisInfoResponse .batteryCollections .Where(battery => battery.presence.Equals((byte)1) && psuLocations.Contains((int)battery.id)) .Select(battery => (int)battery.id) .ToArray(); } return(psuLocations); }
/// <summary> /// SetACSocketPowerStateOff: Verify that only Operator and Admin can execute the command /// </summary> /// <returns></returns> protected bool AcSocketPowerSetByAdminOperatorTest() { CmTestLog.Start(); bool testPassed = true; string failureMessage = string.Empty; const uint NumACSocket = CmConstants.NumPowerSwitches; foreach (WCSSecurityRole roleId in Enum.GetValues(typeof(WCSSecurityRole))) { try { this.AcSocketSetGetValidation(ref testPassed, ref failureMessage, NumACSocket, roleId); } catch (Exception e) { // Check error is due to permission HTTP 401 unauthorize if (!e.Message.Contains("401") && roleId == WCSSecurityRole.WcsCmUser) { // Test failed, http response should contain http 401 error CmTestLog.Failure("We are expecting 401 error, but we received 400 instead."); } } } Console.WriteLine("\n++++++++++++++++++++++++++++++++"); failureMessage = "!!!!!!!!! Successfully finished execution of ACSocketPowerTests."; Console.WriteLine(failureMessage); CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Test Command: ReadChassisLogWithTimestamp. 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:2577] ReadChassisLogWithTimestamp: Verify all users from are able to execute the command public bool ReadChassisLogWithTimestampByAllUsers() { CmTestLog.Start(); bool testPassed = true; // Loop through different user types and ReadChassisLogWithTimestamp foreach (WCSSecurityRole roleId in Enum.GetValues(typeof(WCSSecurityRole))) { ChassisLogResponse chassisLog; // Use different user context this.TestChannelContext = this.ListTestChannelContexts[(int)roleId]; CmTestLog.Info(string.Format("Trying to ReadChassisLogWithTimestamp with user type {0} ", roleId.ToString())); chassisLog = this.TestChannelContext.ReadChassisLogWithTimestamp(DateTime.MinValue, DateTime.Now); if (chassisLog.completionCode != CompletionCode.Success && (roleId == WCSSecurityRole.WcsCmAdmin || roleId == WCSSecurityRole.WcsCmOperator || roleId == WCSSecurityRole.WcsCmUser)) { CmTestLog.Failure(string.Format("Cannot Get Read ChassisLogs WithTimestamp With User {0}", roleId.ToString())); CmTestLog.End(false); return(false); } else { testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, chassisLog.completionCode, "Received ReadChassisLogWithTimestamp for user " + roleId.ToString()); } } CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Sets blade state. If state is set to ON, set the blade to on; otherwise, set the blade to off. /// If bladeId is specified, change blade state to that specific blade; otherwise, the change /// will be made to all blades. /// </summary> protected bool SetBladeState(PowerState state, int bladeId = -1, [CallerMemberName] string testName = null) { try { var message = string.Format("Set {0} to {1} state", state, bladeId > 0 ? string.Format("Blade {0}", bladeId) : "all blades"); CmTestLog.Info(string.Concat("Trying to ", message), testName); ChassisResponse response; if (bladeId > 0) { response = state == PowerState.ON ? this.Channel.SetBladeOn(bladeId) : this.Channel.SetBladeOff(bladeId); } else { response = state == PowerState.ON ? this.Channel.SetAllBladesOn() : this.Channel.SetAllBladesOff(); } var result = ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, message, testName); Thread.Sleep(TimeSpan.FromSeconds(CmConstants.BladePowerOnSeconds)); return(result); } catch (Exception e) { CmTestLog.Exception(e, testName); return(false); } }
/// <summary> /// Restart the CM service /// </summary> /// <param name="currentApi"></param> /// <param name="testName"></param> /// <returns></returns> protected bool RestartCmService(string currentApi, [CallerMemberName] string testName = null) { try { if (!StartStopCmService("stop")) { return(false); } if (!StartStopCmService("start")) { return(false); } CmTestLog.Success(string.Format("{0}: Successfully restarted Chassis Manager service", currentApi)); return(true); } catch (Exception e) { CmTestLog.Failure(string.Format("{0}: Restart Chassis Manager service has failed with an exception.", currentApi)); CmTestLog.Exception(e, testName); return(false); } }
/// <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> /// GetACSocketPowerState: Verify that all users can execute the command /// </summary> /// <returns></returns> protected bool AcSocketPowerGetByAllUserTest() { CmTestLog.Start(); bool testPassed = true; string failureMessage; ChassisResponse acSocketResponse = null; ACSocketStateResponse acSocketPower = null; uint numAcSocket = CmConstants.NumPowerSwitches; Console.WriteLine("!!!!!!!!! Started execution of ACSocketPowerTest."); foreach (WCSSecurityRole roleId in Enum.GetValues(typeof(WCSSecurityRole))) { //Change test connection to different role this.TestChannelContext = this.ListTestChannelContexts[(int)roleId]; for (int testedAcSocket = 1; testedAcSocket <= numAcSocket; testedAcSocket++) { // Turn off ACSocket Power state acSocketResponse = this.Channel.SetACSocketPowerStateOff(testedAcSocket); if (acSocketResponse.completionCode == CompletionCode.Success) { // Check to see if socket power state is return correctly acSocketPower = this.TestChannelContext.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.OFF) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } } // Turn on ACSocket Power state acSocketResponse = this.Channel.SetACSocketPowerStateOn(testedAcSocket); if (acSocketResponse.completionCode == CompletionCode.Success) { // Check to see if socket power state is return correctly acSocketPower = this.TestChannelContext.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.ON) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } } } } failureMessage = "!!!!!!!!! Successfully finished execution of ACSocketPowerTests."; Console.WriteLine(failureMessage); CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// This method returns list of empty slot for CM /// </summary> /// <returns>Returns list of empty slots if CM have any empty slots; return null otherwise.</returns> protected int[] GetEmptyLocations() { int[] emptyLocations; if (this.GetBladeLocations(blade => blade.bladeType.Equals(CmConstants.EmptyBladeType), out emptyLocations)) { return(emptyLocations); } CmTestLog.End(false, "Did NOT find empty locations"); return(null); }
/// <summary> /// This method returns list of JBOD slot for CM /// </summary> /// <returns>Returns list of JBOD if CM have any; return null otherwise.</returns> protected int[] GetJbodLocations() { int[] jbodLocations; if (this.GetBladeLocations(blade => blade.bladeType.Equals(CmConstants.JbodBladeType), out jbodLocations)) { return(jbodLocations); } CmTestLog.End(false, "Did NOT find server locations"); return(null); }
/// <summary> /// Checks if two values are NOT equal. The method logs a success if the two values are NOT equal, /// or it logs a failure. /// </summary> /// <typeparam name="T">The type of the two values to be compared.</typeparam> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> /// <param name="message">The message to be logged.</param> /// <returns>True if the two values are equal; false, otherwise.</returns> internal static bool AreNotEqual <T>(T expected, T actual, string SuccessMessage, [CallerMemberName] string testName = null) { if (!expected.Equals(actual)) { CmTestLog.Success(SuccessMessage, testName); return(true); } CmTestLog.Failure(string.Format("Verifying NOT Equalt Expected and Actual are both: {1}) ", actual), testName); return(false); }
/// <summary> /// Checks if two values are equal. The method logs a success if the two values are equal, /// or it logs a failure. /// </summary> /// <typeparam name="T">The type of the two values to be compared.</typeparam> /// <param name="expected">The expected value.</param> /// <param name="actual">The actual value.</param> /// <param name="message">The message to be logged.</param> /// <returns>True if the two values are equal; false, otherwise.</returns> internal static bool AreEqual <T>(T expected, T actual, string SuccessMessage, [CallerMemberName] string testName = null) { if (expected.Equals(actual)) { CmTestLog.Success(SuccessMessage, testName); return(true); } CmTestLog.Failure(string.Format("(Expected: {0}, Actual: {1}) ", expected, actual), testName); return(false); }
/// <summary> /// Checks if a given condition is true. The method logs a success if the condition is true, /// or it logs a failure. /// </summary> /// <param name="condition">The condition to be checked.</param> /// <param name="message">The message to be logged.</param> /// <returns>True if the condition holds; false, otherwise.</returns> internal static bool IsTrue(bool condition, string message, [CallerMemberName] string testName = null) { if (condition) { CmTestLog.Success(message, testName); return(true); } CmTestLog.Failure(string.Format(string.Format("The following Condition is false: {0} ", message)), testName); return(false); }
/// <summary> /// Test Command: ClearChassisLog /// Test case verifies: Completion code success /// Verifies Log entries count after clear chassis log and read chassislog /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool ClearChassisLog() { CmTestLog.Start(); bool testPassed = true; ChassisLogResponse cmLogsResponse; ChassisResponse cmResponse; CmTestLog.Info(" !!!!!! Started running of clearchassislogtest !!!!!! "); cmResponse = this.Channel.ClearChassisLog(); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, cmResponse.completionCode, "Received for clear chassis log"); CmTestLog.Info("Verifying log entries after clear the chassis logs"); cmLogsResponse = this.Channel.ReadChassisLog(); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, cmResponse.completionCode, "Received for read chassis log"); testPassed &= ChassisManagerTestHelper.AreEqual(CmConstants.LogCount, cmLogsResponse.logEntries.Count, "Received for log entries count"); CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Test Command: ReadBladeLogWithTimestamp. The test case verifies: /// The command returns completion code success; /// The command succeeds even after all logs are cleared. /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool ReadBladeLogWithTimestampTest() { 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 var bladeId = serverLocations.RandomOrDefault(); CmTestLog.Info(string.Format("Pick up a random server blade# {0} for test", bladeId)); bool testPassed = true; ChassisResponse response; // read logs from the blade CmTestLog.Info("Trying to read blade log with timestamp from Blade# " + bladeId); response = this.Channel.ReadBladeLogWithTimestamp(bladeId, DateTime.MinValue, DateTime.Now); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Logs read from Blade# " + bladeId); // clear the logs and read again CmTestLog.Info("Trying to clear the logs on Blade# " + bladeId); response = this.Channel.ClearBladeLog(bladeId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Logs cleared on Blade# " + bladeId); CmTestLog.Info("Trying to read logs again from Blade# " + bladeId); response = this.Channel.ReadBladeLogWithTimestamp(bladeId, DateTime.MinValue, DateTime.Now); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, response.completionCode, "Logs read from Blade# " + bladeId); // end of the test CmTestLog.End(testPassed); return(testPassed); }
protected bool GetAllBladesInfo(out GetAllBladesInfoResponse allBladesInfoResponse, [CallerMemberName] string testName = null) { // if the blade info has already been cached // just return it. if (this.allBladesInfo != null) { allBladesInfoResponse = this.allBladesInfo; return(true); } try { CmTestLog.Info("Trying to get the information for all blades", testName); if (!this.SetPowerState(PowerState.ON) || !this.SetBladeState(PowerState.ON)) { allBladesInfoResponse = null; return(false); } allBladesInfoResponse = this.Channel.GetAllBladesInfo(); if (CompletionCode.Success != allBladesInfoResponse.completionCode) { CmTestLog.Failure("Failed to get all blades info", testName); return(false); } CmTestLog.Success("Get all blades info successfully", testName); this.allBladesInfo = allBladesInfoResponse; // save it return(true); } catch (Exception e) { CmTestLog.Exception(e, testName); allBladesInfoResponse = null; return(false); } }
/// <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> /// Basic validation test to set NextBoot test /// </summary> protected Boolean SetNextBootTest() { CmTestLog.Start(); bool testPassed = true; bool isServer = false; int bladeIndex = 1; string failureMessage; EmptyLocations = GetEmptyLocations(); JbodLocations = GetJbodLocations(); CmTestLog.Info("!!!!!!!!! Starting execution of SetNextBootTest."); //Make sure blade is reacheable //Loop through servers listing and find first Blad to test while (!isServer && bladeIndex <= CmConstants.Population) { if (!JbodLocations.Contains(bladeIndex) && !EmptyLocations.Contains(bladeIndex)) { isServer = true; } else { bladeIndex++; } } if (bladeIndex > CmConstants.Population) { failureMessage = "!!!Failed to find a server blade to run the test."; CmTestLog.Failure(failureMessage); return(false); } Channel.SetPowerOn(bladeIndex); Thread.Sleep(50000); BootResponse bBootType; int index = 1; foreach (BladeBootType testedBootType in Enum.GetValues(typeof(BladeBootType))) { //Doing the same setting twice to make sure we are handling this properly. if (testedBootType.ToString() != BladeBootType.Unknown.ToString()) { //set to persistent. bBootType = Channel.SetNextBoot(bladeIndex, testedBootType, false, false, 0); if (bBootType.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to set non persistant boot type to: {0}", testedBootType); CmTestLog.Failure(failureMessage); testPassed = false; } bBootType = Channel.GetNextBoot(bladeIndex); if (testedBootType.ToString() != bBootType.nextBoot.ToString()) { failureMessage = "!!!The Non persistent boot type did not match what it was set to."; CmTestLog.Failure(failureMessage); testPassed = false; } //set to non persistent. bBootType = Channel.SetNextBoot(bladeIndex, testedBootType, false, true, 1); if (bBootType.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to set Persistent boot type to: {0}", testedBootType); CmTestLog.Failure(failureMessage); testPassed = false; } //Make sure if no restart happens it keeps its value. bBootType = Channel.GetNextBoot(bladeIndex); if (testedBootType.ToString() != bBootType.nextBoot.ToString()) { failureMessage = "!!!The boot type did not match what it was set to."; CmTestLog.Failure(failureMessage); testPassed = false; } //Make sure it loses its value after restart Channel.SetBladeActivePowerCycle(bladeIndex, 0); Thread.Sleep(60000); bBootType = Channel.GetNextBoot(bladeIndex); if (testedBootType.ToString() != BladeBootType.ForcePxe.ToString() && testedBootType.ToString() != bBootType.nextBoot.ToString()) { failureMessage = string.Format( "!!!The boot type did not match what it was set to before power cycle. {0} vs {1} this is round# {2}", testedBootType, bBootType.nextBoot, index); CmTestLog.Failure(failureMessage); testPassed = false; } } } Channel.SetNextBoot(bladeIndex, BladeBootType.NoOverride, false, true, 0); CmTestLog.Info("!!!!!!!!! Successfully finished execution of SetNextBoot tests."); // end of the test CmTestLog.End(testPassed); return(testPassed); }
/// <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 bool GetSetNextBoots(bool testPassed, int bladeIndex, string failureMessage, int index, WCSSecurityRole roleId) { // Use different user context TestChannelContext = ListTestChannelContexts[(int)roleId]; foreach (BladeBootType testedBootType in Enum.GetValues(typeof(BladeBootType))) { //Doing the same setting twice to make sure we are handling this properly. if (testedBootType.ToString() != BladeBootType.Unknown.ToString()) { //set to persistent. BootResponse bBootType = TestChannelContext.SetNextBoot(bladeIndex, testedBootType, false, false, 0); if (bBootType.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to set non persistant boot type to: {0}", testedBootType); CmTestLog.Failure(failureMessage); testPassed = false; } bBootType = TestChannelContext.GetNextBoot(bladeIndex); if (testedBootType.ToString() != bBootType.nextBoot.ToString()) { failureMessage = "!!!The Non persistent boot type did not match what it was set to."; CmTestLog.Failure(failureMessage); testPassed = false; } //set to non persistent. bBootType = TestChannelContext.SetNextBoot(bladeIndex, testedBootType, false, true, 1); if (bBootType.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to set Persistent boot type to: {0}", testedBootType); CmTestLog.Failure(failureMessage); testPassed = false; } //Make sure if no restart happens it keeps its value. bBootType = TestChannelContext.GetNextBoot(bladeIndex); if (testedBootType.ToString() != bBootType.nextBoot.ToString()) { failureMessage = "!!!The boot type did not match what it was set to."; CmTestLog.Failure(failureMessage); testPassed = false; } //Make sure it loses its value after restart Channel.SetBladeActivePowerCycle(bladeIndex, 0); Thread.Sleep(60000); bBootType = Channel.GetNextBoot(bladeIndex); if (testedBootType.ToString() != BladeBootType.ForcePxe.ToString() && testedBootType.ToString() != bBootType.nextBoot.ToString()) { failureMessage = string.Format( "!!!The boot type did not match what it was set to before power cycle. {0} vs {1} this is round# {2}", testedBootType, bBootType.nextBoot, index); CmTestLog.Failure(failureMessage); testPassed = false; } } } //reset for next test Channel.SetNextBoot(bladeIndex, BladeBootType.NoOverride, false, true, 0); return(testPassed); }
/// <summary> /// Basic validation test to set NextBoot test /// </summary> protected Boolean SetNextBootToJbodTest() { CmTestLog.Start(); bool testPassed = true; bool isJBodServer = false; int bladeIndex = 1; string failureMessage; EmptyLocations = GetEmptyLocations(); JbodLocations = GetJbodLocations(); CmTestLog.Info("!!!!!!!!! Starting execution of SetNextBootTest."); //Find first Jbod Server while (!isJBodServer && bladeIndex <= CmConstants.Population) { if (JbodLocations.Contains(bladeIndex)) { isJBodServer = true; } else { bladeIndex++; } } if (bladeIndex > CmConstants.Population) { failureMessage = "!!!Failed to find a server blade to run the test."; CmTestLog.Failure(failureMessage); return(false); } Channel.SetPowerOn(bladeIndex); Thread.Sleep(50000); BootResponse bBootType; foreach (BladeBootType testedBootType in Enum.GetValues(typeof(BladeBootType))) { //Doing the same setting twice to make sure we are handling this properly. if (testedBootType.ToString() != BladeBootType.Unknown.ToString()) { //set to persistent. bBootType = Channel.SetNextBoot(bladeIndex, testedBootType, false, false, 0); if (bBootType.completionCode == CompletionCode.Success && bBootType.completionCode != CompletionCode.CommandNotValidForBlade) { failureMessage = string.Format("Test failed, successfully set nextboot to JBOD type to: {0}", testedBootType); CmTestLog.Failure(failureMessage); testPassed = false; } bBootType = Channel.GetNextBoot(bladeIndex); if (bBootType.completionCode == CompletionCode.Success && bBootType.completionCode != CompletionCode.CommandNotValidForBlade) { failureMessage = string.Format("Test failed, successfully GET nextboot to JBOD type to: {0}", testedBootType); CmTestLog.Failure(failureMessage); testPassed = false; } } } // end of the test CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Basic validation test to set NextBoot test /// </summary> protected Boolean SetNextBootByAllUserTest() { CmTestLog.Start(); bool testPassed = true; bool isServer = false; int bladeIndex = 1; string failureMessage = string.Empty; EmptyLocations = GetEmptyLocations(); JbodLocations = GetJbodLocations(); CmTestLog.Info("!!!!!!!!! Starting execution of SetNextBootTest."); //Make sure blade is reacheable //Loop through servers listing and find first Blad to test while (!isServer && bladeIndex <= CmConstants.Population) { if (!JbodLocations.Contains(bladeIndex) && !EmptyLocations.Contains(bladeIndex)) { isServer = true; } else { bladeIndex++; } } if (bladeIndex > CmConstants.Population) { failureMessage = "!!!Failed to find a server blade to run the test."; CmTestLog.Failure(failureMessage); return(false); } Channel.SetPowerOn(bladeIndex); Thread.Sleep(50000); int index = 1; foreach (WCSSecurityRole roleId in Enum.GetValues(typeof(WCSSecurityRole))) { try { if (!GetSetNextBoots(testPassed, bladeIndex, failureMessage, index, roleId)) { failureMessage = string.Format("Failed to set Persistent boot type by user type: {0}", roleId); CmTestLog.Failure(failureMessage); testPassed = false; break; } } catch (Exception e) { // Check if we got 401 error // Check error is due to permission HTTP 401 unauthorize if (!e.Message.Contains("401")) { // Test failed, http response should contain http 401 error CmTestLog.Failure("We are expecting 401 error, but we received 400 instead."); } } } CmTestLog.Info("!!!!!!!!! Successfully finished execution of SetNextBoot tests."); // end of the test CmTestLog.End(testPassed); return(testPassed); }
/// <summary> /// Starts or stops the CM service /// </summary> /// <example> /// Example 1: start the CM service /// StartStopCmService("start"); /// Example 2: stop the CM service /// StartStopCmService("stop"); /// </example> /// <param name="startStopService"></param> /// <param name="testName"></param> /// <param name="retryStartStop"></param> /// <returns></returns> protected bool StartStopCmService(string startStopService, [CallerMemberName] string testName = null, bool retryStartStop = true) { bool startStopSuccess = true; try { string cmServiceName = "chassismanager"; startStopService = startStopService.ToLower(); if (startStopService == "start") { CmTestLog.Info(string.Format("Trying to start Chassis Manager service on {0}", this.defaultCMName)); } else if (startStopService == "stop") { CmTestLog.Info(string.Format("Trying to stop Chassis Manager service on {0}", this.defaultCMName)); } else { CmTestLog.Failure("startStopService action not defined to 'start' or 'stop' service"); return(false); } // Initialize object to specify all settings for WMI connection ConnectionOptions serviceConnectOptions = new ConnectionOptions(); serviceConnectOptions.Username = string.Format("{0}\\{1}", this.defaultCMName, this.defaultAdminUserName); serviceConnectOptions.Password = this.defaultAdminPassword; // Initialize object to represent scope of management operations ManagementScope serviceScope = new ManagementScope(string.Format("{0}{1}{2}", @"\\", this.defaultCMName, @"\root\cimv2")); serviceScope.Options = serviceConnectOptions; // Define WMI query to execute on CM SelectQuery query = new SelectQuery(string.Format("select * from Win32_service where name = '{0}'", cmServiceName)); using (ManagementObjectSearcher serviceSearcher = new ManagementObjectSearcher(serviceScope, query)) { ManagementObjectCollection serviceCollection = serviceSearcher.Get(); foreach (ManagementObject service in serviceCollection) { if (startStopService == "start") { if (service["Started"].Equals(true)) { CmTestLog.Success("Chassis Manager service already started"); startStopSuccess &= true; continue; } else if (service.GetPropertyValue("State").ToString() == "Stopped") { // Start the service CmTestLog.Info(string.Format("Trying to start Chassis Manager service ...")); service.InvokeMethod("StartService", null); CmTestLog.Info(string.Format("Chassis Manager service is starting. Sleeping for {0} seconds", CmConstants.CmServiceStartStopSeconds)); Thread.Sleep(TimeSpan.FromSeconds(CmConstants.CmServiceStartStopSeconds)); startStopSuccess &= true; continue; } else { CmTestLog.Info("Chassis Manager service not in start or stop state"); startStopSuccess &= false; } } else if (startStopService == "stop") { if (service["Started"].Equals(true)) { // Stop the service CmTestLog.Info(string.Format("Trying to stop Chassis Manager service ...")); service.InvokeMethod("StopService", null); CmTestLog.Info(string.Format("Stopping Chassis Manager service. Sleeping for {0} seconds", CmConstants.CmServiceStartStopSeconds)); Thread.Sleep(TimeSpan.FromSeconds(CmConstants.CmServiceStartStopSeconds)); startStopSuccess &= true; continue; } else if (service.GetPropertyValue("State").ToString() == "Stopped") { CmTestLog.Success("Chassis Manager service already stopped"); startStopSuccess &= true; continue; } else { CmTestLog.Info("Chassis Manager service not in start or stop state"); startStopSuccess &= false; } } else { CmTestLog.Failure("startStopService action not defined to 'start' or 'stop' service"); return(false); } } } } catch (COMException ce) { //if we fail for RPC server not being available we need to try one more time if (ce.Message.Contains("0x800706BA") && retryStartStop == true) { CmTestLog.Info("startStopCmService failed with COMException 0x800706BA. Retrying..."); startStopSuccess = StartStopCmService(startStopService, null, false); } else { throw new Exception("Unexpected COMException occurred or retry failed", ce); } } catch (Exception e) { CmTestLog.Failure("Start or Stop chassis manager service has failed with an exception."); CmTestLog.Exception(e, testName); return(false); } return(startStopSuccess); }
/// <summary> /// Configures App.Config of Chassis Manager service by taking as input key value pairs from dictionary. /// keys in dictionary are the keys in App.Config and values are the value in App.Config that /// are to be changed for each key. ConfigureAppConfig backs up the original App.Config and should be /// restored using cleanUp parameter after testing with ConfigureAppConfig is complete. /// </summary> /// <example> /// Example 1: Change Value of Key "NumFans" in CM service App.Config to "5" /// ConfigureAppConfig(new Dictionary<string, string>() {{"NumFans", "5"}}, false); /// Example 2: Restore original CM service App. Config /// ConfigureAppConfig(null, true); /// </example> /// <remarks> /// ConfigureAppConfig does not restart the CM service after configuring App.Config. Use method RestartCmService. /// </remarks> /// <param name="appConfigKeyValuePairs"></param> /// <param name="cleanUp"></param> /// <param name="testName"></param> /// <returns></returns> protected bool ConfigureAppConfig(Dictionary <string, string> appConfigKeyValuePairs, bool cleanUp, [CallerMemberName] string testName = null) { bool configurationSuccess = true; try { string configFilePath = string.Format("{0}{1}{2}", @"\\", this.defaultCMName, @"\c$\ChassisManager\Microsoft.GFS.WCS.ChassisManager.exe.config"); string backupConfigFilePath = string.Format("{0}{1}{2}", @"\\", this.defaultCMName, @"\c$\ChassisManager\Microsoft.GFS.WCS.ChassisManager.exe.config.backup"); string modifiedConfigFilePath = string.Format("{0}modifiedConfig.config", Path.Combine(Directory.GetCurrentDirectory(), "TestData")); IntPtr token = IntPtr.Zero; // Impersonate remote user in order to copy/modify files bool successLogon = LogonUser(this.defaultAdminUserName, this.defaultCMName, this.defaultAdminPassword, (int)DwLogonType.NewCredentials, (int)DwLogonProvider.WinNT50, ref token); if (successLogon) { CmTestLog.Info("LogonUser: User successfully created"); // Impersonate user using (WindowsImpersonationContext context = WindowsIdentity.Impersonate(token)) { if (!cleanUp) { // Verify input KeyValue pairs is not empty if (appConfigKeyValuePairs.Count < 1) { CmTestLog.Failure("Requested App Config Key Value Pairs is empty"); return(false); } // Delete modified file path if it already exists if (File.Exists(modifiedConfigFilePath)) { File.Delete(modifiedConfigFilePath); CmTestLog.Info("Temporary App.Config already exists. Deleting..."); } // Delete backup file path if it already exists if (File.Exists(backupConfigFilePath)) { File.Delete(backupConfigFilePath); CmTestLog.Info("Backup App.Config already exists. Deleting..."); } // Copy original App.Config to temporary path and backup original File.Copy(configFilePath, modifiedConfigFilePath); File.Move(configFilePath, backupConfigFilePath); // Initialize App.Config in config object to prep for modification ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = modifiedConfigFilePath; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); // Modify KeyValue pairs in App.Config to requested input KeyValue pairs foreach (KeyValuePair <string, string> xmlKeyValue in appConfigKeyValuePairs) { if (config.AppSettings.Settings.AllKeys.Contains(xmlKeyValue.Key)) { config.AppSettings.Settings[xmlKeyValue.Key].Value = xmlKeyValue.Value; CmTestLog.Success(string.Format(string.Format("Changed key:{0} to new value:{1} in App.Config", xmlKeyValue.Key, xmlKeyValue.Value))); configurationSuccess &= true; } else { CmTestLog.Failure(string.Format("Could not find key:{0} in App.Config", xmlKeyValue.Key)); configurationSuccess = false; } } // Save modified App.Config config.Save(); System.Configuration.ConfigurationManager.RefreshSection("appSettings"); // Copy over modified App.Config to original file path if (!File.Exists(configFilePath)) { File.Copy(modifiedConfigFilePath, configFilePath); } else { CmTestLog.Failure("App.Config cannot be renamed, and so, cannot be replaced by modified App.Config"); return(false); } File.Delete(modifiedConfigFilePath); } else { // Revert back to original App.Config using backup file during CleanUp CmTestLog.Info("configureAppConfig CleanUp: Replacing modified App.Config with original App.Config"); if (!File.Exists(backupConfigFilePath)) { CmTestLog.Failure("Backup App.Config does not exist"); return(false); } else { if (File.Exists(configFilePath)) { CmTestLog.Info("Modified App.Config file exists - deleting"); File.Delete(configFilePath); } File.Move(backupConfigFilePath, configFilePath); } CmTestLog.Success("configureAppConfig: Clean up successful"); } // Revert back to original user context.Undo(); } } else { CmTestLog.Failure("UserLogon: User failed to be created"); return(false); } } catch (Exception e) { CmTestLog.Exception(e, testName); return(false); } return(configurationSuccess); }
/// <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); }
/// <summary> /// Verifies that all BladeStateResponses in the given collection are the same as the expectedState. /// If a blade is a server, this method verifies the server has the same state as the expectedState; if a blade /// is a jbod, this method ignores the expectedState parameter and verifies the blade returns CommandNotValidForBlade. /// If there is only one response in the collection and it is from an empty slot, the method returns false; /// in other cases, empty slots in the collection will just be ignored. /// </summary> protected bool VerifyBladeState(PowerState expectedState, IEnumerable <BladeStateResponse> bladeStates, [CallerMemberName] string testName = null) { GetAllBladesInfoResponse allBlades; if (!this.GetAllBladesInfo(out allBlades, testName)) { return(false); } try { var bladeStateCollection = new List <BladeStateResponse>(bladeStates); bool serverResult = true, jbodResult = true; int bladeCount = 0, JbodCount = 0; foreach (var state in bladeStateCollection) { // current blade info var bladeInfo = allBlades.bladeInfoResponseCollection.Single(info => info.bladeNumber == state.bladeNumber); if (bladeInfo.bladeType.ToLower().Equals("server")) { bladeCount++; } if (bladeInfo.bladeType.ToLower().Equals("jbod")) { JbodCount++; } // verify server blade if (bladeInfo.bladeType.Equals(CmConstants.ServerBladeType) && state.bladeState != expectedState) { serverResult = false; CmTestLog.Failure(string.Format("Server Blade# {0} state is not as expected (Expected: {1}, Actual: {2})", state.bladeNumber, expectedState, state.bladeState), testName); } // verify jbod blade else if (bladeInfo.bladeType.Equals(CmConstants.JbodBladeType) && state.completionCode != CompletionCode.CommandNotValidForBlade) { jbodResult = false; CmTestLog.Failure(string.Format("JBOD Blade# {0} completion code is not correct (Expected: {1}, Actual: {2})", state.bladeNumber, CompletionCode.CommandNotValidForBlade, state.completionCode), testName); } } if (bladeCount > 0 && serverResult) { CmTestLog.Success(string.Format("Verified server blades are {0}", expectedState), testName); } else { CmTestLog.Warning("There were no blades to run test against", testName); } if (JbodCount > 0 && jbodResult) { CmTestLog.Success("Verified JBODs return CommandNotValidForBlade", testName); } else { CmTestLog.Warning("There were no JBODs to run test against", testName); } return(serverResult && jbodResult); } catch (Exception e) { CmTestLog.Exception(e, testName); return(false); } }
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 Command: ReadBladeLog, ClearBladeLog. The test case verifies: /// The command returns completion code success on server blades; /// ReadBladeLog succeeds even after all logs are cleared. /// </summary> /// <returns>True if all check-points pass; false, otherwise.</returns> public bool ReadClearBladeLogTest() { CmTestLog.Start(); ChassisLogResponse readLogResponse; BladeResponse clearLogResponse; bool testPassed = true; int[] serverLocations, jbodLocations; if (!this.GetBladeLocations(blade => blade.bladeType.Equals(CmConstants.ServerBladeType), out serverLocations) || !this.GetBladeLocations(blade => blade.bladeType.Equals(CmConstants.JbodBladeType), out jbodLocations)) { CmTestLog.Failure("Cannot find a server/ Jbod blade to execute automation against"); CmTestLog.End(false); return(false); } if (serverLocations == null || serverLocations.Length == 0) { CmTestLog.Warning("There are no server blades to execute the test against."); } else { int bladeId = serverLocations.RandomOrDefault(); CmTestLog.Success("Found server blade at location: " + bladeId); CmTestLog.Info("Power on Blade# " + bladeId); var powerOnResponse = this.Channel.SetPowerOn(bladeId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, powerOnResponse.completionCode, string.Format("Blade# {0} is powered on", bladeId)); CmTestLog.Info("Read logs from Blade# " + bladeId); readLogResponse = this.Channel.ReadBladeLog(bladeId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, readLogResponse.completionCode, "Received Read logs from Blade# " + bladeId); CmTestLog.Info("Clear logs on Blade# " + bladeId + " and read again"); clearLogResponse = this.Channel.ClearBladeLog(bladeId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, clearLogResponse.completionCode, "Logs on Blade# " + bladeId + " is cleared"); readLogResponse = this.Channel.ReadBladeLog(bladeId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, readLogResponse.completionCode, "Read logs from Blade# " + bladeId); } // [TFS WorkItem: 2730] ReadBladeLog: Verify command is not valid to run on JBOD blade if (jbodLocations == null || jbodLocations.Length == 0) { CmTestLog.Warning("There are no JBODs to execute the test against."); } else { int JbodId = jbodLocations.RandomOrDefault(); CmTestLog.Success("Found JBOD blade at location " + JbodId); CmTestLog.Info("Power on Blade# " + JbodId); var powerOnResponse = this.Channel.SetPowerOn(JbodId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, powerOnResponse.completionCode, string.Format("JBOD at location# {0} is powered on", JbodId)); CmTestLog.Info("Trying to read logs for JBOD"); readLogResponse = this.Channel.ReadBladeLog(JbodId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.CommandNotValidForBlade, readLogResponse.completionCode, "Received CommandNotValidForBlade to Read logs for JBOD# " + JbodId); // [TFS WorkItem: 2731] ClearBladeLog: Verify command is not valid to run on JBOD blade CmTestLog.Info("Trying to clear logs for JBOD"); clearLogResponse = this.Channel.ClearBladeLog(JbodId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.CommandNotValidForBlade, clearLogResponse.completionCode, "Received CommandNotValidForBlade to clear logs for JBOD# " + JbodId); } this.EmptyLocations = this.GetEmptyLocations(); if (EmptyLocations == null || EmptyLocations.Length == 0) { CmTestLog.Warning("There are no Empty slots to execute the test against."); } else { int slotId = EmptyLocations.RandomOrDefault(); CmTestLog.Success("Found empty slot at location " + slotId); CmTestLog.Info("Trying to read logs for Empty location"); readLogResponse = this.Channel.ReadBladeLog(slotId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Timeout, readLogResponse.completionCode, "Received Timeout to Read logs for emoty slot# " + slotId); // [TFS WorkItem: 2731] ClearBladeLog: Verify command is not valid to run on JBOD blade CmTestLog.Info("Trying to clear logs for empty slot"); clearLogResponse = this.Channel.ClearBladeLog(slotId); testPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Timeout, clearLogResponse.completionCode, "Received Timeout to clear logs for empty slot# " + slotId); } CmTestLog.End(testPassed); return(true); }
/// <summary> /// SetACSocketPowerStateOff: Verify that only Operator and Admin can execute the command /// </summary> /// <param name="testPassed"></param> /// <param name="failureMessage"></param> /// <param name="numAcSocket"></param> /// <param name="roleId"></param> private void AcSocketSetGetValidation(ref bool testPassed, ref string failureMessage, uint numAcSocket, WCSSecurityRole roleId) { ChassisResponse acSocketResponse = null; ACSocketStateResponse acSocketPower = null; // Use different user context this.TestChannelContext = this.ListTestChannelContexts[(int)roleId]; for (int testedAcSocket = 1; testedAcSocket <= numAcSocket; testedAcSocket++) { // Turn On ACSocket acSocketResponse = this.TestChannelContext.SetACSocketPowerStateOn(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success && (roleId == WCSSecurityRole.WcsCmAdmin || roleId == WCSSecurityRole.WcsCmOperator)) { failureMessage = string.Format("!!!Failed to power ON AC socket when it is already ON for AC Socket# {0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } else if (acSocketResponse.completionCode == CompletionCode.Success && (roleId == WCSSecurityRole.WcsCmUser)) { failureMessage = string.Format("User is not allow to called out to SetACSocketPowerStateOn {0} Socket# {1}", roleId, testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } else { // Verify power state acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.ON) { failureMessage = string.Format( "!!!Failed to power ON AC socket when it is already ON for AC Socket# {0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } } // Turn off ACSocket acSocketResponse = this.TestChannelContext.SetACSocketPowerStateOff(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success && (roleId == WCSSecurityRole.WcsCmAdmin || roleId == WCSSecurityRole.WcsCmOperator)) { failureMessage = string.Format("!!!Failed to power ON AC socket when it is already ON for AC Socket# {0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } else if (acSocketResponse.completionCode == CompletionCode.Success && roleId == WCSSecurityRole.WcsCmUser) { failureMessage = string.Format( "User is not allow to called out to SetACSocketPowerStateOff {0} Socket# {1}", roleId, testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } else { // Verify power state acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.OFF) { failureMessage = string.Format( "!!!Failed to power ON AC socket when it is already ON for AC Socket# {0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } } }// end of for loop }
/// <summary> /// Basic functional validation test for AC SocketPower /// </summary> /// <returns></returns> protected bool AcSocketPowerTest() { CmTestLog.Start(); bool testPassed = true; string failureMessage; ChassisResponse acSocketResponse = null; ACSocketStateResponse acSocketPower = null; uint NumACSocket = CmConstants.NumPowerSwitches; Console.WriteLine("!!!!!!!!! Started execution of ACSocketPowerTest."); for (int testedAcSocket = 1; testedAcSocket <= NumACSocket; testedAcSocket++) { acSocketResponse = this.Channel.SetACSocketPowerStateOff(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to power off from unknown state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.OFF) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketResponse = this.Channel.SetACSocketPowerStateOff(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to power off AC socket when it is already off for socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.OFF) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketResponse = this.Channel.SetACSocketPowerStateOn(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to power ON AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.ON) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketResponse = this.Channel.SetACSocketPowerStateOn(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to power ON AC socket when it is already ON for AC Socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketResponse = this.Channel.SetACSocketPowerStateOff(testedAcSocket); if (acSocketResponse.completionCode != CompletionCode.Success) { failureMessage = string.Format("!!!Failed to power off AC socket from ON state for AC Socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.OFF) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketPower = this.Channel.GetACSocketPowerState(testedAcSocket); if (acSocketPower.powerState != PowerState.OFF) { failureMessage = string.Format("!!!Failed to get power state for AC socket#{0}", testedAcSocket); CmTestLog.Failure(failureMessage); testPassed = false; } } //Test for invalid parameters acSocketResponse = this.Channel.SetACSocketPowerStateOn(0); if (acSocketResponse.completionCode != CompletionCode.ParameterOutOfRange) { failureMessage = string.Format("!!!Failed During SetACSocketPowerStateOn(0), response is: {0}", acSocketResponse.completionCode); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketResponse = this.Channel.SetACSocketPowerStateOn(9999); if (acSocketResponse.completionCode != CompletionCode.ParameterOutOfRange) { failureMessage = string.Format("!!!Failed During SetACSocketPowerStateOn(0), response is: {0}", acSocketResponse.completionCode); CmTestLog.Failure(failureMessage); testPassed = false; } acSocketResponse = this.Channel.SetACSocketPowerStateOn(4); if (acSocketResponse.completionCode != CompletionCode.ParameterOutOfRange) { failureMessage = string.Format("!!!Failed During SetACSocketPowerStateOn(0), response is: {0}", acSocketResponse.completionCode); CmTestLog.Failure(failureMessage); testPassed = false; } Console.WriteLine("\n++++++++++++++++++++++++++++++++"); failureMessage = "!!!!!!!!! Successfully finished execution of ACSocketPowerTests."; Console.WriteLine(failureMessage); CmTestLog.End(testPassed); return(testPassed); }