Skip to content

Commit 601201d

Browse files
Update hacking and fix hacking violations
This does a few things: * Update hacking to the version in global-requirements. Old hacking was installing a version of pbr that was breaking other packages. * Fix all the hacking/pep8 rules that updating hacking raised. * Do some general docstring cleanup, while already in there cleaning up a bunch of docstrings due to H405 violations. Change-Id: I1fc1e59d4c3d7b14631f8b576e3f3854bc452188 Closes-Bug: #1461717
1 parent 141191b commit 601201d

9 files changed

Lines changed: 44 additions & 47 deletions

File tree

ironic_python_agent/backoff.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
LOG = log.getLogger(__name__)
2525

2626

27-
#TODO(JoshNang) move to oslo, i18n
27+
# TODO(JoshNang) move to oslo, i18n
2828
class LoopingCallTimeOut(Exception):
2929
"""Exception for a timed out LoopingCall.
3030
@@ -35,7 +35,9 @@ class LoopingCallTimeOut(Exception):
3535

3636

3737
class BackOffLoopingCall(loopingcall.LoopingCallBase):
38-
"""The passed in function should return True (no error, return to
38+
"""Run a method in a loop with backoff on error.
39+
40+
The passed in function should return True (no error, return to
3941
initial_interval),
4042
False (error, start backing off), or raise LoopingCallDone(retvalue=None)
4143
(quit looping, return retvalue if set).

ironic_python_agent/encoding.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def encode(self, o):
4242
return super(RESTJSONEncoder, self).encode(o) + delimiter
4343

4444
def default(self, o):
45-
"""Turn an object into a serializable object. In particular, by
46-
calling :meth:`.Serializable.serialize`.
45+
"""Turn an object into a serializable object.
46+
47+
In particular, by calling :meth:`.Serializable.serialize` on `o`.
4748
"""
4849
if isinstance(o, Serializable):
4950
return o.serialize()

ironic_python_agent/errors.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def __init__(self, details=None, *args, **kwargs):
3131

3232

3333
class InvalidContentError(RESTError):
34-
"""Error which occurs when a user supplies invalid content, either
35-
because that content cannot be parsed according to the advertised
34+
"""Error which occurs when a user supplies invalid content.
35+
36+
Either because that content cannot be parsed according to the advertised
3637
`Content-Type`, or due to a content validation error.
3738
"""
3839
message = 'Invalid request body'
@@ -43,10 +44,7 @@ def __init__(self, details):
4344

4445

4546
class NotFound(RESTError):
46-
"""Error which occurs when a user supplies invalid content, either
47-
because that content cannot be parsed according to the advertised
48-
`Content-Type`, or due to a content validation error.
49-
"""
47+
"""Error which occurs if a non-existent API endpoint is called."""
5048
message = 'Not found'
5149
status_code = 404
5250
details = 'The requested URL was not found.'
@@ -104,9 +102,7 @@ def __init__(self, details):
104102

105103

106104
class LookupNodeError(IronicAPIError):
107-
"""Error raised when the node configuration lookup to the Ironic API
108-
fails.
109-
"""
105+
"""Error raised when the node lookup to the Ironic API fails."""
110106

111107
message = 'Error getting configuration from Ironic.'
112108

@@ -167,6 +163,7 @@ def __init__(self, device, exit_code, stdout, stderr):
167163

168164
class ConfigDriveTooLargeError(RESTError):
169165
"""Error raised when a configdrive is larger than the partition."""
166+
170167
message = 'Configdrive is too large for intended partition.'
171168

172169
def __init__(self, filename, filesize):
@@ -176,9 +173,7 @@ def __init__(self, filename, filesize):
176173

177174

178175
class ConfigDriveWriteError(RESTError):
179-
"""Error raised when a configdrive directory cannot be written to a
180-
device.
181-
"""
176+
"""Error raised when a configdrive cannot be written to a device."""
182177

183178
message = 'Error writing configdrive to device.'
184179

@@ -211,18 +206,18 @@ def __init__(self, details):
211206

212207

213208
class BlockDeviceError(RESTError):
214-
"""Error raised when a block devices causes an unknown error"""
209+
"""Error raised when a block devices causes an unknown error."""
210+
215211
message = 'Block device caused unknown error'
216212

217213
def __init__(self, details):
218214
super(BlockDeviceError, self).__init__(details)
219215

220216

221217
class VirtualMediaBootError(RESTError):
222-
"""Error raised when booting ironic-python-client from virtual media
223-
fails.
224-
"""
225-
message = 'Booting ironic-python-client from virtual media failed.'
218+
"""Error raised when virtual media device cannot be found for config."""
219+
220+
message = 'Configuring agent from virtual media failed.'
226221

227222
def __init__(self, details):
228223
super(VirtualMediaBootError, self).__init__(details)
@@ -270,9 +265,7 @@ def __init__(self, method):
270265

271266

272267
class IncompatibleHardwareMethodError(RESTError):
273-
"""Error raised when HardwareManager method is incompatible with node
274-
hardware.
275-
"""
268+
"""Error raised when HardwareManager method incompatible with hardware."""
276269

277270
message = 'HardwareManager method is not compatible with hardware.'
278271

@@ -306,6 +299,7 @@ def __init__(self, agent_version, node_version):
306299

307300
class CleaningError(RESTError):
308301
"""Error raised when a cleaning step fails."""
302+
309303
message = 'Clean step failed.'
310304

311305
def __init__(self, details=None):
@@ -329,9 +323,7 @@ def __init__(self, error_msg, exit_code, stdout, stderr):
329323

330324

331325
class DeviceNotFound(NotFound):
332-
"""Error raised when the disk or partition to deploy the image onto is
333-
not found.
334-
"""
326+
"""Error raised when the device to deploy the image onto is not found."""
335327

336328
message = ('Error finding the disk or partition device to deploy '
337329
'the image onto.')

ironic_python_agent/extensions/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def execute_command(self, command_name, **kwargs):
249249

250250
def async_command(command_name, validator=None):
251251
"""Will run the command in an AsyncCommandResult in its own thread.
252+
252253
command_name is set based on the func name and command_params will
253254
be whatever args/kwargs you pass into the decorated command.
254255
Return values of type `str` or `unicode` are prefixed with the
@@ -277,8 +278,9 @@ def wrapper(self, **command_params):
277278

278279

279280
def sync_command(command_name, validator=None):
280-
"""Decorate a method in order to wrap up its return value in a
281-
SyncCommandResult. For consistency with @async_command() can also accept a
281+
"""Decorate a method to wrap its return value in a SyncCommandResult.
282+
283+
For consistency with @async_command() can also accept a
282284
validator which will be used to validate input, although a synchronous
283285
command can also choose to implement validation inline.
284286
"""

ironic_python_agent/ironic_api_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def lookup_node(self, hardware_info, timeout, starting_interval):
9191
return node_content
9292

9393
def _do_lookup(self, hardware_info):
94-
"""The actual call to lookup a node. Should be called inside
95-
loopingcall.BackOffLoopingCall.
94+
"""The actual call to lookup a node.
95+
96+
Should be called as a `loopingcall.BackOffLoopingCall`.
9697
"""
9798
path = '/{api_version}/drivers/{driver}/vendor_passthru/lookup'.format(
9899
api_version=self.api_version,

ironic_python_agent/tests/hardware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@
113113
'\t24min for SECURITY ERASE UNIT. 24min for ENHANCED SECURITY '
114114
'ERASE UNIT.\n'
115115
'Checksum: correct\n'
116-
)
116+
) # noqa
117+
# NOTE(jroll) noqa here is to dodge E131 (indent rules). Since this is a
118+
# massive multi-line string (with specific whitespace formatting), it's easier
119+
# for a human to parse it with indentations on line continuations. The other
120+
# option would be to ignore the 79-character limit here. Ew.
117121

