]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use native methods for list manipulation
authorZhongyue Luo <zhongyue.nah@intel.com>
Mon, 12 Aug 2013 02:41:59 +0000 (10:41 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Mon, 12 Aug 2013 03:07:31 +0000 (11:07 +0800)
It's better to append a item to a list rather than creating a list instance
and extending it. Also the list class has its native method for extension.

Change-Id: If492c35822cd7d83b509692c2226612e565204d3

cinder/backup/drivers/ceph.py
cinder/brick/iscsi/iscsi.py
cinder/brick/local_dev/lvm.py
cinder/volume/drivers/lvm.py
cinder/volume/drivers/rbd.py

index 6e86b74a337efa8f8a80d38755b0cf2ce65f16e6..8d1464ce0a92b9dff2dc9f4eb18cfef5fa2df85c 100644 (file)
@@ -143,9 +143,9 @@ class CephBackupDriver(BackupDriver):
 
         args = ['--id', user]
         if conf:
-            args += ['--conf', conf]
+            args.extend(['--conf', conf])
         if pool:
-            args += '--pool', pool
+            args.extend(['--pool', pool])
 
         return args
 
@@ -376,12 +376,12 @@ class CephBackupDriver(BackupDriver):
         try:
             cmd = ['rbd', 'export-diff'] + src_ceph_args
             if from_snap is not None:
-                cmd += ['--from-snap', from_snap]
+                cmd.extend(['--from-snap', from_snap])
             if src_snap:
                 path = self._utf8("%s/%s@%s" % (src_pool, src_name, src_snap))
             else:
                 path = self._utf8("%s/%s" % (src_pool, src_name))
-            cmd += [path, '-']
+            cmd.extend([path, '-'])
             out, err = self._execute(*cmd)
         except (exception.ProcessExecutionError, exception.Error) as exc:
             LOG.info(_("rbd export-diff failed - %s") % (str(exc)))
@@ -389,7 +389,7 @@ class CephBackupDriver(BackupDriver):
 
         try:
             cmd = ['rbd', 'import-diff'] + dest_ceph_args
-            cmd += ['-', self._utf8("%s/%s" % (dest_pool, dest_name))]
+            cmd.extend(['-', self._utf8("%s/%s" % (dest_pool, dest_name))])
             out, err = self._execute(*cmd, process_input=out)
         except (exception.ProcessExecutionError, exception.Error) as exc:
             LOG.info(_("rbd import-diff failed - %s") % (str(exc)))
index 118fe04e8bcaf9bcd8991ac3ac1f7629f1c20800..de22bb9ce228538566019890274883c681dfa4b5 100644 (file)
@@ -426,8 +426,8 @@ class LioAdm(TargetAdmin):
                             name,
                             chap_auth_userid,
                             chap_auth_password]
-            if extra_args != []:
-                command_args += extra_args
+            if extra_args:
+                command_args.extend(extra_args)
             self._execute(*command_args, run_as_root=True)
         except exception.ProcessExecutionError as e:
                 LOG.error(_("Failed to create iscsi target for volume "
index 72870fcd4210cd3ddb69ef43fc100a57971a1c68..cd71ef75f8e90a4bf73e5ebfd0c35f44c8fc59cc 100644 (file)
@@ -169,10 +169,10 @@ class LVM(object):
         cmd = ['lvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size']
 
         if no_suffix:
-            cmd += ['--nosuffix']
+            cmd.append('--nosuffix')
 
         if vg_name is not None:
-            cmd += [vg_name]
+            cmd.append(vg_name)
 
         (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True)
 
@@ -218,10 +218,10 @@ class LVM(object):
                '-o', 'vg_name,name,size,free',
                '--separator', ':']
         if no_suffix:
-            cmd += ['--nosuffix']
+            cmd.append('--nosuffix')
 
         if vg_name is not None:
-            cmd += [vg_name]
+            cmd.append(vg_name)
 
         (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True)
 
@@ -261,10 +261,10 @@ class LVM(object):
                '--separator', ':']
 
         if no_suffix:
