Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Fix cloud-init GOSC failure on Ubuntu and Photon OS #479

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion linux/deploy_vm/templates/photon-ova-user-data.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ssh_authorized_keys:
packages:
- sudo
- sg3_utils
- chrony
- tar
- ndctl
- python3-rpm
Expand Down
72 changes: 28 additions & 44 deletions linux/guest_customization/check_gosc_log.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,41 @@
# Fetch gosc log file to local and check the log content
- name: "Set guest customization plugin log location on localhost"
ansible.builtin.set_fact:
deploypkg_log_path: "{{ current_test_log_folder }}{{ gosc_deploypkg_log_file }}"
gosc_log_success: true

- include_tasks: ../../common/vm_guest_file_operation.yml
- name: "Fetch GOSC log file {{ gosc_deploypkg_log_file }}"
include_tasks: ../../common/vm_guest_file_operation.yml
vars:
operation: "fetch_file"
src_path: "{{ gosc_deploypkg_log_file }}"
dest_path: "{{ deploypkg_log_path }}"
dest_path: "{{ gosc_deploypkg_log_local }}"

# Check perl GOSC log file
- block:
# Check below message exists
- include_tasks: check_log_msg.yml
vars:
check_log_file: "{{ deploypkg_log_path }}"
check_msg_state: "present"
with_items:
- "Executing traditional GOSC workflow"
- "Deployment succeeded"
- "Ran DeployPkg_DeployPackageFromFile successfully"
loop_control:
loop_var: "check_msg_regexp"
- name: "Check traditional GOSC log in {{ gosc_deploypkg_log_local }}"
when: gosc_workflow == "perl"
include_tasks: check_log_msg.yml
vars:
check_log_file: "{{ gosc_deploypkg_log_local }}"
check_msg_state: "present"
with_items:
- "Executing traditional GOSC workflow"
- "Deployment succeeded"
- "Ran DeployPkg_DeployPackageFromFile successfully"
loop_control:
loop_var: "check_msg_regexp"

# Check cloud-init GOSC log file
- block:
# Collect /var/log/cloud-init.log and /etc/cloud/cloud.cfg
- include_tasks: ../../common/vm_guest_file_operation.yml
vars:
operation: "fetch_file"
src_path: "{{ gosc_cloudinit_log_file }}"
dest_path: "{{ current_test_log_folder }}{{ gosc_cloudinit_log_file }}"

# Check below message exists
- include_tasks: check_log_msg.yml
vars:
check_log_file: "{{ deploypkg_log_path }}"
check_msg_state: "present"
with_items:
- "Executing cloud-init workflow"
- "Deployment for cloud-init succeeded"
- "Ran DeployPkg_DeployPackageFromFile successfully"
loop_control:
loop_var: "check_msg_regexp"
- name: "Check cloud-init GOSC log in {{ gosc_deploypkg_log_local }}"
when: gosc_workflow == "cloud-init"
include_tasks: check_log_msg.yml
vars:
check_log_file: "{{ gosc_deploypkg_log_local }}"
check_msg_state: "present"
with_items:
- "Executing cloud-init workflow"
- "Deployment for cloud-init succeeded"
- "Ran DeployPkg_DeployPackageFromFile successfully"
loop_control:
loop_var: "check_msg_regexp"

# Collect all cloud-init logs and userdata for cloud-init GOSC or VMware Photon OS
- include_tasks: ../utils/collect_cloudinit_logs.yml
when: >
(gosc_workflow == "cloud-init") or
(guest_os_ansible_distribution == "VMware Photon OS")

- name: "Print GOSC log file check result"
ansible.builtin.debug: var=gosc_log_success
- name: "Print result of checking GOSC log"
ansible.builtin.debug:
msg: "Checking GOSC log success: {{ gosc_log_success }}"
6 changes: 3 additions & 3 deletions linux/guest_customization/linux_gosc_execution.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
- name: Customize Linux guest OS
- name: "Customize Linux guest OS"
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
Expand All @@ -26,9 +26,9 @@
timezone: "{{ linux_gosc_spec.timezone }}"
hwclockUTC: "{{ linux_gosc_spec.hwclockUTC }}"
wait_for_customization: true
wait_for_customization_timeout: "{{ timeout | default(omit) }}"
wait_for_customization_timeout: "{{ linux_gosc_timeout | default(omit) }}"
register: customize_linux_result

