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 f9974f78a4..0277fa6578 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 @@ -23,7 +23,7 @@ tpm_cmd = "tpm2_getrandom --hex 16" auth_sec_dict = {"sec_ephemeral": "no", "sec_private": "yes", "sec_desc": "sample vTPM secret", "sec_usage": "vtpm", "sec_name": "VTPM_example"} secret_value = "sec value test" - check_str_remote_log = "migration release-lock-outgoing,incoming" + check_str_remote_log = '["migration release-lock-outgoing,incoming"]' set_remote_libvirtd_log = "yes" libvirtd_file_type = "virtqemud" libvirtd_debug_level = "1" @@ -33,7 +33,12 @@ tpm_model = "tpm-crb" aarch64: tpm_model = "tpm-tis" - + 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" @@ -47,31 +52,15 @@ 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} + nfs_export_dir = "/var/tmp" + src_mount_path = "${client_ip}:${nfs_export_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" + ceph_key = "EXAMPLE_CEPH_KEY" + src_mount_path = "${mon_host}:6789:/" 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 5a1d16123e..b5f0ca31c1 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,11 +1,10 @@ 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_disk from virttest import utils_package from virttest import virsh @@ -163,34 +162,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 +177,21 @@ def setup_nfs(): """ tpm_security_contexts = params.get("tpm_security_contexts") + swtpm_path = params.get("swtpm_path") + client_ip = params.get("client_ip") + nfs_export_dir = params.get("nfs_export_dir") + server_ip = params.get("server_ip", params.get("remote_ip")) + server_user = params.get("server_user", params.get("remote_user")) + server_pwd = params.get("server_pwd", params.get("remote_pwd")) + src_mount_path = params.get("src_mount_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, export_dir=nfs_export_dir) + server_session = remote.wait_for_login("ssh", server_ip, "22", server_user, server_pwd, r"[\#\$]\s*$") + utils_disk.mount(src_mount_path, swtpm_path, session=server_session) setup_vtpm(params, test, vm, migration_obj) check_tpm_security_context(params, vm, test, tpm_security_contexts) check_swtpm_process(params, test) @@ -220,18 +203,31 @@ 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") + src_mount_path = params.get("src_mount_path") + server_ip = params.get("server_ip", params.get("remote_ip")) + server_user = params.get("server_user", params.get("remote_user")) + server_pwd = params.get("server_pwd", params.get("remote_pwd")) 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 - process.run(cmd, ignore_status=False, shell=True) - remote.run_remote_cmd(cmd, params) - - prepare_ceph_disk(params, test, vm) + if not os.path.exists(swtpm_path): + os.mkdir(swtpm_path) + utils_disk.mount(src_mount_path, swtpm_path, fstype="ceph", options="name=admin,secret=%s" % ceph_key) + server_session = remote.wait_for_login("ssh", server_ip, "22", server_user, server_pwd, r"[\#\$]\s*$") + utils_disk.mount(src_mount_path, swtpm_path, fstype="ceph", options="name=admin,secret=%s" % ceph_key, session=server_session) + process.run("restorecon -Rv /var/lib/libvirt/swtpm", ignore_status=False, shell=True) + server_session.close() + + 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) @@ -260,14 +256,27 @@ def verify_test_again(): vm.wait_for_shutdown() check_tpm_security_context(params, vm, test, tpm_security_contexts_restore) - def cleanup_ceph(): + def cleanup_test(): """ - Cleanup steps for ceph case + Cleanup steps """ - cmd = "umount /var/lib/libvirt/swtpm" - process.run(cmd, ignore_status=False, shell=True) - remote.run_remote_cmd(cmd, params) + src_mount_path = params.get("src_mount_path") + swtpm_path = params.get("swtpm_path") + nfs_export_dir = params.get("nfs_export_dir") + server_ip = params.get("server_ip", params.get("remote_ip")) + server_user = params.get("server_user", params.get("remote_user")) + server_pwd = params.get("server_pwd", params.get("remote_pwd")) + + test.log.info("Cleanup steps.") + server_session = remote.wait_for_login("ssh", server_ip, "22", server_user, server_pwd, r"[\#\$]\s*$") + if shared_storage_type == "ceph": + utils_disk.umount(src_mount_path, swtpm_path, fstype="ceph") + utils_disk.umount(src_mount_path, swtpm_path, fstype="ceph", session=server_session) + else: + utils_disk.umount("127.0.0.1:%s" % nfs_export_dir, swtpm_path) + utils_disk.umount(src_mount_path, swtpm_path, session=server_session) + server_session.close() migration_obj.cleanup_connection() vm_name = params.get("migrate_main_vm") @@ -279,8 +288,6 @@ def cleanup_ceph(): migration_obj = base_steps.MigrationBase(test, vm, params) setup_test = eval("setup_%s" % shared_storage_type) if "setup_%s" % shared_storage_type in \ locals() else migration_obj.setup_connection - cleanup_test = eval("cleanup_%s" % shared_storage_type) if "cleanup_%s" % shared_storage_type in \ - locals() else migration_obj.cleanup_connection try: set_secret(params)