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
This commit is contained in:
Xander Madsen 2019-03-06 07:43:23 -05:00 committed by John R Barker
parent 65424dd614
commit d0db99e023
2 changed files with 40 additions and 29 deletions

View file

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

View file

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