From fe7a98ed7ba145447abc48aaca374af830017f54 Mon Sep 17 00:00:00 2001 From: Nithin M N <MN.Nithin@in.bosch.com> Date: Wed, 13 Dec 2023 11:13:51 +0000 Subject: [PATCH] PSDK test case failure fix Adaptations done to convert ova file to vdi file as the test cases expect vdi file Implement authorization for http links given as input to the script Signed-off-by: Nithin M N <MN.Nithin@in.bosch.com> --- psdk-test/psdk_commands.py | 44 ++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/psdk-test/psdk_commands.py b/psdk-test/psdk_commands.py index 5167a075..b0b1f7fe 100644 --- a/psdk-test/psdk_commands.py +++ b/psdk-test/psdk_commands.py @@ -73,19 +73,42 @@ class PsdkCommands(object): print(_err.decode()) return exit_status, _output.decode(), _err.decode() + def convert_ova_to_vdi(self,url, old_sdk, new_sdk): + self._run(["tar", "-xvf", url]) + zipped = self._run(["find", ".", "-name", "*.gz"],output=True) + zipped=zipped.decode('utf-8').strip() + self._run(["gunzip", zipped]) + unzipped=zipped[:-3] + self._run([self.vbox_manage, "clonehd", unzipped, "output.vdi", "--format=VDI"]) + self._run(["rm", unzipped]) + self._run([self.vbox_manage, "closemedium", "disk", "output.vdi"]) + self._run([self.vbox_manage, "closemedium", "disk", unzipped]) + shutil.copy("output.vdi", old_sdk) + shutil.copy("output.vdi", new_sdk) + def setup_disk_files(self, url, old_sdk_filename, new_sdk_filename): if url.startswith("http"): print("Dowloading %s ..." % url) try: response = urllib.request.urlopen(url) - gunzip_response = gzip.GzipFile(fileobj=response) - with open(old_sdk_filename, 'wb') as old_sdk_file, \ - open(new_sdk_filename, 'wb') as new_sdk_file: - content = gunzip_response.read(1024*1024) - while (content): - old_sdk_file.write(content) - new_sdk_file.write(content) + if (url.endswith("ova")): + with open('downloaded_file.ova', 'wb') as file: + content = response.read(1024*1024) + while(content): + file.write(content) + content = response.read(1024*1024) + self.convert_ova_to_vdi("downloaded_file.ova", old_sdk_filename, new_sdk_filename) + self._run(["rm", "downloaded_file.ova"]) + + else: + gunzip_response = gzip.GzipFile(fileobj=response) + with open(old_sdk_filename, 'wb') as old_sdk_file, \ + open(new_sdk_filename, 'wb') as new_sdk_file: content = gunzip_response.read(1024*1024) + while (content): + old_sdk_file.write(content) + new_sdk_file.write(content) + content = gunzip_response.read(1024*1024) except urllib.error.HTTPError as e: print("FAILED: Error dowloading image file: ", e.code) exit(1) @@ -103,8 +126,11 @@ class PsdkCommands(object): new_sdk_file.write(content) content = gunzip_response.read(1024*1024) else: - shutil.copy(url, old_sdk_filename) - shutil.copy(url, new_sdk_filename) + if(url.endswith("ova")): + self.convert_ova_to_vdi(url, old_sdk_filename, new_sdk_filename) + else: + shutil.copy(url, old_sdk_filename) + shutil.copy(url, new_sdk_filename) self._run([self.vbox_manage, "internalcommands", "sethduuid", new_sdk_filename]) -- GitLab