X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=doctor_tests%2Fimage.py;h=50841ef6dff247adc67436e29d81673f716008a7;hb=d8eb12f4200c21f569df5bc01d378a846b4c0db0;hp=2e313e1248b1133f5cd3cc1d94cc30f2376ad04f;hpb=25759e0a0204765a7a9454d7586df66592e943c2;p=doctor.git diff --git a/doctor_tests/image.py b/doctor_tests/image.py index 2e313e12..50841ef6 100644 --- a/doctor_tests/image.py +++ b/doctor_tests/image.py @@ -7,7 +7,11 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import os -import urllib.request +try: + from urllib.request import urlopen +except Exception: + from urllib2 import urlopen + from oslo_config import cfg @@ -28,7 +32,7 @@ OPTS = [ help='the name of image file', required=True), cfg.StrOpt('image_download_url', - default='https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img', + default='https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img', # noqa help='the url where to get the image', required=True), ] @@ -46,17 +50,22 @@ class Image(object): def create(self): self.log.info('image create start......') - images = {image.name: image for image in self.glance.images.list()} + if self.conf.image_name == 'cirros': + cirros = [image for image in images if 'cirros' in image] + if cirros: + self.conf.image_name = cirros[0] if self.conf.image_name not in images: if not os.path.exists(self.conf.image_filename): - resp = urllib.request.urlopen(self.conf.image_download_url) + resp = urlopen(self.conf.image_download_url) with open(self.conf.image_filename, "wb") as file: file.write(resp.read()) - self.image = self.glance.images.create(name=self.conf.image_name, - disk_format=self.conf.image_format, - container_format="bare", - visibility="public") + self.image = \ + self.glance.images.create( + name=self.conf.image_name, + disk_format=self.conf.image_format, + container_format="bare", + visibility="public") self.glance.images.upload(self.image['id'], open(self.conf.image_filename, 'rb')) else: