Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / agent / env / basic / image_manager.py
index c3b5c6b..4bae49d 100644 (file)
@@ -19,6 +19,7 @@ class _ImageManager(object):
     A qemu-img wrapper to create qcow2 child image from a parent image.
 
     """
+
     def __init__(self, parent_image_path, child_image_dir):
         """
         :param parent_image_path    str: the parent image path.
@@ -31,7 +32,11 @@ class _ImageManager(object):
         assert os.path.isfile(self.parent_image_path)
         assert os.path.isdir(self.child_image_dir)
 
-    def create_child_image(self, child_name, full_clone=False, image_type='qcow2'):
+    def create_child_image(
+            self,
+            child_name,
+            full_clone=False,
+            image_type='qcow2'):
         """
         create a child image and put it in self.child_image_dir.
 
@@ -39,16 +44,25 @@ class _ImageManager(object):
         :return: return the path of child image.
         """
 
-        image_path = os.path.join(self.child_image_dir, child_name) + '.' + image_type
+        image_path = os.path.join(
+            self.child_image_dir,
+            child_name) + '.' + image_type
         if full_clone:
-            cmd = self._convert_str % {'image_type': image_type, 'child_path': image_path, 'parent_path': self.parent_image_path}
+            cmd = self._convert_str % {
+                'image_type': image_type,
+                'child_path': image_path,
+                'parent_path': self.parent_image_path}
         else:
-            cmd = self._create_child_str % {'child_path': image_path, 'parent_path': self.parent_image_path, 'image_type':image_type}
+            cmd = self._create_child_str % {
+                'child_path': image_path,
+                'parent_path': self.parent_image_path,
+                'image_type': image_type}
         check_call(cmd.split())
         return image_path
 
 
 class ImageManager(object):
+
     def __init__(self, cfg):
         """
         ImageManager creates images from configuration context.
@@ -74,13 +88,22 @@ class ImageManager(object):
 
     @staticmethod
     def _check_cfg(cfg):
-        for key in ('parent_image', 'dst_location', 'full_clone', 'type', 'names'):
+        for key in (
+            'parent_image',
+            'dst_location',
+            'full_clone',
+            'type',
+                'names'):
             if key not in cfg:
                 raise Exception("does't find %s config" % key)
         if cfg['type'] not in ('raw', 'qcow2'):
-            raise Exception("type:%s not supported, only support 'raw' and 'qcow2'" % cfg['type'])
+            raise Exception(
+                "type:%s not supported, only support 'raw' and 'qcow2'" %
+                cfg['type'])
         if not cfg['full_clone'] and cfg['type'] == 'raw':
-            raise Exception("only support 'qcow2' for not full_clone image creation" % cfg['type'])
+            raise Exception(
+                "only support 'qcow2' for not full_clone image creation" %
+                cfg['type'])
         return cfg
 
     def create_all(self):
@@ -90,7 +113,8 @@ class ImageManager(object):
         :return: True for success, False for failure.
         """
         for name in self.names:
-            image = self.mgr.create_child_image(name, self.full_clone, self.image_type)
+            image = self.mgr.create_child_image(
+                name, self.full_clone, self.image_type)
             LOG.info("image: %s created", image)
         return True
 
@@ -101,7 +125,8 @@ class ImageManager(object):
         :return: True for success. Raise exception otherwise.
         """
         for name in self.names:
-            image_path = os.path.join(self.image_dir, name + '.' + self.image_type)
+            image_path = os.path.join(
+                self.image_dir, name + '.' + self.image_type)
             try:
                 os.unlink(image_path)
                 LOG.info("remove:%s successfully", image_path)
@@ -114,7 +139,12 @@ if __name__ == '__main__':
     import argparse
     import json
     parser = argparse.ArgumentParser()
-    parser.add_argument('action', choices = ('create','clean'), help='action:create|clean')
+    parser.add_argument(
+        'action',
+        choices=(
+            'create',
+            'clean'),
+        help='action:create|clean')
     parser.add_argument('--config', help='config file to parse')
     args = parser.parse_args()
     logging.basicConfig(level=logging.INFO)
@@ -124,5 +154,3 @@ if __name__ == '__main__':
         mgr.create_all()
     if args.action == 'clean':
         mgr.clean_all()
-
-