Fix pep8 failed

Change-Id: Ic7b265a480ff62a62aac230dc707534657c8cde8
This commit is contained in:
jacky06 2019-03-02 18:22:56 +08:00
parent 1f512ce8fa
commit 37bf4fa1b6
8 changed files with 43 additions and 49 deletions

View File

@ -251,9 +251,9 @@ class _StepMapping(object):
target = sys.modules[__name__] target = sys.modules[__name__]
for name in dir(target): for name in dir(target):
value = getattr(target, name) value = getattr(target, name)
if (inspect.isclass(value) if (inspect.isclass(value) and
and issubclass(value, base_cls) issubclass(value, base_cls) and
and value is not base_cls): value is not base_cls):
self.steps.append(value) self.steps.append(value)
self.name_to_step = {} self.name_to_step = {}

View File

@ -59,16 +59,16 @@ def match_device(hu_disk, ks_disk):
uspec = hu_disk['uspec'] uspec = hu_disk['uspec']
# True if at least one by-id link matches ks_disk # True if at least one by-id link matches ks_disk
if ('DEVLINKS' in uspec and len(ks_disk.get('extra', [])) > 0 if ('DEVLINKS' in uspec and len(ks_disk.get('extra', [])) > 0 and
and any(x.startswith('/dev/disk/by-id') for x in any(x.startswith('/dev/disk/by-id') for x in
set(uspec['DEVLINKS']) & set(uspec['DEVLINKS']) &
set(['/dev/%s' % l for l in ks_disk['extra']]))): set(['/dev/%s' % l for l in ks_disk['extra']]))):
return True return True
# True if one of DEVLINKS matches ks_disk id # True if one of DEVLINKS matches ks_disk id
if (len(ks_disk.get('extra', [])) == 0 if (len(ks_disk.get('extra', [])) == 0 and
and 'DEVLINKS' in uspec and 'id' in ks_disk 'DEVLINKS' in uspec and 'id' in ks_disk and
and '/dev/%s' % ks_disk['id'] in uspec['DEVLINKS']): '/dev/%s' % ks_disk['id'] in uspec['DEVLINKS']):
return True return True
return False return False
@ -349,8 +349,8 @@ class Nailgun(BaseDataDriver,
if all(( if all((
v["size"] <= 0 v["size"] <= 0
for v in disk["volumes"] for v in disk["volumes"]
if v["type"] not in ("boot", 'lvm_meta_pool') if v["type"] not in ("boot", 'lvm_meta_pool') and
and v.get("mount") != "/boot" v.get("mount") != "/boot"
)): )):
continue continue
@ -437,9 +437,9 @@ class Nailgun(BaseDataDriver,
keep_data=volume.get('keep_data', False)) keep_data=volume.get('keep_data', False))
LOG.debug('Partition name: %s' % prt.name) LOG.debug('Partition name: %s' % prt.name)
elif (volume.get('mount') == '/boot' elif (volume.get('mount') == '/boot' and
and not self._boot_partition_done not self._boot_partition_done and
and disk['name'] in disk['name'] in
[d['name'] for d in self.boot_disks]): [d['name'] for d in self.boot_disks]):
LOG.debug('Adding /boot partition on disk %s: ' LOG.debug('Adding /boot partition on disk %s: '
'size=%s', disk['name'], volume['size']) 'size=%s', disk['name'], volume['size'])

View File

@ -260,7 +260,7 @@ class LVMpv(BlockDevice):
class LVMlv(FileSystemMixin, BlockDevice): class LVMlv(FileSystemMixin, BlockDevice):
def __init__(self, name, size, **fields): def __init__(self, name, size, **fields):
BlockDevice.__init__(self, size, **fields) BlockDevice.__init__(self, size, **fields)
self.name = name self.name = name

View File