- name: Display the Linux customization result
- name: "Display the Linux customization result"
ansible.builtin.debug: var=customize_linux_result
when: enable_debug
4 changes: 3 additions & 1 deletion linux/guest_customization/linux_gosc_start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
include_tasks: linux_gosc_execution.yml
vars:
type: "{{ ip_assignment }}"
timeout: 900
linux_gosc_timeout: 900

# Do not fail GOSC immediately if state keyword doesn't exist
- name: "Wait for GOSC state is completed"
Expand Down Expand Up @@ -75,7 +75,9 @@
- name: "Set fact of GOSC log files"
ansible.builtin.set_fact:
gosc_deploypkg_log_file: "/var/log/vmware-imc/toolsDeployPkg.log"
gosc_deploypkg_log_local: "{{ current_test_log_folder }}/toolsDeployPkg.log"
gosc_cloudinit_log_file: "/var/log/cloud-init.log"
gosc_cloudinit_log_local: "{{ current_test_log_folder }}/cloud-init.log"

# Wait GOSC completes message in logs
- name: "Wait for traditional GOSC complete message"
Expand Down
77 changes: 55 additions & 22 deletions linux/guest_customization/linux_gosc_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
ansible.builtin.set_fact:
enable_cloudinit_gosc: "{% if gosc_workflow == 'cloud-init' %}True{% else %}False{% endif %}"

- include_tasks: ../setup/test_setup.yml
- name: "Test setup"
include_tasks: ../setup/test_setup.yml
vars:
skip_test_no_vmtools: true

- name: "Check GOSC testing is supported or not"
include_tasks: check_gosc_support_status.yml

- name: "Prepare for GOSC testing on VMware Photon OS"
when: guest_os_ansible_distribution == "VMware Photon OS"
block:
# Traditional GOSC in VMware Photon OS is implemented with cloud-init,
# so will upgrade cloud-init to the latest version in VMware Photon OS
Expand All @@ -30,11 +32,12 @@
package_list: ["cloud-init"]
package_state: "latest"

- include_tasks: ../utils/get_cloudinit_version.yml
- name: "Get cloud-init version"
include_tasks: ../utils/get_cloudinit_version.yml

# In VMware Photon OS 4.0, open-vm-tools-gosc is provided with GOSC scripts
# from open-vm-tools 11.3.5
- name: "Install 'open-vm-tools-gosc-{{ vmtools_version }}' for GOSC"
- name: "Install GOSC required package 'open-vm-tools-gosc-{{ vmtools_version }}'"
include_tasks: ../utils/install_uninstall_package.yml
vars:
package_list: ["open-vm-tools-gosc-{{ vmtools_version }}"]
Expand All @@ -44,10 +47,12 @@
- guest_os_ansible_distribution_major_ver | int >= 4
- vmtools_version is defined
- vmtools_version is version('11.3.5', '>=')
when: guest_os_ansible_distribution == "VMware Photon OS"

# Install perl if guest OS doesn't have it
- name: "Prepare for perl GOSC testing on {{ guest_os_ansible_distribution }}"
when:
- not enable_cloudinit_gosc | bool
- guest_os_family == "RedHat"
block:
- name: "Check perl existence"
ansible.builtin.command: "which perl"
Expand All @@ -56,6 +61,7 @@
delegate_to: "{{ vm_guest_ip }}"

- name: "Install perl"
when: which_perl_result.rc is undefined or which_perl_result.rc != 0
block:
- name: "Set perl package name on {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }}"
ansible.builtin.set_fact:
Expand All @@ -68,12 +74,9 @@
vars:
package_list: ["{{ guest_perl_package_name }}"]
package_state: "latest"
when: which_perl_result.rc is undefined or which_perl_result.rc != 0
when:
- not enable_cloudinit_gosc | bool
- guest_os_family == "RedHat"

- name: "Prepare for cloud-init GOSC"
when: enable_cloudinit_gosc
block:
- name: "Install 'cloud-init' for cloud-init GOSC on {{ guest_os_ansible_distribution }}"
include_tasks: ../utils/install_uninstall_package.yml
Expand All @@ -84,6 +87,9 @@

