/// <summary>
        /// Starts serial console port session on the specified serial port
        /// 
        /// </summary>
        /// <returns> Returns information about the new session created including the exit key sequence. If null then failure</returns>
        public StartSerialResponse StartSerialPortConsole(int portId, int sessionTimeoutInSecs, int deviceTimeoutInMsecs, int baudRate)
        {
            StartSerialResponse response = new StartSerialResponse();
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;
            response.serialSessionToken = null;

            Tracer.WriteUserLog("Invoked StartSerialPortConsole(portId: {0})", portId);
            Tracer.WriteInfo("Received StartSerialPortConsole(portId: {0})", portId);

            if (ChassisManagerUtil.CheckSerialConsolePortId((byte)portId) != (byte)CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                Tracer.WriteWarning("StartSerialPortConsole failed: Port ID out of range " + portId);
                response.statusDescription = String.Format("StartSerialPortConsole failed: Port ID out of range " + portId);
                return response;
            }

            ChassisManagerUtil.BaudRateStruct baudRateVal = ChassisManagerUtil.ValidateAndGetBaudRate(baudRate);
            if (!baudRateVal.isValid)
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                Tracer.WriteWarning("StartSerialPortConsole failed: Baud rate ({0}) out of range" + baudRate);
                response.statusDescription = String.Format("StartSerialPortConsole failed: Baud rate ({0}) out of range " + baudRate);
                return response;
            }

            int portIndex = ChassisManagerUtil.GetSerialConsolePortIndexFromId(portId);
            response = ChassisState.SerialConsolePortsMetadata[portIndex].StartSerialPortConsole(ChassisManagerUtil.GetSerialConsolePortIdFromIndex(portIndex), sessionTimeoutInSecs, deviceTimeoutInMsecs, baudRateVal.baudRate);

            if (ChassisManagerUtil.CheckCompletionCode(response.completionCode))
            {
                Tracer.WriteInfo("StartSerialPortConsole succeeded for portId: " + portId);
            }
            else
            {
                Tracer.WriteError("StartSerialPortConsole: failed for portId: {0} and baudRate: {1} with completion code: {2}", portId, baudRate, response.completionCode.ToString());
                response.statusDescription = String.Format("StartSerialPortConsole: failed for portId: {0} and baudRate: {1} with completion code: {1}", portId, baudRate, response.completionCode.ToString());
            }
            return response;
        }
