Skip to content

Commit

Permalink
Update log plugin to support more than one test case runs (#437)
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Zhang <qiz@vmware.com>
  • Loading branch information
keirazhang authored Mar 28, 2023
1 parent 82dd299 commit a5de6a5
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 596 deletions.
30 changes: 30 additions & 0 deletions common/set_current_testcase_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Set current test case index, name and log folder
# Parameters:
# create_test_log_folder: True to create log folder for current test case.
# test_log_folder_mode: The mode of log folder for current test case. Default is 0755.
#
# Supposing there are N test cases,
# if N < 10, test cases will be 1 ~ N
# if N >= 10, test cases will be 01 ~ N
# so that test cases log folders are sorted
- name: "Set current test case index and name"
ansible.builtin.set_fact:
current_testcase_index: "{{ '{:<}'.format(((current_testcase_index | default(0) | int + 1) | string).
rjust(gosv_testcases_count | string | length, '0')) }}"
current_testcase_name: "{{ ansible_play_name }}"

- name: "Set the log folder path for current test case on local machine"
ansible.builtin.set_fact:
current_test_log_folder: "{{ testrun_log_path }}/{{ current_testcase_index }}_{{ ansible_play_name }}"

- name: "Create log folder for current test case"
include_tasks: create_directory.yml
vars:
dir_path: "{{ current_test_log_folder }}"
dir_mode: "{{ test_log_folder_mode | default('0755') }}"
when:
- create_test_log_folder is defined
- create_test_log_folder | bool
4 changes: 0 additions & 4 deletions common/test_rescue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
- name: "Set timestamp of failure state"
ansible.builtin.set_fact:
timestamp: "{{ lookup('pipe', 'date +%Y-%m-%d-%H-%M-%S') }}"
- name: "Set test case name"
ansible.builtin.set_fact:
current_testcase_name: "{{ deploy_casename | default(ansible_play_name) }}"
when: ansible_play_name == "deploy_vm"

- name: "Print failed test case"
ansible.builtin.debug:
Expand Down
16 changes: 5 additions & 11 deletions linux/deploy_vm/deploy_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,18 @@
vars_files:
- "{{ testing_vars_file | default('../../vars/test.yml') }}"
tasks:
- name: "Set current test case index, name and log folder"
include_tasks: ../../common/set_current_testcase_facts.yml
vars:
create_test_log_folder: "{{ new_vm is defined and new_vm | bool }}"

- name: "Skip test case"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: "Skip test case due to new_vm is set to '{{ new_vm | default(false) }}'"
skip_reason: "Skipped"
when: new_vm is undefined or (not new_vm | bool)

- name: "Set current test case log path on local machine"
ansible.builtin.set_fact:
current_test_log_folder: "{{ testrun_log_path }}/{{ ansible_play_name }}"

- name: "Create the current test case log folder with mode '0755'"
ansible.builtin.file:
path: "{{ current_test_log_folder }}"
state: directory
mode: '0755'
register: create_log_path

# Change vm_username to root if it is not. And add a new user after VM deployment
- name: "Set user account for new VM"
include_tasks: set_new_vm_user_account.yml
Expand Down
6 changes: 4 additions & 2 deletions linux/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Deploy a new VM and install guest OS automatically from an ISO image
#
# Initialize undefined variables
- name: "Initialize variables for new VM settings"
ansible.builtin.set_fact:
Expand All @@ -16,9 +18,9 @@
- cpu_number is undefined or not cpu_number
- cpu_cores_per_socket is defined and cpu_cores_per_socket

- name: "Set fact of the deploy VM test case name"
- name: "Update test case name for deploying VM from ISO image"
ansible.builtin.set_fact:
deploy_casename: "deploy_vm_{{ firmware }}_{{ boot_disk_controller }}_{{ network_adapter_type }}"
current_testcase_name: "deploy_vm_{{ firmware }}_{{ boot_disk_controller }}_{{ network_adapter_type }}"

- name: "Initialize the fact whether to install guest OS with desktop"
ansible.builtin.set_fact:
Expand Down
7 changes: 4 additions & 3 deletions linux/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Initialize deploy_casename with guest_id
- name: "Set fact of deploy VM test case name"
# Deploy a new VM from OVA image
#
- name: "Update test case name for deploying VM from OVA image"
ansible.builtin.set_fact:
deploy_casename: "deploy_ova"
current_testcase_name: "deploy_vm_ova"

- name: "Test case block"
block:
Expand Down
5 changes: 0 additions & 5 deletions linux/deploy_vm/flatcar/reconfigure_flatcar_vm.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Reset deploy_casename in case user doesn't provide correct guest_id
- name: "Set fact of deploy VM test case name"
ansible.builtin.set_fact:
deploy_casename: "deploy_flatcar_ova"

