Bump hacking to 3.0.0

The new version enables a lot of standard flake8 checks, so a few
fixes are required. W503 is disabled as it conflicts with W504
and the latter seems to be preferred nowadays.

Change-Id: I929ff36eaa47a42bc551f5c37bd40f64bc4f14d0
This commit is contained in:
Dmitry Tantsur 2020-03-30 11:04:24 +02:00
parent f2053341af
commit 6c9d5dc58b
7 changed files with 34 additions and 28 deletions

View File

@ -67,7 +67,7 @@ CONF.register_opts(opts, group='disk_utils')
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
_PARTED_PRINT_RE = re.compile(r"^(\d+):([\d\.]+)MiB:" _PARTED_PRINT_RE = re.compile(r"^(\d+):([\d\.]+)MiB:"
"([\d\.]+)MiB:([\d\.]+)MiB:(\w*):(.*):(.*);") r"([\d\.]+)MiB:([\d\.]+)MiB:(\w*):(.*):(.*);")
CONFIGDRIVE_LABEL = "config-2" CONFIGDRIVE_LABEL = "config-2"
MAX_CONFIG_DRIVE_SIZE_MB = 64 MAX_CONFIG_DRIVE_SIZE_MB = 64
@ -282,8 +282,8 @@ def make_partitions(dev, root_mb, swap_mb, ephemeral_mb,
# a PrEP partition at the start of the disk. This is an 8 MiB partition # a PrEP partition at the start of the disk. This is an 8 MiB partition
# with the boot and prep flags set. The bootloader should be installed # with the boot and prep flags set. The bootloader should be installed
# here. # here.
if (cpu_arch.startswith("ppc64") and boot_mode == "bios" and if (cpu_arch.startswith("ppc64") and boot_mode == "bios"
boot_option == "local"): and boot_option == "local"):
LOG.debug("Add PReP boot partition (8 MB) to device: " LOG.debug("Add PReP boot partition (8 MB) to device: "
"%(dev)s for node %(node)s", "%(dev)s for node %(node)s",
{'dev': dev, 'node': node_uuid}) {'dev': dev, 'node': node_uuid})
@ -906,11 +906,11 @@ def create_config_drive_partition(node_uuid, device, configdrive):
confdrive_mb, confdrive_file = _get_configdrive(configdrive, confdrive_mb, confdrive_file = _get_configdrive(configdrive,
node_uuid) node_uuid)
if confdrive_mb > MAX_CONFIG_DRIVE_SIZE_MB: if confdrive_mb > MAX_CONFIG_DRIVE_SIZE_MB:
raise exception.InstanceDeployFailure( raise exception.InstanceDeployFailure(
_('Config drive size exceeds maximum limit of 64MiB. ' _('Config drive size exceeds maximum limit of 64MiB. '
'Size of the given config drive is %(size)d MiB for ' 'Size of the given config drive is %(size)d MiB for '
'node %(node)s.') 'node %(node)s.')
% {'size': confdrive_mb, 'node': node_uuid}) % {'size': confdrive_mb, 'node': node_uuid})
LOG.debug("Adding config drive partition %(size)d MiB to " LOG.debug("Adding config drive partition %(size)d MiB to "
"device: %(dev)s for node %(node)s", "device: %(dev)s for node %(node)s",
@ -959,8 +959,8 @@ def create_config_drive_partition(node_uuid, device, configdrive):
"node %(node)s. Creating config drive " "node %(node)s. Creating config drive "
"at the end of the disk %(disk)s.", "at the end of the disk %(disk)s.",
{'node': node_uuid, 'disk': device}) {'node': node_uuid, 'disk': device})
startlimit = (MAX_DISK_SIZE_MB_SUPPORTED_BY_MBR - startlimit = (MAX_DISK_SIZE_MB_SUPPORTED_BY_MBR
MAX_CONFIG_DRIVE_SIZE_MB - 1) - MAX_CONFIG_DRIVE_SIZE_MB - 1)
endlimit = MAX_DISK_SIZE_MB_SUPPORTED_BY_MBR - 1 endlimit = MAX_DISK_SIZE_MB_SUPPORTED_BY_MBR - 1
utils.execute('parted', '-a', 'optimal', '-s', '--', device, utils.execute('parted', '-a', 'optimal', '-s', '--', device,

View File

@ -104,8 +104,8 @@ class Counter(object):
raise TypeError(_("The metric name is expected to be a string. " raise TypeError(_("The metric name is expected to be a string. "
"Value is %s") % name) "Value is %s") % name)
if (sample_rate is not None and if (sample_rate is not None
(sample_rate < 0.0 or sample_rate > 1.0)): and (sample_rate < 0.0 or sample_rate > 1.0)):
msg = _("sample_rate is set to %s. Value must be None " msg = _("sample_rate is set to %s. Value must be None "
"or in the interval [0.0, 1.0]") % sample_rate "or in the interval [0.0, 1.0]") % sample_rate
raise ValueError(msg) raise ValueError(msg)

View File

@ -511,6 +511,12 @@ class MakePartitionsTestCase(base.IronicLibTestCase):
return ['parted', '-a', 'optimal', '-s', dev, return ['parted', '-a', 'optimal', '-s', dev,
'--', 'unit', 'MiB', 'mklabel', label] '--', 'unit', 'MiB', 'mklabel', label]
def _add_efi_sz(self, x):
return str(x + self.efi_size)
def _add_bios_sz(self, x):
return str(x + self.bios_size)
def _test_make_partitions(self, mock_exc, boot_option, boot_mode='bios', def _test_make_partitions(self, mock_exc, boot_option, boot_mode='bios',
disk_label=None, cpu_arch=""): disk_label=None, cpu_arch=""):
mock_exc.return_value = ('', '') mock_exc.return_value = ('', '')
@ -521,14 +527,13 @@ class MakePartitionsTestCase(base.IronicLibTestCase):
cpu_arch=cpu_arch) cpu_arch=cpu_arch)
if boot_option == "local" and boot_mode == "uefi": if boot_option == "local" and boot_mode == "uefi":
add_efi_sz = lambda x: str(x + self.efi_size)
expected_mkpart = ['mkpart', 'primary', 'fat32', '1', expected_mkpart = ['mkpart', 'primary', 'fat32', '1',
add_efi_sz(1), self._add_efi_sz(1),
'set', '1', 'boot', 'on', 'set', '1', 'boot', 'on',
'mkpart', 'primary', 'linux-swap', 'mkpart', 'primary', 'linux-swap',
add_efi_sz(1), add_efi_sz(513), 'mkpart', self._add_efi_sz(1), self._add_efi_sz(513),
'primary', '', add_efi_sz(513), 'mkpart', 'primary', '', self._add_efi_sz(513),
add_efi_sz(1537)] self._add_efi_sz(1537)]
else: else:
if boot_option == "local": if boot_option == "local":
if disk_label == "gpt": if disk_label == "gpt":
@ -539,14 +544,15 @@ class MakePartitionsTestCase(base.IronicLibTestCase):
'9', '521', 'mkpart', 'primary', '9', '521', 'mkpart', 'primary',
'', '521', '1545'] '', '521', '1545']
else: else:
add_bios_sz = lambda x: str(x + self.bios_size)
expected_mkpart = ['mkpart', 'primary', '', '1', expected_mkpart = ['mkpart', 'primary', '', '1',
add_bios_sz(1), self._add_bios_sz(1),
'set', '1', 'bios_grub', 'on', 'set', '1', 'bios_grub', 'on',
'mkpart', 'primary', 'linux-swap', 'mkpart', 'primary', 'linux-swap',
add_bios_sz(1), add_bios_sz(513), self._add_bios_sz(1),
self._add_bios_sz(513),
'mkpart', 'primary', '', 'mkpart', 'primary', '',
add_bios_sz(513), add_bios_sz(1537)] self._add_bios_sz(513),
self._add_bios_sz(1537)]
elif cpu_arch.startswith('ppc64'): elif cpu_arch.startswith('ppc64'):
expected_mkpart = ['mkpart', 'primary', '', '1', '9', expected_mkpart = ['mkpart', 'primary', '', '1', '9',
'set', '1', 'boot', 'on', 'set', '1', 'boot', 'on',
@ -563,8 +569,8 @@ class MakePartitionsTestCase(base.IronicLibTestCase):
'513', 'mkpart', 'primary', '', '513', '513', 'mkpart', 'primary', '', '513',
'1537'] '1537']
self.dev = 'fake-dev' self.dev = 'fake-dev'
parted_cmd = (self._get_parted_cmd(self.dev, disk_label) + parted_cmd = (self._get_parted_cmd(self.dev, disk_label)
expected_mkpart) + expected_mkpart)
parted_call = mock.call(*parted_cmd, use_standard_locale=True, parted_call = mock.call(*parted_cmd, use_standard_locale=True,
run_as_root=True, check_exit_code=[0]) run_as_root=True, check_exit_code=[0])
fuser_cmd = ['fuser', 'fake-dev'] fuser_cmd = ['fuser', 'fake-dev']