示例#2
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()
        {
            StartSerialResponse myResponse = new StartSerialResponse();
            try
            {
                if (this.argVal.ContainsKey('i'))
                {
                    dynamic myportId = null;
                    dynamic sessionTimeoutInSecs = null;
                    dynamic deviceTimeoutInMSecs = null;
                    this.argVal.TryGetValue('i', out myportId);
                    this.argVal.TryGetValue('s', out sessionTimeoutInSecs);
                    this.argVal.TryGetValue('d', out deviceTimeoutInMSecs);

                    if (this.argVal.TryGetValue('s', out sessionTimeoutInSecs) &&
                        this.argVal.TryGetValue('d', out deviceTimeoutInMSecs))
                    {
                        myResponse = WcsCli2CmConnectionManager.channel.StartSerialPortConsole((int)myportId,
                            (int)sessionTimeoutInSecs, (int)deviceTimeoutInMSecs);
                    }
                    else
                    {
                        myResponse = WcsCli2CmConnectionManager.channel.StartSerialPortConsole(
                            (int)myportId, 0, 0);
                    }

                    // set port Id
                    portId = (int)myportId;
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
            }

            if (myResponse.completionCode == Contracts.CompletionCode.Success)
            {
                if (myResponse.serialSessionToken != null)
                {
                    Console.WriteLine(myResponse.serialSessionToken);

                    // set the serial cache
                    SessionString = myResponse.serialSessionToken;

                    if (portId > 0)
                    {
                        // Console client
                        if (!this.isSerialClient)
                        {
                            // Automatically start into VT100 mode.
                            // This is a blocking method.
                            SetupVt100(enterEncodeCRLF);
                        }
                        else // Serial client
                        {
                            SharedFunc.SetSerialSession(true);
                            EstablishPortSerialSessionOverSerialClient();
                        }

                        // When the setup ends, call a close session by default
                        // as the session should be destroyed.
                        WcsCli2CmConnectionManager.channel.StopSerialPortConsole(portId, SessionString, false);
                    }
                    else
                    {
                        ErrorMessage("failed to start serial session due to conversion of port Id", false, false);
                    }

                    return;
                }
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Failure)
            {
                Console.WriteLine(WcsCliConstants.commandFailure);
                return;
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Timeout)
            {
                Console.WriteLine(WcsCliConstants.commandTimeout);
                return;
            }
            else
            {
                Console.WriteLine(WcsCliConstants.unknownError);
            }
        }
        /// <summary>
        /// Starts serial session on a blade
        /// </summary>
        /// <returns> Returns information about the new session created including the session token. If null then failure</returns>
        public StartSerialResponse StartBladeSerialSession(int bladeId, int sessionTimeoutInSecs, bool powerOnWait)
        {
            StartSerialResponse response = new StartSerialResponse();
            response.serialSessionToken = null;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteInfo("Received StartBladeSerialSession(bladeId: {0})", bladeId);
            Tracer.WriteUserLog("Invoked StartBladeSerialSession(bladeId: {0})", bladeId);

            if (ChassisManagerUtil.CheckBladeId((byte)bladeId) != (byte)CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                Tracer.WriteWarning("StartBladeSerialSession failed: Blade ID: {0} out of range ", bladeId);
                return response;
            }

            if (!FunctionValidityChecker.CheckBladeTypeValidity((byte)bladeId))
            {
                response.completionCode = Contracts.CompletionCode.CommandNotValidForBlade;
                response.statusDescription = response.statusDescription;
                return response;
            }

            if (!BladeSerialSessionMetadata.CheckBladeSerialSessionTimeout(sessionTimeoutInSecs))
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = "Session Timeout out of range";
                return response;
            }

            if (powerOnWait)
            {
                // Power on blade and keep trying to open a serial session
                BladeResponse powerOn = SetPowerOn(bladeId);

                if (powerOn.completionCode == Contracts.CompletionCode.Success)
                {
                    int retry = 0;

                    while (retry < ConfigLoaded.SerialSessionPowerOnRetry)
                    {
                        response = ChassisState.BladeSerialMetadata[bladeId].StartBladeSerialSession(bladeId, sessionTimeoutInSecs);

                        // if the response times out, sleep and retry.
                        if (response.completionCode == Contracts.CompletionCode.FirmwareDecompressing)
                        {
                            BladePowerStatePacket powerPacket = ChassisState.BladePower[bladeId - 1].GetCachedBladePowerState();

                            if (powerPacket.CompletionCode == CompletionCode.Success)
                            {
                                // sleep for five seconds
                                Thread.Sleep(TimeSpan.FromSeconds(powerPacket.DecompressionTime));
                            }
                            else
                            {
                                // sleep for five seconds
                                Thread.Sleep(ConfigLoaded.SerialSessionPowerOnWait);
                            }

                            retry++;
                        }
                        else
                        {
                            // if StartBladeSerialSession fails or completes successfully for any other reson,
                            // then just exit the loop.  Or if it succeeds exit the loop.
                            break;
                        }
                    }
                }
                else
                {
                    response.completionCode = Contracts.CompletionCode.DevicePoweredOff;
                    response.statusDescription = "Device Failed to Power On.";
                }
            }
            else
            {

                Contracts.ChassisResponse chassisResponse = CheckBladeAndFirmwareState((byte)bladeId);
                if (chassisResponse.completionCode != Contracts.CompletionCode.Success)
                {
                    response.completionCode = chassisResponse.completionCode;
                    response.statusDescription = chassisResponse.statusDescription;
                    return response;
                }

                response = ChassisState.BladeSerialMetadata[bladeId].StartBladeSerialSession(bladeId, sessionTimeoutInSecs);
                if (ChassisManagerUtil.CheckCompletionCode(response.completionCode))
                {
                    Tracer.WriteInfo("StartBladeSerialSession succeeded for bladeId: " + bladeId);
                }
                else
                {
                    Tracer.WriteError("StartBladeSerialSession failed for bladeId: {0} with completion code: {1}", bladeId, response.completionCode.ToString());
                }
            }

            return response;
        }
        private StartSerialResponse StartBladeSerialSessionAndKillExistingSession(ref TestResponse response, StartSerialResponse startSerialResponse, int bladeId)
        {
            // kill any existing serial session first
            CmTestLog.Info(string.Format("Kill all existing serial session for Blade# {0}", bladeId));
            ChassisResponse killSession = this.Channel.StopBladeSerialSession(bladeId, null, true);
            if (!(CompletionCode.NoActiveSerialSession == killSession.completionCode || CompletionCode.Success == killSession.completionCode))
            {
                response.Result = false;
                response.ResultDescription.Append("\nFailed to kill existing session for blade# " + bladeId);
            }

            // start blade serial session
            CmTestLog.Info(string.Format("Trying to start a serial session for Blade# {0}", bladeId));
            string sessionToken;
            TestResponse testResponse = this.VerifyStartBladeSerialSession(response, bladeId, ref startSerialResponse, out sessionToken);
            response.Result &= testResponse.Result;
            response.ResultDescription.Append(testResponse.ResultDescription);
            return startSerialResponse;
        }
