Skip to content

Commit

Permalink
migration: Update migration with shared tpm case
Browse files Browse the repository at this point in the history
Use the new directory instead of the swtpm directory as the path to
store the image.

Signed-off-by: lcheng <[email protected]>
  • Loading branch information
cliping committed Jul 24, 2024
1 parent 9ea3a9b commit 28f1e9c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 28f1e9c

Please sign in to comment.