Skip to content

Commit e002d4d

Browse files
authored
migration: Update external tpm case (#6351)
Running chcon on a read-only system will fail. So update case. Signed-off-by: lcheng <[email protected]>
1 parent abe2901 commit e002d4d

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

libvirt/tests/cfg/migration/migration_with_vtpm/migration_with_external_tpm.cfg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
storage_type = 'nfs'
55
setup_local_nfs = 'yes'
66
disk_type = "file"
7-
disk_source_protocol = "netfs"
87
mnt_path_name = ${nfs_mount_dir}
98
# Console output can only be monitored via virsh console output
109
only_pty = True
@@ -26,6 +25,7 @@
2625
client_pwd = "${migrate_source_pwd}"
2726
status_error = "no"
2827
transport_type = "ssh"
28+
migrate_desturi_type = "ssh"
2929
virsh_migrate_desturi = "qemu+ssh://${migrate_dest_host}/system"
3030
# vtpm setting
3131
func_supported_since_libvirt_ver = (9, 0, 0)
@@ -35,11 +35,8 @@
3535
aarch64:
3636
tpm_dict = {'tpm_model': 'tpm-tis', 'backend': {'backend_type': 'external', 'source': {'type': 'unix', 'mode': 'connect', 'path': '/var/tmp/guest-swtpm.sock'}}}
3737
statedir = "/var/tmp/mytpm"
38-
swtpm_setup_path = '/usr/bin/swtpm_setup'
39-
swtpm_path = '/usr/bin/swtpm'
4038
tpm_cmd = "tpm2_getrandom --hex 16"
4139
tpm_security_contexts= "user_tmp_t"
42-
4340
variants:
4441
- persistent_and_p2p:
4542
virsh_migrate_options = "--live --p2p --verbose --undefinesource --persistent"

libvirt/tests/src/migration/migration_with_vtpm/migration_with_external_tpm.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from virttest.libvirt_xml import vm_xml
1313
from virttest.utils_libvirt import libvirt_vmxml
14-
from virttest.utils_test import libvirt
1514

1615
from provider.migration import base_steps
1716

@@ -84,41 +83,35 @@ def launch_external_swtpm(params, test, skip_setup=False, on_remote=False):
8483
tpm_dict = eval(params.get('tpm_dict', '{}'))
8584
source_socket = tpm_dict['backend']['source']['path']
8685
statedir = params.get("statedir")
87-
swtpm_setup_path = params.get("swtpm_setup_path")
88-
swtpm_path = params.get("swtpm_path")
8986

9087
test.log.info("Launch external swtpm process: (on_remote: %s)", on_remote)
9188
if not skip_setup:
92-
cmd1 = 'chcon -t virtd_exec_t %s' % swtpm_setup_path
93-
cmd2 = 'chcon -t virtd_exec_t %s' % swtpm_path
9489
if on_remote:
9590
remote.run_remote_cmd("rm -rf %s" % statedir, params)
9691
remote.run_remote_cmd("mkdir %s" % statedir, params)
97-
remote.run_remote_cmd(cmd1, params)
98-
remote.run_remote_cmd(cmd2, params)
9992
else:
10093
if os.path.exists(statedir):
10194
shutil.rmtree(statedir)
10295
os.mkdir(statedir)
10396
process.run("ls -lZd %s" % statedir)
104-
process.run(cmd1, ignore_status=False, shell=True)
105-
process.run(cmd2, ignore_status=False, shell=True)
106-
cmd3 = "systemd-run %s --tpm2 --tpmstate %s --create-ek-cert --create-platform-cert --overwrite" % (swtpm_setup_path, statedir)
107-
cmd4 = "systemd-run %s socket --ctrl type=unixio,path=%s,mode=0600 --tpmstate dir=%s,mode=0600 --tpm2 --terminate" % (swtpm_path, source_socket, statedir)
97+
cmd1 = "swtpm_setup --tpm2 --tpmstate %s --create-ek-cert --create-platform-cert --overwrite" % statedir
10898
try:
10999
if not skip_setup:
110100
if on_remote:
111-
remote.run_remote_cmd(cmd3, params)
101+
remote.run_remote_cmd(cmd1, params)
112102
else:
113-
process.run(cmd3, ignore_status=False, shell=True)
103+
process.run(cmd1, ignore_status=False, shell=True)
114104
if on_remote:
115-
remote.run_remote_cmd(cmd4, params)
105+
cmd2 = "nohup swtpm socket --ctrl type=unixio,path=%s,mode=0600 --tpmstate dir=%s,mode=0600 --tpm2 --terminate > /dev/null 2>&1 &" % (source_socket, statedir)
106+
remote.run_remote_cmd(cmd2, params)
116107
remote.run_remote_cmd('chcon -t svirt_image_t %s' % source_socket, params)
117108
remote.run_remote_cmd('chown qemu:qemu %s' % source_socket, params)
118109
else:
119-
process.run(cmd4, ignore_status=False, shell=True)
110+
cmd2 = "swtpm socket --ctrl type=unixio,path=%s,mode=0600 --tpmstate dir=%s,mode=0600 --tpm2 --terminate &" % (source_socket, statedir)
111+
process.run(cmd2, ignore_status=False, shell=True, ignore_bg_processes=True)
112+
process.run("ps aux|grep 'swtpm socket'|grep -v avocado-runner-avocado-vt|grep -v grep", ignore_status=True, shell=True)
120113
# Make sure the socket is created
121-
utils_misc.wait_for(lambda: os.path.isdir(source_socket), timeout=3)
114+
utils_misc.wait_for(lambda: os.path.exists(source_socket), timeout=3)
122115
process.run('chcon -t svirt_image_t %s' % source_socket, ignore_status=False, shell=True)
123116
process.run('chown qemu:qemu %s' % source_socket, ignore_status=False, shell=True)
124117
except Exception as err:
@@ -177,7 +170,8 @@ def setup_test():
177170
"""
178171
tpm_security_contexts = params.get("tpm_security_contexts")
179172

180-
libvirt.set_vm_disk(vm, params)
173+
test.log.debug("Setup steps.")
174+
migration_obj.setup_connection()
181175
launch_external_swtpm(params, test)
182176
launch_external_swtpm(params, test, skip_setup=False, on_remote=True)
183177
setup_vtpm(params, test, vm)
@@ -211,18 +205,14 @@ def cleanup_test():
211205
Cleanup steps
212206
213207
"""
214-
swtpm_setup_path = params.get("swtpm_setup_path")
215-
swtpm_path = params.get("swtpm_path")
216208
statedir = params.get("statedir")
217209

218-
cmd1 = "restorecon %s" % swtpm_setup_path
219-
cmd2 = "restorecon %s" % swtpm_path
220-
process.run(cmd1, ignore_status=False, shell=True)
221-
process.run(cmd2, ignore_status=False, shell=True)
210+
remote.run_remote_cmd('pkill swtpm', params, ignore_status=True)
211+
remote.run_remote_cmd("rm -rf /var/lib/swtpm-localca/*", params, ignore_status=True)
212+
process.run("pkill swtpm", shell=True, ignore_status=True)
213+
process.run("rm -rf /var/lib/swtpm-localca/*", shell=True, ignore_status=True)
222214
if os.path.exists(statedir):
223215
shutil.rmtree(statedir)
224-
remote.run_remote_cmd(cmd1, params)
225-
remote.run_remote_cmd(cmd2, params)
226216
remote.run_remote_cmd("rm -rf %s" % statedir, params)
227217
migration_obj.cleanup_connection()
228218

0 commit comments

Comments
 (0)