redhat-cop / infra.leapp

Collection of Ansible roles for automating RHEL in-place upgrades using Leapp.
MIT License
48 stars 41 forks source link

Loop running leapp_known_inhibitors failing to due key not being included in data structure created for high (errors) #215

Closed aharold92 closed 2 months ago

aharold92 commented 2 months ago

We are receiving this error after we started using the infra.leapp 1.3.1 version

FAILED! => {"msg": "The conditional check 'item.key not in leapp_known_inhibitors' failed. The error was: error while evaluating conditional (item.key not in leapp_known_inhibitors): 'dict object' has no attribute 'key'. 'dict object' has no attribute 'key'\n\nThe error appears to be in '/runner/requirements_collections/ansible_collections/infra/leapp/roles/analysis/tasks/analysis-leapp.yml': line 96, column 3, but may \nbe elsewhere in the file depending on the exact syntax problem. \n\n The offending line appears to be:\n\n-name: analysis-leapp | Capture inhibitors in a list leapp_inhibitors\n ^ here\n"}

This error occurs because the data structure created by the task - name: Construct a data structure to add high errors to leapp_report_json does not include a key in the data structure.

That exclusion then leads to a data structure that looks like the following

          "audience": "sysadmin",
          "flags": [
            "inhibitor"
          ],
          "severity": "high",
          "summary": "Risk Factor: high (error)\nTitle: Not enough space available on /var/lib/leapp/scratch: Needed at least 4992 MiB.\nSummary: {\"detail\": \"The file system hosting the /var/lib/leapp/scratch directory does not contain enough free space to proceed all parts of the in-place upgrade. Note the calculated required free space is the minimum derived from upgrades of minimal systems and the actual needed free space could be higher.\\nNeeded at least: 4992 MiB.\\nSuggested free space: 5992 MiB (or more).\"}\nKey: 0f6a4d531ad6079bd7a85b02bc922ccc7c143312\n----------------------------------------",
          "title": "Likely issues found with high (error) severity found, see summary.",
          "hostname": "tst-ssplappi109.bbtnet.com"
        } 

This data structure is then added to leapp_report_json.

Then when the role reaches the following task

- name: analysis-leapp | Capture inhibitors in a list leapp_inhibitors
  ansible.builtin.set_fact:
    leapp_inhibitors: "{{ leapp_inhibitors | default([]) + [item] }}"
  when:
    - item.key not in leapp_known_inhibitors
    - (leapp_high_sev_as_inhibitors | bool and item.severity == 'high') or
      'inhibitor' in item.flags
  loop: "{{ leapp_report_json.entries }}"

It fails because it is looping through the entries in leapp_report_json searching for keys in the leapp_known_inhibitors to exclude. Key does not exist as a dict entry in the generated data structure for high (error) items and the task fails.

swapdisk commented 2 months ago

I've been able to reproduce this in my test environment. I had to force the "Not enough space available on /var/lib/leapp/scratch" finding by mounting /var/lib/leapp from 1 Gb volume. The line "Risk Factor: high (error)" in the leapp-report.txt file is what triggers the failure. Also, the failure will only happen if leapp_known_inhibitors has been defined. It will not fail with the leapp_known_inhibitors is left as default of [].

We also need to talk about why are we parsing the leapp-report.txt file rather than just using the json report data.

Lastly, that this particular finding is not reported as an inhibitor already seems like a Leapp bug to me.

swapdisk commented 2 months ago

Fixed with #216.