Skip to content

Commit

Permalink
[Linux] Fix undefined variables at rescue or always block when test_s…
Browse files Browse the repository at this point in the history
…etup failed (#504)

Signed-off-by: Qi Zhang <qiz@vmware.com>
  • Loading branch information
keirazhang committed Sep 26, 2023
1 parent 904cec0 commit 2887517
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
50 changes: 28 additions & 22 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,37 @@
- 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
- name: "Test case failure"
include_tasks: ../../common/test_rescue.yml
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

0 comments on commit 2887517

Please sign in to comment.