Skip to content

Commit

Permalink
qemu: Automatically create swtpm device
Browse files Browse the repository at this point in the history
- Create device if QEMUTPM is set
- Recommend swtpm packages
- Add swtpm test deps

See: https://progress.opensuse.org/issues/101015
  • Loading branch information
kalikiana committed Oct 25, 2021
1 parent 81bfead commit 813154f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backend/qemu.pm
Expand Up @@ -831,7 +831,11 @@ sub start_qemu {

if ($vars->{QEMUTPM}) {
my $tpmn = $vars->{QEMUTPM} eq 'instance' ? $vars->{WORKER_INSTANCE} : $vars->{QEMUTPM};
sp('chardev', "socket,id=chrtpm,path=/tmp/mytpm$tpmn/swtpm-sock");
my $vmpath = "/tmp/mytpm$tpmn";
mkdir $vmpath unless -d $vmpath;
my $vmsock = "$vmpath/swtpm-sock";
runcmd('swtpm', 'socket', '--tpm2', '--tpmstate', "dir=$vmpath", '--ctrl', "type=unixio,path=$vmsock", '--log', 'level-20', '-d') unless -e $vmsock;
sp('chardev', "socket,id=chrtpm,path=$vmsock");
sp('tpmdev', 'emulator,id=tpm0,chardev=chrtpm');
if ($arch eq 'aarch64') {
sp('device', 'tpm-tis-device,tpmdev=tpm0');
Expand Down
11 changes: 11 additions & 0 deletions dist/rpm/os-autoinst.spec
Expand Up @@ -131,6 +131,17 @@ Requires: qemu-tools

%description qemu-kvm

%package swtpm
Summary: Convenience package providing os-autoinst+swtpm
Group: Development/Tools/Other
Requires: os-autoinst
Requires: libtpms0
Requires: swtpm

%description swtpm
Convenience package providing os-autoinst and swtpm dependencies.
%endif

%package qemu-x86
Summary: Convenience package providing os-autoinst+qemu-x86
Group: Development/Tools/Other
Expand Down
2 changes: 2 additions & 0 deletions t/18-qemu-options.t
Expand Up @@ -112,12 +112,14 @@ subtest qemu_huge_pages_option => sub {
# of QEMU here.
subtest qemu_tpm_option => sub {
# call isotovideo with QEMUTPM=instance
path('/tmp/mytpm3/swtpm-sock')->touch;
run_isotovideo(QEMU_ONLY_EXEC => 1, QEMUTPM => 'instance');
like($log, qr|-chardev socket,id=chrtpm,path=/tmp/mytpm3/swtpm-sock|, '-chardev socket option added (instance)');
like($log, qr|-tpmdev emulator,id=tpm0,chardev=chrtpm|, '-tpmdev emulator option added');
like($log, qr|-device tpm-tis,tpmdev=tpm0|, '-device tpm-tis option added');

# call isotovideo with QEMUTPM=2
path('/tmp/mytpm2/swtpm-sock')->touch;
run_isotovideo(QEMU_ONLY_EXEC => 1, QEMUTPM => '2');
like($log, qr|-chardev socket,id=chrtpm,path=/tmp/mytpm2/swtpm-sock|, '-chardev socket option added (2)');

Expand Down

0 comments on commit 813154f

Please sign in to comment.