Enforce all flake8 rules except E129

Bring ironic-python-agent in line with the other ironic projects.

Stop ignoring all E12* errors except E129
Stop ignoring E711

Change-Id: Icb9bc198473d1b5e807c20869eb2af7f4d7ac360
This commit is contained in:
John L. Villalovos 2015-10-02 10:01:00 -07:00
parent 0144e79df5
commit dcbba2b121
17 changed files with 104 additions and 97 deletions

View File

@ -144,7 +144,8 @@ def main():
os.makedirs(output_dir) os.makedirs(output_dir)
output_kernel = os.path.join(output_dir, os.path.basename(kernel)) output_kernel = os.path.join(output_dir, os.path.basename(kernel))
output_cpio = os.path.join(output_dir, output_cpio = os.path.join(
output_dir,
os.path.basename(orig_cpio).replace('.cpio.gz', '-oem.cpio.gz')) os.path.basename(orig_cpio).replace('.cpio.gz', '-oem.cpio.gz'))
inject_oem(orig_cpio, oem_dir, output_cpio) inject_oem(orig_cpio, oem_dir, output_cpio)
shutil.copy(kernel, output_kernel) shutil.copy(kernel, output_kernel)

View File

@ -431,7 +431,8 @@ class GenericHardwareManager(HardwareManager):
if hint_value != current_value: if hint_value != current_value:
LOG.debug("Root device hint %(hint)s=%(value)s does not " LOG.debug("Root device hint %(hint)s=%(value)s does not "
"match the device %(device)s value of " "match the device %(device)s value of "
"%(current)s", {'hint': hint, "%(current)s", {
'hint': hint,
'value': hint_value, 'device': device, 'value': hint_value, 'device': device,
'current': current_value}) 'current': current_value})
return False return False
@ -465,7 +466,8 @@ class GenericHardwareManager(HardwareManager):
return dev.name return dev.name
else: else:
raise errors.DeviceNotFound("No suitable device was found for " raise errors.DeviceNotFound(
"No suitable device was found for "
"deployment using these hints %s" % root_device_hints) "deployment using these hints %s" % root_device_hints)
def erase_block_device(self, node, block_device): def erase_block_device(self, node, block_device):
@ -552,12 +554,14 @@ class GenericHardwareManager(HardwareManager):
return False return False
if 'enabled' in security_lines: if 'enabled' in security_lines:
raise errors.BlockDeviceEraseError(('Block device {0} already has ' raise errors.BlockDeviceEraseError(
'a security password set').format(block_device.name)) ('Block device {0} already has a security password set'
).format(block_device.name))
if 'not frozen' not in security_lines: if 'not frozen' not in security_lines:
raise errors.BlockDeviceEraseError(('Block device {0} is frozen ' raise errors.BlockDeviceEraseError(
'and cannot be erased').format(block_device.name)) ('Block device {0} is frozen and cannot be erased'
).format(block_device.name))
utils.execute('hdparm', '--user-master', 'u', '--security-set-pass', utils.execute('hdparm', '--user-master', 'u', '--security-set-pass',
'NULL', block_device.name) 'NULL', block_device.name)
@ -573,8 +577,9 @@ class GenericHardwareManager(HardwareManager):
# Verify that security is now 'not enabled' # Verify that security is now 'not enabled'
security_lines = self._get_ata_security_lines(block_device) security_lines = self._get_ata_security_lines(block_device)
if 'not enabled' not in security_lines: if 'not enabled' not in security_lines:
raise errors.BlockDeviceEraseError(('An unknown error occurred ' raise errors.BlockDeviceEraseError(
'erasing block device {0}').format(block_device.name)) ('An unknown error occurred erasing block device {0}'
).format(block_device.name))
return True return True

View File

@ -33,9 +33,9 @@ class FunctionalBase(test_base.BaseTestCase):
# Build a basic standalone agent using the config option defaults. # Build a basic standalone agent using the config option defaults.
# 127.0.0.1:6835 is the fake Ironic client. # 127.0.0.1:6835 is the fake Ironic client.
self.agent = agent.IronicPythonAgent( self.agent = agent.IronicPythonAgent(
'http://127.0.0.1:6835', 'localhost', ('0.0.0.0', 'http://127.0.0.1:6835', 'localhost',
int(test_port)), 3, 10, None, 300, 1, ('0.0.0.0', int(test_port)), 3, 10, None, 300, 1, 'agent_ipmitool',
'agent_ipmitool', True) True)
self.process = multiprocessing.Process( self.process = multiprocessing.Process(
target=self.agent.run) target=self.agent.run)
self.process.start() self.process.start()
@ -46,8 +46,8 @@ class FunctionalBase(test_base.BaseTestCase):
max_tries = os.environ.get('IPA_WAIT_TIME', '2') max_tries = os.environ.get('IPA_WAIT_TIME', '2')
while tries < int(max_tries): while tries < int(max_tries):
try: try:
return requests.get('http://localhost:%s/v1/commands' % return requests.get(
test_port) 'http://localhost:%s/v1/commands' % test_port)
except requests.ConnectionError: except requests.ConnectionError:
time.sleep(.1) time.sleep(.1)
tries += 1 tries += 1

