From 6db3560f8b04a188e8d33e28dbd0b7206ae04c07 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Mon, 12 Aug 2013 10:41:59 +0800 Subject: [PATCH] Use native methods for list manipulation 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 | 10 +++++----- cinder/brick/iscsi/iscsi.py | 4 ++-- cinder/brick/local_dev/lvm.py | 18 +++++++++--------- cinder/volume/drivers/lvm.py | 4 ++-- cinder/volume/drivers/rbd.py | 9 +++++---- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/cinder/backup/drivers/ceph.py b/cinder/backup/drivers/ceph.py index 6e86b74a3..8d1464ce0 100644 --- a/cinder/backup/drivers/ceph.py +++ b/cinder/backup/drivers/ceph.py @@ -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))) diff --git a/cinder/brick/iscsi/iscsi.py b/cinder/brick/iscsi/iscsi.py index 118fe04e8..de22bb9ce 100644 --- a/cinder/brick/iscsi/iscsi.py +++ b/cinder/brick/iscsi/iscsi.py @@ -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 " diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 72870fcd4..cd71ef75f 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -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, diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 6b5414297..bff05b36b 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -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) diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index 91c132f1f..5d7f20f5b 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -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) -- 2.45.2