Skip to content

Commit

Permalink
[Linux] Support RHEL CoreOS automation testing (#477)
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Zhang <qiz@vmware.com>
  • Loading branch information
keirazhang authored Aug 15, 2023
1 parent e03f031 commit 1c5ae22
Show file tree
Hide file tree
Showing 35 changed files with 404 additions and 346 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ This project supports below scenarios for end-to-end guest operating system vali
| openSUSE Leap 15.3 and later | :heavy_check_mark: | | :heavy_check_mark: |
| BCLinux 8.x | :heavy_check_mark: | | :heavy_check_mark: |
| BCLinux-for-Euler 21.10 | :heavy_check_mark: | | :heavy_check_mark: |
| Red Hat Enterprise Linux CoreOS (RHCOS) 4.13 and later | | :heavy_check_mark: | :heavy_check_mark: |

**Notes**
1. This compatible guest operating systems list is used for this project only. For guest operating system support status on ESXi, please refer to [VMware Compatibility Guide](https://www.vmware.com/resources/compatibility/search.php?deviceCategory=software&testConfig=16).
Expand Down
2 changes: 1 addition & 1 deletion common/collect_ovf_vm_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
ansible.builtin.set_fact:
ovf_vm_guest_os: "{{ guest_detailed_data_dict.prettyName | default('') }}"
ovf_vm_guest_build: "{{ guest_detailed_data_dict.kernelVersion | default('') }}"
ovf_vm_guest_bitness: "{{ guest_detailed_data_dict.bitness | default('') }}"
ovf_vm_guest_bitness: "{{ guest_detailed_data_dict.bitness | default('') }}"

- name: "Set fact of Linux guest OS distribution"
block:
Expand Down
10 changes: 5 additions & 5 deletions common/create_temp_file_dir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
---
# Create a temporary file or directory
# Parameters:
# tmp_state: file or directory. By default, temporary file will be created.
# tmp_dir: (Optional) the location where temporary file or diretotry will be created.
# tmp_state: file or directory. By default, temporary file will be created
# tmp_prefix: the prefix of temporary file or directory
# tmp_suffix: the suffix of temporar file or directory
# tmp_prefix: (Optional) the prefix of temporary file or directory.
# tmp_suffix: (Optional) the suffix of temporar file or directory.
# Return:
# tmp_path: the path to temporary file or directory
#
Expand All @@ -31,11 +31,11 @@
- name: "Modify the mode of temporary file"
ansible.builtin.file:
path: "{{ tmp_path }}"
mode: "0644"
mode: "0666"
when: tmp_state == "file"

- name: "Modify the mode of temporary directory"
ansible.builtin.file:
path: "{{ tmp_path }}"
mode: "0755"
mode: "0777"
when: tmp_state == "directory"
17 changes: 14 additions & 3 deletions common/vm_remove_serial_port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Remove a serial port to VM by using output file
# Parameter:
# vm_serial_port_file_path: The serial port output file on datastore.

# Before removing serial port, remove the serial port output file
- include_tasks: esxi_check_delete_datastore_file.yml
#
- name: "Remove the serial port output file before removing serial port"
include_tasks: esxi_check_delete_datastore_file.yml
vars:
file_in_datastore: "{{ datastore }}"
file_in_datastore_path: "{{ vm_serial_port_file_path.split(']')[-1].strip(' ') }}"
Expand All @@ -28,3 +28,14 @@

- name: "Display result of removing serial port"
ansible.builtin.debug: var=remove_serial_port

- name: "Check serial port is removed"
ansible.builtin.assert:
that:
- remove_serial_port.changed is defined
- remove_serial_port.changed
fail_msg: "Failed to remove serial port from VM"

- name: "Clean serial port output file path on datastore"
ansible.builtin.set_fact:
vm_serial_port_file_path: ""
1 change: 1 addition & 0 deletions common/vm_upgrade_hardware_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- name: "Update VM hardware version"
ansible.builtin.set_fact:
vm_hardware_version: "{{ vm_upgrade_hw_result.instance.hw_version }}"
vm_hardware_version_num: "{{ vm_upgrade_hw_result.instance.hw_version.split('-')[1] }}"

- ansible.builtin.debug:
msg: "VM hardware version is upgraded to: {{ vm_hardware_version }}"
1 change: 0 additions & 1 deletion linux/check_inbox_driver/check_inbox_driver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- name: check_inbox_driver
hosts: localhost
gather_facts: false
vars:
tasks:
- name: "Initialized inbox drivers' versions dict"
ansible.builtin.set_fact:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
tasks:
- name: "Test case block"
block:
- include_tasks: ../setup/test_setup.yml
- name: "Test setup"
include_tasks: ../setup/test_setup.yml
vars:
skip_test_no_vmtools: true

Expand All @@ -23,32 +24,35 @@
when: guest_os_ansible_distribution == 'FreeBSD'

# Take quiesce snapshot
- name: Set quiesce snapshot variables
- name: "Set quiesce snapshot variables"
ansible.builtin.set_fact:
qs_snapshot_name: "quiesce_snapshot_{{ lookup('pipe', 'date +%Y-%m-%d-%H-%M-%S') }}"
backup_script_dir: "/etc/vmware-tools/backupScripts.d"
vss_shell_script: "vss_script_sh.sh"
vss_bin_script: "vss_script_bin_{{ guest_os_bit | replace('-', '') }}"
vss_log_path: "/vss.log"
vss_log_path: |-
{%- if guest_os_ansible_distribution in ['Flatcar', 'RHCOS'] -%}/var/vss.log
{%- else -%}/vss.log
{%- endif -%}
vss_content: ""

# Copy vss_script_sh.sh to /etc/vmware-tools/backupScripts.d/vss_script_sh.sh
# Create vss_script_sh.sh under /etc/vmware-tools/backupScripts.d/
- name: "Create backup script dir {{ backup_script_dir }}"
ansible.builtin.file:
path: "{{ backup_script_dir }}"
state: directory
mode: 0755
delegate_to: "{{ vm_guest_ip }}"

- name: "Copy custom script {{ vss_shell_script }}"
ansible.builtin.copy:
- name: "Add custom shell script {{ vss_shell_script }}"
ansible.builtin.template:
src: "{{ vss_shell_script }}"
dest: "{{ backup_script_dir }}/{{ vss_shell_script }}"
mode: 0755
delegate_to: "{{ vm_guest_ip }}"

# Copy pre-freeze-script and post-thaw-script to /usr/sbin/
- name: Copy custom script pre-freeze-script and post-thaw-script to /usr/sbin
- name: "Copy custom binary scripts pre-freeze-script and post-thaw-script to /usr/sbin"
ansible.builtin.copy:
src: "{{ vss_bin_script }}"
dest: "/usr/sbin/{{ item }}"
Expand All @@ -57,26 +61,21 @@
- pre-freeze-script
- post-thaw-script
delegate_to: "{{ vm_guest_ip }}"
when: guest_os_ansible_distribution != 'Flatcar'
when: guest_os_ansible_distribution not in ['Flatcar', 'RHCOS']

# Ensure /vss.log is absent
- name: "Remove {{ vss_log_path }} if it exists"
ansible.builtin.file:
path: "{{ vss_log_path }}"
state: absent
delegate_to: "{{ vm_guest_ip }}"

- include_tasks: ../../common/vm_take_snapshot.yml
- name: "Take quiesce snapshot"
include_tasks: ../../common/vm_take_snapshot.yml
vars:
snapshot_name: "{{ qs_snapshot_name }}"
is_quiesce: "yes"
dump_memory: "no"

# After snapshot is taken, check log file /vss.log in guest, which should have below contents:
# /usr/sbin/pre-freeze-script freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw
# /usr/sbin/post-thaw-script thaw
- name: "Check {{ vss_log_path }} existence"
include_tasks: ../utils/get_file_stat_info.yml
vars:
Expand All @@ -87,45 +86,54 @@
msg: "{{ vss_log_path }} doesn't exist after quiesce snapshot"
when: not (guest_file_exists | bool)

# Retrieve /vss.log
- include_tasks: ../../common/vm_guest_file_operation.yml
- name: "Retrieve {{ vss_log_path }}"
include_tasks: ../../common/vm_guest_file_operation.yml
vars:
operation: "fetch_file"
src_path: "{{ vss_log_path }}"
dest_path: "{{ current_test_log_folder }}{{ vss_log_path }}"

- name: "Get file content in /vss.log"
- name: "Get file content in {{ vss_log_path }}"
ansible.builtin.shell: "cat {{ current_test_log_folder }}{{ vss_log_path }}"
changed_when: false
register: vss_content

# Test failed for non-Flatcar guest
- name: "{{ ansible_play_name }} failed"
ansible.builtin.fail:
msg: "{{ vss_log_path }} has incorrect content"
when: (guest_os_ansible_distribution != 'Flatcar') and
(( not vss_content ) or
( vss_content.stdout_lines is undefined ) or
( vss_content.stdout_lines | length != 4 ) or
( vss_content.stdout_lines[0] != "/usr/sbin/pre-freeze-script freeze" ) or
( vss_content.stdout_lines[1] != "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze" ) or
( vss_content.stdout_lines[2] != "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw" ) or
( vss_content.stdout_lines[3] != "/usr/sbin/post-thaw-script thaw" ))
# Guest OS is not Flatcar or RHCOS
# After quiesce snapshot is taken, guest log file /vss.log should have below contents:
# /usr/sbin/pre-freeze-script freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw
# /usr/sbin/post-thaw-script thaw
- name: "Check file content in {{ vss_log_path }}"
ansible.builtin.assert:
that:
- vss_content.stdout_lines is defined
- vss_content.stdout_lines | length == 4
- vss_content.stdout_lines[0] == "/usr/sbin/pre-freeze-script freeze"
- vss_content.stdout_lines[1] == "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze"
- vss_content.stdout_lines[2] == "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw"
- vss_content.stdout_lines[3] == "/usr/sbin/post-thaw-script thaw"
fail_msg: "{{ vss_log_path }} has incorrect content"
when: guest_os_ansible_distribution not in ['Flatcar', 'RHCOS']

# Test failed for Flatcar guest
- name: "{{ ansible_play_name }} failed"
ansible.builtin.fail:
msg: "{{ vss_log_path }} has incorrect content"
when: (guest_os_ansible_distribution == 'Flatcar') and
(( not vss_content ) or
( vss_content.stdout_lines is undefined ) or
( vss_content.stdout_lines | length != 2 ) or
( vss_content.stdout_lines[0] != "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze") or
( vss_content.stdout_lines[1] != "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw" ))
# Guest OS is Flatcar or RHCOS
# After quiesce snapshot is taken, guest log file /var/vss.log should have below contents:
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze
# /etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw
- name: "Check file content in {{ vss_log_path }}"
ansible.builtin.assert:
that:
- vss_content.stdout_lines is defined
- vss_content.stdout_lines | length == 2
- vss_content.stdout_lines[0] == "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh freeze"
- vss_content.stdout_lines[1] == "/etc/vmware-tools/backupScripts.d/vss_script_sh.sh thaw"
fail_msg: "{{ vss_log_path }} has incorrect content"
when: guest_os_ansible_distribution in ['Flatcar', 'RHCOS']

# Remove quiesce snapshot for successful test
- include_tasks: ../../common/vm_remove_snapshot.yml
- name: "Remove quiesce snapshot for successful test"
include_tasks: ../../common/vm_remove_snapshot.yml
vars:
snapshot_name: "{{ qs_snapshot_name }}"
rescue:
- include_tasks: ../../common/test_rescue.yml
- name: "Test case failure"
include_tasks: ../../common/test_rescue.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
echo $0 $@ >> /vss.log
echo $0 $@ >> {{ vss_log_path }}
exit 0
23 changes: 23 additions & 0 deletions linux/deploy_vm/collect_serial_port_log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Collect VM serial port log file
#
- name: "Collect VM serial port log"
when:
- vm_dir_name is defined
- vm_dir_name
- vm_serial_port_file_path is defined
- vm_serial_port_file_path
block:
- name: "Set fact of VM serial port log file name"
ansible.builtin.set_fact:
vm_serial_port_file_name: "{{ vm_serial_port_file_path.split()[-1] | basename }}"

- name: "Download VM serial port log file from datastore"
include_tasks: ../../common/esxi_download_datastore_file.yml
vars:
src_datastore: "{{ datastore }}"
src_file_path: "{{ vm_dir_name }}/{{ vm_serial_port_file_name }}"
dest_file_path: "{{ current_test_log_folder }}/{{ vm_serial_port_file_name }}"
download_file_fail_ignore: true
28 changes: 17 additions & 11 deletions linux/deploy_vm/collect_vm_logs.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Collect cloud-init logs for deploying Ubuntu live-server,
# cloud image or Photon OVA.
# Collect VM guest info and cloud-init logs for deploying Ubuntu live-server,
# cloud image, VMware Photon OS OVA or Amazon Linux OVA.
#
- name: "Collect VM logs"
- name: "Collect VM deployement logs"
when:
- vm_exists is defined
- vm_exists
block:
- name: "Get VM's power state"
include_tasks: ../../common/vm_get_power_state.yml

- name: "Collect cloud-init logs"
- name: "Collect VM's guest info and cloud-init logs"
when:
- vm_power_state_get is defined
- vm_power_state_get == "poweredOn"
block:
- name: "Get VMware Tools status"
include_tasks: ../../common/vm_get_vmtools_status.yml

# VM's guest info will be collected by log plugin
- name: "Get VM's guest info"
include_tasks: ../../common/vm_get_guest_info.yml
when:
- unattend_install_conf is defined
- unattend_install_conf | lower is not match('.*bclinux-for-euler.*')
- vmtools_is_running

- name: "Collect cloud-init logs"
include_tasks: ../utils/collect_cloudinit_logs.yml
when:
- guestinfo_guest_id is defined
- ((guestinfo_guest_id is match('ubuntu.*') and
unattend_install_conf is defined and
(unattend_install_conf is match('Ubuntu/Server/') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity'))) or
(unattend_install_conf is match('Ubuntu/Server/') or
unattend_install_conf is match('Ubuntu/Desktop/Subiquity'))) or
(ova_guest_os_type is defined and
ova_guest_os_type in ['photon', 'ubuntu', 'amazon']))
when:
- vm_power_state_get is defined
- vm_power_state_get == "poweredOn"
when:
- vm_exists is defined
- vm_exists
26 changes: 5 additions & 21 deletions linux/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,30 +244,12 @@
boot_order_list: ['disk']
when: guest_id is match('ubuntu.*')

- name: "Download serial output file before removing serial port"
include_tasks: ../../common/esxi_download_datastore_file.yml
vars:
src_datastore: "{{ datastore }}"
src_file_path: "{{ vm_dir_name }}/{{ vm_serial_port_output_file | basename }}"
dest_file_path: "{{ current_test_log_folder }}/{{ vm_serial_port_output_file | basename }}"
download_file_fail_ignore: true
when:
- vm_dir_name is defined
- vm_dir_name
- vm_serial_port_output_file is defined
- vm_serial_port_output_file
- name: "Collect serial port log before removing serial port"
include_tasks: collect_serial_port_log.yml

- name: "Remove serial port"
include_tasks: ../../common/vm_remove_serial_port.yml

- name: "Failed to remove serial port"
ansible.builtin.fail:
msg: "Failed to remove serial port from VM"
when: >
remove_serial_port is undefined or
remove_serial_port.changed is undefined or
not remove_serial_port.changed
- name: "OS auto install is completed. Power on VM now"
include_tasks: ../../common/vm_set_power_state.yml
vars:
Expand Down Expand Up @@ -367,8 +349,10 @@
Oracle Linux 9.0 UEK R7 upgrading failed. Before upgrade, the UEK R7
version is '{{ ol9_uekr7_before_upgrade }}', after upgrade the UEK R7
version is '{{ ol9_uekr7_after_upgrade }}'.
rescue:
- name: "Collect serial port log at test failure"
include_tasks: collect_serial_port_log.yml

- name: "Test case failure"
include_tasks: ../../common/test_rescue.yml
vars:
Expand Down
Loading

0 comments on commit 1c5ae22

Please sign in to comment.