Skip to main content

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 function handling different actions like listing, editing, unscheduling, deleting, running, configuring, downloading, and previewing. Each action corresponds to a specific function call. The suma_download function then validates and formats the oslevel parameter, computes the request type and name, performs preview and download actions, and finally installs the updates if required.

Flow drill down


Handling Different Actions

First, the main function handles different actions such as 'list', 'edit', 'unschedule', 'delete', 'run', 'config', 'default', 'download', and 'preview'. Each action corresponds to a specific function call that manages software updates and configurations for AIX systems.

    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 function validates and formats the oslevel parameter. This ensures that the oslevel is in the correct format before proceeding with the download or preview actions.

    # 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 function computes the SUMA request type based on the oslevel property. This step is crucial for determining the type of software update or configuration request.

    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 function computes the SUMA request name based on metadata information. This name is used to identify the specific request for software updates or configurations.

    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 function performs the preview and download actions. It first runs a preview to check if there are any updates to download. If there are updates, it proceeds with the download action.

    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 parameter is not set, the suma_download function installs the downloaded updates using the install_all_updates command. This step ensures that the updates are applied to the AIX system.

    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 function computes the request name based on the request type and oslevel. It handles different formats of oslevel and ensures that the correct request name is generated for the SUMA request.

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