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] Set VM boot order before vHBA testing and test file read/write on new disk #491

Merged
merged 6 commits into from
Aug 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions common/test_rescue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@
download_file_fail_ignore: true
when: vm_dir_name is defined and vm_dir_name

- name: "Download serial output file"
include_tasks: 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: "Take a snapshot at VM current state"
include_tasks: vm_take_snapshot.yml
vars:
Expand Down
8 changes: 4 additions & 4 deletions linux/nvdimm_cold_add_remove/cold_add_nvdimm_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
- name: "Test file read/write on new partition {{ new_nvdimm_part_dev_path }}"
include_tasks: ../vhba_hot_add_remove/test_file_read_write.yml
vars:
test_partition_name: "{{ new_nvdimm_part_name }}"
test_partition_uuid: "{{ new_nvdimm_part_uuid }}"
test_partition_device_path: "{{ new_nvdimm_part_dev_path }}"
test_partition_fstype: "{{ new_nvdimm_part_fstype }}"
new_partition_name: "{{ new_nvdimm_part_name }}"
new_partition_uuid: "{{ new_nvdimm_part_uuid }}"
new_partition_device_path: "{{ new_nvdimm_part_dev_path }}"
new_partition_fstype: "{{ new_nvdimm_part_fstype }}"
41 changes: 41 additions & 0 deletions linux/utils/freebsd_get_geom_conf_xml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Description:
# Get GEOM config info in XML on FreeBSD
#
- name: "Set fact of local file to save FreeBSD GEOM config info"
ansible.builtin.set_fact:
freebsd_geom_xml_file: "{{ current_test_log_folder }}/geom_conf_{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}.xml"

- name: "Check exitence of current test case log folder"
ansible.builtin.stat:
path: "{{ current_test_log_folder }}"
register: test_log_folder_stat

- name: "Create log folder for current test case"
include_tasks: ../../common/create_directory.yml
vars:
dir_path: "{{ current_test_log_folder }}"
dir_mode: "0777"
when: not (test_log_folder_stat.exists | default(False))

- name: "Create local file to save FreeBSD GEOM config info"
ansible.builtin.file:
path: "{{ freebsd_geom_xml_file }}"
state: touch
mode: "0666"

- name: "Get FreeBSD GEOM config info"
ansible.builtin.shell: "sysctl kern.geom.confxml"
delegate_to: "{{ vm_guest_ip }}"
register: geom_in_xml_result

- name: "Write FreeBSD GEOM info to XML file"
ansible.builtin.copy:
content: "{{ geom_in_xml_result.stdout | replace('kern.geom.confxml: ', '') }}"
dest: "{{ freebsd_geom_xml_file }}"

- name: "Print the file path of FreeBSD GEOM config info"
ansible.builtin.debug:
msg: "FreeBSD GEOM config in XML format are saved into file {{ freebsd_geom_xml_file }}"
89 changes: 89 additions & 0 deletions linux/utils/freebsd_get_partition_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Description:
# Get disk partition info by partition name or UUID on FreeBSD
# Paramters:
# disk_partition_name: The disk partition name on FreeBSD
# disk_partition_uuid: The disk partition UUID on FreeBSD
# Return:
# disk_partition_info: The disk partition info on FreeBSD
#
- name: "Check paramters to get FreeBSD disk partition info"
ansible.builtin.assert:
that:
- disk_partition_name | default('') or disk_partition_uuid | default('')
fail_msg: >-
Parameter 'disk_partition_name' or 'disk_partition_uuid' must be set
to get disk partition info.

- name: "Initialize facts of FreeBSD disk partition info"
ansible.builtin.set_fact:
disk_partition_info: {}
disk_partition_config_info: {}

- name: "Get FreeBSD GEOM config file in XML"
include_tasks: freebsd_get_geom_conf_xml.yml

- name: "Set facts of XPATHs for geting disk partition info"
ansible.builtin.set_fact:
xpath_of_disk_part: "/mesh/class[name='PART']/geom/provider[name='{{ disk_partition_name }}']/*"
xpath_of_disk_part_config: "/mesh/class[name='PART']/geom/provider[name='{{ disk_partition_name }}']/config/*"
when:
- disk_partition_name is defined
- disk_partition_name

- name: "Set facts of XPATHs for geting disk partition info"
ansible.builtin.set_fact:
xpath_of_disk_part: "/mesh/class[name='PART']/geom/provider/*[../config[rawuuid='{{ disk_partition_uuid }}']]"
xpath_of_disk_part_config: "/mesh/class[name='PART']/geom/provider/config[rawuuid='{{ disk_partition_uuid }}']/*"
when:
- disk_partition_uuid is defined
- disk_partition_uuid

