Skip to content

Commit

Permalink
[Linux] Improve check_os_fullname test case to check guest id and gue…
Browse files Browse the repository at this point in the history
…st family (#419)

* [Linux] Improve check_os_fullname test case to check guest id and guest family

Signed-off-by: Qi Zhang <[email protected]>
  • Loading branch information
keirazhang authored Feb 8, 2023
1 parent 5f80f1f commit ebca3b3
Show file tree
Hide file tree
Showing 33 changed files with 527 additions and 385 deletions.
2 changes: 1 addition & 1 deletion common/update_ini_style_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#

- name: "Update section {{ section_name }}"
ini_file:
community.general.ini_file:
path: "{{ file_path }}"
section: "{{ section_name }}"
option: "{{ option_name | default(omit) }}"
Expand Down
8 changes: 5 additions & 3 deletions common/vm_get_guest_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
- vm_guestinfo.instance is defined
- vm_guestinfo.instance.guest is defined

- ansible.builtin.debug:
- name: "Display VM's guest info"
ansible.builtin.debug:
msg:
- "VM guest info VMware tools info: {{ guestinfo_vmtools_info }}"
- "VM guest info guest id: {{ guestinfo_guest_id }}"
- "VM guest info guest full name: {{ guestinfo_guest_full_name }}"
- "VM guset info guest detailed data: {{ guestinfo_detailed_data }}"
- "VM guest info VMware tools info: {{ guestinfo_vmtools_info }}"
- "VM guest info guest family: {{ guestinfo_guest_family }}"
- "VM guest info guest detailed data: {{ guestinfo_detailed_data }}"
8 changes: 7 additions & 1 deletion common/vm_get_vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
# Get VM's vmx file path
- include_tasks: vm_get_config.yml
vars:
property_list: ['config.files.logDirectory', 'config.files.vmPathName', 'config.guestId', 'config.version']
property_list:
- 'config.files.logDirectory'
- 'config.files.vmPathName'
- 'config.guestId'
- 'config.guestFullName'
- 'config.version'

- name: Set fact of VM path related variables
ansible.builtin.set_fact:
Expand All @@ -14,6 +19,7 @@
vm_vmx_path: "{{ vm_config.config.files.vmPathName | replace('[', '/vmfs/volumes/') | replace('] ', '/') }}"
datastore: "{{ vm_config.config.files.logDirectory.split(' ')[0].strip('['']') }}"
vm_guest_id: "{{ vm_config.config.guestId }}"
vm_guest_os_version: "{{ vm_config.config.guestFullName }}"
vm_hardware_version: "{{ vm_config.config.version }}"
vm_hardware_version_num: "{{ vm_config.config.version.split('-')[-1] }}"

Expand Down
6 changes: 6 additions & 0 deletions env_setup/env_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
- include_tasks: ../common/vcenter_get_version_build.yml
when: vcenter_is_defined is defined and vcenter_is_defined
- include_tasks: ../common/esxi_get_version_build.yml

- name: "ESXi version {{ esxi_version }} is not supported"
ansible.builtin.fail:
msg: "This project only supports guest OS validation on ESXi 6.5 or later"
when: esxi_version == 'N/A' or esxi_version is version('6.5.0', '<')

# Get ESXi server model info
- include_tasks: ../common/esxi_get_model.yml

Expand Down
2 changes: 1 addition & 1 deletion linux/check_efi_firmware/check_efi_firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
# Description:
# This test case is used for check VM EFI firmware is reported correctly in dmesg
# and in "vmware.log" file, if VM firmware is BIOS, this test case result is 'No Run'.
# and in "vmware.log" file, if VM firmware is BIOS, this test case result is 'Not Applicable'.
#
- name: check_efi_firmware
hosts: localhost
Expand Down
32 changes: 22 additions & 10 deletions linux/check_os_fullname/almalinux_fullname_map.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
# Copyright 2022-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Map AlmaLinux when ESXi version > 7.0.3 and VMware Tools version > 11.3.5
- name: "Set guest_fullname variable for AlmaLinux on ESXi 7.0.3 later and VMTools 11.3.5 later"
# Guest id "almalinux_64Guest and full name "AlmaLinux (64-bit)" is available on ESXi 8.0.0 or later
# Guest full name of AlmaLinux is mapped to "AlmaLinux (64-bit)" when
# VMware Tools version is 12.0.0 or later, ESXi version is 8.0.0 or later.
- name: "Set expected guest id and full name for AlmaLinux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}"
ansible.builtin.set_fact:
guest_fullname: "AlmaLinux ({{ guest_os_bit }})"
expected_guest_id: "almalinux_64Guest"
expected_guest_fullname: "AlmaLinux (64-bit)"
when:
- esxi_version is version('7.0.3', '>')
- vmtools_version is version('11.3.5', '>')
- vmtools_version is version('12.0.0', '>=')
- esxi_version is version('8.0.0', '>=')

# Map AlmaLinux when ESXi version <= 7.0.3 or VMware Tools version <= 11.3.5
- name: "Set guest_fullname variable for AlmaLinux on ESXi 7.0.3 and earlier, or VMTools 11.3.5 and earlier"
# Guest full name of AlmaLinux is mapped to VM's guest OS version when:
# VMware Tools version is 12.0.0 or later, ESXi version is 7.0.3 or earlier.
- name: "Set expected guest id and full name for AlmaLinux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}"
ansible.builtin.set_fact:
expected_guest_id: "{{ vm_guest_id }}"
expected_guest_fullname: "{{ vm_guest_os_version }}"
when:
- vmtools_version is version('12.0.0', '>=')
- esxi_version is version('8.0.0', '<')

# Guest full name of AlmaLinux is mapped to "Other N.x Linux (64-bit)" when
# VMware Tools version is 11.3.5 or earlier
- name: "Set expected guest id and full name for AlmaLinux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}"
include_tasks: otherlinux_fullname_map.yml
when: >
esxi_version is version('7.0.3', '<=') or
vmtools_version is version('11.3.5', '<=')
when: vmtools_version is version('12.0.0', '<')
20 changes: 20 additions & 0 deletions linux/check_os_fullname/amazon_fullname_map.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Guest id "amazonlinux2_64Guest" and full name "Amazon Linux 2 (64-bit)" is available on ESXi 6.7 U1 or later
# Guest id "amazonlinux3_64Guest" and full name "Amazon Linux 3 (64-bit)" is available on ESXi 7.0.1 or later
- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}"
ansible.builtin.set_fact:
expected_guest_major_ver: |-
{%- if (esxi_version is version('6.7.0', '>') and esxi_version is version('7.0.1', '<')) or
(esxi_version is version('6.7.0', '==') and esxi_update_version | int > 0) -%}
{{ [guest_os_ansible_distribution_major_ver | int, 2] | min }}
{%- elif esxi_version is version('7.0.1', '>=') -%}
{{ [guest_os_ansible_distribution_major_ver | int, 3 ] | min }}
{%- endif %}
- name: "Set expected guest id and full name for Amazon Linux on ESXi {{ esxi_version }}"
ansible.builtin.set_fact:
expected_guest_id: "amazonlinux{{ expected_guest_major_ver }}_64Guest"
expected_guest_fullname: "Amazon Linux {{ expected_guest_major_ver }} (64-bit)"
when: expected_guest_major_ver
48 changes: 0 additions & 48 deletions linux/check_os_fullname/amazonlinux_fullname_map.yml

