From 946b929eab62fd4e766c415c2c58e845c457f62b Mon Sep 17 00:00:00 2001 From: Zhang Pinge <50477615+warku123@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:19:53 +0800 Subject: [PATCH] Add 2 function in hyperv test (#35) * Add 2 function in hyperv test * Add description for 2 function * Delete one function & change name for another one * Change to f-string --- hypervisor/virt/hyperv/hypervcli.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hypervisor/virt/hyperv/hypervcli.py b/hypervisor/virt/hyperv/hypervcli.py index 8cda9f1..ddd6e73 100644 --- a/hypervisor/virt/hyperv/hypervcli.py +++ b/hypervisor/virt/hyperv/hypervcli.py @@ -261,3 +261,27 @@ def guest_resume(self, guest_name): else: logger.error("Failed to resume hyperv guest") return False + + def guest_uuid_change(self, guid, guest_name): + """ + Change guid for guest + :param guid: the guid for guest + :param guest_name: the name for the guest + :return: change guid successfully, return True, else, return False. + """ + create_function_cmd = r"PowerShell (Invoke-WebRequest http://10.73.131.85/ci/hyperv/New-VMBIOSGUID.ps1 -OutFile ./New-VMBIOSGUID.ps1)" + ret, _ = self.ssh.runcmd(create_function_cmd) + if ret: + logger.error("Failed to create function") + return False + + import_module_cmd = r"Import-Module ./New-VMBIOSGUID.ps1 -Force" + set_ignore_verfiy_cmd = r"$ConfirmPreference = 'None'" + change_guid_cmd = f'PowerShell -Command "{set_ignore_verfiy_cmd}; {import_module_cmd}; New-VMBIOSGUID -VM {guest_name} -NewID {guid}"' + ret, _ = self.ssh.runcmd(change_guid_cmd) + if not ret: + logger.info("Succeeded to change hypervisor guid") + return True + else: + logger.error("Failed to change hypervisor guid") + return False