- name: "Get disk partition"
community.general.xml:
path: "{{ freebsd_geom_xml_file }}"
xpath: "{{ xpath_of_disk_part }}"
content: text
register: geom_part_xml

- name: "Set fact of disk partition info"
ansible.builtin.set_fact:
disk_partition_info: >-
{{
disk_partition_info | combine({'config': ''}) if geom_item['config'] is defined
else disk_partition_info | combine(geom_item)
}}
with_items: "{{ geom_part_xml.matches }}"
loop_control:
loop_var: geom_item
when:
- geom_part_xml.matches is defined
- geom_part_xml.matches | length > 0

- debug: var=disk_partition_info
- name: "Get disk partition config"
community.general.xml:
path: "{{ freebsd_geom_xml_file }}"
xpath: "{{ xpath_of_disk_part_config }}"
content: text
register: geom_conf_xml

- name: "Set fact of disk partition info"
ansible.builtin.set_fact:
disk_partition_config_info: "{{ disk_partition_config_info | combine(geom_item) }}"
with_items: "{{ geom_conf_xml.matches }}"
loop_control:
loop_var: geom_item
when:
- geom_conf_xml.matches is defined
- geom_conf_xml.matches | length > 0

- debug: var=disk_partition_config_info
- name: "Update fact of disk partition with config info"
ansible.builtin.set_fact:
disk_partition_info: "{{ disk_partition_info | combine({'config': disk_partition_config_info}) }}"

- name: "Print disk partition info on FreeBSD"
ansible.builtin.debug: var=disk_partition_info
17 changes: 7 additions & 10 deletions linux/vhba_hot_add_remove/freebsd_create_disk_partition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ansible.builtin.set_fact:
partition_name: ""
partition_device_path: ""
partition_uuid: ""

- name: "Set default partition filesystem to ext4"
ansible.builtin.set_fact:
Expand Down Expand Up @@ -61,19 +62,15 @@
register: partition_result
when: partition_fstype == "ufs"

- name: "Get the UUID of partition {{ partition_device_path }}"
ansible.builtin.shell: "gpart list {{ disk_name }} | grep rawuuid"
changed_when: false
delegate_to: "{{ vm_guest_ip }}"
register: blkid_part_result
- name: "Get disk partition info"
include_tasks: ../utils/freebsd_get_partition_info.yml
vars:
disk_partition_name: "{{ partition_name }}"

- name: "Set the fact of partition {{ partition_device_path }} UUID"
ansible.builtin.set_fact:
partition_uuid: "{{ blkid_part_result.stdout.split(':')[-1] }}"
when:
- blkid_part_result is defined
- blkid_part_result.stdout is defined
- blkid_part_result.stdout
partition_uuid: "{{ disk_partition_info.config.rawuuid }}"
when: disk_partition_info.config.rawuuid | default('')

- name: "Check the UUID of partition {{ partition_device_path }}"
ansible.builtin.assert:
Expand Down
66 changes: 43 additions & 23 deletions linux/vhba_hot_add_remove/hot_add_remove_disk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,30 @@
ansible.builtin.set_fact:
new_disk_size_gb: 1

- include_tasks: ../../common/vm_hot_add_ctrl_disk.yml
# Disk hot-add
- name: "Get guest disk list before hot-add"
include_tasks: ../utils/get_device_list.yml
vars:
guest_device_type: "disk"

- name: "Set the fact of guest disk list before hot-add"
ansible.builtin.set_fact:
guest_disk_list_before_hotadd: "{{ guest_device_list }}"

- name: "Print guest disk list before hot-add"
ansible.builtin.debug: var=guest_disk_list_before_hotadd

- name: "Hot add a new disk on a new {{ new_disk_ctrl_type }} controller"
include_tasks: ../../common/vm_hot_add_ctrl_disk.yml
vars:
disk_controller_type: "{{ new_disk_ctrl_type }}"
disk_size_gb: "{{ new_disk_size_gb }}"
ctrl_number: "{{ new_ctrl_number }}"
unit_number: "{{ new_unit_number }}"
when: add_new_controller

- include_tasks: ../../common/vm_hot_add_remove_disk.yml
- name: "Hot add a new disk on an existing {{ new_disk_ctrl_type }} controller"
include_tasks: ../../common/vm_hot_add_remove_disk.yml
vars:
disk_operation: 'present'
disk_controller_type: "{{ new_disk_ctrl_type }}"
Expand All @@ -22,17 +37,18 @@
unit_number: "{{ new_unit_number }}"
when: not add_new_controller

