Skip to content

Commit

Permalink
[RHELC-1605] Add collecting of post-conversion report
Browse files Browse the repository at this point in the history
Add collecting of the post-conversion report is possible because in
convert2rhel was added new feature enabling this.

Remember that post-conversion report is generated only if the analysis
step is successful, otherwise only the pre-conversion report is
generated.
  • Loading branch information
hosekadam committed Sep 19, 2024
1 parent 412e6f1 commit e6c4e48
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/tests/output/
/changelogs/.plugin-cache.yaml
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -136,3 +137,7 @@ pre-commit

# Ignore ansible.cfg
ansible.cfg

# Igone helper folder and file for testing
ansible_collections/
hosts
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ ANSIBLE_COLLECTIONS_PATH=
PYTHON = python3
PYTHON_VENV = .venv

create-folder-for-test:
mkdir -p ansible_collections/infra/convert2rhel/
cp -r playbooks plugins roles meta galaxy.yml ansible_collections/infra/convert2rhel/

install-deps:
virtualenv -p '$(PYTHON)' $(PYTHON_VENV); \
. $(PYTHON_VENV)/bin/activate; \
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ See [Using Ansible collections](https://docs.ansible.com/ansible/devel/user_guid

We are a fledgling community and welcome any new contributors. Get started by opening an issue or pull request. Refer to our [contribution guide](CONTRIBUTING.md) for more information.

## Testing
For testing, you have two options. Use manually provisioned machine and run the playbook manually or use the automated
way using `Makefile` and `molecule` plugin.

### Manually provisioned machine
- Provision machine (e.g. using vagrant). This can be done by `vagrant init eurolinux-vagrant/centos-7` or by using
Vagrantfile. Capture it's IP and directory where you are running this command.
- Move to `infra.convert2rhel` and create needed folders for ansible by running `make create-folder-for-test`. This
will create structure of directories ansible needs. Remember, you need to run this command each time you change
something in the project.
- Run `export ANSIBLE_COLLECTIONS_PATH=$(pwd)` to set where should ansible look for the expected dir structure.
- Create file in which you will specify hosts to run the ansible playbook.
E.g. the file is created in `playbook/` called `hosts` and contain:
```
[testing]
<IP-of-the-machine> ansible_python_interpreter=/usr/bin/python2.7
```
Note: the specified `ansible_python_interpreter` is mainly for easier debugging if you have the correct version of
`ansible-core` (2.16.11), without this you can get a bit confusing error message.
Note: if you want to subscribe the system, you can replace the config file by credentials you have
in the `analysis/tasks/analysis-c2r.yml` or `convert/tasks/main.yml`
- Run the ansible playbook you want using:
```
ansible-playbook --private-key <path-where-vagrant-was-called>/.vagrant/machines/default/libvirt/private_key -i <specified-hosts> <playbook-path> -u root -vv
```
e.g.
```
ansible-playbook --private-key ~/vagrant-box/vagrant/.vagrant/machines/default/libvirt/private_key -i playbooks/hosts playbooks/analysis.yml -u root -vv
```
## Automated way
TBD
## Reporting issues
Please open a [new issue](https://github.com/redhat-cop/infra.convert2rhel/issues/new/choose) for any bugs or security vulnerabilities you may encounter. We also invite you to open an issue if you have ideas on how we can improve the solution or want to make a suggestion for enhancment.
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
molecule
molecule==24.2.1
molecule-plugins[vagrant]
ansible-lint
ansible-core==2.16.11
10 changes: 5 additions & 5 deletions roles/analysis/tasks/analysis-c2r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
changed_when: "'Pre-conversion analysis report' not in convert2rhel.stdout"
notify: Remove temporary configuration file

- name: Include check-results-file.yml
ansible.builtin.include_tasks: check-results-file.yml
- name: Set the activity
ansible.builtin.set_fact:
activity: "analysis"

- name: Include the parse_c2r_report role to check if conversion inhibited
- name: Include the handle_report to check if report available and if conversion inhibited
ansible.builtin.include_role:
name: infra.convert2rhel.parse_c2r_report

name: infra.convert2rhel.handle_c2r_report
...
11 changes: 0 additions & 11 deletions roles/analysis/tasks/check-results-file.yml

This file was deleted.

1 change: 1 addition & 0 deletions roles/analysis/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
analysis_convert2rhel_enable_repos_args: "{{ ('--enablerepo ' + analysis_convert2rhel_repos_enabled | default([], true) | join(' --enablerepo ')) if analysis_convert2rhel_repos_enabled | length > 0 else '' }}"
analysis_convert2rhel_disable_repos_args: "{{ ('--disablerepo ' + analysis_convert2rhel_repos_disabled | default([], true) | join(' --disablerepo ')) if analysis_convert2rhel_repos_disabled | length > 0 else '' }}"

# used only in handlers/main.yml
analysis_result_filename_prefix: /var/log/convert2rhel/convert2rhel-pre-conversion
analysis_result_filename_txt: "{{ analysis_result_filename_prefix }}.txt"
...
10 changes: 9 additions & 1 deletion roles/convert/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
async: "{{ convert_async_timeout_maximum | int }}"
poll: "{{ convert_async_poll_interval | int }}"
changed_when: convert2rhel.rc != 0
# When ihibitor is found the return code is 2. This will cause a fail and the report parsing will be skipped
# which is unsolicited. This is different from `convert2rhel analyze` where the exit code is 0 if inhibitor
# is found. This is a bug and is tracked under RHELC-1736
failed_when: convert2rhel.rc != 0 and convert2rhel.rc != 2
notify: Remove temporary configuration file

- name: Set the activity for correct handling of the report
ansible.builtin.set_fact:
activity: "convert"

- name: Include the parse_c2r_report role to check if conversion inhibited
ansible.builtin.include_role:
name: infra.convert2rhel.parse_c2r_report
name: infra.convert2rhel.handle_c2r_report

- name: Reboot if requested
ansible.builtin.reboot:
Expand Down
25 changes: 25 additions & 0 deletions roles/handle_c2r_report/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Handle C2R Report
================

This role is designed to handle the Convert2RHEL (C2R) report. It extracts relevant information and prepares it for further analysis or conversion tasks.

### Process of handling:
The handling is divided into two parts based on which activity is being done.
- When the analysis is executed, check for exitense and then parse is required only for the pre-conversion report.
- For convert checking if post-conversion report is available is needed because the report can miss in situation
when the conversion process fails in the analysis part. In that moment, only the pre-conversion report is generated.

Those actions are controlled by fact `activity` which must be set in the different role related to the activity.
The rest of the actions use fact `handle_c2r_report_result_filename_txt` and `handle_c2r_report_result_filename_json`
for checking and parsing the right places.

Dependencies
------------

This role is a dependency for the `analysis` and `convert` roles. It also depend on them as setting `activity` fact is
needed.

License
-------

MIT
11 changes: 11 additions & 0 deletions roles/handle_c2r_report/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# defaults file for handle_c2r_report

handle_c2r_report_analysis_result_filename_prefix: /var/log/convert2rhel/convert2rhel-pre-conversion
handle_c2r_report_analysis_result_filename_txt: "{{ handle_c2r_report_analysis_result_filename_prefix }}.txt"
handle_c2r_report_analysis_result_filename_json: "{{ handle_c2r_report_analysis_result_filename_prefix }}.json"

handle_c2r_report_convert_result_filename_prefix: /var/log/convert2rhel/convert2rhel-post-conversion
handle_c2r_report_convert_result_filename_txt: "{{ handle_c2r_report_convert_result_filename_prefix }}.txt"
handle_c2r_report_convert_result_filename_json: "{{ handle_c2r_report_convert_result_filename_prefix }}.json"
...
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions roles/handle_c2r_report/tasks/check-results-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Result file status
ansible.builtin.stat:
path: "{{ handle_c2r_report_result_filename_txt }}"
register: result
- name: Print the value of a variable with message
ansible.builtin.debug:
msg: "The value of my_variable is: {{ handle_c2r_report_result_filename_txt }}"
- name: Set variable
ansible.builtin.set_fact:
result_file_exists: result.stat.exists
- name: Check that result file exists
ansible.builtin.assert:
that: result.stat.exists
msg: "The analysis report file {{ handle_c2r_report_result_filename_txt }} was not created."
...
45 changes: 45 additions & 0 deletions roles/handle_c2r_report/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: Handle analysis report
when: activity == "analysis"
block:
- name: Set needed filepath
ansible.builtin.set_fact:
handle_c2r_report_result_filename_txt: "{{ handle_c2r_report_analysis_result_filename_txt }}"
handle_c2r_report_result_filename_json: "{{ handle_c2r_report_analysis_result_filename_json }}"
- name: Include check-results-file.yml
ansible.builtin.include_tasks: check-results-file.yml
- name: Include the parse-c2r-report.yml task to check if conversion inhibited
ansible.builtin.include_tasks: parse-c2r-report.yml

- name: Handle convert report
when: activity == "convert"
block:
- name: Check if post-conversion report is available
ansible.builtin.stat:
path: "{{ handle_c2r_report_convert_result_filename_txt }}"
register: post_conversion_file
- name: Handle the post-conversion report exists situation
when: post_conversion_file.stat.exists
block:
- name: Set filepath to post-conversion report
ansible.builtin.set_fact:
handle_c2r_report_result_filename_txt: "{{ handle_c2r_report_convert_result_filename_txt }}"
handle_c2r_report_result_filename_json: "{{ handle_c2r_report_convert_result_filename_json }}"
- name: Include check-results-file.yml
ansible.builtin.include_tasks: check-results-file.yml
- name: Handle conversion report
ansible.builtin.include_tasks: parse-c2r-report.yml
- name: Handle the post-conversion report doesn't exist situation
when: not post_conversion_file.stat.exists
block:
# When the post-conversion report isn't available, the pre-conversion report is
# Conversion probably failed in analysis step
- name: Set filepath to pre-conversion report
ansible.builtin.set_fact:
handle_c2r_report_result_filename_txt: "{{ handle_c2r_report_analysis_result_filename_txt }}"
handle_c2r_report_result_filename_json: "{{ handle_c2r_report_analysis_result_filename_json }}"
- name: Include check-results-file.yml
ansible.builtin.include_tasks: check-results-file.yml
- name: Handle analysis report
ansible.builtin.include_tasks: parse-c2r-report.yml
...
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

- name: Collect human readable report results
ansible.builtin.slurp:
src: "{{ parse_c2r_report_result_filename_txt }}"
src: "{{ handle_c2r_report_result_filename_txt }}"
register: results_txt

- name: Collect JSON report results
ansible.builtin.slurp:
src: "{{ parse_c2r_report_result_filename_json }}"
src: "{{ handle_c2r_report_result_filename_json }}"
register: results_json

- name: Parse report results
Expand All @@ -36,7 +36,7 @@
ansible.builtin.shell:
cmd: >-
set -o pipefail;
cat {{ parse_c2r_report_result_filename_txt }} |
cat {{ handle_c2r_report_result_filename_txt }} |
sed -e 's/\x1b\[[0-9;]*m//g' |
awk '/\((ERROR|SKIP|OVERRIDABLE)\)/,/^$/'
register: convert2rhel_inhibitors_txt
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions roles/parse_c2r_report/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions roles/parse_c2r_report/defaults/main.yml

This file was deleted.

0 comments on commit e6c4e48

Please sign in to comment.