View File

@ -20,7 +20,8 @@ from ironic_python_agent.tests.functional import base
class TestCommands(base.FunctionalBase): class TestCommands(base.FunctionalBase):
def test_empty_commands(self): def test_empty_commands(self):
commands = requests.get('http://localhost:%s/v1/commands' % commands = requests.get(
os.environ.get('TEST_PORT', '9999')) 'http://localhost:%s/v1/commands' % os.environ.get('TEST_PORT',
'9999'))
self.assertEqual(200, commands.status_code) self.assertEqual(200, commands.status_code)
self.assertEqual({'commands': []}, commands.json()) self.assertEqual({'commands': []}, commands.json())

View File

@ -159,8 +159,8 @@ class TestImageExtension(test_base.BaseTestCase):
@mock.patch.object(os, 'makedirs') @mock.patch.object(os, 'makedirs')
@mock.patch.object(image, '_get_partition') @mock.patch.object(image, '_get_partition')
def test__install_grub2_uefi_umount_fails( def test__install_grub2_uefi_umount_fails(
self, mock_get_part_uuid, mkdir_mock, environ_mock, self, mock_get_part_uuid, mkdir_mock, environ_mock, mock_execute,
mock_execute, mock_dispatch): mock_dispatch):
mock_get_part_uuid.side_effect = [self.fake_root_part, mock_get_part_uuid.side_effect = [self.fake_root_part,
self.fake_efi_system_part] self.fake_efi_system_part]
@ -217,8 +217,7 @@ class TestImageExtension(test_base.BaseTestCase):
KNAME="test2" UUID="%s" TYPE="part"''' % self.fake_root_uuid) KNAME="test2" UUID="%s" TYPE="part"''' % self.fake_root_uuid)
mock_execute.side_effect = (None, None, [lsblk_output]) mock_execute.side_effect = (None, None, [lsblk_output])
root_part = image._get_partition(self.fake_dev, root_part = image._get_partition(self.fake_dev, self.fake_root_uuid)
self.fake_root_uuid)
self.assertEqual('/dev/test2', root_part) self.assertEqual('/dev/test2', root_part)
expected = [mock.call('partx', '-u', self.fake_dev, attempts=3, expected = [mock.call('partx', '-u', self.fake_dev, attempts=3,
delay_on_retry=True), delay_on_retry=True),

View File

@ -229,11 +229,14 @@ class TestHardwareManagerLoading(test_base.BaseTestCase):
fake_ep = mock.Mock() fake_ep = mock.Mock()
fake_ep.module_name = 'fake' fake_ep.module_name = 'fake'
fake_ep.attrs = ['fake attrs'] fake_ep.attrs = ['fake attrs']
ext1 = extension.Extension('fake_generic0', fake_ep, None, ext1 = extension.Extension(
'fake_generic0', fake_ep, None,
FakeHardwareManager(hardware.HardwareSupport.GENERIC)) FakeHardwareManager(hardware.HardwareSupport.GENERIC))
ext2 = extension.Extension('fake_mainline0', fake_ep, None, ext2 = extension.Extension(
'fake_mainline0', fake_ep, None,
FakeHardwareManager(hardware.HardwareSupport.MAINLINE)) FakeHardwareManager(hardware.HardwareSupport.MAINLINE))
ext3 = extension.Extension('fake_generic1', fake_ep, None, ext3 = extension.Extension(
'fake_generic1', fake_ep, None,
FakeHardwareManager(hardware.HardwareSupport.GENERIC)) FakeHardwareManager(hardware.HardwareSupport.GENERIC))
self.correct_hw_manager = ext2.obj self.correct_hw_manager = ext2.obj
self.fake_ext_mgr = extension.ExtensionManager.make_test_instance([ self.fake_ext_mgr = extension.ExtensionManager.make_test_instance([
@ -670,8 +673,9 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
True) True)
res = self.hardware._shred_block_device(self.node, block_device) res = self.hardware._shred_block_device(self.node, block_device)
self.assertFalse(res) self.assertFalse(res)
mocked_execute.assert_called_once_with('shred', '--force', '--zero', mocked_execute.assert_called_once_with(
'--verbose', '--iterations', '1', '/dev/sda') 'shred', '--force', '--zero', '--verbose', '--iterations', '1',
'/dev/sda')
@mock.patch.object(utils, 'execute') @mock.patch.object(utils, 'execute')
def test_erase_block_device_shred_fail_processerror(self, mocked_execute): def test_erase_block_device_shred_fail_processerror(self, mocked_execute):
@ -680,8 +684,9 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
True) True)
res = self.hardware._shred_block_device(self.node, block_device) res = self.hardware._shred_block_device(self.node, block_device)
self.assertFalse(res) self.assertFalse(res)
mocked_execute.assert_called_once_with('shred', '--force', '--zero', mocked_execute.assert_called_once_with(
'--verbose', '--iterations', '1', '/dev/sda') 'shred', '--force', '--zero', '--verbose', '--iterations', '1',
'/dev/sda')
@mock.patch.object(utils, 'execute') @mock.patch.object(utils, 'execute')
def test_erase_block_device_ata_security_enabled(self, mocked_execute): def test_erase_block_device_ata_security_enabled(self, mocked_execute):
@ -778,10 +783,10 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
expected_option, expected_option,
'NULL', '/dev/sda') 'NULL', '/dev/sda')
test_security_erase_option(self, test_security_erase_option(
'\tsupported: enhanced erase', '--security-erase-enhanced') self, '\tsupported: enhanced erase', '--security-erase-enhanced')
test_security_erase_option(self, test_security_erase_option(
'\tnot\tsupported: enhanced erase', '--security-erase') self, '\tnot\tsupported: enhanced erase', '--security-erase')
@mock.patch.object(utils, 'execute') @mock.patch.object(utils, 'execute')
def test_get_bmc_address(self, mocked_execute): def test_get_bmc_address(self, mocked_execute):

