Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Fix undefined variables at rescue or always block when test_setup failed #504

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions linux/check_inbox_driver/check_inbox_driver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
hosts: localhost
gather_facts: false
tasks:
- name: "Initialized inbox drivers' versions dict"
ansible.builtin.set_fact:
inbox_drivers_versions: {}

- name: "Test case block"
block:
- name: "Test setup"
include_tasks: ../setup/test_setup.yml
vars:
skip_test_no_vmtools: false

- name: "Initialized inbox drivers' versions dict"
ansible.builtin.set_fact:
inbox_drivers_versions: {}

- name: "Get OS release"
include_tasks: get_os_release.yml

Expand Down Expand Up @@ -59,31 +59,36 @@
- name: "Get Linux inbox drivers"
include_tasks: get_inbox_drivers.yml
when: guest_os_ansible_distribution != "FreeBSD"

- name: "Get FreeBSD inbox drivers"
include_tasks: get_freebsd_inbox_drivers.yml
when: guest_os_ansible_distribution == "FreeBSD"

rescue:
- include_tasks: ../../common/test_rescue.yml
keirazhang marked this conversation as resolved.
Show resolved Hide resolved
always:
- name: "Print inbox drivers versions"
ansible.builtin.debug: var=inbox_drivers_versions
- name: "Dump inbox drivers versions into a json file"
when:
- inbox_drivers_versions is defined
- inbox_drivers_versions | length > 0
block:
- name: "Print inbox drivers versions"
ansible.builtin.debug: var=inbox_drivers_versions

- name: "Create test case log direcotry"
include_tasks: ../../common/create_directory.yml
vars:
dir_path: "{{ current_test_log_folder }}"
- name: "Create test case log direcotry"
include_tasks: ../../common/create_directory.yml
vars:
dir_path: "{{ current_test_log_folder }}"

- name: "Set fact of the output file path"
ansible.builtin.set_fact:
os_release_info_file_path: "{{ current_test_log_folder }}/{{ inbox_drivers_versions['Release'].replace('/','-').replace(' ','-') | lower }}.json"
- name: "Set fact of the output file path"
ansible.builtin.set_fact:
os_release_info_file_path: "{{ current_test_log_folder }}/{{ inbox_drivers_versions['Release'].replace('/','-').replace(' ','-') | lower }}.json"

- name: "The inbox drivers versions will be dump to a json file"
ansible.builtin.debug: var=os_release_info_file_path
- name: "The inbox drivers versions will be dump to a json file"
ansible.builtin.debug: var=os_release_info_file_path

- name: "Dump inbox drivers versions"
ansible.builtin.copy:
dest: "{{ os_release_info_file_path }}"
content: "{{ [inbox_drivers_versions] | to_nice_json }}"
mode: '0644'
- name: "Dump inbox drivers versions"
ansible.builtin.copy:
dest: "{{ os_release_info_file_path }}"
content: "{{ [inbox_drivers_versions] | to_nice_json }}"
mode: '0644'
8 changes: 7 additions & 1 deletion linux/utils/freebsd_get_partition_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@

- name: "Set fact of disk partition info"
ansible.builtin.set_fact:
freebsd_geom_part_list: "{{ freebsd_geom_list | map(attribute='provider') | flatten }}"
freebsd_geom_part_list: >-
{{
freebsd_geom_list |
selectattr('provider', 'defined') |
map(attribute='provider') |
flatten
}}

- name: "Set fact of disk partition info by name"
ansible.builtin.set_fact:
Expand Down
3 changes: 3 additions & 0 deletions linux/vgauth_check_service/vgauth_check_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@
include_tasks: ../utils/collect_vgauth_logs.yml
vars:
vgauth_log_file_src: "{{ vgauth_latest_log_file }}"
when:
- vgauth_latest_log_file is defined
- vgauth_latest_log_file