From 3c01b06b3cacaa42596ca831172e8310b33ac26d Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Mon, 25 Sep 2023 11:16:16 +0800 Subject: [PATCH 1/2] [Linux] Fix undefined variables Signed-off-by: Qi Zhang --- .../check_inbox_driver/check_inbox_driver.yml | 47 ++++++++++--------- linux/utils/freebsd_get_partition_info.yml | 8 +++- .../vgauth_check_service.yml | 3 ++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/linux/check_inbox_driver/check_inbox_driver.yml b/linux/check_inbox_driver/check_inbox_driver.yml index fd7f8ab26..6a3e5df88 100644 --- a/linux/check_inbox_driver/check_inbox_driver.yml +++ b/linux/check_inbox_driver/check_inbox_driver.yml @@ -10,10 +10,6 @@ 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" @@ -21,6 +17,10 @@ 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 @@ -59,7 +59,7 @@ - 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" @@ -67,23 +67,28 @@ rescue: - 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' diff --git a/linux/utils/freebsd_get_partition_info.yml b/linux/utils/freebsd_get_partition_info.yml index b9766506e..f79c6850f 100644 --- a/linux/utils/freebsd_get_partition_info.yml +++ b/linux/utils/freebsd_get_partition_info.yml @@ -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: diff --git a/linux/vgauth_check_service/vgauth_check_service.yml b/linux/vgauth_check_service/vgauth_check_service.yml index d331fdb6b..7901b7ac2 100644 --- a/linux/vgauth_check_service/vgauth_check_service.yml +++ b/linux/vgauth_check_service/vgauth_check_service.yml @@ -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 From da78745d635e2fa7f5017a65111d42c771c47fbf Mon Sep 17 00:00:00 2001 From: "Qi (Keira) Zhang" Date: Tue, 26 Sep 2023 11:20:24 +0800 Subject: [PATCH 2/2] Add task name for rescue Signed-off-by: Qi (Keira) Zhang --- linux/check_inbox_driver/check_inbox_driver.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux/check_inbox_driver/check_inbox_driver.yml b/linux/check_inbox_driver/check_inbox_driver.yml index 6a3e5df88..73ac4816e 100644 --- a/linux/check_inbox_driver/check_inbox_driver.yml +++ b/linux/check_inbox_driver/check_inbox_driver.yml @@ -65,7 +65,8 @@ 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: "Dump inbox drivers versions into a json file" when: