def test_api_redfish_processor(self):
        """
        Tests the /Systems/{identifier}/processors APIs with UCS nodes
        :return:
        """
        ucsComputeList = ucs_common.get_ucs_compute_id_list()
        errUrls = ''

        for node in ucsComputeList:
            url = "/redfish/v1/Systems/{}/Processors".format(node)
            api_data = fit_common.rackhdapi(url)
            if api_data['status'] != 200:
                errUrls += url + ' returned status ' + str(api_data['status']) + \
                    ', Expected 200,\n'
                continue
            if len(api_data['json']['Members']) == 0:
                errUrls += url + ' CPU count is 0,\n'
                continue
            for member in api_data['json']['Members']:
                _url = member['@odata.id']
                _api_data = fit_common.rackhdapi(_url)
                if _api_data['status'] != 200:
                    errUrls += _url + ' returned status ' + str(api_data['status']) + \
                        ', Expected 200,\n'
                _body = _api_data['json']
                schema = {
                    "str": ["Socket", "ProcessorType", "ProcessorArchitecture",
                            "InstructionSet", "Manufacturer", "Model"],
                    "int": ["MaxSpeedMHz", "TotalCores", "TotalThreads"]
                }
                errData = ucs_common.validate_redfish_data_payload(_body, schema, url)
                if errData:
                    errUrls += errData
        self.assertEqual(len(errUrls), 0, errUrls)
    def test_api_redfish_chassis(self):
        """
        Tests the redfish /Chassis APIs with UCS nodes
        :return:
        """
        ucsEnclList = ucs_common.get_ucs_encl_id_list()
        errUrls = ''

        api_data = fit_common.rackhdapi('/redfish/v1/Chassis')
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
        for chassis in api_data['json']['Members']:
            url = chassis['@odata.id']
            id = url[len('/redfish/v1/Chassis/'):]
            if id in ucsEnclList:
                ucsEnclList.remove(id)
                api_data = fit_common.rackhdapi(url)
                if api_data['status'] != 200:
                    errUrls += url + ' returned status ' + str(api_data['status']) + ',\n'
                _body = api_data['json']
                schema = {
                    "str": ["Name", "ChassisType", "Manufacturer", "Model",
                            "SerialNumber", "IndicatorLED"],
                    "dict": ["Thermal", "Power", "Links"]
                }
                errData = ucs_common.validate_redfish_data_payload(_body, schema, url)
                if errData:
                    errUrls += errData
        self.assertEqual(len(ucsEnclList), 0, 'not all UCS chassis were listed under /chassis')
        self.assertEqual(len(errUrls), 0, errUrls)
    def test_api_redfish_system(self):
        """
        Tests the redfish /Systems APIs with UCS nodes
        :return:
        """
        ucsComputeList = ucs_common.get_ucs_compute_id_list()
        errUrls = ''

        api_data = fit_common.rackhdapi('/redfish/v1/Systems')
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
        for chassis in api_data['json']['Members']:
            url = chassis['@odata.id']
            id = url[len('/redfish/v1/Systems/'):]
            if id in ucsComputeList:
                ucsComputeList.remove(id)
                api_data = fit_common.rackhdapi(url)
                if api_data['status'] != 200:
                    errUrls += url + ' returned status ' + str(api_data['status']) + ',\n'
                _body = api_data['json']
                schema = {
                    "str": ["Name", "SystemType", "Manufacturer", "Model", "SerialNumber",
                            "IndicatorLED", "PowerState", "BiosVersion"],
                    "dict": ["ProcessorSummary", "MemorySummary", "Actions", "Processors",
                             "EthernetInterfaces", "SimpleStorage", "LogServices",
                             "Links", "Storage"]
                }
                errData = ucs_common.validate_redfish_data_payload(_body, schema, url)
                if errData:
                    errUrls += errData
        self.assertEqual(len(ucsComputeList), 0, 'not all UCS computes were listed under /System')
        self.assertEqual(len(errUrls), 0, errUrls)
    def test_api_redfish_processor(self):
        """
        Tests the /Systems/{identifier}/processors APIs with UCS nodes
        :return:
        """
        ucsComputeList = ucs_common.get_ucs_compute_id_list()
        errUrls = ''

        for node in ucsComputeList:
            url = "/redfish/v1/Systems/{}/Processors".format(node)
            api_data = fit_common.rackhdapi(url)
            if api_data['status'] != 200:
                errUrls += url + ' returned status ' + str(api_data['status']) + \
                    ', Expected 200,\n'
                continue
            if len(api_data['json']['Members']) == 0:
                errUrls += url + ' CPU count is 0,\n'
                continue
            for member in api_data['json']['Members']:
                _url = member['@odata.id']
                _api_data = fit_common.rackhdapi(_url)
                if _api_data['status'] != 200:
                    errUrls += _url + ' returned status ' + str(api_data['status']) + \
                        ', Expected 200,\n'
                _body = _api_data['json']
                schema = {
                    "str": ["Socket", "ProcessorType", "ProcessorArchitecture",
                            "InstructionSet", "Manufacturer", "Model"],
                    "int": ["MaxSpeedMHz", "TotalCores", "TotalThreads"]
                }
                errData = ucs_common.validate_redfish_data_payload(_body, schema, url)
                if errData:
                    errUrls += errData
        self.assertEqual(len(errUrls), 0, errUrls)
    def test_api_redfish_system(self):
        """
        Tests the redfish /Systems APIs with UCS nodes
        :return:
        """
        ucsComputeList = ucs_common.get_ucs_compute_id_list()
        errUrls = ''

        api_data = fit_common.rackhdapi('/redfish/v1/Systems')
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
        for chassis in api_data['json']['Members']:
            url = chassis['@odata.id']
            id = url[len('/redfish/v1/Systems/'):]
            if id in ucsComputeList:
                ucsComputeList.remove(id)
                api_data = fit_common.rackhdapi(url)
                if api_data['status'] != 200:
                    errUrls += url + ' returned status ' + str(api_data['status']) + ',\n'
                _body = api_data['json']
                schema = {
                    "str": ["Name", "SystemType", "Manufacturer", "Model", "SerialNumber",
                            "IndicatorLED", "PowerState", "BiosVersion"],
                    "dict": ["ProcessorSummary", "MemorySummary", "Actions", "Processors",
                             "EthernetInterfaces", "SimpleStorage", "LogServices",
                             "Links", "Storage"]
                }
                errData = ucs_common.validate_redfish_data_payload(_body, schema, url)
                if errData:
                    errUrls += errData
        self.assertEqual(len(ucsComputeList), 0, 'not all UCS computes were listed under /System')
        self.assertEqual(len(errUrls), 0, errUrls)
    def test_api_redfish_chassis(self):
        """
        Tests the redfish /Chassis APIs with UCS nodes
        :return:
        """
        ucsEnclList = ucs_common.get_ucs_encl_id_list()
        errUrls = ''

        api_data = fit_common.rackhdapi('/redfish/v1/Chassis')
        self.assertEqual(api_data['status'], 200,
                         'Incorrect HTTP return code, expected 200, got:' + str(api_data['status']))
        for chassis in api_data['json']['Members']:
            url = chassis['@odata.id']
            id = url[len('/redfish/v1/Chassis/'):]
            if id in ucsEnclList:
                ucsEnclList.remove(id)
                api_data = fit_common.rackhdapi(url)
                if api_data['status'] != 200:
                    errUrls += url + ' returned status ' + str(api_data['status']) + ',\n'
                _body = api_data['json']
                schema = {
                    "str": ["Name", "ChassisType", "Manufacturer", "Model",
                            "SerialNumber", "IndicatorLED"],
                    "dict": ["Thermal", "Power", "Links"]
                }
                errData = ucs_common.validate_redfish_data_payload(_body, schema, url)
                if errData:
                    errUrls += errData
        self.assertEqual(len(ucsEnclList), 0, 'not all UCS chassis were listed under /chassis')
        self.assertEqual(len(errUrls), 0, errUrls)
 def validate_simple_storage_data(self, body, url):
     """
     Validate simple storage non-empty data body
     """
     errData = ''
     schema = {"str": ["Name", "Id", "Description"], "list": ["Devices"]}
     errStr = ucs_common.validate_redfish_data_payload(body, schema, url)
     if errStr:
         errData += errStr
     if not re.compile('^\w{0,}_\w{1,3}_\w{1,}_\w{1}$').match(body['Id']):
         errData += "Invalid simpleStorage Id \"{}\" for {}, \n".format(
             body['Id'], url)
     return errData
 def validate_simple_storage_data(self, body, url):
     """
     Validate simple storage non-empty data body
     """
     errData = ''
     schema = {
         "str": ["Name", "Id", "Description"],
         "list": ["Devices"]
     }
     errStr = ucs_common.validate_redfish_data_payload(body, schema, url)
     if errStr:
         errData += errStr
     if not re.compile('^\w{0,}_\w{1,3}_\w{1,}_\w{1}$').match(body['Id']):
         errData += "Invalid simpleStorage Id \"{}\" for {}, \n".format(body['Id'], url)
     return errData