Skip to content

Commit c56a615

Browse files
committed
vm: split out set_variable_from_file
Signed-off-by: Tu Dinh <ngoc-tu.dinh@vates.tech>
1 parent 4a2f547 commit c56a615

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/vm.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import tempfile
6+
import uuid
67

78
import lib.commands as commands
89
import lib.efi as efi
@@ -629,6 +630,16 @@ def clone(self, *, name=None):
629630
uuid = self.host.xe('vm-clone', {'uuid': self.uuid, 'new-name-label': name})
630631
return VM(uuid, self.host)
631632

633+
def set_variable_from_file(
634+
self, filepath: str, variable_guid: str | uuid.UUID, variable_name: str, attr: int | str
635+
):
636+
dest = self.host.ssh(['mktemp'])
637+
try:
638+
self.host.scp(filepath, dest)
639+
self.host.ssh(['varstore-set', self.uuid, str(variable_guid), variable_name, str(attr), dest])
640+
finally:
641+
self.host.ssh(['rm', '-f', dest])
642+
632643
def install_uefi_certs(self, auths: Iterable[efi.EFIAuth]):
633644
"""
634645
Install UEFI certs to the VM's NVRAM store.
@@ -642,15 +653,7 @@ def install_uefi_certs(self, auths: Iterable[efi.EFIAuth]):
642653
assert auth.name in ['PK', 'KEK', 'db', 'dbx']
643654
logging.info(f"Installing UEFI certs to VM {self.uuid}: {[auth.name for auth in auths]}")
644655
for auth in auths:
645-
dest = self.host.ssh(['mktemp'])
646-
try:
647-
self.host.scp(auth.auth(), dest)
648-
self.host.ssh([
649-
'varstore-set', self.uuid, auth.guid.as_str(), auth.name,
650-
str(efi.EFI_AT_ATTRS), dest
651-
])
652-
finally:
653-
self.host.ssh(['rm', '-f', dest])
656+
self.set_variable_from_file(auth.auth(), auth.guid.as_str(), auth.name, efi.EFI_AT_ATTRS)
654657

655658
def booted_with_secureboot(self):
656659
""" Returns True if the VM is on and SecureBoot is confirmed to be on from within the VM. """

0 commit comments

Comments
 (0)