- include_tasks: wait_device_list_changed.yml
- name: "Wait for hot-added disk being present in guest OS"
include_tasks: wait_device_list_changed.yml
vars:
device_list_before_change: "{{ guest_disk_list_before_hotadd }}"
wait_device_state: "present"

- name: "Get guest device list after hot add"
- name: "Get guest disk list after hot-add"
include_tasks: ../utils/get_device_list.yml
vars:
guest_device_type: "disk"

- name: "Set the fact of guest device list after hot add"
- name: "Set the fact of guest disk list after hot-add"
ansible.builtin.set_fact:
guest_disk_list_after_hotadd: "{{ guest_device_list }}"

Expand All @@ -42,7 +58,7 @@
- guest_disk_list_after_hotadd | difference(guest_disk_list_before_hotadd) | length == 1
fail_msg: "Guest OS failed to recognize the new hot-added {{ new_disk_ctrl_type }} disk"

- name: "Print guest disk list after hot add"
- name: "Print guest disk list after hot-add"
ansible.builtin.debug: var=guest_disk_list_after_hotadd

- name: "Set fact of the new guest disk info"
Expand Down Expand Up @@ -92,49 +108,53 @@
ansible.builtin.set_fact:
new_partition_name: "{{ partition_name }}"
new_partition_device_path: "{{ partition_device_path }}"
new_partition_fstype: "ext4"
new_partition_fstype: "{{ 'ext4' if guest_os_family != 'FreeBSD' else 'ufs' }}"
new_partition_uuid: "{{ partition_uuid }}"

- name: "Test disk I/O on new disk {{ new_guest_disk_info.name }}"
include_tasks: test_disk_io.yml
vars:
test_disk_name: "{{ new_guest_disk_info.name }}"

# After reboot disk boot order might be changed, but at now
# community.vmware.vmware_guest_boot_info can't get the boot order info.
# So comment this out until boot disk reordering is resolved.
#- name: "Test file read/write on new partition {{ new_partition_device_path }}"
# include_tasks: test_file_read_write.yml
# vars:
# test_partition_name: "{{ new_partition_name }}"
# test_partition_uuid: "{{ new_partition_uuid }}"
# test_partition_device_path: "{{ new_partition_device_path }}"
# test_partition_fstype: "{{ new_partition_fstype }}"

- include_tasks: ../../common/vm_hot_add_remove_disk.yml
- name: "Test file read and write on new partition {{ new_partition_device_path }}"
include_tasks: test_file_read_write.yml

# Disk hot-remove
- name: "Get guest disk list before hot-remove"
include_tasks: ../utils/get_device_list.yml
vars:
guest_device_type: "disk"

- name: "Set the fact of guest device before hot-remove"
ansible.builtin.set_fact:
guest_disk_list_before_hotremove: "{{ guest_device_list }}"

- name: "Hot remove the new disk from VM"
include_tasks: ../../common/vm_hot_add_remove_disk.yml
vars:
disk_operation: 'absent'
ctrl_number: "{{ new_ctrl_number }}"
unit_number: "{{ new_unit_number }}"
disk_controller_type: "{{ new_disk_ctrl_type }}"

- include_tasks: wait_device_list_changed.yml
- name: "Wait for disk being absent in guest OS"
include_tasks: wait_device_list_changed.yml
vars:
device_list_before_change: "{{ guest_disk_list_after_hotadd }}"
wait_device_name: "{{ new_guest_disk_info.name }}"
wait_device_state: "absent"

- name: "Get guest device list after hot add"
- name: "Get guest disk list after hot-remove"
include_tasks: ../utils/get_device_list.yml
vars:
guest_device_type: "disk"

- name: "Set the fact of guest device list after hot add"
- name: "Set the fact of guest disk list after hot-remove"
ansible.builtin.set_fact:
guest_disk_list_after_hotremove: "{{ guest_device_list }}"

- name: "Check new disk is removed from guest OS"
ansible.builtin.assert:
that:
- guest_disk_list_after_hotremove | difference(guest_disk_list_before_hotadd) | length == 0
- guest_disk_list_before_hotremove | difference(guest_disk_list_after_hotremove) | length == 1
keirazhang marked this conversation as resolved.
Show resolved Hide resolved
fail_msg: "After disk hot-remove, the Guest OS still can see it"
Loading