Handling Actions and Managing Software Updates
This document explains the flow of handling various actions and managing software updates and configurations for AIX systems. It covers the steps involved in validating and formatting parameters, computing request types and names, performing preview and download actions, and installing updates.
The flow starts with the main
suma_download
oslevel
Flow drill down
Handling Different Actions
First, the main
if action == 'list':
suma_params['task_id'] = module.params['task_id']
suma_list()
elif action == 'edit':
suma_params['task_id'] = module.params['task_id']
suma_params['sched_time'] = module.params['sched_time']
suma_edit()
elif action == 'unschedule':
suma_params['task_id'] = module.params['task_id']
suma_unschedule()
elif action == 'delete':
suma_params['task_id'] = module.params['task_id']
suma_delete()
elif action == 'run':
suma_params['task_id'] = module.params['task_id']
suma_run()
Validating and Formatting oslevel
Next, the suma_download
oslevel
# Check oslevel format
if not suma_params['oslevel'].strip() or suma_params['oslevel'].upper() == 'LATEST':
suma_params['oslevel'] = 'Latest'
else:
if re.match(r"^[0-9]{4}(|-00|-00-00|-00-00-0000)$", suma_params['oslevel']):
msg_oslevel = suma_params['oslevel']
msg = f"Bad parameter: oslevel is '{msg_oslevel}', \
specify a non 0 value for the Technical Level or the Service Pack"
module.log(msg)
results['msg'] = msg
module.fail_json(**results)
elif not re.match(r"^[0-9]{4}-[0-9]{2}(|-[0-9]{2}|-[0-9]{2}-[0-9]{4})$",
suma_params['oslevel']):
msg_oslevel = suma_params['oslevel']
msg = f"Bad parameter: oslevel is '{msg_oslevel}', \
should repect the format: xxxx-xx or xxxx-xx-xx or xxxx-xx-xx-xxxx"
module.log(msg)
results['msg'] = msg
module.fail_json(**results)
Computing Request Type
Then, the suma_download
oslevel
rq_type = compute_rq_type(suma_params['oslevel'], suma_params['last_sp'])
if rq_type == 'ERROR':
msg_oslevel = suma_params['oslevel']
msg = f"Bad parameter: oslevel is '{msg_oslevel}', parsing error"
module.log(msg)
results['msg'] = msg
module.fail_json(**results)
suma_params['RqType'] = rq_type
module.debug(f"SUMA req Type: {rq_type}")
Computing Request Name
Moving on, the suma_download
suma_params['RqName'] = compute_rq_name(rq_type, suma_params['oslevel'], suma_params['last_sp'])
debug_rqname = suma_params['RqName']
module.debug(f"Suma req Name: {debug_rqname}")
Preview and Download Actions
Next, the suma_download
stdout = suma_command('Preview')
module.debug(f"SUMA preview stdout:{stdout}")
# parse output to see if there is something to download
downloaded = 0
failed = 0
skipped = 0
for line in stdout.rstrip().splitlines():
line = line.rstrip()
matched = re.match(r"^\s+(\d+)\s+downloaded$", line)
if matched:
downloaded = int(matched.group(1))
continue
matched = re.match(r"^\s+(\d+)\s+failed$", line)
if matched:
failed = int(matched.group(1))
continue
matched = re.match(r"^\s+(\d+)\s+skipped$", line)
if matched:
skipped = int(matched.group(1))
Installing Updates
Finally, if the download_only
suma_download
install_all_updates
if not suma_params['download_only']:
cmd_DLTarget = suma_params['DLTarget']
cmd = f"/usr/sbin/install_all_updates -Yd {cmd_DLTarget}"
module.debug(f"SUMA command:{cmd}")
results['meta']['messages'].append(msg)
rc, stdout, stderr = module.run_command(cmd)
results['cmd'] = cmd
results['stdout'] = stdout
results['stderr'] = stderr
results['changed'] = True
if rc != 0:
msg = f"Suma install command '{cmd}' failed with return code {rc}."
module.log(msg + f", stderr:{stderr}, stdout:{stdout}")
results['msg'] = msg
module.fail_json(**results)
module.log(f"Suma install command output: {stdout}")
Computing Request Name Details
Diving into, the compute_rq_name
def compute_rq_name(rq_type, oslevel, last_sp):
"""
Compute rq_name.
if oslevel is a TL then return the SP extratced from it
if oslevel is a complete SP (12 digits) then return RqName = oslevel
if oslevel is an incomplete SP (8 digits) or equal Latest then execute
a metadata suma request to find the complete SP level (12 digits).
The return format depends on rq_type value,
- for Latest: return None
- for TL: return the TL value in the form xxxx-xx
- for SP: return the SP value in the form xxxx-xx-xx-xxxx
arguments:
rq_type type of request, can be Latest, SP or TL
oslevel requested oslevel
last_sp if set get the latest SP level for specified oslevel
note:
Exits with fail_json in case of error
return:
rq_name value
"""
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human