/// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            BladeResponse myResponse = new BladeResponse();
            AllBladesResponse myResponses = new AllBladesResponse();

            dynamic bladeId = null;
            dynamic action = null;

            try
            {
                if (!this.argVal.TryGetValue('d', out action))
                {
                    action = 0; // default NoAction
                }

                if (this.argVal.ContainsKey('a'))
                {
                    myResponses = WcsCli2CmConnectionManager.channel.SetAllBladesPsuAlert(
                        this.argVal.ContainsKey('c'), (int)action, this.argVal.ContainsKey('r'));
                }
                else if (this.argVal.ContainsKey('i'))
                {
                    if (this.argVal.TryGetValue('i', out bladeId))
                    {
                        myResponse = WcsCli2CmConnectionManager.channel.SetBladePsuAlert((int)bladeId,
                            this.argVal.ContainsKey('c'), (int)action, this.argVal.ContainsKey('r'));
                    }
                    else
                    {
                        Console.WriteLine(WcsCliConstants.commandFailure +
                            " No blade ID specified, please look at command help.");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if ((this.argVal.ContainsKey('a') && myResponses == null) || (this.argVal.ContainsKey('a') &&
                myResponses.bladeResponseCollection == null) || myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (this.argVal.ContainsKey('a'))
            {
                for (int index = 0; index < myResponses.bladeResponseCollection.Count(); index++)
                {
                    ResponseValidation.ValidateBladeResponse(myResponses.bladeResponseCollection[index].bladeNumber, "activate/deactivate PSU alert done", myResponses.bladeResponseCollection[index]);
                }
            }
            else
            {
                ResponseValidation.ValidateBladeResponse(myResponse.bladeNumber, "activate/deactivate PSU alert done", myResponse);
            }
        }
        internal override void commandImplementation()
        {
            uint sledId = 1;
            BladeResponse myResponse = new BladeResponse();
            AllBladesResponse myResponses = new AllBladesResponse();
            try
            {
                if (this.argVal.ContainsKey('a'))
                {
                    myResponses = WcsCli2CmConnectionManager.channel.SetAllBladesPowerLimitOn();
                }
                else if (this.argVal.ContainsKey('i'))
                {
                    dynamic mySledId = null;
                    this.argVal.TryGetValue('i', out mySledId);
                    sledId = (uint)mySledId;
                    myResponse = WcsCli2CmConnectionManager.channel.SetBladePowerLimitOn((int)mySledId);
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if ((this.argVal.ContainsKey('a') && myResponses == null) || myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (this.argVal.ContainsKey('a'))
            {
                for (int index = 0; index < myResponses.bladeResponseCollection.Count(); index++)
                {
                    if (ResponseValidation.ValidateBladeResponse(myResponses.bladeResponseCollection[index].bladeNumber, null, myResponses.bladeResponseCollection[index], false))
                    {
                        Console.WriteLine(WcsCliConstants.commandSuccess + "Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ": Power Limit Activated");
                    }
                }
            }
            else
            {
                if (ResponseValidation.ValidateBladeResponse(myResponse.bladeNumber, null, myResponse, false))
                {
                   Console.WriteLine(WcsCliConstants.commandSuccess + "Blade " + myResponse.bladeNumber + ": Power Limit Activated");
                }
            }
        }
        /// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            BladeResponse myResponse = new BladeResponse();

            try
            {
                dynamic mySledId = null;
                this.argVal.TryGetValue('i', out mySledId);
                myResponse = WcsCli2CmConnectionManager.channel.ClearBladeLog((int)mySledId);
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            ResponseValidation.ValidateBladeResponse(myResponse.bladeNumber, null, myResponse, true);
        }
        /// <summary>
        /// Set power limit ON for specified blade
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <returns>Blade response indicating blade operation was success/failure</returns>
        public BladeResponse SetBladePowerLimitOn(int bladeId)
        {
            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;

            Tracer.WriteUserLog("Invoked SetBladePowerLimitOn(bladeId: {0})", bladeId);

            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladePowerLimitOn", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            if (!WcsBladeFacade.ActivatePowerLimit((byte)(bladeId), true))
            {
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
                return response;
            }
            Tracer.WriteInfo("ActivatePowerLimit({0}): Activated", bladeId);
            response.completionCode = Contracts.CompletionCode.Success;

            return response;
        }
        /// <summary>
        /// Set Soft Blade power ON
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <returns>Blade response indicating blade operation was success/failure</returns>
        public BladeResponse SetBladeOn(int bladeId)
        {
            Tracer.WriteInfo("Received SetBladeOn(bladeId: {0})", bladeId);
            Tracer.WriteUserLog("Invoked SetBladeOn(bladeId: {0})", bladeId);

            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladeOn", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            if (BladePowerCommands.BladeOn(bladeId))
            {
                Tracer.WriteInfo("SetBladeOn({0}): Blade soft power set to ON", bladeId);
                response.completionCode = Contracts.CompletionCode.Success;
            }
            else
            {
                Tracer.WriteError("SetBladeOn({0}): Failed to set Blade soft power ON", bladeId);
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
            }

            return response;
        }
        /// <summary>
        /// Sets the default blade board power state ON
        /// Indicates whether the system should be powered on or kept shutdown after power comes back to the system
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <returns>Blade Response success/failure.</returns>
        public BladeResponse SetBladeDefaultPowerStateOn(int bladeId)
        {
            Tracer.WriteInfo("Received SetBladeDefaultPowerStateOn({0})", bladeId);

            Tracer.WriteUserLog("Invoked SetBladeDefaultPowerStateOn({0})", bladeId);

            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladeDefaultPowerStateOn", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            Ipmi.PowerRestoreOption powerState = Ipmi.PowerRestoreOption.AlwaysPowerUp;

            Tracer.WriteInfo("SetBladeDefaultPowerStateOn for Blade: ", bladeId);

            Ipmi.PowerRestorePolicy powerPolicy = WcsBladeFacade.SetPowerRestorePolicy((byte)bladeId, powerState);

            if (powerPolicy.CompletionCode != (byte)CompletionCode.Success)
            {
                Tracer.WriteError("SetBladeDefaultPowerStateOn failed with completion code: {0:X}", powerPolicy.CompletionCode);
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
            }
            else
            {
                response.completionCode = Contracts.CompletionCode.Success;
                Tracer.WriteInfo("SetBladeDefaultPowerStateOn succeeded for Blade: ", bladeId);
            }
            return response;
        }
        /// <summary>
        /// Power cycle specified blade
        /// </summary>
        /// <param name="bladeId">if bladeId id -1, then bladeId not provided</param>
        /// <param name="offTime">time for which the blades will be powered off in seconds</param>
        /// <returns>Blade response indicating if blade operation was success/failure</returns>
        public BladeResponse SetBladeActivePowerCycle(int bladeId, uint offTime)
        {
            Tracer.WriteUserLog("Invoked SetBladeActivePowerCycle(bladeId: {0}, offTime: {1})", bladeId, offTime);

            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladeActivePowerCycle", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            // Check that the power off time is valid for a byte value since the IPMI command takes a byte value
            if (offTime > Byte.MaxValue)
            {
                Tracer.WriteWarning("SetBladeActivePowerCycle failed, Invalid power off time: {0}", offTime);

                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = Contracts.CompletionCode.ParameterOutOfRange.ToString();
                return response;
            }

            if (BladePowerCommands.PowerCycle(bladeId, offTime))
            {
                response.completionCode = Contracts.CompletionCode.Success;
            }
            else
            {
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
            }

            return response;
        }
 private bool VerifySetBladePower(ref bool testPassed, WCSSecurityRole roleId, BladeResponse bladeRes)
 {
     if (bladeRes.completionCode != CompletionCode.Success && (roleId == WCSSecurityRole.WcsCmAdmin))
     {
         CmTestLog.Failure(string.Format("Cannot Set blade Power using WcsAdmin User {0}", roleId));
         CmTestLog.End(false);
         return false;
     }
     else if (bladeRes.completionCode == CompletionCode.Success && (roleId == WCSSecurityRole.WcsCmUser || roleId == WCSSecurityRole.WcsCmOperator))
     {
         CmTestLog.Failure(string.Format("User/Operator is able to set blade power {0}", roleId));
         CmTestLog.End(false);
         return false;
     }
     else
     {
         testPassed &= ChassisManagerTestHelper.AreEqual(bladeRes.completionCode, CompletionCode.Success, string.Format("Received success with user {0}", Enum.GetName(typeof(WCSSecurityRole), roleId)));
     }
     return testPassed;
 }
        internal override void commandImplementation()
        {
            uint sledId = 1;
            BladeResponse myResponse = new BladeResponse();
            AllBladesResponse myResponses = new AllBladesResponse();
            try
            {
                if (this.argVal.ContainsKey('a'))
                {
                    myResponses = WcsCli2CmConnectionManager.channel.SetAllBladesPowerLimitOff();
                }
                else if (this.argVal.ContainsKey('i'))
                {
                    dynamic mySledId = null;
                    this.argVal.TryGetValue('i', out mySledId);
                    sledId = (uint)mySledId;
                    myResponse = WcsCli2CmConnectionManager.channel.SetBladePowerLimitOff((int)mySledId);
                }
            }          
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if ((this.argVal.ContainsKey('a') && myResponses == null) || myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (this.argVal.ContainsKey('a'))
            {
                for (int index = 0; index < myResponses.bladeResponseCollection.Count(); index++)
                {
                    if (myResponses.bladeResponseCollection[index].completionCode == Contracts.CompletionCode.Success)
                    {
                        Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ": Power Limit Deactive");
                    }
                    else if (myResponse.completionCode == Contracts.CompletionCode.Unknown)
                    {
                        Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ": " + WcsCliConstants.bladeStateUnknown);
                    }
                    else
                    {
                        // Display error if other than success/unknown
                        Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + " failed with completion code: " + myResponses.bladeResponseCollection[index].completionCode.ToString());
                    }
                }
            }
            else
            {
                if (myResponse.completionCode == Contracts.CompletionCode.Success)
                {
                    Console.WriteLine("Blade " + myResponse.bladeNumber + ": Power Limit Deactive");
                }
                else if (myResponse.completionCode == Contracts.CompletionCode.Unknown)
                {
                    Console.WriteLine("Blade " + myResponse.bladeNumber + ": " + WcsCliConstants.bladeStateUnknown);
                }
                else
                {
                    // Display error if other than success/unknown
                    Console.WriteLine("Blade " + myResponse.bladeNumber + ": " + myResponse.completionCode.ToString());
                }
            }
        }
        private TestResponse InvalidRequestForInvalidPassThroughSetBladeMezzPassThroughMode(int bladeId)
        {
            TestCase testCase = new TestCase("InvalidRequestForInvalidPassThroughSetBladeMezzPassThroughMode", 24197);

            CmTestLog.Info(string.Format(
                "\n !!!!!!Verifying {0} Returns Status Description InvalidRequest for Invalid PassThroughModeEnabled. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeMezzResponse = new BladeResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            Dictionary<string, string> InvalidPassThroughModeEnabled = new Dictionary<string, string>();

            InvalidPassThroughModeEnabled.Add("min64", "-9223372036854775808");
            InvalidPassThroughModeEnabled.Add("max64", "9223372036854775807");
            InvalidPassThroughModeEnabled.Add("invalidString", "abc123_!&");
            InvalidPassThroughModeEnabled.Add("emptyString", string.Empty);
            InvalidPassThroughModeEnabled.Add("invalidTrue1", "ttrue");
            InvalidPassThroughModeEnabled.Add("invalidTrue2", "frue");
            InvalidPassThroughModeEnabled.Add("invalidFalse1", "ffalse");
            InvalidPassThroughModeEnabled.Add("invalidFalse2", "fazse");
            InvalidPassThroughModeEnabled.Add("nullString", null);

            // test SetBladeMezzPassThroughMode passThroughModeEnabled parameter for each invalid value
            foreach (string invalidValue in InvalidPassThroughModeEnabled.Values)
            {
                setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(bladeId, invalidValue);
                LogMessage.Message = string.Format(
                        "{0}: Command returns completion code {1} and status description {2} for invalid passThroughModeEnabled {3} for bladeId {4}",
                        currentApi, setBladeMezzResponse.completionCode, setBladeMezzResponse.statusDescription, invalidValue, bladeId);

                if (setBladeMezzResponse.completionCode == CompletionCode.Failure &&
                    setBladeMezzResponse.statusDescription == "Invalid Request")
                    LogMessage.Log(LogMessage.MessageType.Success, ref response);
                else
                    LogMessage.Log(LogMessage.MessageType.Failure, ref response);
            }

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }
        private TestResponse FruContentMatchesAfterHardCycleForGetBladeMezzAssetInfo(int bladeId)
        {
            TestCase testCase = new TestCase("FruContentMatchesAfterHardCycleForGetBladeMezzAssetInfo", 27449);

            CmTestLog.Info(string.Format("\n !!!!!!Verifying {0} Returns Correct Fru Information After Hard-Power Cycle. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeMessAssetInfoResponse previousGetMezzAssetResponse = new BladeMessAssetInfoResponse();
            BladeMessAssetInfoResponse currentGetMezzAssetResponse = new BladeMessAssetInfoResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            previousGetMezzAssetResponse = this.TestChannelContext.GetBladeMezzAssetInfo(bladeId);

            // Hard-Power Off Blade
            BladeResponse setPowerResponse = new BladeResponse();
            setPowerResponse = this.TestChannelContext.SetPowerOff(bladeId);
            LogMessage.Message = string.Format("{0}: Hard-Powered Off Blade {1}",
                this.currentApi, bladeId);
            if (setPowerResponse.completionCode != CompletionCode.Success)
            {
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                return response;
            }
            else
                LogMessage.Log(LogMessage.MessageType.Success, ref  response);

            // Thread Sleep
            LogMessage.Message = string.Format("Blade Powered Off. Thread sleeping for {0} seconds...",
                CmConstants.BladePowerOffSeconds);
            LogMessage.Log(LogMessage.MessageType.Info, ref response);
            Thread.Sleep(TimeSpan.FromSeconds(CmConstants.BladePowerOffSeconds));

            // Hard-Power On Blade
            setPowerResponse = this.TestChannelContext.SetPowerOn(bladeId);
            LogMessage.Message = string.Format("{0}: Hard-Powered On Blade {1}",
                this.currentApi, bladeId);
            if (setPowerResponse.completionCode != CompletionCode.Success)
            {
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                return response;
            }
            else
                LogMessage.Log(LogMessage.MessageType.Success, ref  response);

            // Thread Sleep
            LogMessage.Message = string.Format("Blade Powered On. Thread sleeping for {0} seconds...",
                CmConstants.BladePowerOnSeconds);
            LogMessage.Log(LogMessage.MessageType.Info, ref response);
            Thread.Sleep(TimeSpan.FromSeconds(CmConstants.BladePowerOnSeconds));

            // Get Fru Content after Hard-Power cycle
            currentGetMezzAssetResponse = this.TestChannelContext.GetBladeMezzAssetInfo(bladeId);
            LogMessage.Message = string.Format(
                "{0}: Command returns completionCode {1} for blade {2}",
                this.currentApi, currentGetMezzAssetResponse.completionCode, bladeId);
            if (currentGetMezzAssetResponse.completionCode != CompletionCode.Success)
            {
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                return response;
            }
            else
                LogMessage.Log(LogMessage.MessageType.Success, ref response);

            // Verify Fru Contents are same as before
            VerifyFruStringsMatch(previousGetMezzAssetResponse.bladeNumber.ToString(),
                currentGetMezzAssetResponse.bladeNumber.ToString(), ref response);
            VerifyFruStringsMatch(previousGetMezzAssetResponse.productAreaManufactureName,
                currentGetMezzAssetResponse.productAreaManufactureName, ref response);
            VerifyFruStringsMatch(previousGetMezzAssetResponse.productAreaProductName,
                currentGetMezzAssetResponse.productAreaProductName, ref response);
            VerifyFruStringsMatch(previousGetMezzAssetResponse.productAreaPartModelNumber,
                currentGetMezzAssetResponse.productAreaPartModelNumber, ref response);
            VerifyFruStringsMatch(previousGetMezzAssetResponse.productAreaProductVersion,
                currentGetMezzAssetResponse.productAreaProductVersion, ref response);
            VerifyFruStringsMatch(previousGetMezzAssetResponse.productAreaSerialNumber,
                currentGetMezzAssetResponse.productAreaSerialNumber, ref response);
            VerifyFruStringsMatch(previousGetMezzAssetResponse.productAreaAssetTag,
                currentGetMezzAssetResponse.productAreaAssetTag, ref response);

            testCase.LogPassOrFail(ref response, this.currentApi);
            return response;
        }
        /// <summary>
        /// Set blade power limit to given value for the specified blade
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <param name="powerLimitInWatts">Power limit to set</param>
        /// <returns>Blade response indicating blade operation was success/failure</returns>
        public BladeResponse SetBladePowerLimit(int bladeId, double powerLimitInWatts)
        {
            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladePowerLimit", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            if (ChassisManagerUtil.CheckBladePowerLimit(powerLimitInWatts))
            {
                Tracer.WriteUserLog("Invoked SetBladePowerLimit( bladeId: {0}, powerLimitInWatts: {1})", bladeId, powerLimitInWatts);

                // TODO: Remove hard-coded correction-time, action and sampling period and move it to config
                // TODO: Change this to get correction-time and sampling period from getpowerlimit
                // Note: Action is set to 0 (do nothing). Setting action to 1 will cause blade shutdown upon power limit violation
                // Note: 6 sec correction time and 1 sec sampling period is the minimum time period that works
                Ipmi.ActivePowerLimit myActiveLimit = WcsBladeFacade.SetPowerLimit((byte)(bladeId), (short)powerLimitInWatts, 6000, 0, 1);
                Tracer.WriteInfo("SetPowerLimit({0}): Set {1} CC {2}", bladeId, myActiveLimit.LimitSet, myActiveLimit.CompletionCode);

                if (myActiveLimit.CompletionCode == (byte)CompletionCode.Success)
                {
                    response.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                    response.completionCode = Contracts.CompletionCode.Failure;
                    response.statusDescription = response.completionCode.ToString();
                }
            }
            else
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = response.completionCode.ToString();
            }

            return response;
        }
        /// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            dynamic bladeId = null;
            dynamic defaultPowerCap = null;
            dynamic waitTime = null;

            BladeResponse myResponse = new BladeResponse();
            AllBladesResponse myResponses = new AllBladesResponse();
            try
            {
                if (this.argVal.ContainsKey('a') && this.argVal.TryGetValue('c', out defaultPowerCap) &&
                    this.argVal.TryGetValue('t', out waitTime))
                {
                    myResponses = WcsCli2CmConnectionManager.channel.SetAllBladesPsuAlertDefaultPowerCap(
                        (ushort)defaultPowerCap, (ushort)waitTime);
                }
                else if (this.argVal.TryGetValue('i', out bladeId) && this.argVal.TryGetValue('c', out defaultPowerCap) &&
                    this.argVal.TryGetValue('t', out waitTime))
                {
                    myResponse = WcsCli2CmConnectionManager.channel.SetBladePsuAlertDefaultPowerCap((int)bladeId,
                        (ushort)defaultPowerCap, (ushort)waitTime);
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if ((this.argVal.ContainsKey('a') && myResponses == null) || (this.argVal.ContainsKey('a') &&
                myResponses.bladeResponseCollection == null) || myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (this.argVal.ContainsKey('a'))
            {
                foreach (var response in myResponses.bladeResponseCollection)
                {
                    ResponseValidation.ValidateBladeResponse(response.bladeNumber, "psu alert default power cap set", response, true);
                }
            }
            else
            {
                ResponseValidation.ValidateBladeResponse(myResponse.bladeNumber, "psu alert default power cap set", myResponse, true);
            }
        }
        /// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            BladeResponse myResponse = new BladeResponse();

            try
            {
                dynamic bladeId = null;
                dynamic modeEnabled = null;

                if (!(this.argVal.ContainsKey('i')))
                {
                    Console.WriteLine(WcsCliConstants.commandFailure +
                        " No blade ID specified, please look at command help");
                    Console.WriteLine(WcsCliConstants.setBladeMezzPassThroughModeHelp);
                    return;
                }
                else
                {
                    this.argVal.TryGetValue('i', out bladeId);
                }

                if (!(this.argVal.ContainsKey('m')))
                {
                    Console.WriteLine(WcsCliConstants.commandFailure +
                        " No pass through mode enabled specified, please look at command help");
                    Console.WriteLine(WcsCliConstants.setBladeMezzPassThroughModeHelp);
                    return;
                }
                else
                {
                    this.argVal.TryGetValue('m', out modeEnabled);
                }

                myResponse = WcsCli2CmConnectionManager.channel.SetBladeMezzPassThroughMode(
                    (int)bladeId, (string)modeEnabled);
            }

            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            ResponseValidation.ValidateResponse("Pass Through Mode on Blade Tray Mezz has been successfully set", myResponse, true);
        }
        /// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            uint sledId = 1;
            BladeResponse myResponse = new BladeResponse();
            AllBladesResponse allBladesResponse = new AllBladesResponse();
            dynamic myOffTime = null;

            if (this.argVal.ContainsKey('t'))
            {
                this.argVal.TryGetValue('t', out myOffTime);
            }
            else
            {
                myOffTime = WcsCliConstants.powercycleOfftime;
            }

            try
            {
                if (this.argVal.ContainsKey('a'))
                {
                    allBladesResponse = WcsCli2CmConnectionManager.channel.SetAllBladesActivePowerCycle((uint)myOffTime);
                }
                else if (this.argVal.ContainsKey('i'))
                {
                    dynamic mySledId = null;
                    this.argVal.TryGetValue('i', out mySledId);
                    sledId = (uint)mySledId;
                    myResponse = WcsCli2CmConnectionManager.channel.SetBladeActivePowerCycle((int)mySledId, (uint)myOffTime);
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if ((this.argVal.ContainsKey('a') && allBladesResponse == null) || myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (this.argVal.ContainsKey('a'))
            {
                if (allBladesResponse.completionCode == Contracts.CompletionCode.Success)
                {
                    for (int index = 0; index < allBladesResponse.bladeResponseCollection.Count(); index++)
                    {
                        if (ResponseValidation.ValidateBladeResponse(allBladesResponse.bladeResponseCollection[index].bladeNumber, null, allBladesResponse.bladeResponseCollection[index], false))
                        {
                            Console.WriteLine(WcsCliConstants.commandSuccess + " Blade " + allBladesResponse.bladeResponseCollection[index].bladeNumber + ": OK");
                        }
                    }
                }
                else
                {
                    // Display error if not Success/Unknown
                    Console.WriteLine(WcsCliConstants.commandFailure + " Completion code: " + allBladesResponse.completionCode.ToString());
                }
            }
            else
            {
                ResponseValidation.ValidateBladeResponse(myResponse.bladeNumber, null, myResponse, true);
            }
        }
Beispiel #16
0
        /// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            BladeResponse myResponse = new BladeResponse();
            AllBladesResponse myResponses = new AllBladesResponse();
            dynamic myState = null;
            dynamic mySledId = null;
            this.argVal.TryGetValue('s', out myState);

            try
            {
                if (this.argVal.ContainsKey('a'))
                {
                    if ((uint)myState == 0)
                    {
                        myResponses = WcsCli2CmConnectionManager.channel.SetAllBladesDefaultPowerStateOff();
                    }
                    else if ((uint)myState == 1)
                    {
                        myResponses = WcsCli2CmConnectionManager.channel.SetAllBladesDefaultPowerStateOn();
                    }
                    else
                    {
                        Console.WriteLine("Invalid power state.");
                        return;
                    }
                }
                else if (this.argVal.ContainsKey('i'))
                {
                    this.argVal.TryGetValue('i', out mySledId);
                    if ((uint)myState == 0)
                    {
                        myResponse = WcsCli2CmConnectionManager.channel.SetBladeDefaultPowerStateOff((int)mySledId);
                    }
                    else if ((uint)myState == 1)
                    {
                        myResponse = WcsCli2CmConnectionManager.channel.SetBladeDefaultPowerStateOn((int)mySledId);
                    }
                    else
                    {
                        Console.WriteLine("Invalid power state.");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if ((this.argVal.ContainsKey('a') && myResponses == null) || myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (this.argVal.ContainsKey('a'))
            {
                for (int index = 0; index < myResponses.bladeResponseCollection.Count(); index++)
                {
                    if (myResponses.bladeResponseCollection[index].completionCode == Contracts.CompletionCode.Success)
                    {
                        if ((uint)myState == 0)
                        {
                            Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ":OFF");
                        }
                        else if ((uint)myState == 1)
                        {
                            Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ":ON");
                        }
                    }
                    else if (myResponses.bladeResponseCollection[index].completionCode == Contracts.CompletionCode.Unknown)
                    {
                        Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ": " + WcsCliConstants.bladeStateUnknown);
                    }
                    else
                    {
                        Console.WriteLine("Blade " + myResponses.bladeResponseCollection[index].bladeNumber + ": " + myResponses.bladeResponseCollection[index].completionCode.ToString());
                    }
                }
            }
            else
            {
                if (myResponse.completionCode == Contracts.CompletionCode.Success)
                {
                    if ((uint)myState == 0)
                    {
                        Console.WriteLine("Blade " + myResponse.bladeNumber + ":OFF");
                    }
                    else if ((uint)myState == 1)
                    {
                        Console.WriteLine("Blade " + myResponse.bladeNumber + ":ON");
                    }
                }
                else if (myResponse.completionCode == Contracts.CompletionCode.Unknown)
                {
                    Console.WriteLine("Blade " + myResponse.bladeNumber + ": " + WcsCliConstants.bladeStateUnknown);
                }
                else
                {
                    Console.WriteLine("Blade " + myResponse.bladeNumber + ": " + myResponse.completionCode.ToString());
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// command specific implementation 
        /// argVal command class member has all user-entered command argument indicators and parameter values
        /// Currently just prints all argument indicators and argument values
        /// </summary>
        internal override void commandImplementation()
        {
            BladeResponse myResponse = new BladeResponse();

            try
            {
                dynamic mySledId = null;
                this.argVal.TryGetValue('i', out mySledId);
                myResponse = WcsCli2CmConnectionManager.channel.ClearBladeLog((int)mySledId);
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if (myResponse == null)
            {
                Console.WriteLine(WcsCliConstants.serviceResponseEmpty);
                return;
            }

            if (myResponse.completionCode == Contracts.CompletionCode.Success)
            {
                Console.WriteLine(WcsCliConstants.commandSucceeded);
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Unknown)
            {
                Console.WriteLine("Blade: " + WcsCliConstants.bladeStateUnknown);
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Failure)
            {
                Console.WriteLine(WcsCliConstants.commandFailure);
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Timeout)
            {
                Console.WriteLine(WcsCliConstants.commandTimeout);
            }
            else
            {
                Console.WriteLine("Command failed with the completion code: {0}", myResponse.completionCode);
            }
        }
        private TestResponse OnlyAdminCanExecuteSetBladeMezzPassThroughMode(int bladeId)
        {
            TestCase testCase = new TestCase("OnlyAdminCanExecuteSetBladeMezzPassThroughMode", 24171);

            CmTestLog.Info(string.Format(
                "\n !!!!!!Verifying {0} Can Only Be Executed By WcsCmAdmin Users. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeMezzResponse = new BladeResponse();

            // Loop through different user types
            foreach (WCSSecurityRole roleId in Enum.GetValues(typeof(WCSSecurityRole)))
            {
                this.TestChannelContext = this.ListTestChannelContexts[(int)roleId];

                try
                {
                    setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(bladeId, "true");
                    LogMessage.Message = string.Format(
                            "{0}: Command returns completion code {1} for user {2} for blade Id {3}",
                            currentApi, setBladeMezzResponse.completionCode, Enum.GetName(typeof(WCSSecurityRole), roleId), bladeId);

                    if (setBladeMezzResponse.completionCode == CompletionCode.Success &&
                        roleId == WCSSecurityRole.WcsCmAdmin)
                        LogMessage.Log(LogMessage.MessageType.Success, ref response);
                    else
                        LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                }
                catch (Exception ex)
                {
                    // Check error is due to permission HTTP 400 unauthorize
                    if (ex.Message.Contains("400"))
                    {
                        // Check if 400 error due to WcsAdmin (fail)
                        LogMessage.Message = string.Format("{0}: Command returned Bad Request for user {1} for bladeId {2}",
                            currentApi, Enum.GetName(typeof(WCSSecurityRole), roleId), bladeId);

                        if (roleId != WCSSecurityRole.WcsCmAdmin)
                            LogMessage.Log(LogMessage.MessageType.Success, ref response);
                        else
                            LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                    }
                    else
                    {
                        ChassisManagerTestHelper.IsTrue(false, "Exception: " + ex.Message);
                        response.Result = false;
                        response.ResultDescription.Append(ex.Message);
                    }
                }
            }

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }
        private void VerifySetBladeOn(int[] bladeLocations, out int bladeId, out BladeResponse bladeOn)
        {
            int randSlot = ChassisManagerTestHelper.RandomInteger(0, bladeLocations.Length);
            bladeId = bladeLocations[randSlot];

            bladeOn = this.Channel.SetBladeOn(bladeId);
        }
        private TestResponse ParameterOutOfRangeBladeIdSetBladeMezzPassThroughMode()
        {
            TestCase testCase = new TestCase("ParameterOutOfRangeBladeIdSetBladeMezzPassThroughMode", 24178);

            CmTestLog.Info(string.Format(
                "\n !!!!!!Verifying {0} Returns ParameterOutOfRange for Invalid BladeId. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeMezzResponse = new BladeResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            foreach (int invalidValue in Enum.GetValues(typeof(InvalidBladeId)))
            {
                setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(invalidValue, "true");
                LogMessage.Message = string.Format(
                        "{0}: Command returns completion code {1} for invalid blade Id {2}",
                        this.currentApi, setBladeMezzResponse.completionCode, invalidValue);

                if (setBladeMezzResponse.completionCode != CompletionCode.ParameterOutOfRange)
                    LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                else
                    LogMessage.Log(LogMessage.MessageType.Success, ref response);
            }

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }
        /// <summary>
        /// Clear blade log
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <returns>Blade response indicating clear log operation was success/failure</returns>
        public BladeResponse ClearBladeLog(int bladeId)
        {
            Tracer.WriteUserLog(" Invoked ClearBladeLog(bladeID: {0})", bladeId);

            byte MaxbladeCount = (byte)ConfigLoaded.Population;
            Tracer.WriteInfo("Received clearbladelog({0})", bladeId);

            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Contracts.ChassisResponse varResponse = ValidateRequest("ClearBladeLog", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            bool status = WcsBladeFacade.ClearSel((byte)bladeId);
            if (status != true)
            {
                Tracer.WriteWarning("Clear SEL log failed");
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
                return response;
            }
            response.completionCode = Contracts.CompletionCode.Success;
            return response;
        }
        private TestResponse TrueAfterRestartGetBladeMezzPassThroughMode(int bladeId)
        {
            TestCase testCase = new TestCase("TrueAfterRestartGetBladeMezzPassThroughMode", 24181);

            CmTestLog.Info(string.Format(
                "\n !!!!!!Verifying {0} Returns Correct Pass-ThroughMode After Restarting Blade. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeActivePowerCycleResponse = new BladeResponse();
            BladeStateResponse getBladeStateResponse = new BladeStateResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            // Restart blade
            setBladeActivePowerCycleResponse = this.TestChannelContext.SetBladeActivePowerCycle(bladeId, Convert.ToInt32(CmConstants.OffTimeSec));
            if (setBladeActivePowerCycleResponse.completionCode != CompletionCode.Success)
            {
                LogMessage.Message = string.Format(
                    "{0}: Failed to restart blade {1} with completion code {2}",
                    this.currentApi, bladeId, setBladeActivePowerCycleResponse.completionCode);
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
            }

            // Sleep Thread for 2 minutes 30 seconds
            CmTestLog.Info(string.Format("Thread sleeping for {0} seconds...",
                TimeSpan.FromSeconds(150)));
            Thread.Sleep(TimeSpan.FromSeconds(150));

            // Verify blade soft-powered on
            getBladeStateResponse = this.TestChannelContext.GetBladeState(bladeId);
            if (getBladeStateResponse.completionCode != CompletionCode.Success ||
                getBladeStateResponse.bladeState != PowerState.ON)
            {
                LogMessage.Message = string.Format(
                        "{0}: Blade {1} did not soft-power ON",
                        this.currentApi, bladeId);
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
            }
            else
            {
                CallAndVerifyGetBladeMezzPassThroughMode(bladeId, ref response, "true");
            }

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }
        /// <summary>
        /// Switch blade Attention LED On
        /// </summary>
        /// <param name="bladeId">Blade ID (1-48)</param>
        /// <returns>Blade Response Packet with status Success/Failure.</returns>
        public BladeResponse SetBladeAttentionLEDOn(int bladeId)
        {
            byte MaxbladeCount = (byte)ConfigLoaded.Population;
            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = string.Empty;
            Tracer.WriteUserLog("Invoked SetBladeAttentionLEDOn({0})", bladeId);
            Tracer.WriteInfo("Received SetBladeAttentionLEDOn({0})", bladeId);

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladeAttentionLEDOn", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            if (SetStatusLedOn(bladeId))
            {
                response.completionCode = Contracts.CompletionCode.Success;
                Tracer.WriteInfo("Blade attention LED is turned ON successfully for blade: " + bladeId);
            }
            else
            {
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
                Tracer.WriteError("Blade attention LED Failed to turn ON for blade:" + bladeId);
            }
            return response;
        }
        private TestResponse VerifySuccessWithCapitalizationOfPassThroughSetBladeMezzPassThroughMode(int bladeId)
        {
            TestCase testCase = new TestCase("VerifySuccessWithCapitalizationOfPassThroughSetBladeMezzPassThroughMode", 24201);

            CmTestLog.Info(string.Format(
                "\n !!!!!!Verifying {0} Returns Completion Code Success for PassThroughModeEnabled With Capitalization. WorkItemIds: 24200 and {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeMezzResponse = new BladeResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            Dictionary<string, string> CapitalizedPassThroughModeEnabled = new Dictionary<string, string>();

            CapitalizedPassThroughModeEnabled.Add("Value1", "true");
            CapitalizedPassThroughModeEnabled.Add("Value2", "false");
            CapitalizedPassThroughModeEnabled.Add("Value3", "TRUE");
            CapitalizedPassThroughModeEnabled.Add("Value4", "FALSE");
            CapitalizedPassThroughModeEnabled.Add("Value5", "tRue");
            CapitalizedPassThroughModeEnabled.Add("Value6", "faLse");

            foreach (string capitalizedValue in CapitalizedPassThroughModeEnabled.Values)
            {
                setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(bladeId, capitalizedValue);

                LogMessage.Message = string.Format(
                        "{0}: Command returned Completion Code {1} for PassThroughModeEnabled value {2} for blade Id {3}",
                        this.currentApi, setBladeMezzResponse.completionCode, capitalizedValue, bladeId);

                if (setBladeMezzResponse.completionCode != CompletionCode.Success)
                    LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                else
                    LogMessage.Log(LogMessage.MessageType.Success, ref response);
            }

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }
        /// <summary>
        /// Set the Pass-through Mode for FPGA Mezzanine
        /// </summary>
        /// <param name="bladeId"></param>
        /// <param name="passThroughModeEnabled"></param>
        /// <returns>BladeResponse</returns>
        public BladeResponse SetBladeMezzPassThroughMode(int bladeId, string passThroughModeEnabled)
        {
            string apiName = "SetBladeMezzPassThroughMode";
            bool passThroughMode;

            // Initialize Response
            Tracer.WriteInfo(string.Format("Received {0}(bladeId: {1})", apiName, bladeId));
            Tracer.WriteUserLog(string.Format("Invoked {0}(bladeId: {1})", apiName, bladeId));
            BladeResponse setPassThroughResponse = new BladeResponse();
            setPassThroughResponse.bladeNumber = bladeId;

            try
            {
                // Verify passThroughModeEnabled input is either "true" or "false"
                passThroughModeEnabled = passThroughModeEnabled != null ? // check if string is null
                    passThroughModeEnabled.ToLower() : string.Empty; // convert to lower case : set as empty string
                if (passThroughModeEnabled == "true")
                    passThroughMode = true;
                else if (passThroughModeEnabled == "false")
                    passThroughMode = false;
                else
                {
                    setPassThroughResponse.completionCode = Contracts.CompletionCode.Failure;
                    setPassThroughResponse.statusDescription = "Invalid Request";
                    return setPassThroughResponse;
                }

                // Validate Request
                Contracts.ChassisResponse varResponse = ValidateRequest(apiName, bladeId);
                if (varResponse.completionCode != Contracts.CompletionCode.Success)
                {
                    setPassThroughResponse.completionCode = varResponse.completionCode;
                    setPassThroughResponse.statusDescription = varResponse.statusDescription;
                    return setPassThroughResponse;
                }

                // Invoke SetMezzPassThroughMode to send MasterWriteRead IPMI command to blade BMC
                // in order to set FPGA Mezzanine Pass-Through Mode
                setPassThroughResponse.completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping(
                    (byte)WcsBladeMezz.SetMezzPassThroughMode(bladeId, passThroughMode, apiName));

            }
            catch (Exception ex)
            {
                Tracer.WriteError(string.Format("Exception occured in {0}(): {1}", apiName, ex));
                setPassThroughResponse.completionCode = Contracts.CompletionCode.Failure;
                setPassThroughResponse.statusDescription = setPassThroughResponse.completionCode.ToString() + ": " + ex.Message;
            }

            return setPassThroughResponse;
        }
        private void CallAndVerifySetBladeMezzPassThroughMode(int bladeId, ref TestResponse response,
            string passThroughModeEnabled)
        {
            BladeResponse setBladeMezzResponse = new BladeResponse();

            setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(bladeId, passThroughModeEnabled);
            LogMessage.Message = string.Format(
                    "{0}: Command returns completion code {1} for blade Id {2} and passThroughModeEnabled {3}",
                    "SetBladeMezzPassThroughMode", setBladeMezzResponse.completionCode, bladeId, passThroughModeEnabled);

            if (setBladeMezzResponse.completionCode != CompletionCode.Success)
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
            else
                LogMessage.Log(LogMessage.MessageType.Success, ref response);
        }
        /// <summary>
        /// Set blade power limit to given value for the specified blade
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <param name="powerLimitInWatts">Power limit to set</param>
        /// <returns>Blade response indicating blade operation was success/failure</returns>
        public BladeResponse SetBladePowerLimit(int bladeId, double powerLimitInWatts)
        {
            BladeResponse response = new BladeResponse();
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;
            // Keeping these method specific values as local variables
            const int retryCount = 3;
            byte retryCompletionCode = Convert.ToByte(CompletionCode.IpmiNodeBusy);
            const int retrySnoozeTimeInMilliseconds = 250;

            Contracts.ChassisResponse varResponse = ValidateRequest("SetBladePowerLimit", bladeId);
            if (varResponse.completionCode != Contracts.CompletionCode.Success)
            {
                response.completionCode = varResponse.completionCode;
                response.statusDescription = varResponse.statusDescription;
                return response;
            }

            if (ChassisManagerUtil.CheckBladePowerLimit(powerLimitInWatts))
            {
                Tracer.WriteUserLog("Invoked SetBladePowerLimit( bladeId: {0}, powerLimitInWatts: {1})", bladeId, powerLimitInWatts);
                Tracer.WriteInfo("Invoked SetBladePowerLimit( bladeId: {0}, powerLimitInWatts: {1})", bladeId, powerLimitInWatts);

                for (int iteration = 0; iteration < retryCount; iteration++)
                {
                    // Note: Action is set to 0 (do nothing). Setting action to 1 will cause blade shutdown upon power limit violation
                    // Note: 6 sec correction time and 1 sec sampling period is the minimum time period that works
                    Ipmi.ActivePowerLimit myActiveLimit = WcsBladeFacade.SetPowerLimit((byte)(bladeId), (short)powerLimitInWatts,
                        ConfigLoaded.SetPowerLimitCorrectionTimeInMilliseconds, 0, 1);
                    Tracer.WriteInfo("SetPowerLimit-Iteration({0}): SetLimit ({1}) CompletionCode ({2}).", iteration + 1,
                        myActiveLimit.LimitSet, myActiveLimit.CompletionCode);

                    if (myActiveLimit.CompletionCode == (byte)CompletionCode.Success)
                    {
                        Tracer.WriteInfo("SetPowerLimit-Iteration({0}) SUCCESS: Bladeid ({1}) CompletionCode ({2}).", iteration + 1,
                            bladeId, myActiveLimit.CompletionCode);

                        response.completionCode = Contracts.CompletionCode.Success;
                    }
                    else if (myActiveLimit.CompletionCode == retryCompletionCode)
                    {
                        Tracer.WriteWarning("SetPowerLimit-Iteration({0}) RETRY: Bladeid ({1}) CompletionCode ({2}).", iteration + 1,
                            bladeId, myActiveLimit.CompletionCode);

                        // Not sure if this is needed.. snooze time with random backoff delay to avoid congestion
                        Thread.Sleep(iteration * retrySnoozeTimeInMilliseconds);
                        continue; //Go to the next retry iteration
                    }
                    else
                    {
                        Tracer.WriteError("SetPowerLimit-Iteration({0}) FAILURE: Bladeid ({1}) CompletionCode ({2}).", iteration + 1,
                            bladeId, myActiveLimit.CompletionCode);

                        response.completionCode = Contracts.CompletionCode.Failure;
                        response.statusDescription = response.completionCode.ToString();
                    }
                    break;
                }
            }
            else
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = response.completionCode.ToString();
            }

            return response;
        }
        private TestResponse FailureForEmptySetBladeMezzPassThroughMode(int bladeId)
        {
            TestCase testCase = new TestCase("FailureForEmptySetBladeMezzPassThroughMode", 24169);

            CmTestLog.Info(string.Format("\n !!!!!!Verifying {0} Returns Failure for Empty Location. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeMezzResponse = new BladeResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            // Call API and verify Failure
            setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(bladeId, "true");
            LogMessage.Message = string.Format(
                    "{0}: Command failed for empty location with completion code {1} and blade Id {2}",
                    this.currentApi, setBladeMezzResponse.completionCode, bladeId);

            if (setBladeMezzResponse.completionCode != CompletionCode.Failure)
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
            else
                LogMessage.Log(LogMessage.MessageType.Success, ref response);

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }
        /// <summary>
        /// Power On specified blade
        /// </summary>
        /// <param name="bladeId">Blade ID(1-48)</param>
        /// <returns>Blade Response, indicates success/failure.</returns>
        public BladeResponse SetPowerOn(int bladeId)
        {
            Tracer.WriteInfo("Received SetPowerOn(bladeId: {0})", bladeId);
            Tracer.WriteUserLog("Invoked SetPowerOn(bladeId: {0})", bladeId);

            BladeResponse response = new BladeResponse();
            byte maxbladeCount = (byte)ConfigLoaded.Population;
            response.bladeNumber = bladeId;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            // Check for correct blade id
            if (ChassisManagerUtil.CheckBladeId(bladeId) == CompletionCode.InvalidBladeId)
            {
                Tracer.WriteWarning("Invalid blade Id {0}", bladeId);
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = Contracts.CompletionCode.ParameterOutOfRange.ToString();
                return response;
            }

            if (BladePowerCommands.PowerOn(bladeId))
            {
                response.completionCode = Contracts.CompletionCode.Success;
                Tracer.WriteInfo("Successfully set power to ON for blade: " + bladeId);
            }
            else
            {
                Tracer.WriteError("Failed to set power to ON for blade: " + bladeId);
                response.completionCode = Contracts.CompletionCode.Failure;
                response.statusDescription = response.completionCode.ToString();
            }
            return response;
        }
        private TestResponse FailureForSoftOffSetBladeMezzPassThroughMode(int bladeId)
        {
            TestCase testCase = new TestCase("FailureForSoftOffSetBladeMezzPassThroughMode", 27172);

            CmTestLog.Info(string.Format(
                "\n !!!!!!Verifying {0} Returns Failure for Server Blade Soft-Powered Off. WorkItemId: {1}!!!!!!",
                this.currentApi, testCase.WorkItemId));
            TestResponse response = new TestResponse();

            BladeResponse setBladeMezzResponse = new BladeResponse();
            this.TestChannelContext = this.ListTestChannelContexts[(int)WCSSecurityRole.WcsCmAdmin];

            // Soft-Power Off server blade
            BladeResponse bladeResponse = this.TestChannelContext.SetBladeOff(bladeId);
            if (bladeResponse.completionCode != CompletionCode.Success)
            {
                LogMessage.Message = string.Format(
                    "{0}: Unable to soft-power off server blade {1}",
                    this.currentApi, bladeId);
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
            }
            else
            {
                CmTestLog.Info(string.Format("Hard-powered On blade {0}. Thread sleeping for {1} seconds...",
                bladeId, CmConstants.BladePowerOnSeconds));
                Thread.Sleep(TimeSpan.FromSeconds(CmConstants.BladePowerOnSeconds));

                // Call API and verify Failure
                setBladeMezzResponse = this.TestChannelContext.SetBladeMezzPassThroughMode(bladeId, "true");
                LogMessage.Message = string.Format(
                        "{0}: Command returns completion code {1} after blade {2} is soft-powered off",
                        this.currentApi, setBladeMezzResponse.completionCode, bladeId);

                if (setBladeMezzResponse.completionCode != CompletionCode.Failure)
                    LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                else
                    LogMessage.Log(LogMessage.MessageType.Success, ref response);
            }

            // Code clean-up. Soft-power on blade
            bladeResponse = this.TestChannelContext.SetBladeOn(bladeId);
            if (bladeResponse.completionCode != CompletionCode.Success)
            {
                LogMessage.Message = string.Format(
                    "{0}: Unable to soft-power on server blade {1}",
                    this.currentApi, bladeId);
                LogMessage.Log(LogMessage.MessageType.Failure, ref response);
                return response;
            }

            testCase.LogPassOrFail(ref response, currentApi);
            return response;
        }