/// <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); } }
/// <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); }