118122
BLK_DEVICE_TEMPLATE = (
119123
'KNAME="sda" MODEL="TinyUSB Drive" SIZE="3116853504" '

ironic_python_agent/tests/multi_hardware.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,16 @@ def test_generic_method_only(self):
140140
self.assertEqual(1, self.generic_hwm.obj._call_counts['generic_only'])
141141

142142
def test_both_succeed(self):
143-
"""In the case where both managers will work; only the most specific
144-
manager should have it's function called.
145-
"""
143+
# In the case where both managers will work; only the most specific
144+
# manager should have it's function called.
146145
hardware.dispatch_to_managers('both_succeed')
147146

148147
self.assertEqual(1, self.mainline_hwm.obj._call_counts['both_succeed'])
149148
self.assertEqual(0, self.generic_hwm.obj._call_counts['both_succeed'])
150149

151150
def test_mainline_fails(self):
152-
"""Ensure that if the mainline manager is unable to run the method
153-
that we properly fall back to generic.
154-
"""
151+
# Ensure that if the mainline manager is unable to run the method
152+
# that we properly fall back to generic.
155153
hardware.dispatch_to_managers('mainline_fail')
156154

157155
self.assertEqual(
@@ -184,9 +182,8 @@ def test_dispatch_to_all_managers_generic_method_only(self):
184182
'FakeMainlineHardwareManager': None}, results)
185183

186184
def test_dispatch_to_all_managers_both_succeed(self):
187-
"""In the case where both managers will work; only the most specific
188-
manager should have it's function called.
189-
"""
185+
# In the case where both managers will work; only the most specific
186+
# manager should have it's function called.
190187
results = hardware.dispatch_to_all_managers('both_succeed')
191188

192189
self.assertEqual({'FakeGenericHardwareManager': 'generic_both',
@@ -196,9 +193,8 @@ def test_dispatch_to_all_managers_both_succeed(self):
196193
self.assertEqual(1, self.generic_hwm.obj._call_counts['both_succeed'])
197194

198195
def test_dispatch_to_all_managers_mainline_fails(self):
199-
"""Ensure that if the mainline manager is unable to run the method
200-
that we properly fall back to generic.
201-
"""
196+
# Ensure that if the mainline manager is unable to run the method
197+
# that we properly fall back to generic.
202198
hardware.dispatch_to_all_managers('mainline_fail')
203199

204200
self.assertEqual(

ironic_python_agent/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def _get_vmedia_device():
105105

106106

107107
def _get_vmedia_params():
108-
"""This method returns the parameters passed to the agent through virtual
109-
media floppy.
108+
"""This method returns the parameters passed through virtual media floppy.
110109
111110
:returns: a partial dict of potential agent configuration parameters
112111
:raises: VirtualMediaBootError when it cannot find the virtual media device

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The order of packages is significant, because pip processes them in the order
22
# of appearance. Changing the order has an impact on the overall integration
33
# process, which may cause wedges in the gate later.
4-
hacking>=0.8.0,<0.9
4+
hacking>=0.10.0,<0.11
55
coverage>=3.6
66
discover
77
mock>=1.0

0 commit comments

Comments
 (0)