This file was deleted.

50 changes: 16 additions & 34 deletions linux/check_os_fullname/centos_fullname_map.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Map CentOS when ESXi < 6.5.0
- name: Set guest_fullname variable for CentOS on ESXi < 6.5.0
# Guest id "centos7_64Guest" and full name "CentOS 7 (64-bit)" is available on ESXi 6.5 or later
# Guest id "centos8_64Guest" and full name "CentOS 8 (64-bit)" is available on ESXi 6.7 or later
# Guest id "centos9_64Guest" and full name "CentOS 9 (64-bit)" is available on ESXi 7.0.1 or later
- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}"
ansible.builtin.set_fact:
guest_fullname: "CentOS 4/5 or later ({{ guest_os_bit }})"
when: esxi_version is version('6.5.0', '<')
expected_guest_major_ver: |-
{%- if esxi_version is version('6.5.0', '>=') and esxi_version is version('6.7.0', '<') -%}
{{ [guest_os_ansible_distribution_major_ver | int, 7 ] | min }}
{%- elif esxi_version is version('6.7.0', '>=') and esxi_version is version('7.0.1', '<') -%}
{{ [guest_os_ansible_distribution_major_ver | int, 8 ] | min }}
{%- elif esxi_version is version('7.0.1', '>=') -%}
{{ [guest_os_ansible_distribution_major_ver | int, 9 ] | min }}
{%- endif %}
# Map CentOS-5 and earlier when ESXi >= 6.5.0
- name: Set guest_fullname variable for CentOS on ESXi >= 6.5.0
- name: "Set expected guest id and full name for CentOS on ESXi {{ esxi_version }}"
ansible.builtin.set_fact:
guest_fullname: "CentOS {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})"
when:
- guest_os_ansible_distribution_major_ver | int <= 5
- esxi_version is version('6.5.0', '>=')