# Use Ignition to configure ssh authorized key and user password
- name: "Generate Ignition config file"
include_tasks: generate_ignition_config.yml
Expand Down
4 changes: 0 additions & 4 deletions linux/deploy_vm/reconfigure_vm_with_cloudinit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
- name: "Set fact of the deploy VM test case name"
ansible.builtin.set_fact:
deploy_casename: "deploy_{{ ova_guest_os_type }}_ova"

- name: "Set fact of cloud-init final message"
ansible.builtin.set_fact:
cloudinit_final_msg: "The system is finally up, after $UPTIME seconds"
Expand Down
41 changes: 20 additions & 21 deletions linux/setup/test_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
# If base snapshot does not exist, will take a snapshot of VM as the
# base snapshot, if it exists, then revert to it directly.
#
- name: "Set current test case name and log path on local machine"
ansible.builtin.set_fact:
current_testcase_name: "{{ ansible_play_name }}"
current_test_log_folder: "{{ testrun_log_path }}/{{ ansible_play_name }}"
- name: "Set current test case index, name and log folder"
include_tasks: ../../common/set_current_testcase_facts.yml

# Check base snapshot existence and/or revert to it
- include_tasks: base_snapshot_check_revert.yml
- name: "Check base snapshot existence and/or revert to it"
include_tasks: base_snapshot_check_revert.yml

# Get VM guest IP
- include_tasks: ../../common/update_inventory.yml
- name: "Get VM guest IP"
include_tasks: ../../common/update_inventory.yml

- name: "Print VM guest IP address"
ansible.builtin.debug: var=vm_guest_ip

# Get VMware tools status if required
- include_tasks: ../../common/vm_get_vmtools_status.yml
- name: "Get VMware tools status"
include_tasks: ../../common/vm_get_vmtools_status.yml

# Skip test case run when VMware tools is required but not installed or not running
- include_tasks: ../../common/skip_test_case.yml
- name: "Block test case because VMware Toos is not installed or not running"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: "Test case is blocked because VMware tools installed: {{ vmtools_is_installed | default(false) }}, running: {{ vmtools_is_running | default(false) }}"
skip_reason: "Blocked"
Expand All @@ -32,26 +30,26 @@
- skip_test_no_vmtools
- not (vmtools_is_running is defined and vmtools_is_running | bool)

# Get guest OS system info
- include_tasks: ../utils/get_linux_system_info.yml
- name: "Get guest OS system info"
include_tasks: ../utils/get_linux_system_info.yml
when: guest_os_system_info_retrieved is undefined or not guest_os_system_info_retrieved

# Get VMware tools version info
- include_tasks: ../utils/get_guest_ovt_version_build.yml
- name: "Get VMware Tools version and build"
include_tasks: ../utils/get_guest_ovt_version_build.yml
when:
- vmtools_is_installed is defined
- vmtools_is_installed | bool
- vmtools_info_from_vmtoolsd is undefined or not vmtools_info_from_vmtoolsd

# Get VM guest info guest id, guest full name and guest detailed data
- include_tasks: ../../common/vm_get_guest_info.yml
- name: "Get VM guest info including guest id, full name, family and detailed data"
include_tasks: ../../common/vm_get_guest_info.yml
when:
- vmtools_is_running is defined
- vmtools_is_running | bool
- guestinfo_gathered is undefined or not guestinfo_gathered

# Create a base snapshot if it does not exist
- include_tasks: create_base_snapshot.yml
- name: "Take a base snapshot if it does not exist"
include_tasks: create_base_snapshot.yml
when: not (base_snapshot_exists | bool)

# Hit issue in Ubuntu 22.04 casually: Temporary failure in name resolution. Restarting servcie can fix it
Expand All @@ -62,7 +60,8 @@
delegate_to: "{{ vm_guest_ip }}"
register: dns_servers_output

- include_tasks: ../utils/service_operation.yml
- name: "Restart service 'systemd-resolved'"
include_tasks: ../utils/service_operation.yml
vars:
service_name: "systemd-resolved"
service_enabled: true
Expand Down
14 changes: 14 additions & 0 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
vars:
dir_path: "{{ local_cache }}"
dir_mode: "0777"

- name: "Get test cases number in total"
ansible.builtin.set_fact:
gosv_testcases_count: >-
{{
lookup('file', testing_testcase_file |
default('linux/gosv_testcase_list.yml')) |
from_yaml | length
}}
- name: "Print test cases number in total"
ansible.builtin.debug:
msg: "There are {{ gosv_testcases_count }} test cases to run in total."

# Prepare testing environment
- import_playbook: env_setup/env_setup.yml
# Execute test case one by one
Expand Down
Loading

0 comments on commit a5de6a5

Please sign in to comment.