Skip to content

Commit aa73638

Browse files
Merge pull request #132 from chiranthanmv/payload-unit-test
Adds Payload unit test and doc notes
2 parents 0d29b69 + 41dd384 commit aa73638

File tree

3 files changed

+308
-7
lines changed

3 files changed

+308
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ install-unit-test-requirements:
7676

7777
.PHONY: install-ansible-lint
7878
install-ansible-lint:
79-
python -m pip install ansible-lint ansible-compat==25.6.0
79+
python -m pip install ansible-lint
8080

8181
######################################################################################
8282
# testing targets

plugins/modules/platform_update.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
notes:
2121
- The current version supports IBM Fix Central website as the update source .
2222
- Support for additional update sources will be added in future releases.
23+
- For any update operation, if the Ansible response status is C(ok) with C(changed) set to C(false)
24+
and the result is C(COMPLETED_WITH_ERROR) with the reason C("update not available"),
25+
it means the target is already up-to-date.
2326
description:
2427
- This module allows updating System Firmware, VIOS, SR-IOV adapters, and I/O adapters either individually or through a single consolidated update flow.
2528
- This operations can be configured using I(platform_config) parameter.
@@ -112,7 +115,7 @@
112115
description:
113116
- ID of the specific adapter to be updated.
114117
- Required only when C(all) is not specified.
115-
type: str
118+
type: int
116119
subtype:
117120
description:
118121
- Specifies the level of update to apply.
@@ -126,7 +129,9 @@
126129
type: dict
127130
suboptions:
128131
is_quick_evac:
129-
description: Whether to enable quick evacuation.
132+
description:
133+
- Indicates whether to perform a quick evacuation during partition migration.
134+
- Must always be set to C(true) when performing partition migration.
130135
type: bool
131136
destination_managed_system:
132137
description: Target managed system name.
@@ -211,7 +216,7 @@
211216
update_type: NoUpdate
212217
update_order: 1
213218
sriov_adapter_update:
214-
- adapter_id: "ent0"
219+
- adapter_id: 1
215220
subtype: DriverOnly
216221
217222
- name: Update all SR-IOV adapters (Adapter) using IBM Fix Central (No Firware Update)
@@ -867,13 +872,16 @@ def platform_update(module):
867872
module.fail_json(msg=error_msg)
868873

869874
for adapter in sriov_update:
875+
if adapter.get('all') is False:
876+
adapter['all'] = None
870877
if adapter.get('all'):
871878
available_adapter_id = output.get("SRIOVAdapterUpdate", {}).get("AdapterID")
872879
else:
873880
adapter_id = adapter.get("adapter_id")
874-
if int(adapter_id) not in output.get("SRIOVAdapterUpdate", {}).get("AdapterID"):
881+
if adapter_id not in output.get("SRIOVAdapterUpdate", {}).get("AdapterID"):
875882
error_msg = f"SRIOVAdapter with ID {adapter_id} is not present for system {system_name}"
876883
module.fail_json(msg=error_msg)
884+
adapter['adapter_id'] = str(adapter_id)
877885

878886
# IO Adapter Avaiabillty check
879887
if all_io_updates:
@@ -892,7 +900,7 @@ def platform_update(module):
892900
if output.get('IOAdapterUpdate', {}).get(vios_id, []):
893901
available_io_updates = {'IOAdapterUpdate': {vios_id: output.get('IOAdapterUpdate', {}).get(vios_id, [])}}
894902
else:
895-
error_msg = f"No available I/O adapters found for VIOS {output.get('vios_name')}"
903+
error_msg = f"No available I/O adapters found for VIOS {io_update.get('vios_name')}"
896904
module.fail_json(msg=error_msg)
897905
else:
898906
io_id = str(io_update.get('vios_id')).zfill(3)
@@ -1157,7 +1165,7 @@ def run_module():
11571165
elements='dict',
11581166
options=dict(
11591167
all=dict(type="bool"),
1160-
adapter_id=dict(type='str'),
1168+
adapter_id=dict(type='int'),
11611169
subtype=dict(type='str', choices=['DriverOnly', 'Adapter'])
11621170
)
11631171
)