# Map CentOS-6, CentOS-7 when ESXi = 6.5.0
- name: Set guest_fullname variable for CentOS on ESXi = 6.5.0
ansible.builtin.set_fact:
guest_fullname: "CentOS {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})"
when:
- guest_os_ansible_distribution_major_ver | int == 6 or guest_os_ansible_distribution_major_ver | int == 7
- esxi_version is version('6.5.0', '==')

# Map CentOS-8 and later when ESXi = 6.5.0
- name: Set guest_fullname variable for CentOS on ESXi = 6.5.0
ansible.builtin.set_fact:
guest_fullname: "CentOS 7 ({{ guest_os_bit }})"
when:
- guest_os_ansible_distribution_major_ver | int >= 8
- esxi_version is version('6.5.0', '==')

# Map CentOS-6 and later when ESXi >= 6.7.0
- name: Set guest_fullname variable for CentOS on ESXi >= 6.7.0
ansible.builtin.set_fact:
guest_fullname: "CentOS {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})"
when:
- guest_os_ansible_distribution_major_ver | int >= 6
- esxi_version is version('6.7.0', '>=')
expected_guest_id: "centos{{ expected_guest_major_ver }}{{ expected_guest_id_suffix }}"
expected_guest_fullname: "CentOS {{ expected_guest_major_ver }} ({{ guest_os_bit }})"
when: expected_guest_major_ver
121 changes: 84 additions & 37 deletions linux/check_os_fullname/check_os_fullname.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Description:
# This test case is used for check VM guest OS fullname is reported correctly
# in guest info through VMware tools. When VMware tools is not installed or not
# running in VM, this test case result is 'No Run'.
# running in VM, this test case result is 'Blocked'.
#
- name: check_os_fullname
hosts: localhost
Expand All @@ -14,66 +14,113 @@
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

# Run this test when VMware tools is running
- include_tasks: ../../common/esxi_get_version_build.yml
- name: "Set VMware Tools debug logging directory"
ansible.builtin.set_fact:
vmtools_log_dir: "/tmp/vmware-tools-{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"

- name: "Enable debug logging for VMware Tools"
include_tasks: ../utils/enable_vmtools_logging.yml

- name: "Get ESXi version and build"
include_tasks: ../../common/esxi_get_version_build.yml
when: esxi_version is undefined or esxi_update_version is undefined

- name: "Get OS fullname in guest OS"
- name: "Display guest OS distribution"
ansible.builtin.debug:
msg: "{{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }}"
msg: "{{ vm_guest_os_distribution }}"

- name: "Initalize facts for checking guest full name"
- name: "Initialize facts for checking guest id and guest full name"
ansible.builtin.set_fact:
expected_guest_id: ""
expected_guest_id_suffix: "{% if guest_os_bit == '64-bit' %}64{% endif %}Guest"
expected_guest_major_ver: ""
expected_guest_fullname: ""
expected_guest_family: "linuxGuest"
guest_is_otherlinux: true

