diff options
author | Jeff Lane <jeffrey.lane@canonical.com> | 2021-03-08 18:44:01 -0500 |
---|---|---|
committer | Jeff Lane <jeffrey.lane@canonical.com> | 2021-03-08 18:44:01 -0500 |
commit | 174adad0a3b70844793a17ba77fe4094bcebfb14 (patch) | |
tree | 41afa83874de84b3fd73e4591956980a322972a7 /bin | |
parent | f667217098b4322d10fba3d5f66ad8f50110a87f (diff) |
bin/virtualization.py: fix issue when UVT_IMAGE_OR_SOURCE does not exist and args.image is not set. lp: #1918097
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/virtualization.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/bin/virtualization.py b/bin/virtualization.py index 939a8a6..2f17d32 100755 --- a/bin/virtualization.py +++ b/bin/virtualization.py @@ -566,7 +566,7 @@ class UVTKVMTest(object): """ url = urlparse(self.image) - if url.scheme == 'file': + if url.scheme == 'file' or os.path.isfile(url.path): logging.debug("Cloud image exists locally at %s" % url.path) self.image = url.path else: @@ -621,7 +621,13 @@ class UVTKVMTest(object): logging.debug("Creating VM") cmd = ('uvt-kvm create {} arch={}'.format(self.name, self.arch)) - if self.image.find(".img") > 0: + logging.debug("Checking for local image") + try: + self.image.find(".img") > 0 + except AttributeError: + logging.debug("No user provided image found.") + logging.debug("I will attempt to sync the image from ubuntu.com") + else: cmd = cmd + " --backing-image-file {} ".format(self.image) if not self.run_command(cmd): @@ -815,9 +821,13 @@ class LXDTest(object): def test_uvtkvm(args): logging.debug("Executing UVT KVM Test") - - image = args.image or os.environ['UVT_IMAGE_OR_SOURCE'] - + # if args.image is not set and UVT_IMAGE_OR_SOURCE does not exist, a key + # error is generated we need to handle. + try: + image = args.image or os.environ['UVT_IMAGE_OR_SOURCE'] + except KeyError: + logging.warning("UVT_IMAGE_OR_SOURCE is not set") + image = None uvt_test = UVTKVMTest(image) uvt_test.get_image_or_source() result = uvt_test.start() |