-            cmd += ['--nosuffix']
+            cmd.append('--nosuffix')
 
         if vg_name is not None:
-            cmd += [vg_name]
+            cmd.append(vg_name)
 
         (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True)
 
@@ -359,13 +359,13 @@ class LVM(object):
             cmd = ['lvcreate', '-n', name, self.vg_name, '-L', size_str]
 
         if mirror_count > 0:
-            cmd += ['-m', mirror_count, '--nosync']
+            cmd.extend(['-m', mirror_count, '--nosync'])
             terras = int(size_str[:-1]) / 1024.0
             if terras >= 1.5:
                 rsize = int(2 ** math.ceil(math.log(terras) / math.log(2)))
                 # NOTE(vish): Next power of two for region size. See:
                 #             http://red.ht/U2BPOD
-                cmd += ['-R', str(rsize)]
+                cmd.extend(['-R', str(rsize)])
 
         try:
             self._execute(*cmd,
@@ -394,7 +394,7 @@ class LVM(object):
                '--snapshot', '%s/%s' % (self.vg_name, source_lv_name)]
         if lv_type != 'thin':
             size = source_lvref['size']
-            cmd += ['-L', '%sg' % (size)]
+            cmd.extend(['-L', '%sg' % (size)])
 
         try:
             self._execute(*cmd,
index 6b54142978a6d6e23086d429de4fdec535d840ea..bff05b36b17bf1361028d896bcb0f7e792541f86 100644 (file)
@@ -85,13 +85,13 @@ class LVMVolumeDriver(driver.VolumeDriver):
 
         cmd = ['lvcreate', '-L', sizestr, '-n', volume_name, vg]
         if self.configuration.lvm_mirrors:
-            cmd += ['-m', self.configuration.lvm_mirrors, '--nosync']
+            cmd.extend(['-m', self.configuration.lvm_mirrors, '--nosync'])
             terras = int(sizestr[:-1]) / 1024.0
             if terras >= 1.5:
                 rsize = int(2 ** math.ceil(math.log(terras) / math.log(2)))
                 # NOTE(vish): Next power of two for region size. See:
                 #             http://red.ht/U2BPOD
-                cmd += ['-R', str(rsize)]
+                cmd.extend(['-R', str(rsize)])
 
         self._try_execute(*cmd, run_as_root=True, no_retry_list=no_retry_list)
 
index 91c132f1fbfef32c02d3e473579c0941ebb1f7de..5d7f20f5b1096b6d62bf54dab464521acaeb4cdc 100644 (file)
@@ -297,7 +297,8 @@ class RBDDriver(driver.VolumeDriver):
         return ceph_backup.CephBackupDriver.get_backup_snaps(rbd_image)
 
     def _get_mon_addrs(self):
-        args = ['ceph', 'mon', 'dump', '--format=json'] + self._ceph_args()
+        args = ['ceph', 'mon', 'dump', '--format=json']
+        args.extend(self._ceph_args())
         out, _ = self._execute(*args)
         lines = out.split('\n')
         if lines[0].startswith('dumped monmap epoch'):
@@ -548,8 +549,8 @@ class RBDDriver(driver.VolumeDriver):
                     '--pool', self.configuration.rbd_pool,
                     tmp.name, volume['name']]
             if self._supports_layering():
-                args += ['--new-format']
-            args += self._ceph_args()
+                args.append('--new-format')
+            args.extend(self._ceph_args())
             self._try_execute(*args)
         self._resize(volume)
 
@@ -563,7 +564,7 @@ class RBDDriver(driver.VolumeDriver):
             args = ['rbd', 'export',
                     '--pool', self.configuration.rbd_pool,
                     volume['name'], tmp_file]
-            args += self._ceph_args()
+            args.extend(self._ceph_args())
             self._try_execute(*args)
             image_utils.upload_volume(context, image_service,
                                       image_meta, tmp_file)