# Need to install the latest cloud-init to Oracle Linux 8.7, 9.1 and pass the GOSC tests in Ansible
- name: "Update cloud-init GOSC in OracleLinux 8.7 & 9.1"
when:
- guest_os_ansible_distribution == "OracleLinux"
- guest_os_ansible_distribution_ver in ['8.7', '9.1']
block:
- name: "Known issue - failure of cloud-init GOSC in Oracle Linux 8.7 and 9.1"
ansible.builtin.debug:
Expand Down Expand Up @@ -112,9 +118,6 @@
vars:
package_list: ["cloud-init"]
package_state: "latest"
when:
- guest_os_ansible_distribution == "OracleLinux"
- guest_os_ansible_distribution_ver in ['8.7', '9.1']

# Check whether cloud-init version meets cloud-init GOSC requirements
# Debian 10 and 11 cloud-init GOSC requires cloud-init 22.1 or later installed.
Expand All @@ -126,9 +129,11 @@
gosc_required_cloudinit_version: >-
{% if guest_os_ansible_distribution != 'Debian' %}18.5{% else %}22.1{% endif %}

- include_tasks: ../utils/get_cloudinit_version.yml
- name: "Get cloud-init version"
include_tasks: ../utils/get_cloudinit_version.yml

- include_tasks: ../../common/skip_test_case.yml
- name: "Skip test case due to cloud-init version doesn't meet cloud-init GOSC requirements"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_reason: "Not Supported"
skip_msg: >-
Expand All @@ -137,7 +142,6 @@
when: >
(not cloudinit_version) or
not (cloudinit_version is version(gosc_required_cloudinit_version, '>='))
when: enable_cloudinit_gosc

- name: "Get DNS server info before GOSC"
include_tasks: ../utils/get_system_dns.yml
Expand All @@ -154,14 +158,14 @@
- name: "Update cloud-init config for {{ gosc_workflow }} GOSC"
include_tasks: ../utils/enable_disable_cloudinit_cfg.yml

# Prepare router VM, vSwitch and portgroup
- include_tasks: ../../common/network_testbed_setup.yml
- name: "Prepare router VM, vSwitch and portgroup"
include_tasks: ../../common/network_testbed_setup.yml
when:
- router_vm_required | default(false)
- router_vm_deployed is undefined or not router_vm_deployed | bool

# Initialize the GOSC spec
- name: Initialize the GOS customization spec
- name: "Initialize the GOS customization spec"
ansible.builtin.set_fact:
linux_gosc_spec: {'domain': 'gosc.test.com', 'timezone': "Europe/Berlin", 'dns_suffix': ["test.com", "gosc.test.com"]}

Expand Down Expand Up @@ -190,9 +194,38 @@
- {'hwclockUTC': true}
when: ip_assignment == "dhcp"

# Execute guest customization on VM
- include_tasks: linux_gosc_start.yml
# Check guest customization results
- include_tasks: linux_gosc_verify.yml
- name: "Execute guest customization on VM"
include_tasks: linux_gosc_start.yml

- name: "Check guest customization results"
include_tasks: linux_gosc_verify.yml
rescue:
- include_tasks: ../../common/test_rescue.yml
- name: "Test case failure"
include_tasks: ../../common/test_rescue.yml
always:
- name: "Collect GOSC log"
when:
- gosc_deploypkg_log_local is defined
- gosc_deploypkg_log_local
block:
- name: "Get stat of {{ gosc_deploypkg_log_local }}"
ansible.builtin.stat:
path: "{{ gosc_deploypkg_log_local }}"
register: gosc_deploypkg_log_stat

- name: "Fetch GOSC log file {{ gosc_deploypkg_log_file }}"
include_tasks: ../../common/vm_guest_file_operation.yml
vars:
operation: "fetch_file"
src_path: "{{ gosc_deploypkg_log_file }}"
dest_path: "{{ gosc_deploypkg_log_local }}"
when:
- not (gosc_deploypkg_log_stat.stat.exists | default(False))
- vmtools_is_running is defined
- vmtools_is_running | bool

- name: "Colect cloud-init logs"
include_tasks: ../utils/collect_cloudinit_logs.yml
when: >
(gosc_workflow == "cloud-init") or
(guest_os_ansible_distribution == "VMware Photon OS")