@ -155,8 +155,8 @@ class TestSizeUnit(unittest2.TestCase):
def test_in_unit(self): def test_in_unit(self):
size = block_device.SizeUnit.new_by_string('2.2 YiB') size = block_device.SizeUnit.new_by_string('2.2 YiB')
for unit, expect in ( for unit, expect in (
('B', 2659636803152184399101952), ('B', 2659636803152184399101952),
('s', 5194603131156610154496), ('s', 5194603131156610154496),
('KiB', 2597301565578305077248), ('KiB', 2597301565578305077248),
('MiB', 2536427310135063552), ('MiB', 2536427310135063552),
('GiB', 2476979795053773), ('GiB', 2476979795053773),

View File

@ -430,8 +430,7 @@ LIST_BLOCK_DEVICES_SAMPLE = [
'size': 500107862016}, 'size': 500107862016},
{'uspec': {'uspec':
{'DEVLINKS': [ {'DEVLINKS': [
'/dev/disk/by-id/by-id/md-fake-raid-uuid', '/dev/disk/by-id/by-id/md-fake-raid-uuid', ],
],
'ID_SERIAL_SHORT': 'fake_serial_raid', 'ID_SERIAL_SHORT': 'fake_serial_raid',
'ID_WWN': 'fake_wwn_raid', 'ID_WWN': 'fake_wwn_raid',
'DEVPATH': '/devices/virtual/block/md123', 'DEVPATH': '/devices/virtual/block/md123',
@ -536,8 +535,7 @@ LIST_BLOCK_DEVICES_MPATH = [
'bspec': { 'bspec': {
'sz': '976773168', 'iomin': '4096', 'size64': '500107862016', 'sz': '976773168', 'iomin': '4096', 'size64': '500107862016',
'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096', 'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096',
'ra': '256', 'ro': '0', 'maxsect': '1024' 'ra': '256', 'ro': '0', 'maxsect': '1024'},
},
'size': 500107862016}, 'size': 500107862016},
{'uspec': {'uspec':
{'DEVLINKS': [ {'DEVLINKS': [
@ -551,23 +549,20 @@ LIST_BLOCK_DEVICES_MPATH = [
'ID_MODEL': 'fake_id_model', 'ID_MODEL': 'fake_id_model',
'DEVNAME': '/dev/sdb', 'DEVNAME': '/dev/sdb',
'MAJOR': '8', 'MAJOR': '8',
'DEVTYPE': 'disk', 'MINOR': '0', 'ID_BUS': 'ata' 'DEVTYPE': 'disk', 'MINOR': '0', 'ID_BUS': 'ata'},
},
'startsec': '0', 'startsec': '0',
'device': '/dev/sdb', 'device': '/dev/sdb',
'espec': {'state': 'running', 'timeout': '30', 'removable': '0'}, 'espec': {'state': 'running', 'timeout': '30', 'removable': '0'},
'bspec': { 'bspec': {
'sz': '976773168', 'iomin': '4096', 'size64': '500107862016', 'sz': '976773168', 'iomin': '4096', 'size64': '500107862016',
'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096', 'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096',
'ra': '256', 'ro': '0', 'maxsect': '1024' 'ra': '256', 'ro': '0', 'maxsect': '1024'},
},
'size': 500107862016}, 'size': 500107862016},
{'uspec': {'uspec':
{'DEVLINKS': [ {'DEVLINKS': [
'disk/by-id/scsi-SATA_VBOX_HARDDISK_VB69050467-b385c7cd', 'disk/by-id/scsi-SATA_VBOX_HARDDISK_VB69050467-b385c7cd',
'/dev/disk/by-id/wwn-fake_wwn_1', '/dev/disk/by-id/wwn-fake_wwn_1',
'/dev/disk/by-id/dm-uuid-mpath-fake_wwn_1' '/dev/disk/by-id/dm-uuid-mpath-fake_wwn_1'],
],
'ID_SERIAL_SHORT': 'fake_serial_1', 'ID_SERIAL_SHORT': 'fake_serial_1',
'ID_WWN': 'fake_wwn_1', 'ID_WWN': 'fake_wwn_1',
'DEVPATH': '/devices/pci0000:00/0000:00:1f.2/ata1/host0/', 'DEVPATH': '/devices/pci0000:00/0000:00:1f.2/ata1/host0/',
@ -582,8 +577,7 @@ LIST_BLOCK_DEVICES_MPATH = [
'bspec': { 'bspec': {
'sz': '976773168', 'iomin': '4096', 'size64': '500107862016', 'sz': '976773168', 'iomin': '4096', 'size64': '500107862016',
'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096', 'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096',
'ra': '256', 'ro': '0', 'maxsect': '1024' 'ra': '256', 'ro': '0', 'maxsect': '1024'},
},
'size': 500107862016}, 'size': 500107862016},
{'uspec': {'uspec':
{'DEVLINKS': [ {'DEVLINKS': [
@ -596,16 +590,14 @@ LIST_BLOCK_DEVICES_MPATH = [
'ID_MODEL': 'fake_id_model', 'ID_MODEL': 'fake_id_model',
'DEVNAME': '/dev/sdc', 'DEVNAME': '/dev/sdc',
'MAJOR': '8', 'MAJOR': '8',
'DEVTYPE': 'disk', 'MINOR': '0', 'ID_BUS': 'ata' 'DEVTYPE': 'disk', 'MINOR': '0', 'ID_BUS': 'ata'},
},
'startsec': '0', 'startsec': '0',
'device': '/dev/sdc', 'device': '/dev/sdc',
'espec': {'state': 'running', 'timeout': '30', 'removable': '0'}, 'espec': {'state': 'running', 'timeout': '30', 'removable': '0'},
'bspec': { 'bspec': {
'sz': '976773168', 'iomin': '4096', 'size64': '500107862016', 'sz': '976773168', 'iomin': '4096', 'size64': '500107862016',
'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096', 'ss': '512', 'ioopt': '0', 'alignoff': '0', 'pbsz': '4096',
'ra': '256', 'ro': '0', 'maxsect': '1024' 'ra': '256', 'ro': '0', 'maxsect': '1024'},
},
'size': 500107862016}, 'size': 500107862016},
] ]

View File

@ -85,7 +85,7 @@ class BlockDeviceMock(object):
entry = meta[path] entry = meta[path]
except KeyError: except KeyError:
raise OSError( raise OSError(
errno.ENOENT, 'FAKE: No such file or directory', path) errno.ENOENT, 'FAKE: No such file or directory', path)
return entry return entry

View File

@ -447,40 +447,40 @@ def match_device(uspec1, uspec2):
""" """
# False if ID_WWN is given and does not match each other # False if ID_WWN is given and does not match each other
if ('ID_WWN' in uspec1 and 'ID_WWN' in uspec2 if ('ID_WWN' in uspec1 and 'ID_WWN' in uspec2 and
and uspec1['ID_WWN'] != uspec2['ID_WWN']): uspec1['ID_WWN'] != uspec2['ID_WWN']):
return False return False
# False if ID_SERIAL_SHORT is given and does not match each other # False if ID_SERIAL_SHORT is given and does not match each other
if ('ID_SERIAL_SHORT' in uspec1 and 'ID_SERIAL_SHORT' in uspec2 if ('ID_SERIAL_SHORT' in uspec1 and 'ID_SERIAL_SHORT' in uspec2 and
and uspec1['ID_SERIAL_SHORT'] != uspec2['ID_SERIAL_SHORT']): uspec1['ID_SERIAL_SHORT'] != uspec2['ID_SERIAL_SHORT']):
return False return False
# True if at least one by-id link is the same for both uspecs # True if at least one by-id link is the same for both uspecs
if ('DEVLINKS' in uspec1 and 'DEVLINKS' in uspec2 if ('DEVLINKS' in uspec1 and 'DEVLINKS' in uspec2 and
and any(x.startswith('/dev/disk/by-id') for x in any(x.startswith('/dev/disk/by-id') for x in
set(uspec1['DEVLINKS']) & set(uspec2['DEVLINKS']))): set(uspec1['DEVLINKS']) & set(uspec2['DEVLINKS']))):
return True return True
# True if ID_WWN is given and matches each other # True if ID_WWN is given and matches each other
# and DEVTYPE is given and is 'disk' # and DEVTYPE is given and is 'disk'
if (uspec1.get('ID_WWN') == uspec2.get('ID_WWN') is not None if (uspec1.get('ID_WWN') == uspec2.get('ID_WWN') is not None and
and uspec1.get('DEVTYPE') == uspec2.get('DEVTYPE') == 'disk'): uspec1.get('DEVTYPE') == uspec2.get('DEVTYPE') == 'disk'):
return True return True
# True if ID_WWN is given and matches each other # True if ID_WWN is given and matches each other
# and DEVTYPE is given and is 'partition' # and DEVTYPE is given and is 'partition'
# and MINOR is given and matches each other # and MINOR is given and matches each other
if (uspec1.get('ID_WWN') == uspec2.get('ID_WWN') is not None if (uspec1.get('ID_WWN') == uspec2.get('ID_WWN') is not None and
and uspec1.get('DEVTYPE') == uspec2.get('DEVTYPE') == 'partition' uspec1.get('DEVTYPE') == uspec2.get('DEVTYPE') == 'partition' and
and uspec1.get('MINOR') == uspec2.get('MINOR') is not None): uspec1.get('MINOR') == uspec2.get('MINOR') is not None):
return True return True
# True if ID_SERIAL_SHORT is given and matches each other # True if ID_SERIAL_SHORT is given and matches each other
# and DEVTYPE is given and is 'disk' # and DEVTYPE is given and is 'disk'
if (uspec1.get('ID_SERIAL_SHORT') == uspec2.get('ID_SERIAL_SHORT') if (uspec1.get('ID_SERIAL_SHORT') == uspec2.get('ID_SERIAL_SHORT')
is not None is not None and
and uspec1.get('DEVTYPE') == uspec2.get('DEVTYPE') == 'disk'): uspec1.get('DEVTYPE') == uspec2.get('DEVTYPE') == 'disk'):
return True return True
# True if DEVPATH is given and matches each other # True if DEVPATH is given and matches each other

View File

@ -50,6 +50,8 @@ commands =
oslo-config-generator --config-file etc/oslo-config-generator/bareon.conf oslo-config-generator --config-file etc/oslo-config-generator/bareon.conf
[flake8] [flake8]
# [E731] Do not assign a lambda expression, use a def. This reduces readability in some cases.
ignore = E731
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,docs exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,docs
show-pep8 = True show-pep8 = True
show-source = True show-source = True