|
11 | 11 |
|
12 | 12 | from virttest.libvirt_xml import vm_xml |
13 | 13 | from virttest.utils_libvirt import libvirt_vmxml |
14 | | -from virttest.utils_test import libvirt |
15 | 14 |
|
16 | 15 | from provider.migration import base_steps |
17 | 16 |
|
@@ -84,41 +83,35 @@ def launch_external_swtpm(params, test, skip_setup=False, on_remote=False): |
84 | 83 | tpm_dict = eval(params.get('tpm_dict', '{}')) |
85 | 84 | source_socket = tpm_dict['backend']['source']['path'] |
86 | 85 | statedir = params.get("statedir") |
87 | | - swtpm_setup_path = params.get("swtpm_setup_path") |
88 | | - swtpm_path = params.get("swtpm_path") |
89 | 86 |
|
90 | 87 | test.log.info("Launch external swtpm process: (on_remote: %s)", on_remote) |
91 | 88 | 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 |
94 | 89 | if on_remote: |
95 | 90 | remote.run_remote_cmd("rm -rf %s" % statedir, params) |
96 | 91 | remote.run_remote_cmd("mkdir %s" % statedir, params) |
97 | | - remote.run_remote_cmd(cmd1, params) |
98 | | - remote.run_remote_cmd(cmd2, params) |
99 | 92 | else: |
100 | 93 | if os.path.exists(statedir): |
101 | 94 | shutil.rmtree(statedir) |
102 | 95 | os.mkdir(statedir) |
103 | 96 | 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 |
108 | 98 | try: |
109 | 99 | if not skip_setup: |
110 | 100 | if on_remote: |
111 | | - remote.run_remote_cmd(cmd3, params) |
| 101 | + remote.run_remote_cmd(cmd1, params) |
112 | 102 | else: |
113 | | - process.run(cmd3, ignore_status=False, shell=True) |
| 103 | + process.run(cmd1, ignore_status=False, shell=True) |
114 | 104 | 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) |
116 | 107 | remote.run_remote_cmd('chcon -t svirt_image_t %s' % source_socket, params) |
117 | 108 | remote.run_remote_cmd('chown qemu:qemu %s' % source_socket, params) |
118 | 109 | 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) |
120 | 113 | # 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) |
122 | 115 | process.run('chcon -t svirt_image_t %s' % source_socket, ignore_status=False, shell=True) |
123 | 116 | process.run('chown qemu:qemu %s' % source_socket, ignore_status=False, shell=True) |
124 | 117 | except Exception as err: |
@@ -177,7 +170,8 @@ def setup_test(): |
177 | 170 | """ |
178 | 171 | tpm_security_contexts = params.get("tpm_security_contexts") |
179 | 172 |
|
180 | | - libvirt.set_vm_disk(vm, params) |
| 173 | + test.log.debug("Setup steps.") |
| 174 | + migration_obj.setup_connection() |
181 | 175 | launch_external_swtpm(params, test) |
182 | 176 | launch_external_swtpm(params, test, skip_setup=False, on_remote=True) |
183 | 177 | setup_vtpm(params, test, vm) |
@@ -211,18 +205,14 @@ def cleanup_test(): |
211 | 205 | Cleanup steps |
212 | 206 |
|
213 | 207 | """ |
214 | | - swtpm_setup_path = params.get("swtpm_setup_path") |
215 | | - swtpm_path = params.get("swtpm_path") |
216 | 208 | statedir = params.get("statedir") |
217 | 209 |
|
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) |
222 | 214 | if os.path.exists(statedir): |
223 | 215 | shutil.rmtree(statedir) |
224 | | - remote.run_remote_cmd(cmd1, params) |
225 | | - remote.run_remote_cmd(cmd2, params) |
226 | 216 | remote.run_remote_cmd("rm -rf %s" % statedir, params) |
227 | 217 | migration_obj.cleanup_connection() |
228 | 218 |
|
|
0 commit comments