diff --git a/vmtp/cfg.default.yaml b/vmtp/cfg.default.yaml index 4ac7043..68f1ec4 100644 --- a/vmtp/cfg.default.yaml +++ b/vmtp/cfg.default.yaml @@ -45,6 +45,9 @@ dns_nameservers: [ '8.8.8.8' ] # # A link to a Ubuntu Server 14.04 qcow2 image can be used here: # https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img +# +# To upload the image as a file, prepend it with file:// like below +# file:// vm_image_url: '' # ----------------------------------------------------------------------------- diff --git a/vmtp/compute.py b/vmtp/compute.py index adf8c6a..5282508 100644 --- a/vmtp/compute.py +++ b/vmtp/compute.py @@ -42,10 +42,20 @@ class Compute(object): ''' retry = 0 try: - # Upload the image - img = glance_client.images.create( - name=str(final_image_name), disk_format="qcow2", container_format="bare", - is_public=True, copy_from=image_url) + # check image is file/url based. + file_prefix = "file://" + if image_url.startswith(file_prefix): + image_location = image_url.split(file_prefix)[1] + with open(image_location) as f_image: + img = glance_client.images.create( + name=str(final_image_name), disk_format="qcow2", + container_format="bare", is_public=True, data=f_image) + else: + # Upload the image + img = glance_client.images.create( + name=str(final_image_name), disk_format="qcow2", + container_format="bare", is_public=True, + copy_from=image_url) # Check for the image in glance while img.status in ['queued', 'saving'] and retry < retry_count: @@ -61,11 +71,15 @@ class Compute(object): print "Cannot upload image without admin access. Please make sure the "\ "image is uploaded and is either public or owned by you." return False + except IOError: + # catch the exception for file based errors. + print "Failed while uploading the image. Please make sure the " \ + "image at the specified location %s is correct." % image_url + return False except Exception: print "Failed while uploading the image, please make sure the cloud "\ "under test has the access to URL: %s." % image_url return False - return True def delete_image(self, glance_client, img_name): diff --git a/vmtp/vmtp.py b/vmtp/vmtp.py index 04f6375..bfe8ef2 100755 --- a/vmtp/vmtp.py +++ b/vmtp/vmtp.py @@ -822,7 +822,8 @@ def parse_opts_from_cli(): parser.add_argument('--vm-image-url', dest='vm_image_url', action='store', - help='URL to a Linux image in qcow2 format that can be downloaded from', + help='URL to a Linux image in qcow2 format that can be downloaded from' + 'or location of the image file with prefix file://', metavar='') parser.add_argument('--test-description', dest='test_description',