Fix redfish_facts GetPsuInventory command not returning correct output (#52675)

* Move GetPsuInventory from Systems category to Chassis category

* Change get_psu_inventory to search through Chassis instead of Systems and PoweredBy for PowerSupplies

* Remove GetPsuInventory from Examples

* remove trailing whitespace

* Change boolean check from '!= None' to 'is not None'

* Don't include 'Absent' PSUs in get_psu_inventory()

* Add check to see if Power key is in Chassis before proceeding

* remove trailing whitespace

* Add continue step for when powersupply property is not found, and check if resulting entries is empty, returning message if nothing was found rather than an empty list
pull/53390/head
Xander Madsen 6 years ago committed by John R Barker
parent 65424dd614
commit d0db99e023

@ -911,42 +911,53 @@ class RedfishUtils(object):
result = {} result = {}
psu_list = [] psu_list = []
psu_results = [] psu_results = []
key = "PoweredBy" key = "PowerSupplies"
# Get these entries, but does not fail if not found # Get these entries, but does not fail if not found
properties = ['Name', 'Model', 'SerialNumber', 'PartNumber', 'Manufacturer', properties = ['Name', 'Model', 'SerialNumber', 'PartNumber', 'Manufacturer',
'FirmwareVersion', 'PowerCapacityWatts', 'PowerSupplyType', 'FirmwareVersion', 'PowerCapacityWatts', 'PowerSupplyType',
'Status'] 'Status']
# Get a list of all PSUs and build respective URIs # Get a list of all Chassis and build URIs, then get all PowerSupplies
response = self.get_request(self.root_uri + self.systems_uri) # from each Power entry in the Chassis
if response['ret'] is False: chassis_uri_list = self.chassis_uri_list
return response for chassis_uri in chassis_uri_list:
result['ret'] = True response = self.get_request(self.root_uri + chassis_uri)
data = response['data']
if 'Links' not in data:
return {'ret': False, 'msg': "Property not found"}
if key not in data[u'Links']:
return {'ret': False, 'msg': "Key %s not found" % key}
for psu in data[u'Links'][u'PoweredBy']:
psu_list.append(psu[u'@odata.id'])
for p in psu_list:
psu = {}
uri = self.root_uri + p
response = self.get_request(uri)
if response['ret'] is False: if response['ret'] is False:
return response return response
result['ret'] = True result['ret'] = True
data = response['data'] data = response['data']
for property in properties: if 'Power' in data:
if property in data: power_uri = data[u'Power'][u'@odata.id']
psu[property] = data[property] else:
psu_results.append(psu) continue
response = self.get_request(self.root_uri + power_uri)
data = response['data']
if key not in data:
return {'ret': False, 'msg': "Key %s not found" % key}
psu_list = data[key]
for psu in psu_list:
psu_not_present = False
psu_data = {}
for property in properties:
if property in psu:
if psu[property] is not None:
if property == 'Status':
if 'State' in psu[property]:
if psu[property]['State'] == 'Absent':
psu_not_present = True
psu_data[property] = psu[property]
if psu_not_present:
continue
psu_results.append(psu_data)
result["entries"] = psu_results result["entries"] = psu_results
if not result["entries"]:
return {'ret': False, 'msg': "No PowerSupply objects found"}
return result return result
def get_system_inventory(self): def get_system_inventory(self):

@ -73,7 +73,7 @@ EXAMPLES = '''
- name: Get several inventories - name: Get several inventories
redfish_facts: redfish_facts:
category: Systems category: Systems
command: GetNicInventory,GetPsuInventory,GetBiosAttributes command: GetNicInventory,GetBiosAttributes
baseuri: "{{ baseuri }}" baseuri: "{{ baseuri }}"
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
@ -129,10 +129,10 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.redfish_utils import RedfishUtils from ansible.module_utils.redfish_utils import RedfishUtils
CATEGORY_COMMANDS_ALL = { CATEGORY_COMMANDS_ALL = {
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory", "Systems": ["GetSystemInventory", "GetCpuInventory",
"GetNicInventory", "GetStorageControllerInventory", "GetNicInventory", "GetStorageControllerInventory",
"GetDiskInventory", "GetBiosAttributes", "GetBootOrder"], "GetDiskInventory", "GetBiosAttributes", "GetBootOrder"],
"Chassis": ["GetFanInventory"], "Chassis": ["GetFanInventory", "GetPsuInventory"],
"Accounts": ["ListUsers"], "Accounts": ["ListUsers"],
"Update": ["GetFirmwareInventory"], "Update": ["GetFirmwareInventory"],
"Manager": ["GetManagerNicInventory", "GetLogs"], "Manager": ["GetManagerNicInventory", "GetLogs"],
@ -211,8 +211,6 @@ def main():
for command in command_list: for command in command_list:
if command == "GetSystemInventory": if command == "GetSystemInventory":
result["system"] = rf_utils.get_system_inventory() result["system"] = rf_utils.get_system_inventory()
elif command == "GetPsuInventory":
result["psu"] = rf_utils.get_psu_inventory()
elif command == "GetCpuInventory": elif command == "GetCpuInventory":
result["cpu"] = rf_utils.get_cpu_inventory() result["cpu"] = rf_utils.get_cpu_inventory()
elif command == "GetNicInventory": elif command == "GetNicInventory":
@ -235,6 +233,8 @@ def main():
for command in command_list: for command in command_list:
if command == "GetFanInventory": if command == "GetFanInventory":
result["fan"] = rf_utils.get_fan_inventory() result["fan"] = rf_utils.get_fan_inventory()
elif command == "GetPsuInventory":
result["psu"] = rf_utils.get_psu_inventory()
elif category == "Accounts": elif category == "Accounts":
# execute only if we find an Account service resource # execute only if we find an Account service resource

Loading…
Cancel
Save