Skip to content

Commit

Permalink
Fix redfish_facts GetPsuInventory command not returning correct output (
Browse files Browse the repository at this point in the history
ansible#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
  • Loading branch information
xmadsen authored and gundalow committed Mar 6, 2019
1 parent 65424dd commit d0db99e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
59 changes: 35 additions & 24 deletions lib/ansible/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,42 +911,53 @@ def get_psu_inventory(self):
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):
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/remote_management/redfish/redfish_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
- name: Get several inventories
redfish_facts:
category: Systems
command: GetNicInventory,GetPsuInventory,GetBiosAttributes
command: GetNicInventory,GetBiosAttributes
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
Expand Down Expand Up @@ -129,10 +129,10 @@
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"],
Expand Down Expand Up @@ -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":
Expand All @@ -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
Expand Down

0 comments on commit d0db99e

Please sign in to comment.