DevStack support
[doctor.git] / doctor_tests / image.py
index 9961b22..50841ef 100644 (file)
@@ -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
 
@@ -46,11 +50,14 @@ 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 = \