Skip to content

Commit

Permalink
Distinguish severities in ansible playbooks and improve message output
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Waltlova <[email protected]>
  • Loading branch information
andywaltlova committed Feb 3, 2024
1 parent 179d6bf commit a3b229a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
39 changes: 37 additions & 2 deletions playbooks/leapp_preupgrade_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
ansible.builtin.set_fact:
report_content: "{{ report_content_raw.content | b64decode }}"

- name: Set total problems count
ansible.builtin.set_fact:
total_problems_count: "{{ report_content.entries | length }}"

- name: Set inhibitor count
ansible.builtin.set_fact:
inhibitor_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'inhibitor') | list | length }}"
Expand All @@ -182,12 +186,43 @@
ansible.builtin.set_fact:
error_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'error') | list | length }}"

- name: Transform severities in leapp report to distinguish errors and inhibitors from other high risks entries
set_fact:
report_content_edited: >-
{{
{
"entries": report_content.entries | default([]) | map(
lambda entry: entry | combine(
{"severity": "error"} if "error" in entry.groups else
{"severity": "inhibitor"} if "inhibitor" in entry.groups else {}
)
) | list
}
}}
- name: Set message if inhibitors or errors present
set_fact:
message: >-
"The upgrade cannot proceed.
Your system has {{ error_count }} error{{ 's' if error_count != 1 else '' }}
and {{ inhibitor_count }} inhibitor{{ 's' if inhibitor_count != 1 else '' }}
out of {{ total_problems_count }} potential problems."
when: inhibitor_count != 0 or error_count != 0


- name: Set message if no inhibitors and no errors present
set_fact:
message: >-
{{ 'No problems found. The system is ready for upgrade.' if total_problems_count == 0
else 'The upgrade can proceed. However, there is one or more warnings about issues that might occur after the upgrade.'}}
when: inhibitor_count == 0 and error_count == 0

- name: Set result
ansible.builtin.set_fact:
task_results:
report_json: "{{ report_content }}"
report_json: "{{ report_content_edited }}"
report: "{{ report_content_txt_raw.content | b64decode }}"
message: "Your system has {{ error_count }} errors and {{ inhibitor_count }} inhibitors out of {{report_content.entries | length}} potential problems."
message: "{{ message }}"
alert: "{{ (inhibitor_count | int > 0) or (error_count | int > 0) }}"

- name: Start insights-client for immediate data collection of leapp-report
Expand Down
5 changes: 2 additions & 3 deletions playbooks/leapp_preupgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,9 @@
)
)
if reboot_required:
problem_info = message.lstrip("Your system has ").rstrip(".")
message = (
"System will be upgraded (%s). Rebooting system in 1 minute."
% problem_info
"System will be upgraded. Rebooting system in 1 minute. "
"After reboot check inventory to verify the system is registered with new RHEL major version."
)
alert = inhibitor_count > 0 or error_count > 0
status = (
Expand Down
23 changes: 20 additions & 3 deletions playbooks/leapp_upgrade_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,33 @@
ansible.builtin.set_fact:
report_content: "{{ report_content_raw.content | b64decode }}"

- name: Transform severities in leapp report to distinguish errors and inhibitors from other high risks entries
set_fact:
report_content_edited: >-
{{
{
"entries": report_content.entries | default([]) | map(
lambda entry: entry | combine(
{"severity": "error"} if "error" in entry.groups else
{"severity": "inhibitor"} if "inhibitor" in entry.groups else {}
)
) | list
}
}}
- name: Prepare final result
block:
- name: Set default fail message
set_fact:
message: "Upgrade of your system failed. Please check the /var/log/leapp/leapp-report.json and /var/log/rhc-worker-playbook/ansible logs for details."
message: >-
"The upgrade cannot proceed. You must resolve existing issues to perform the upgrade.
Please check the /var/log/leapp/leapp-report.json and /var/log/rhc-worker-playbook/ansible logs for details."
- name: Set message if leapp upgrade succeeded
set_fact:
message: "Upgrade ran successfully. System has now been rebooted. If everything works fine, the system is running the new RHEL version after reboot. Check inventory to verify the system is\
\ in new major version."
message: >-
"No problems found. The system will be upgraded. Rebooting system in 1 minute.
After reboot check inventory to verify the RHEL system is registered with new major version."
when: is_leapp_upgrade_successful is true

- name: Set report content as empty if upgrade was successful
Expand Down
5 changes: 2 additions & 3 deletions playbooks/leapp_upgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,9 @@
)
)
if reboot_required:
problem_info = message.lstrip("Your system has ").rstrip(".")
message = (
"System will be upgraded (%s). Rebooting system in 1 minute."
% problem_info
"System will be upgraded. Rebooting system in 1 minute. "
"After reboot check inventory to verify the system is registered with new RHEL major version."
)
alert = inhibitor_count > 0 or error_count > 0
status = (
Expand Down
5 changes: 2 additions & 3 deletions scripts/leapp_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,9 @@ def parse_results(output, reboot_required=False):
)
)
if reboot_required:
problem_info = message.lstrip("Your system has ").rstrip(".")
message = (
"System will be upgraded (%s). Rebooting system in 1 minute."
% problem_info
"System will be upgraded. Rebooting system in 1 minute. "
"After reboot check inventory to verify the system is registered with new RHEL major version."
)
alert = inhibitor_count > 0 or error_count > 0
status = (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_gather_report_files_exist_with_reboot(mock_find_level, mock_exists):
assert output.report_json.get("test") == "hi"
assert (
output.message
== "System will be upgraded (0 errors and 0 inhibitors out of 0 potential problems). Rebooting system in 1 minute."
== "System will be upgraded. Rebooting system in 1 minute. After reboot check inventory to verify the system is registered with new RHEL major version."
)


Expand Down

0 comments on commit a3b229a

Please sign in to comment.