From b80a02a29e355d2119d2875927d96b0f5ea93fe8 Mon Sep 17 00:00:00 2001 From: Thierry Escande Date: Tue, 5 Sep 2023 12:49:33 +0200 Subject: [PATCH] Add vtpm methods to VM class This adds get_vtpm(), create_vtpm(), and destroy_vtpm() methods to the VM class. vm.get_vtpm() returns the vtpm uuid associated to the vm if it exists, None otherwise. vm.create_vtpm() creates a vtpm and associates it to the vm. It returns the newly created vtpm uuid, or fails if a vtpm is already associated to the vm. vm.destroy_vm() destroys the existing vtpm associated to the vm if one exists. It doesn't fail if no vtpm is associated to the vm. Signed-off-by: Thierry Escande --- lib/vm.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/vm.py b/lib/vm.py index 01dfd8572..2e60c6c8f 100644 --- a/lib/vm.py +++ b/lib/vm.py @@ -401,6 +401,19 @@ def get_all_efi_bins(self): return binaries + def get_vtpm_uuid(self): + return self.host.xe('vtpm-list', {'vm': self.uuid}, minimal=True) + + def create_vtpm(self): + logging.info("Creating vTPM for vm %s" % self.uuid) + return self.host.xe('vtpm-create', {'vm-uuid': self.uuid}) + + def destroy_vtpm(self): + vtpm_uuid = self.get_vtpm_uuid() + assert vtpm_uuid, "A vTPM must be present" + logging.info("Destroying vTPM %s" % vtpm_uuid) + return self.host.xe('vtpm-destroy', {'uuid': vtpm_uuid}, force=True) + def clone(self): name = self.name() + '_clone_for_tests' logging.info("Clone VM")