- name: "Set fact of guest OS is not other Linux"
ansible.builtin.set_fact:
guest_fullname: "guest fullname not defined in test case"
guest_is_otherlinux: false
when: >-
guest_os_ansible_distribution in ["RedHat", "CentOS", "OracleLinux", "AlmaLinux", "Rocky",
"SLES", "SLED", "VMware Photon OS", "Amazon", "Fedora",
"Ubuntu", "Debian"]
# Map Ubuntu
- name: "Set guest_fullname variable for Ubuntu"
- name: "Set fact of expected guest id suffix"
ansible.builtin.set_fact:
guest_fullname: "Ubuntu Linux ({{ guest_os_bit }})"
when: guest_os_ansible_distribution == "Ubuntu"
expected_guest_id_suffix: "{{ expected_guest_id_suffix | replace('64', '_64') }}"
when: >-
guest_os_ansible_distribution in ["RedHat", "SLES", "SLED",
"CentOS", "OracleLinux", "Debian"]
# Map RHEL full name
- include_tasks: rhel_fullname_map.yml
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
include_tasks: rhel_fullname_map.yml
when: guest_os_ansible_distribution == "RedHat"

# Map SLES full name
- include_tasks: sles_fullname_map.yml
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
include_tasks: sles_fullname_map.yml
when: guest_os_ansible_distribution in ["SLES", "SLED"]

# Map VMware Photon OS guest full name
- include_tasks: photon_fullname_map.yml
when: guest_os_ansible_distribution == "VMware Photon OS"

- include_tasks: "{{ guest_os_ansible_distribution | lower }}_fullname_map.yml"
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
include_tasks: "{{ guest_os_ansible_distribution | lower }}_fullname_map.yml"
when: guest_os_ansible_distribution in ["Amazon", "CentOS", "OracleLinux", "AlmaLinux", "Rocky", "Debian"]

# Map FreeBSD guest full name
- name: "Set guest_fullname variable for FreeBSD"
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
ansible.builtin.set_fact:
guest_fullname: "FreeBSD {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})"
when: guest_os_ansible_distribution == "FreeBSD"
expected_guest_id: "ubuntu{{ expected_guest_id_suffix }}"
expected_guest_fullname: "Ubuntu Linux ({{ guest_os_bit }})"
when: guest_os_ansible_distribution == "Ubuntu"

# Map Fedora
- name: "Set guest_fullname variable for Fedora"
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
ansible.builtin.set_fact:
guest_fullname: "Red Hat Fedora ({{ guest_os_bit }})"
when: guest_os_ansible_distribution == "Fedora"
expected_guest_id: "vmwarePhoton64Guest"
expected_guest_fullname: "VMware Photon OS (64-bit)"
when: guest_os_ansible_distribution == "VMware Photon OS"

# Map Other Linux
- name: "Set fact of the guest is other linux"
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
ansible.builtin.set_fact:
guest_is_otherlinux: true
when: guest_fullname == "guest fullname not defined in test case"
expected_guest_id: "fedora{{ expected_guest_id_suffix }}"
expected_guest_fullname: "Red Hat Fedora ({{ guest_os_bit }})"
when: guest_os_ansible_distribution == "Fedora"

- include_tasks: otherlinux_fullname_map.yml
- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}"
include_tasks: otherlinux_fullname_map.yml
when: guest_is_otherlinux

# Validate guest OS fullname in guestinfo
- include_tasks: validate_os_fullname.yml
- name: "Validate guest OS full name in guestinfo"
include_tasks: validate_os_fullname.yml
rescue:
- include_tasks: ../../common/test_rescue.yml
- name: "Test rescue"
include_tasks: ../../common/test_rescue.yml
always:
- name: "Get VMware Tools log directory stat info"
include_tasks: ../utils/get_file_stat_info.yml
vars:
guest_file_path: "{{ vmtools_log_dir }}"

- name: "Collect VMware Tools logs"
block:
- name: "Archive VMware Tools debug logs"
ansible.builtin.archive:
path: "{{ vmtools_log_dir }}"
dest: "{{ vmtools_log_dir }}.tgz"
mode: "0644"
delegate_to: "{{ vm_guest_ip }}"
register: archive_vmtools_logs

- name: "Fetch VMware Tools debug logs"
include_tasks: ../utils/fetch_file.yml
vars:
fetch_file_src_path: "{{ vmtools_log_dir }}.tgz"
fetch_file_dst_path: "{{ current_test_log_folder }}/"
fetch_file_ignore_errors: true
when:
- archive_vmtools_logs is defined
- archive_vmtools_logs.changed is defined
- archive_vmtools_logs.changed
when: guest_file_exists
Loading

0 comments on commit ebca3b3

Please sign in to comment.