View File

@ -111,13 +111,12 @@ class TestMultipleHardwareManagerLoading(test_base.BaseTestCase):
fake_ep = mock.Mock() fake_ep = mock.Mock()
fake_ep.module_name = 'fake' fake_ep.module_name = 'fake'
fake_ep.attrs = ['fake attrs'] fake_ep.attrs = ['fake attrs']
self.generic_hwm = extension.Extension('fake_generic', fake_ep, None, self.generic_hwm = extension.Extension(
FakeGenericHardwareManager()) 'fake_generic', fake_ep, None, FakeGenericHardwareManager())
self.mainline_hwm = extension.Extension('fake_mainline', fake_ep, None, self.mainline_hwm = extension.Extension(
FakeMainlineHardwareManager()) 'fake_mainline', fake_ep, None, FakeMainlineHardwareManager())
self.fake_ext_mgr = extension.ExtensionManager.make_test_instance([ self.fake_ext_mgr = extension.ExtensionManager.make_test_instance(
self.generic_hwm, self.mainline_hwm [self.generic_hwm, self.mainline_hwm])
])
self.extension_mgr_patcher = mock.patch('stevedore.ExtensionManager') self.extension_mgr_patcher = mock.patch('stevedore.ExtensionManager')
self.mocked_extension_mgr = self.extension_mgr_patcher.start() self.mocked_extension_mgr = self.extension_mgr_patcher.start()

View File

@ -80,9 +80,8 @@ exit 1
fp = open(tmpfilename2, 'r') fp = open(tmpfilename2, 'r')
runs = fp.read() runs = fp.read()
fp.close() fp.close()
self.assertNotEqual(runs.strip(), 'failure', 'stdin did not ' self.assertNotEqual(runs.strip(), 'failure',
'always get passed ' 'stdin did not always get passed correctly')
'correctly')
runs = int(runs.strip()) runs = int(runs.strip())
self.assertEqual(10, runs, self.assertEqual(10, runs,
'Ran %d times instead of 10.' % (runs,)) 'Ran %d times instead of 10.' % (runs,))

View File

@ -56,9 +56,7 @@ commands =
python setup.py build_sphinx python setup.py build_sphinx
[flake8] [flake8]
# E711: ignored because it is normal to use "column == None" in sqlalchemy ignore = E129
ignore = E12,E711
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*ironic/nova*,tools exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*ironic/nova*,tools
[hacking] [hacking]