Skip to content

Commit

Permalink
Sync message format between scripts and ansible playbooks
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Waltlova <[email protected]>
  • Loading branch information
andywaltlova committed Feb 6, 2024
1 parent deb4a68 commit 8953a9d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 44 deletions.
3 changes: 1 addition & 2 deletions playbooks/leapp_preupgrade_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@
- name: Set message if inhibitors or errors present
set_fact:
message: >-
"The upgrade cannot proceed.
Your system has {{ error_count + inhibitor_count }} inhibitor{{ 's' if inhibitor_count + error_count != 1 else '' }}
"The upgrade cannot proceed. Your system has {{ error_count + inhibitor_count }} inhibitor{{ 's' if inhibitor_count + error_count != 1 else '' }}
out of {{ total_problems_count }} potential problems."
when: inhibitor_count != 0 or error_count != 0

Expand Down
30 changes: 19 additions & 11 deletions playbooks/leapp_preupgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,34 @@
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"
total_problems_count = len(report_entries)
error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
)
inhibitor_count = len(
[entry for entry in report_entries if "inhibitor" in entry.get("groups")]
)
message = (
"Your system has %s error%s and %s inhibitor%s out of %s potential problem%s."
% (
error_count,
"" if error_count == 1 else "s",
inhibitor_count,
"" if inhibitor_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
if inhibitor_count == 0 and error_count == 0:
if total_problems_count == 0:
message = "No problems found. The system is ready for upgrade."
else:
message = "The upgrade can proceed. However, there is one or more warnings about issues that might occur after the upgrade."
else:
message = (
"The upgrade cannot proceed. "
"Your system has %s inhibitor%s out of %s potential problem%s."
% (
inhibitor_count + error_count,
"" if inhibitor_count + error_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
)
)
)
if reboot_required:
message = (
"System will be upgraded. Rebooting system in 1 minute. "
"No problems found. 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
Expand Down
17 changes: 15 additions & 2 deletions playbooks/leapp_upgrade_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@
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 }}"

- name: Set errors count
ansible.builtin.set_fact:
error_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'error') | list | length }}"

- name: Init new empty entries for report with edited severity
ansible.builtin.set_fact:
report_content_edited: >-
Expand Down Expand Up @@ -210,8 +222,9 @@
- name: Set default fail message
set_fact:
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."
"The upgrade cannot proceed.
Your system has {{ error_count + inhibitor_count }} inhibitor{{ 's' if inhibitor_count + error_count != 1 else '' }}
out of {{ total_problems_count }} potential problems."
- name: Set message if leapp upgrade succeeded
set_fact:
Expand Down
30 changes: 19 additions & 11 deletions playbooks/leapp_upgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,34 @@
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"
total_problems_count = len(report_entries)
error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
)
inhibitor_count = len(
[entry for entry in report_entries if "inhibitor" in entry.get("groups")]
)
message = (
"Your system has %s error%s and %s inhibitor%s out of %s potential problem%s."
% (
error_count,
"" if error_count == 1 else "s",
inhibitor_count,
"" if inhibitor_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
if inhibitor_count == 0 and error_count == 0:
if total_problems_count == 0:
message = "No problems found. The system is ready for upgrade."
else:
message = "The upgrade can proceed. However, there is one or more warnings about issues that might occur after the upgrade."
else:
message = (
"The upgrade cannot proceed. "
"Your system has %s inhibitor%s out of %s potential problem%s."
% (
inhibitor_count + error_count,
"" if inhibitor_count + error_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
)
)
)
if reboot_required:
message = (
"System will be upgraded. Rebooting system in 1 minute. "
"No problems found. 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
Expand Down
30 changes: 19 additions & 11 deletions scripts/leapp_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,26 +335,34 @@ def parse_results(output, reboot_required=False):
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"

total_problems_count = len(report_entries)
error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
)
inhibitor_count = len(
[entry for entry in report_entries if "inhibitor" in entry.get("groups")]
)
message = (
"Your system has %s error%s and %s inhibitor%s out of %s potential problem%s."
% (
error_count,
"" if error_count == 1 else "s",
inhibitor_count,
"" if inhibitor_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",

if inhibitor_count == 0 and error_count == 0:
if total_problems_count == 0:
message = "No problems found. The system is ready for upgrade."
else:
message = "The upgrade can proceed. However, there is one or more warnings about issues that might occur after the upgrade."
else:
message = (
"The upgrade cannot proceed. "
"Your system has %s inhibitor%s out of %s potential problem%s."
% (
inhibitor_count + error_count,
"" if inhibitor_count + error_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
)
)
)

if reboot_required:
message = (
"System will be upgraded. Rebooting system in 1 minute. "
"No problems found. 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
Expand Down
14 changes: 7 additions & 7 deletions tests/test_parse_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_gather_report_files_exist(mock_find_level, mock_exists, groups_value):
assert output.report_json.get("entries")[0]["severity"] == "inhibitor"

num_errors = test_json_content.count("error")
errors_str = "%s error%s" % (num_errors, "" if num_errors == 1 else "s")
num_inhibitor = test_json_content.count("inhibitor")
inhibitor_str = "%s inhibitor%s" % (
num_inhibitor,
"" if num_inhibitor == 1 else "s",
num_inhibitor + num_errors,
"" if num_inhibitor + num_errors == 1 else "s",
)

assert output.message == "Your system has %s and %s out of 1 potential problem." % (
errors_str,
inhibitor_str,
assert (
output.message
== "The upgrade cannot proceed. Your system has %s out of 1 potential problem."
% (inhibitor_str,)
)


Expand All @@ -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. Rebooting system in 1 minute. After reboot check inventory to verify the system is registered with new RHEL major version."
== "No problems found. 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 8953a9d

Please sign in to comment.