示例#5
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()
        {
            StartSerialResponse myResponse = new StartSerialResponse();
            BladeInfoResponse bladeInfo = new BladeInfoResponse();

            try
            {
                if (this.argVal.ContainsKey('i'))
                {
                    dynamic mySledId = null;
                    dynamic sessionTimeoutInSecs = null;
                    this.argVal.TryGetValue('i', out mySledId);
                    
                    // Determine blade type
                    bladeInfo = WcsCli2CmConnectionManager.channel.GetBladeInfo((int)mySledId);
                    if (bladeInfo.completionCode == Contracts.CompletionCode.Success)
                    {
                        if (bladeInfo.bladeType == WcsCliConstants.BladeTypeCompute)
                        {
                            // Compute blade needs CR+LF for Enter key
                            enterEncodeCRLF = true;
                        }
                        else if (bladeInfo.bladeType == WcsCliConstants.BladeTypeJBOD)
                        {
                            // JBOD only needs CR for Enter key
                            enterEncodeCRLF = false;
                        }

                        // Open serial session
                        if (this.argVal.TryGetValue('s', out sessionTimeoutInSecs))
                        {
                            myResponse = WcsCli2CmConnectionManager.channel.StartBladeSerialSession(
                            (int)mySledId, (int)sessionTimeoutInSecs);
                        }
                        else
                        {
                            myResponse = WcsCli2CmConnectionManager.channel.StartBladeSerialSession(
                            (int)mySledId, 0);
                        }

                    }
                    else
                    {
                        myResponse.completionCode = Contracts.CompletionCode.Failure;
                    }

                    // set blade Id
                    bladeId = (int)mySledId;
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
            }

            if (myResponse.completionCode == Contracts.CompletionCode.Success)
            {
                if (myResponse.serialSessionToken != null)
                {
                    // set the serial cache
                    SessionString = myResponse.serialSessionToken;

                    if (bladeId > 0)
                    {
                        // Console client
                        if (!this.isSerialClient)
                        {
                            // Automatically start into VT100 mode.
                            // This is a blocking method.
                            SetupVt100(enterEncodeCRLF);
                        }
                        else // Serial client
                        {
                            SharedFunc.SetSerialSession(true);
                            EstablishBladeSerialSessionOverSerialClient();
                        }
                        // When the setup ends, call a close session by default
                        // as the session should be destroyed.
                        WcsCli2CmConnectionManager.channel.StopBladeSerialSession(bladeId, SessionString);
                    }
                    else
                    {
                        ErrorMessage("failed to start serial session due to conversion of blade Id", false, false);
                    }
                    return;
                }
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Failure)
            {
                Console.WriteLine(WcsCliConstants.commandFailure);
                return;
            }
            else if (myResponse.completionCode == Contracts.CompletionCode.Timeout)
            {
                Console.WriteLine(WcsCliConstants.commandTimeout);
                return;
            }
            else
            {
                Console.WriteLine(WcsCliConstants.unknownError);
            }
        }
 private TestResponse VerifyStartSerialPortConsoleByUser(TestResponse testRunResponse, WCSSecurityRole roleId, StartSerialResponse startSerialPortResponse)
 {
     if (!(startSerialPortResponse.completionCode == CompletionCode.Success || CompletionCode.SerialSessionActive == startSerialPortResponse.completionCode) && (roleId == WCSSecurityRole.WcsCmAdmin || roleId == WCSSecurityRole.WcsCmOperator))
     {
         testRunResponse.Result = false;
         testRunResponse.ResultDescription.Append(string.Format("\nFailed to start serial session with WcsAdmin/WcsOperator User {0}, completion code returned: {1} ", roleId, startSerialPortResponse.completionCode));
         return testRunResponse;
     }
     else if ((startSerialPortResponse.completionCode == CompletionCode.Success || CompletionCode.SerialSessionActive == startSerialPortResponse.completionCode) && (roleId == WCSSecurityRole.WcsCmUser))
     {
         testRunResponse.Result = false;
         testRunResponse.ResultDescription.Append(string.Format("User is able to start blade serial session {0}", roleId, "completion code returned: {1} ", startSerialPortResponse.completionCode));
         return testRunResponse;
     }
     else
     {
         testRunResponse.Result &= ChassisManagerTestHelper.IsTrue((startSerialPortResponse.completionCode == CompletionCode.Success || CompletionCode.SerialSessionActive == startSerialPortResponse.completionCode),
              string.Format("Received success with user {0}", Enum.GetName(typeof(WCSSecurityRole), roleId)));
     }
     return testRunResponse;
 }
        /// <summary>
        /// Verifies StartPortSerialConsole: Checks Completion Code: Success and Get session Token from response
        /// </summary>
        /// <param name="response"></param>
        /// <param name="bladeId"></param>
        /// <param name="startResponse"></param>
        /// <param name="sessionToken"></param>
        /// <returns></returns>
        private TestResponse VerifyStartSerialPortConsole(TestResponse response, StartSerialResponse startResponse)
        {
            // Verify Completion code & Session Token
            if (!ChassisManagerTestHelper.AreEqual(CompletionCode.Success, startResponse.completionCode, "Port serial console started"))
            {
                response.Result = false;
                response.ResultDescription.Append("\nFailed to start port serial console, completion code returned: " + startResponse.completionCode);
                CmTestLog.Failure(response.ResultDescription.ToString());
                return response;
            }
            if (!ChassisManagerTestHelper.IsTrue(!string.IsNullOrEmpty(startResponse.serialSessionToken), "Serial session token received"))
            {
                response.Result = false;
                response.ResultDescription.Append("\nFailed to receive serial session token, Session token returned: " + startResponse.serialSessionToken);
                CmTestLog.Failure(response.ResultDescription.ToString());
                return response;
            }

            CmTestLog.Success("Successfully started port serial console & received session token");
            return response;
        }
        /// <summary>
        /// Verifies StartBladeSerialSession: Checks Completion Code: Success and Get session Token from response
        /// </summary>
        /// <param name="response"></param>
        /// <param name="bladeId"></param>
        /// <param name="startResponse"></param>
        /// <param name="sessionToken"></param>
        /// <returns></returns>
        private TestResponse VerifyStartBladeSerialSession(TestResponse response, int bladeId, ref StartSerialResponse startResponse, out string sessionToken)
        {
            sessionToken = string.Empty;
            startResponse = this.Channel.StartBladeSerialSession(bladeId, CmConstants.SerialTimeoutSeconds);

            // Verify Completion code & Session Token
            if (!ChassisManagerTestHelper.AreEqual(CompletionCode.Success, startResponse.completionCode, "Serial session started"))
            {
                response.Result = false;
                response.ResultDescription.Append(String.Format("\nFailed to start serial session with blade# {0}, completion code returned: {1}", bladeId, startResponse.completionCode));
                CmTestLog.Failure(response.ResultDescription.ToString());
                return response;
            }
            sessionToken = startResponse.serialSessionToken;
            if (!ChassisManagerTestHelper.IsTrue(!string.IsNullOrEmpty(sessionToken), "Serial session token received for blade# " + bladeId))
            {
                response.Result = false;
                response.ResultDescription.Append("\nFailed to receive serial session token, Session token returned: " + startResponse.serialSessionToken);
                CmTestLog.Failure(response.ResultDescription.ToString());
                return response;
            }

            CmTestLog.Success("Successfully started blade serial session & received session token for blade# "+ bladeId);
            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()
        {
            StartSerialResponse myResponse = new StartSerialResponse();
            try
            {
                if (this.argVal.ContainsKey('i'))
                {
                    dynamic myportId = null;
                    int sessionTimeoutInSecs = 0; // initializing it to 0 since we want to use the default value for this and not override it here
                    dynamic deviceTimeoutInMSecs = null;
                    dynamic baudRate = null;
                    this.argVal.TryGetValue('i', out myportId);
                    this.argVal.TryGetValue('d', out deviceTimeoutInMSecs);
                    this.argVal.TryGetValue('r', out baudRate);

                    // If the baud rate is not specified by the user, we use the default
                    if (!this.argVal.TryGetValue('r', out baudRate))
                    {
                        baudRate = 9600; // default baud rate when the user does not specify
                    }

                    if (!this.argVal.TryGetValue('d', out deviceTimeoutInMSecs))
                    {
                        deviceTimeoutInMSecs = 0;
                    }

                    myResponse = WcsCli2CmConnectionManager.channel.StartSerialPortConsole((int)myportId,
                        (int)sessionTimeoutInSecs, (int)deviceTimeoutInMSecs, (int)baudRate);

                    // set port Id
                    portId = (int)myportId;
                }
            }
            catch (Exception ex)
            {
                SharedFunc.ExceptionOutput(ex);
                return;
            }

            if (myResponse.completionCode == Contracts.CompletionCode.Success)
            {
                if (myResponse.serialSessionToken != null)
                {
                    // set the serial cache
                    SessionString = myResponse.serialSessionToken;

                    if (portId > 0)
                    {
                        // Console client
                        if (!this.isSerialClient)
                        {
                            // Automatically start into VT100 mode.
                            // This is a blocking method.
                            SetupVt100(enterEncodeCRLF);
                        }
                        else // Serial client
                        {
                            SharedFunc.SetSerialSession(true);
                            EstablishPortSerialSessionOverSerialClient();
                        }

                        // When the setup ends, call a close session by default
                        // as the session should be destroyed.
                        WcsCli2CmConnectionManager.channel.StopSerialPortConsole(portId, SessionString, false);

                        // Display that serial session has ended
                        Console.WriteLine("Port serial session ended..\n");
                    }
                    else
                    {
                        ErrorMessage("failed to start serial session due to conversion of port Id", false, false);
                    }

                    return;
                }
            }
            ResponseValidation.ValidateResponse(null, myResponse, false);
        }
示例#10
0
        /// <summary>
        /// ***TODO - M2*** Starts serial session on a blade
        /// </summary>
        /// <returns> Returns information about the new session created including the exit key sequence. If null then failure</returns>
        public StartSerialResponse StartBladeSerialSession(int bladeId, int sessionTimeoutInSecs)
        {
            StartSerialResponse response = new StartSerialResponse();
            response.serialSessionToken = null;
            response.completionCode = Contracts.CompletionCode.Unknown;
            response.statusDescription = String.Empty;

            Tracer.WriteInfo("Received startbladeserialsession({0})", bladeId);
            Tracer.WriteUserLog("Invoked StartBladeSerialSession(bladeId: {0})", bladeId);

            if (ChassisManagerUtil.CheckBladeId((byte)bladeId) != (byte)CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                Tracer.WriteWarning("StartBladeSerialSession failed : Blade ID: {0} out of range ", bladeId);
                return response;
            }

            if (!FunctionValidityChecker.checkBladeStateValidity((byte)bladeId))
            {
                response.completionCode = Contracts.CompletionCode.DevicePoweredOff;
                return response;
            }

            if (!FunctionValidityChecker.checkBladeTypeValidity((byte)bladeId))
            {
                response.completionCode = Contracts.CompletionCode.CommandNotValidForBlade;
                response.statusDescription = response.completionCode.ToString();
                return response;
            }

            if (!ChassisManagerUtil.CheckBladeSerialSessionTimeout(sessionTimeoutInSecs))
            {
                response.completionCode = Contracts.CompletionCode.ParameterOutOfRange;
                response.statusDescription = response.completionCode.ToString();
                return response;
            }

            response = BladeSerialSessionMetadata.StartBladeSerialSession(bladeId, sessionTimeoutInSecs);
            if (ChassisManagerUtil.CheckCompletionCode(response.completionCode))
            {
                Tracer.WriteInfo("StartBladeSerialSession succeeded for bladeId: " + bladeId);
            }
            else
            {
                Tracer.WriteError("StartBladeSerialSession: failed for bladeId: {0} with completion code: {1}", bladeId, response.completionCode.ToString());
            }

            response.statusDescription = response.completionCode.ToString();

            return response;
        }