コード例 #1
0
        private void VerifyCmOrPdbAssetInfo(ref bool cmOrPdbPassed, bool verifyingCmAssetInfo, int user, string payload)
        {
            int maxStringLength = 56;
            string propertyValue;
            string currentApi = verifyingCmAssetInfo ? "GetChassisManagerAssetInfo" : "GetPdbAssetInfo";
            ChassisAssetInfoResponse cmOrPdbAssetInfo = new ChassisAssetInfoResponse();

            this.TestChannelContext = this.ListTestChannelContexts[user];

            if (verifyingCmAssetInfo)
            {
                cmOrPdbAssetInfo = this.TestChannelContext.GetChassisManagerAssetInfo();
            }
            else
            {
                cmOrPdbAssetInfo = this.TestChannelContext.GetPdbAssetInfo();
            }

            // get completion code success
            cmOrPdbPassed = ChassisManagerTestHelper.AreEqual(CompletionCode.Success, cmOrPdbAssetInfo.completionCode,
                string.Format("{0}: Completion Code Success", currentApi));

            if (cmOrPdbPassed)
            {
                // Get CM or PDB Fru XML Sample
                string fruDefFileDir = Path.Combine(Directory.GetCurrentDirectory(), "TestData");
                string fruFileName = verifyingCmAssetInfo ? Path.Combine(fruDefFileDir, "ChassisManagerFruSample.xml") : Path.Combine(fruDefFileDir, "PdbFruSample.xml");

                if (!File.Exists(fruFileName))
                {
                    throw new ApplicationException(string.Format("{0}: Sample Xml file is NOT found under the path {1}", currentApi, fruDefFileDir));
                }

                // Extract CmFruSample Xml file
                XmlReader cmOrPdbFruXml = XmlReader.Create(fruFileName);

                cmOrPdbFruXml.ReadToFollowing("chassisAreaPartNumber");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.chassisAreaPartNumber,
                    string.Format("{0}: Received Chassis Area Part Number", currentApi));

                cmOrPdbFruXml.ReadToFollowing("chassisAreaSerialNumber");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.chassisAreaSerialNumber,
                    string.Format("{0}: Received Chassis Area Serial Number", currentApi));

                cmOrPdbFruXml.ReadToFollowing("boardAreaManufacturerName");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.boardAreaManufacturerName,
                    string.Format("{0}: Received Board Area Manufacturer Name", currentApi));

                cmOrPdbFruXml.ReadToFollowing("boardAreaManufacturerDate");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                Match propertyMatch = Regex.Match(propertyValue, @"0[1-9]|[1-12]/0[0-9]|[0-31]/[1-2][09][01789]\d\s\d?\d:\d?\d:\d?\d\s[aApP][mM]");
                cmOrPdbPassed &= ChassisManagerTestHelper.IsTrue(propertyMatch.Success,
                    string.Format("{0}: Received Board Area Manufacturer Date", currentApi));

                cmOrPdbFruXml.ReadToFollowing("boardAreaProductName");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.boardAreaProductName,
                    string.Format("{0}: Received Board Area Product Name", currentApi));

                cmOrPdbFruXml.ReadToFollowing("boardAreaSerialNumber");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.boardAreaSerialNumber,
                    string.Format("{0}: Received Board Area Serial Number", currentApi));

                cmOrPdbFruXml.ReadToFollowing("boardAreaPartNumber");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.boardAreaPartNumber,
                    string.Format("{0}: Received Board Area Part Number", currentApi));

                cmOrPdbFruXml.ReadToFollowing("productAreaManufactureName");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.productAreaManufactureName,
                    string.Format("{0}: Received Product Area Manufacture Name", currentApi));

                cmOrPdbFruXml.ReadToFollowing("productAreaProductName");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.productAreaProductName,
                    string.Format("{0}: Received Product Area Product Name", currentApi));

                cmOrPdbFruXml.ReadToFollowing("productAreaPartModelNumber");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.productAreaPartModelNumber,
                    string.Format("{0}: Received Product Area Part Model Number", currentApi));

                cmOrPdbFruXml.ReadToFollowing("productAreaProductVersion");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.productAreaProductVersion,
                    string.Format("{0}: Received Product Area Product Version", currentApi));

                cmOrPdbFruXml.ReadToFollowing("productAreaSerialNumber");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.productAreaSerialNumber,
                    string.Format("{0}: Received Product Area Serial Number", currentApi));

                cmOrPdbFruXml.ReadToFollowing("productAreaAssetTag");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.productAreaAssetTag,
                    string.Format("{0}: Received Product Area Asset Tag", currentApi));

                cmOrPdbFruXml.ReadToFollowing("manufacturer");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.manufacturer,
                    string.Format("{0}: Received Manufacturer", currentApi));

                cmOrPdbFruXml.ReadToFollowing("serviceVersion");
                propertyValue = cmOrPdbFruXml.ReadElementContentAsString();
                cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(propertyValue, cmOrPdbAssetInfo.serviceVersion,
                    string.Format("{0}: Received Service Version", currentApi));

                // Verify multirecord fields are set
                if (payload != null)
                {
                    string[] payLoadFields = payload.Split(',').Select(field => field.Trim()).ToArray();

                    int fieldCount = 0;
                    string expectedField = null;

                    // Verify payLoad matches MultiRecordFields (only first two fields allowed)
                    if (cmOrPdbAssetInfo.multiRecordFields.Count() <= 2)
                    {
                        foreach (string actualField in cmOrPdbAssetInfo.multiRecordFields)
                        {
                            if (payLoadFields[fieldCount].Length > 56)
                            {
                                expectedField = payLoadFields[fieldCount].Substring(0, maxStringLength);
                            }
                            else
                            {
                                expectedField = payLoadFields[fieldCount];
                            }

                            cmOrPdbPassed &= ChassisManagerTestHelper.AreEqual(expectedField, actualField,
                                string.Format("{0}{1}", currentApi, string.Format(": Received Field{0} '{1}'", fieldCount.ToString(), payLoadFields[fieldCount])));
                            fieldCount++;
                        }
                    }
                    else
                    {
                        CmTestLog.Failure(string.Format("{0}: Command exceeded number of MultiRecord Fields allowed", currentApi));
                    }
                }

                // Close XmlReader
                cmOrPdbFruXml.Close();
            }
        }
        /// <summary>
        /// Get the CM or PDB FRU areas information. The FRU area consists of 3 parts:
        /// (i) Chassis Info Area; (ii) Board Info Area; and (iii) Product Info Area.
        /// deviceType parameter uniquely identifies CM and PDB based on their
        /// unique FRU EEPROM addresses.
        /// </summary>
        /// <returns>AssetInfoResponse</returns>
        private ChassisAssetInfoResponse GetChassisAssetInfo(DeviceType deviceType)
        {
            ChassisAssetInfoResponse assetInfo = new ChassisAssetInfoResponse();

            ServiceVersionResponse version = GetServiceVersion();

            if (version.completionCode == Contracts.CompletionCode.Success)
            {
                assetInfo.serviceVersion = version.serviceVersion;
            }

            try
            {
                Ipmi.FruDevice fruDevice = ChassisState.CmFruData.ReadFru((DeviceType)deviceType);

                if (fruDevice.CompletionCode == (byte)CompletionCode.Success)
                {
                    // Populate Chassis Info Area parameters
                    assetInfo.chassisAreaPartNumber = fruDevice.ChassisInfo.PartNumber.ToString();
                    assetInfo.chassisAreaSerialNumber = fruDevice.ChassisInfo.SerialNumber.ToString();

                    // Populate Board Info Area parameters
                    assetInfo.boardAreaManufacturerName = fruDevice.BoardInfo.Maufacturer.ToString();
                    assetInfo.boardAreaManufacturerDate = fruDevice.BoardInfo.MfgDateTime.ToString();
                    assetInfo.boardAreaProductName = fruDevice.BoardInfo.ProductName.ToString();
                    assetInfo.boardAreaSerialNumber = fruDevice.BoardInfo.SerialNumber.ToString();
                    assetInfo.boardAreaPartNumber = fruDevice.BoardInfo.ProductPartNumber.ToString();

                    // Populate Product Info Area parameters
                    assetInfo.productAreaManufactureName = fruDevice.ProductInfo.ManufacturerName.ToString();
                    assetInfo.productAreaProductName = fruDevice.ProductInfo.ProductName.ToString();
                    assetInfo.productAreaPartModelNumber = fruDevice.ProductInfo.PartModelNumber.ToString();
                    assetInfo.productAreaProductVersion = fruDevice.ProductInfo.ProductVersion.ToString();
                    assetInfo.productAreaSerialNumber = fruDevice.ProductInfo.SerialNumber.ToString();
                    assetInfo.productAreaAssetTag = fruDevice.ProductInfo.AssetTag.ToString();

                    // Populate Multi Record Info Area parameters
                    if (fruDevice.MultiRecordInfo != null)
                    {
                        // Populate Multi Record Info Area parameters
                        assetInfo.manufacturer = fruDevice.MultiRecordInfo.Manufacturer.ToString();

                        List<Ipmi.FruByteString> fields = fruDevice.MultiRecordInfo.Fields.ToList();
                        foreach (Ipmi.FruByteString field in fields)
                        {
                            assetInfo.multiRecordFields.Add(field.ToString());
                        }
                    }
                    else
                    {
                        Tracer.WriteError("GetChassisAssetInfo(). FRU Multi Record Area is empty.");
                    }

                    assetInfo.completionCode = Contracts.CompletionCode.Success;
                }
                else
                {
                     Tracer.WriteError("GetChassisAssetInfo() FRU Read failed with completion code: {0:X}",
                            fruDevice.CompletionCode);
                    assetInfo.completionCode = Contracts.CompletionCode.Failure;
                }
            }
            catch (Exception ex)
            {
                Tracer.WriteError(
                    " GetChassisAssetInfo failed with the exception: " + ex.Message);
                if (assetInfo.completionCode != Contracts.CompletionCode.Success)
                {
                    assetInfo.completionCode = Contracts.CompletionCode.Failure;
                    assetInfo.statusDescription = String.Format("GetChassisAssetInfo() failed with unknown error");
                }
            }

            return assetInfo;
        }
        /// <summary>
        /// command specific implementation 
        /// </summary>
        internal override void commandImplementation()
        {
            ChassisAssetInfoResponse myResponse = new ChassisAssetInfoResponse();
            try
            {
                myResponse = WcsCli2CmConnectionManager.channel.GetPdbAssetInfo();
            }

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

            if (ResponseValidation.ValidateResponse(null, myResponse, false))
            {
                Console.WriteLine(WcsCliConstants.commandSuccess);
                Console.WriteLine();
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Power Distribution Board (PDB) Chassis Info Area");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine(
                    "Chassis Part Number = " + myResponse.chassisAreaPartNumber);
                Console.WriteLine(
                    "Chassis Serial Number = " + myResponse.chassisAreaSerialNumber);
                Console.WriteLine("--------------------------------------");
                Console.WriteLine();

                Console.WriteLine("Power Distribution Board (PDB) Board Info Area");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine(
                    "Board Manufacturer Name = " + myResponse.boardAreaManufacturerName);
                Console.WriteLine(
                    "Board Manufacturer Date = " + myResponse.boardAreaManufacturerDate);
                Console.WriteLine(
                    "Board Product Name = " + myResponse.boardAreaProductName);
                Console.WriteLine(
                    "Board Serial Number = " + myResponse.boardAreaSerialNumber);
                Console.WriteLine(
                    "Board Part Number = " + myResponse.boardAreaPartNumber);
                Console.WriteLine("--------------------------------------");
                Console.WriteLine();

                Console.WriteLine("Power Distribution Board (PDB) Product Info Area");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine(
                    "Product Manufacturer Name = " + myResponse.productAreaManufactureName);
                Console.WriteLine(
                    "Product Product Name = " + myResponse.productAreaProductName);
                Console.WriteLine(
                    "Product Part/Model Number = " + myResponse.productAreaPartModelNumber);
                Console.WriteLine(
                    "Product Version = " + myResponse.productAreaProductVersion);
                Console.WriteLine(
                    "Product Serial Number = " + myResponse.productAreaSerialNumber);
                Console.WriteLine("PD Product Asset Tag = "
                    + myResponse.productAreaAssetTag);
                Console.WriteLine("--------------------------------------");
                Console.WriteLine();

                Console.WriteLine("Power Distribution Board (PDB) Multi Record Info Area");
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Manufacturer = " + myResponse.manufacturer);
                Console.WriteLine("Custom Fields");
                Console.WriteLine(string.Join("\n", myResponse.multiRecordFields.ToArray()));
            }
        }