tests/unit/modules/test_platform_update.py

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,290 @@ def fail_json(self, msg):
217217

218218
]
219219

220+
platform_config_test_data1 = [
221+
222+
# VIOS update with IO adapter update (list of devices)
223+
(
224+
{
225+
'platform_config': {
226+
'vios_update': [
227+
{
228+
'update_type': 'Update',
229+
'vios_name': 'vios2',
230+
'update_order': 2,
231+
'vios_image_name': 'image_name',
232+
'io_adapter_update': [
233+
{
234+
'all': None,
235+
'device': 'ent0',
236+
'repository': 'IBMWebsite'
237+
},
238+
{
239+
'all': None,
240+
'device': 'ent1',
241+
'repository': 'IBMWebsite'
242+
}
243+
]
244+
}
245+
]
246+
}
247+
},
248+
{
249+
'platform_config': {
250+
'VIOSUpdate': [
251+
{
252+
'UpdateType': 'Update',
253+
'VIOSName': 'vios2',
254+
'UpdateOrder': 2,
255+
'Name': 'image_name',
256+
'IOAdapterUpdate': [
257+
{
258+
'Device': 'ent0',
259+
'Repository': 'IBMWebsite'
260+
},
261+
{
262+
'Device': 'ent1',
263+
'Repository': 'IBMWebsite'
264+
}
265+
]
266+
}
267+
]
268+
}
269+
}
270+
),
271+
272+
# Multiple VIOS update
273+
(
274+
{
275+
'platform_config': {
276+
'vios_update': [
277+
{
278+
'update_type': 'Update',
279+
'vios_name': 'vios2',
280+
'update_order': 1,
281+
'vios_image_name': 'image_name',
282+
'io_adapter_update': [
283+
{
284+
'all': None,
285+
'device': ['ent0', 'ent1'],
286+
'repository': 'IBMWebsite'
287+
}
288+
]
289+
},
290+
{
291+
'update_type': 'Update',
292+
'vios_name': 'vios1',
293+
'update_order': 2,
294+
'vios_image_name': 'image_name',
295+
'io_adapter_update': None
296+
}
297+
]
298+
}
299+
},
300+
{
301+
'platform_config': {
302+
'VIOSUpdate': [
303+
{
304+
'UpdateType': 'Update',
305+
'VIOSName': 'vios2',
306+
'UpdateOrder': 1,
307+
'Name': 'image_name',
308+
'IOAdapterUpdate': [
309+
{
310+
'Device': ['ent0', 'ent1'],
311+
'Repository': 'IBMWebsite'
312+
}
313+
]
314+
},
315+
{
316+
'UpdateType': 'Update',
317+
'VIOSName': 'vios1',
318+
'UpdateOrder': 2,
319+
'Name': 'image_name',
320+
}
321+
]
322+
}
323+
}
324+
),
325+
326+
# System firmware update
327+
(
328+
{
329+
'platform_config': {
330+
'system_firmware_update': {
331+
'update_type': 'Update',
332+
'update_order': 1,
333+
'repository': 'IBMWebsite',
334+
'level': 'latest',
335+
'sriov_adapter_update': None
336+
}
337+
}
338+
},
339+
{
340+
'platform_config': {
341+
'SystemFirmwareUpdate': {
342+
'UpdateType': 'Update',
343+
'UpdateOrder': 1,
344+
'Repository': 'IBMWebsite',
345+
'Level': 'latest',
346+
}
347+
}
348+
}
349+
),
350+
351+
# Sriov Adapter Update
352+
(
353+
{
354+
'platform_config': {
355+
'system_firmware_update': {
356+
'update_type': 'NoUpdate',
357+
'update_order': 1,
358+
'repository': None,
359+
'level': 'latest',
360+
'sriov_adapter_update': [
361+
{
362+
'all': None,
363+
'adapter_id': '1',
364+
'subtype': 'Adapter'
365+
}
366+
]
367+
}
368+
}
369+
},
370+
{
371+
'platform_config': {
372+
'SystemFirmwareUpdate': {
373+
'UpdateType': 'NoUpdate',
374+
'UpdateOrder': 1,
375+
'Level': 'latest',
376+
'SRIOVAdapterUpdate': [
377+
{
378+
'AdapterID': '1',
379+
'SubType': 'adapterdriver,adapter'
380+
}
381+
]
382+
}
383+
}
384+
}
385+
),
386+
387+
# Multiple Sriov Adapter Update
388+
(
389+
{
390+
'platform_config': {
391+
'system_firmware_update': {
392+
'update_type': 'NoUpdate',
393+
'update_order': 1,
394+
'repository': None,
395+
'level': 'latest',
396+
'sriov_adapter_update': [
397+
{
398+
'all': None,
399+
'adapter_id': '1',
400+
'subtype': 'Adapter'
401+
},
402+
{
403+
'all': None,
404+
'adapter_id': '2',
405+
'subtype': 'DriverOnly'
406+
}
407+
]
408+
}
409+
}
410+
},
411+
{
412+
'platform_config': {
413+
'SystemFirmwareUpdate': {
414+
'UpdateType': 'NoUpdate',
415+
'UpdateOrder': 1,
416+
'Level': 'latest',
417+
'SRIOVAdapterUpdate': [
418+
{
419+
'AdapterID': '1',
420+
'SubType': 'adapterdriver,adapter'
421+
},
422+
{
423+
'AdapterID': '2',
424+
'SubType': 'adapterdriver'
425+
}
426+
]
427+
}
428+
}
429+
}
430+
),
431+
432+
# Partition migration with defaults
433+
(
434+
{
435+
'platform_config': {
436+
'partition_migration': {
437+
'is_quick_evac': True,
438+
'destination_managed_system': 'sysA',
439+
'leave_partition_in_target': False
440+
}
441+
}
442+
},
443+
{
444+
'platform_config': {
445+
'PartitionMigration': {
446+
'IsQuickEvac': True,
447+
'DestinationManagedSystem': 'sysA',
448+
'LeavePartitionInTarget': False
449+
}
450+
}
451+
}
452+
),
453+
454+
# Mixed config: system firmware + VIOS update + partition migration
455+
(
456+
{
457+
'platform_config': {
458+
'system_firmware_update': {
459+
'update_type': 'Update',
460+
'update_order': 1,
461+
'repository': 'IBMWebsite',
462+
'level': 'FW940',
463+
'SRIOVAdapterUpdate': None
464+
},
465+
'vios_update': [
466+
{
467+
'update_type': 'Update',
468+
'vios_name': 'vios3',
469+
'update_order': 1
470+
}
471+
],
472+
'partition_migration': {
473+
'is_quick_evac': True,
474+
'destination_managed_system': 'sysB',
475+
'LeavePartitionInTarget': False
476+
}
477+
}
478+
},
479+
{
480+
'platform_config': {
481+
'SystemFirmwareUpdate': {
482+
'UpdateType': 'Update',
483+
'UpdateOrder': 1,
484+
'Repository': 'IBMWebsite',
485+
'Level': 'FW940',
486+
},
487+
'VIOSUpdate': [
488+
{
489+
'UpdateType': 'Update',
490+
'VIOSName': 'vios3',
491+
'UpdateOrder': 1
492+
}
493+
],
494+
'PartitionMigration': {
495+
'IsQuickEvac': True,
496+
'DestinationManagedSystem': 'sysB',
497+
'LeavePartitionInTarget': False
498+
}
499+
}
500+
}
501+
)
502+
]
503+
220504

221505
def common_mock_setup(mocker):
222506
hmc_platform_update = importlib.import_module(IMPORT_HMC_PLATFORM_UPDATE)
@@ -250,3 +534,12 @@ def test_call_platform_config(mocker, platform_config_test_input, expectedError)
250534

251535
assert "ParameterError:" in str(excinfo.value)
252536
assert expectedError in str(excinfo.value)
537+
538+
539+
@pytest.mark.parametrize("platform_config_test_input, expected", platform_config_test_data1)
540+
def test_call_platform_config_payload(mocker, platform_config_test_input, expected):
541+
hmc_module = common_mock_setup(mocker)
542+
543+
cleanup_data = hmc_module.cleanup_entries(platform_config_test_input)
544+
result = hmc_module.map_entries(cleanup_data)
545+
assert result == expected

0 commit comments

Comments
 (0)