diff --git a/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg b/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg index 330781b12d..7f11adeff6 100644 --- a/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg +++ b/libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_shared_tpm.cfg @@ -30,7 +30,12 @@ libvirtd_debug_filters = "1:*" libvirtd_debug_file = '/var/log/libvirt/virtqemud.log' func_supported_since_libvirt_ver = (9, 0, 0) - + swtpm_path = "/var/lib/libvirt/swtpm" + storage_type = 'nfs' + setup_local_nfs = 'yes' + disk_type = "file" + disk_source_protocol = "netfs" + mnt_path_name = ${nfs_mount_dir} variants: - persistent_and_p2p: virsh_migrate_options = "--live --p2p --verbose --undefinesource --persistent" @@ -44,31 +49,14 @@ transient_vm = "yes" variants shared_storage_type: - nfs: - image_convert = "no" - storage_type = 'nfs' - setup_local_nfs = 'yes' - disk_type = "file" - disk_source_protocol = "netfs" - nfs_mount_dir = "/var/lib/libvirt/swtpm" - mnt_path_name = ${nfs_mount_dir} tpm_security_contexts = "nfs_t" tpm_security_contexts_restore = "${tpm_security_contexts}" - ceph: - disk_type = "network" - nfs_mount_dir = - mnt_path_name = - setup_local_nfs = 'no' - disk_source_protocol = "rbd" - disk_source_port = "6789" - disk_source_name = "migration-with-vtpm-pool" tpm_security_contexts = "svirt_image_t" tpm_security_contexts_restore = "virt_var_lib_t" disk_dict = {"device": "disk", "type_name": "network", "driver": {"name": "qemu", "type": "raw", "cache": "none"}, "target": {"dev": "vda", "bus": "virtio"}} seclabel_dict = {"type": "static", "model": "selinux", "relabel": "yes", "label": "system_u:system_r:svirt_t:s0:c392,c662"} - cleanup_disks = "yes" - image_convert = "yes" - variants: - - non_auth: - mon_host = "EXAMPLE_MON_HOST" - disk_source_host = "EXAMPLE_HOSTS" - host_dict = {"name": "${disk_source_host}", "port": "${disk_source_port}"} + mon_host = "EXAMPLE_MON_HOST" + disk_source_host = "EXAMPLE_MON_HOST" + ceph_key = "EXAMPLE_CEPH_KEY" + host_dict = {"name": "${disk_source_host}", "port": "${disk_source_port}"} diff --git a/libvirt/tests/src/migration/migration_with_vtpm/migration_with_shared_tpm.py b/libvirt/tests/src/migration/migration_with_vtpm/migration_with_shared_tpm.py index a920f52a47..93e3f64646 100644 --- a/libvirt/tests/src/migration/migration_with_vtpm/migration_with_shared_tpm.py +++ b/libvirt/tests/src/migration/migration_with_vtpm/migration_with_shared_tpm.py @@ -1,9 +1,7 @@ import os -from avocado.utils import distro from avocado.utils import process -from virttest import ceph from virttest import libvirt_version from virttest import remote from virttest import utils_package @@ -163,34 +161,6 @@ def setup_vtpm(params, test, vm, migration_obj): vm.wait_for_login().close() -def prepare_ceph_disk(params, test, vm): - """ - Prepare ceph disk - - :param params: dict, test parameters - :param vm: VM object - :param test: test object - """ - mon_host = params.get("mon_host") - disk_source_name = params.get("disk_source_name") - seclabel_dict = eval(params.get("seclabel_dict", "{}")) - vm_name = params.get("migrate_main_vm") - - detected_distro = distro.detect() - rbd_img_prefix = '_'.join(['rbd', detected_distro.name, - detected_distro.version, - detected_distro.release, - detected_distro.arch]) - disk_source_name = os.path.join(disk_source_name, rbd_img_prefix + '.img') - params.update({"disk_source_name": disk_source_name}) - ceph.rbd_image_rm(mon_host, disk_source_name.split("/")[0], - disk_source_name.split("/")[1]) - vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) - vmxml.set_seclabel([seclabel_dict]) - vmxml.sync() - libvirt.set_vm_disk(vm, params) - - def run(test, params, env): """ Test migration with vtpm device with shared TPM state. @@ -206,9 +176,13 @@ def setup_nfs(): """ tpm_security_contexts = params.get("tpm_security_contexts") + swtpm_path = params.get("swtpm_path") test.log.info("Setup for nfs storage type.") libvirt.set_vm_disk(vm, params) + if not os.path.exists(swtpm_path): + os.mkdir(swtpm_path) + libvirt.setup_or_cleanup_nfs(True, mount_dir=swtpm_path, is_mount=True) setup_vtpm(params, test, vm, migration_obj) check_tpm_security_context(params, vm, test, tpm_security_contexts) check_swtpm_process(params, test) @@ -222,16 +196,24 @@ def setup_ceph(): tpm_security_contexts = params.get("tpm_security_contexts") mon_host = params.get("mon_host") set_remote_libvirtd_log = "yes" == params.get("set_remote_libvirtd_log", "no") + swtpm_path = params.get("swtpm_path") + seclabel_dict = eval(params.get("seclabel_dict", "{}")) + ceph_key = params.get("ceph_key") test.log.info("Setup for ceph storage type.") if set_remote_libvirtd_log: migration_obj.set_remote_log() - cmd = "mount -t ceph %s:6789:/ /var/lib/libvirt/swtpm -o name=admin" % mon_host + if not os.path.exists(swtpm_path): + os.mkdir(swtpm_path) + cmd = "mount -t ceph %s:6789:/ %s -o name=admin,secret=%s" % (mon_host, swtpm_path, ceph_key) process.run(cmd, ignore_status=False, shell=True) remote.run_remote_cmd(cmd, params) - prepare_ceph_disk(params, test, vm) + vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) + vmxml.set_seclabel([seclabel_dict]) + vmxml.sync() + libvirt.set_vm_disk(vm, params) setup_vtpm(params, test, vm, migration_obj) check_tpm_security_context(params, vm, test, tpm_security_contexts) check_swtpm_process(params, test) @@ -256,6 +238,15 @@ def verify_test_again(): vm.wait_for_shutdown() check_tpm_security_context(params, vm, test, tpm_security_contexts_restore) + def cleanup_nfs(): + """ + Cleanup steps for nfs case + + """ + cmd = "umount /var/lib/libvirt/swtpm" + process.run(cmd, ignore_status=False, shell=True) + migration_obj.cleanup_connection() + def cleanup_ceph(): """ Cleanup steps for ceph case @@ -279,6 +270,7 @@ def cleanup_ceph(): try: set_secret(params) + base_steps.prepare_cpu_for_mig(params) setup_test() migration_obj.run_migration() verify_test()