View File

@ -66,14 +66,14 @@ def execute(*cmd, **kwargs):
Executes and logs results from a system command. See docs for Executes and logs results from a system command. See docs for
oslo_concurrency.processutils.execute for usage. oslo_concurrency.processutils.execute for usage.
:param \*cmd: positional arguments to pass to processutils.execute() :param cmd: positional arguments to pass to processutils.execute()
:param use_standard_locale: keyword-only argument. True | False. :param use_standard_locale: keyword-only argument. True | False.
Defaults to False. If set to True, Defaults to False. If set to True,
execute command with standard locale execute command with standard locale
added to environment variables. added to environment variables.
:param log_stdout: keyword-only argument. True | False. Defaults :param log_stdout: keyword-only argument. True | False. Defaults
to True. If set to True, logs the output. to True. If set to True, logs the output.
:param \*\*kwargs: keyword arguments to pass to processutils.execute() :param kwargs: keyword arguments to pass to processutils.execute()
:returns: (stdout, stderr) from process execution :returns: (stdout, stderr) from process execution
:raises: UnknownArgumentError on receiving unknown arguments :raises: UnknownArgumentError on receiving unknown arguments
:raises: ProcessExecutionError :raises: ProcessExecutionError

View File

@ -15,7 +15,7 @@ flake8-import-order==0.13
flake8==2.5.5 flake8==2.5.5
future==0.16.0 future==0.16.0
greenlet==0.4.10 greenlet==0.4.10
hacking==1.0.0 hacking==3.0.0
imagesize==0.7.1 imagesize==0.7.1
iso8601==0.1.11 iso8601==0.1.11
Jinja2==2.10 Jinja2==2.10

View File

@ -5,7 +5,7 @@
coverage!=4.4,>=4.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0
eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT
flake8-import-order>=0.13 # LGPLv3 flake8-import-order>=0.13 # LGPLv3
hacking>=1.0.0,<1.1.0 # Apache-2.0 hacking>=3.0.0,<3.1.0 # Apache-2.0
mock>=2.0.0 # BSD mock>=2.0.0 # BSD
stestr>=1.0.0 # Apache-2.0 stestr>=1.0.0 # Apache-2.0
oslotest>=3.2.0 # Apache-2.0 oslotest>=3.2.0 # Apache-2.0

View File

@ -20,7 +20,7 @@ commands = stestr run {posargs}
[flake8] [flake8]
show-source = True show-source = True
ignore = E129 ignore = E129,W503
exclude = .venv,.tox,dist,doc,*.egg,.update-venv exclude = .venv,.tox,dist,doc,*.egg,.update-venv
import-order-style = pep8 import-order-style = pep8
application-import-names = ironic_lib application-import-names = ironic_lib