Browse Source

Fix: pep8 airship-drydock-omni-test fix

Fixes for pep8 test.

Change-Id: Id2b7a187ffe56a47a184314d1a19507a78f7d88a
Roman Gorshunov 5 months ago
parent
commit
d5c54eab68

+ 2
- 2
python/drydock_provisioner/control/health.py View File

@@ -96,7 +96,7 @@ class HealthCheckCombined(object):
96 96
             now = self.state_manager.get_now()
97 97
             if now is None:
98 98
                 raise Exception('None received from database for now()')
99
-        except Exception as ex:
99
+        except Exception:
100 100
             hcm = HealthCheckMessage(
101 101
                 msg='Unable to connect to database', error=True)
102 102
             health_check.add_detail_msg(msg=hcm)
@@ -110,7 +110,7 @@ class HealthCheckCombined(object):
110 110
             maas_validation.start()
111 111
             if maas_validation.task.get_status() == ActionResult.Failure:
112 112
                 raise Exception('MaaS task failure')
113
-        except Exception as ex:
113
+        except Exception:
114 114
             hcm = HealthCheckMessage(
115 115
                 msg='Unable to connect to MaaS', error=True)
116 116
             health_check.add_detail_msg(msg=hcm)

+ 1
- 1
python/drydock_provisioner/control/tasks.py View File

@@ -328,7 +328,7 @@ class TaskResource(StatefulResource):
328 328
             subtask_errors = req.get_param_as_bool('subtaskerrors')
329 329
             try:
330 330
                 layers = int(req.params.get('layers', '0'))
331
-            except Exception as ex:
331
+            except Exception:
332 332
                 layers = 0
333 333
 
334 334
             first_task = self.get_task(req, resp, task_id, builddata)

+ 16
- 14
python/drydock_provisioner/drivers/node/maasdriver/actions/node.py View File

@@ -320,12 +320,13 @@ class DestroyNode(BaseMaasAction):
320 320
                     # node release with erase disk will take sometime monitor it
321 321
                     attempts = 0
322 322
                     max_attempts = (
323
-                        config.config_mgr.conf.timeouts.destroy_node *
324
-                        60) // config.config_mgr.conf.maasdriver.poll_interval
323
+                        config.config_mgr.conf.timeouts.destroy_node
324
+                        * 60) // config.config_mgr.conf.maasdriver.poll_interval
325 325
 
326
-                    while (attempts < max_attempts and
327
-                           (not machine.status_name.startswith('Ready')
328
-                            and not machine.status_name.startswith('Failed'))):
326
+                    while (attempts < max_attempts
327
+                            and (not machine.status_name.startswith('Ready')
328
+                                 and not
329
+                                 machine.status_name.startswith('Failed'))):
329 330
                         attempts = attempts + 1
330 331
                         time.sleep(
331 332
                             config.config_mgr.conf.maasdriver.poll_interval)
@@ -373,7 +374,7 @@ class DestroyNode(BaseMaasAction):
373 374
                         # setting power type attibutes to empty string
374 375
                         # will remove them from maas BMC table
375 376
                         machine.reset_power_parameters()
376
-                except AttributeError as attr_er:
377
+                except AttributeError:
377 378
                     pass
378 379
 
379 380
                 machine.delete()
@@ -778,7 +779,7 @@ class CreateNetworkTemplate(BaseMaasAction):
778 779
                                                 ctx_type='network')
779 780
                                             vlan.update()
780 781
                                             dhcp_config_set = True
781
-                                        except RackControllerConflict as rack_ex:
782
+                                        except RackControllerConflict:
782 783
                                             msg = (
783 784
                                                 "More than two rack controllers on vlan %s, "
784 785
                                                 "skipping enabling %s." %
@@ -1207,9 +1208,10 @@ class ConfigureHardware(BaseMaasAction):
1207 1208
                             * 60
1208 1209
                         ) // config.config_mgr.conf.maasdriver.poll_interval
1209 1210
 
1210
-                        while (attempts < max_attempts and
1211
-                               (machine.status_name != 'Ready' and
1212
-                                not machine.status_name.startswith('Failed'))):
1211
+                        while (attempts < max_attempts
1212
+                               and (machine.status_name != 'Ready'
1213
+                                    and not
1214
+                                    machine.status_name.startswith('Failed'))):
1213 1215
                             attempts = attempts + 1
1214 1216
                             time.sleep(config.config_mgr.conf.maasdriver.
1215 1217
                                        poll_interval)
@@ -1397,7 +1399,7 @@ class ApplyNodeNetworking(BaseMaasAction):
1397 1399
                         try:
1398 1400
                             machine.release()
1399 1401
                             machine.refresh()
1400
-                        except errors.DriverError as ex:
1402
+                        except errors.DriverError:
1401 1403
                             msg = (
1402 1404
                                 "Node %s could not be released, skipping deployment."
1403 1405
                                 % n.name)
@@ -2203,7 +2205,7 @@ class ApplyNodeStorage(BaseMaasAction):
2203 2205
                         size_str is interpreted in the context of this device
2204 2206
         :return size: The calculated size in bytes
2205 2207
         """
2206
-        pattern = '(>?)(\d+)([mMbBgGtT%]{1,2})'
2208
+        pattern = r'(>?)(\d+)([mMbBgGtT%]{1,2})'
2207 2209
         regex = re.compile(pattern)
2208 2210
         match = regex.match(size_str)
2209 2211
 
@@ -2400,8 +2402,8 @@ class DeployNode(BaseMaasAction):
2400 2402
 
2401 2403
             attempts = 0
2402 2404
             max_attempts = (
2403
-                config.config_mgr.conf.timeouts.deploy_node *
2404
-                60) // config.config_mgr.conf.maasdriver.poll_interval
2405
+                config.config_mgr.conf.timeouts.deploy_node
2406
+                * 60) // config.config_mgr.conf.maasdriver.poll_interval
2405 2407
 
2406 2408
             while (attempts < max_attempts
2407 2409
                    and (not machine.status_name.startswith('Deployed')

+ 1
- 1
python/drydock_provisioner/drivers/node/maasdriver/api_client.py View File

@@ -93,7 +93,7 @@ class MaasRequestFactory(object):
93 93
     def test_authentication(self):
94 94
         try:
95 95
             resp = self.get('account/', op='list_authorisation_tokens')
96
-        except requests.Timeout as ex:
96
+        except requests.Timeout:
97 97
             raise errors.TransientDriverError("Timeout connection to MaaS")
98 98
         except Exception as ex:
99 99
             raise errors.PersistentDriverError(

+ 2
- 2
python/drydock_provisioner/drivers/node/maasdriver/models/base.py View File

@@ -66,7 +66,7 @@ class ResourceBase(object):
66 66
     """
67 67
 
68 68
     def interpolate_url(self):
69
-        pattern = '\{([a-z_]+)\}'
69
+        pattern = r'\{([a-z_]+)\}'
70 70
         regex = re.compile(pattern)
71 71
         start = 0
72 72
         new_url = self.resource_url
@@ -184,7 +184,7 @@ class ResourceCollectionBase(object):
184 184
 
185 185
     def interpolate_url(self):
186 186
         """Parse URL for placeholders and replace them with current instance values."""
187
-        pattern = '\{([a-z_]+)\}'
187
+        pattern = r'\{([a-z_]+)\}'
188 188
         regex = re.compile(pattern)
189 189
         start = 0
190 190
         new_url = self.collection_url

+ 2
- 2
python/drydock_provisioner/drivers/node/maasdriver/models/machine.py View File

@@ -624,8 +624,8 @@ class Machines(model_base.ResourceCollectionBase):
624 624
                 field = k[13:]
625 625
                 result = [
626 626
                     i for i in result if str(
627
-                        getattr(i, 'power_parameters', {}).get(field, None)) ==
628
-                    str(v)
627
+                        getattr(i, 'power_parameters', {}).
628
+                        get(field, None)) == str(v)
629 629
                 ]
630 630
             else:
631 631
                 result = [

+ 1
- 1
python/drydock_provisioner/drivers/node/maasdriver/models/node_results.py View File

@@ -54,7 +54,7 @@ class NodeResult(model_base.ResourceBase):
54 54
         """Decode the result data from base64."""
55 55
         try:
56 56
             return base64.b64decode(self.data)
57
-        except binascii.Error as e:
57
+        except binascii.Error:
58 58
             return None
59 59
 
60 60
     def get_type_desc(self):

+ 1
- 1
python/drydock_provisioner/objects/builddata.py View File

@@ -48,7 +48,7 @@ class BuildData(object):
48 48
                 data_element = data_element.decode('utf-8')
49 49
             elif not isinstance(data_element, str):
50 50
                 data_element = str(data_element)
51
-        except Exception as ex:
51
+        except Exception:
52 52
             raise errors.BuildDataError(
53 53
                 "Error saving build data - data_element type %s could"
54 54
                 "not be cast to string." % str(type(data_element)))

+ 4
- 4
python/drydock_provisioner/objects/node.py View File

@@ -107,10 +107,10 @@ class BaremetalNode(drydock_provisioner.objects.hostprofile.HostProfile):
107 107
         try:
108 108
             pn = site_design.get_network(self.primary_network)
109 109
             domain = pn.dns_domain or "local"
110
-        except errors.DesignError as dex:
110
+        except errors.DesignError:
111 111
             self.logger.debug("Primary network not found, use domain 'local'.")
112 112
             domain = "local"
113
-        except AttributeError as aex:
113
+        except AttributeError:
114 114
             self.logger.debug(
115 115
                 "Primary network does not define a domain, use domain 'local'."
116 116
             )
@@ -255,8 +255,8 @@ class BaremetalNode(drydock_provisioner.objects.hostprofile.HostProfile):
255 255
         :param address: String value that is used to find the logicalname.
256 256
         :return: String value of the logicalname or the alias_name if logicalname is not found.
257 257
         """
258
-        nodes = xml_root.findall(".//node[businfo='" + bus_type + "@" +
259
-                                 address + "'].logicalname")
258
+        nodes = xml_root.findall(".//node[businfo='" + bus_type + "@"
259
+                                 + address + "'].logicalname")
260 260
         if len(nodes) >= 1 and nodes[0].text:
261 261
             if (len(nodes) > 1):
262 262
                 self.logger.info("Multiple nodes found for businfo=%s@%s" %

+ 2
- 2
python/drydock_provisioner/orchestrator/actions/orchestrator.py View File

@@ -1118,8 +1118,8 @@ class BootactionReport(BaseAction):
1118 1118
                 bas = self.state_manager.get_boot_actions_for_node(n)
1119 1119
                 running_bas = {
1120 1120
                     k: v
1121
-                    for (k, v) in bas.items() if v.get('action_status') ==
1122
-                    hd_fields.ActionResult.Incomplete
1121
+                    for (k, v) in bas.items() if v.
1122
+                    get('action_status') == hd_fields.ActionResult.Incomplete
1123 1123
                 }
1124 1124
                 if len(running_bas) > 0:
1125 1125
                     still_running = True

+ 1
- 1
python/drydock_provisioner/orchestrator/orchestrator.py View File

@@ -269,7 +269,7 @@ class Orchestrator(object):
269 269
                         site_design,
270 270
                         state_manager=self.state_manager,
271 271
                         resolve_aliases=resolve_aliases)
272
-                except Exception as ex:
272
+                except Exception:
273 273
                     node_failed.append(n)
274 274
                     self.logger.error(
275 275
                         "Failed to build applied model for node %s." % n.name)

+ 1
- 1
python/drydock_provisioner/orchestrator/util.py View File

@@ -29,7 +29,7 @@ class SimpleBytes():
29 29
         :param size_str: A string representing the desired size
30 30
         :return size: The calculated size in bytes
31 31
         """
32
-        pattern = '(\d+)([mMbBgGtT]{1,2})'
32
+        pattern = r'(\d+)([mMbBgGtT]{1,2})'
33 33
         regex = re.compile(pattern)
34 34
         match = regex.match(size_str)
35 35
 

+ 2
- 2
python/drydock_provisioner/orchestrator/validations/boot_storage_rational.py View File

@@ -51,7 +51,7 @@ class BootStorageRational(Validators):
51 51
                                 self.report_error(
52 52
                                     msg, [baremetal_node.doc_ref],
53 53
                                     "Configure a larger root volume")
54
-                        except errors.InvalidSizeFormat as e:
54
+                        except errors.InvalidSizeFormat:
55 55
                             msg = (
56 56
                                 'Root volume has an invalid size format on BaremetalNode'
57 57
                                 '%s.' % baremetal_node.name)
@@ -74,7 +74,7 @@ class BootStorageRational(Validators):
74 74
                                 self.report_error(
75 75
                                     msg, [baremetal_node.doc_ref],
76 76
                                     "Configure a larger boot volume.")
77
-                        except errors.InvalidSizeFormat as e:
77
+                        except errors.InvalidSizeFormat:
78 78
                             msg = (
79 79
                                 'Boot volume has an invalid size format on BaremetalNode '
80 80
                                 '%s.' % baremetal_node.name)

+ 1
- 1
python/drydock_provisioner/orchestrator/validations/bootaction_validity.py View File

@@ -45,7 +45,7 @@ class BootactionPackageListValid(Validators):
45 45
 
46 46
     def __init__(self):
47 47
         super().__init__('Bootaction pkg_list Validation', 'DD4002')
48
-        version_fields = '(\d+:)?([a-zA-Z0-9.+~-]+)(-[a-zA-Z0-9.+~]+)'
48
+        version_fields = r'(\d+:)?([a-zA-Z0-9.+~-]+)(-[a-zA-Z0-9.+~]+)'
49 49
         self.version_fields = re.compile(version_fields)
50 50
 
51 51
     def run_validation(self, site_design, orchestrator=None):

+ 2
- 2
python/drydock_provisioner/orchestrator/validations/network_trunking_rational.py View File

@@ -30,8 +30,8 @@ class NetworkTrunkingRational(Validators):
30 30
         for network_link in network_link_list:
31 31
             allowed_networks = network_link.allowed_networks
32 32
             # if allowed networks > 1 trunking must be enabled
33
-            if (len(allowed_networks) > 1 and network_link.trunk_mode ==
34
-                    hd_fields.NetworkLinkTrunkingMode.Disabled):
33
+            if (len(allowed_networks) > 1 and network_link.
34
+                    trunk_mode == hd_fields.NetworkLinkTrunkingMode.Disabled):
35 35
                 msg = ('If there is more than 1 allowed network,'
36 36
                        'trunking mode must be enabled')
37 37
                 self.report_error(

+ 1
- 1
python/drydock_provisioner/statemgmt/design/resolver.py View File

@@ -117,7 +117,7 @@ class ReferenceResolver(object):
117 117
         :param design_uri: Tuple as returned by urllib.parse for the design reference
118 118
         """
119 119
         ks_sess = KeystoneUtils.get_session()
120
-        (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme)
120
+        (new_scheme, foo) = re.subn(r'^[^+]+\+', '', design_uri.scheme)
121 121
         url = urllib.parse.urlunparse(
122 122
             (new_scheme, design_uri.netloc, design_uri.path, design_uri.params,
123 123
              design_uri.query, design_uri.fragment))

+ 6
- 6
python/drydock_provisioner/statemgmt/state.py View File

@@ -110,9 +110,9 @@ class DrydockState(object):
110 110
         """
111 111
         query_text = sql.text(
112 112
             "SELECT * FROM tasks WHERE "  # nosec no strings are user-sourced
113
-            "parent_task_id = :parent_task_id AND "
114
-            "status IN ('" + hd_fields.TaskStatus.Terminated + "','" +
115
-            hd_fields.TaskStatus.Complete + "')")
113
+            "parent_task_id = :parent_task_id AND status "
114
+            "IN ('" + hd_fields.TaskStatus.Terminated + "','"
115
+            + hd_fields.TaskStatus.Complete + "')")
116 116
         return self._query_subtasks(task_id, query_text,
117 117
                                     "Error querying complete subtask: %s")
118 118
 
@@ -126,9 +126,9 @@ class DrydockState(object):
126 126
         """
127 127
         query_text = sql.text(
128 128
             "SELECT * FROM tasks WHERE "  # nosec no strings are user-sourced
129
-            "parent_task_id = :parent_task_id AND "
130
-            "status NOT IN ['" + hd_fields.TaskStatus.Terminated + "','" +
131
-            hd_fields.TaskStatus.Complete + "']")
129
+            "parent_task_id = :parent_task_id AND status "
130
+            "NOT IN ['" + hd_fields.TaskStatus.Terminated + "','"
131
+            + hd_fields.TaskStatus.Complete + "']")
132 132
         return self._query_subtasks(task_id, query_text,
133 133
                                     "Error querying active subtask: %s")
134 134
 

+ 7
- 7
python/tests/unit/test_api_tasks_unit.py View File

@@ -43,13 +43,13 @@ class TestTasksApiUnit(object):
43 43
         try:
44 44
             response_json['build_data']
45 45
             key_error = False
46
-        except KeyError as ex:
46
+        except KeyError:
47 47
             key_error = True
48 48
         assert key_error
49 49
         try:
50 50
             response_json['subtask_errors']
51 51
             key_error = False
52
-        except KeyError as ex:
52
+        except KeyError:
53 53
             key_error = True
54 54
         assert key_error
55 55
 
@@ -95,7 +95,7 @@ class TestTasksApiUnit(object):
95 95
         try:
96 96
             response_json['subtask_errors']
97 97
             key_error = False
98
-        except KeyError as ex:
98
+        except KeyError:
99 99
             key_error = True
100 100
         assert key_error
101 101
 
@@ -132,7 +132,7 @@ class TestTasksApiUnit(object):
132 132
         try:
133 133
             response_json['11111111-1111-1111-1111-111111111116']
134 134
             key_error = False
135
-        except KeyError as ex:
135
+        except KeyError:
136 136
             key_error = True
137 137
         assert key_error
138 138
 
@@ -156,13 +156,13 @@ class TestTasksApiUnit(object):
156 156
         try:
157 157
             response_json['11111111-1111-1111-1111-111111111116']
158 158
             key_error = False
159
-        except KeyError as ex:
159
+        except KeyError:
160 160
             key_error = True
161 161
         assert key_error is False
162 162
         try:
163 163
             response_json['subtask_errors']
164 164
             key_error = False
165
-        except KeyError as ex:
165
+        except KeyError:
166 166
             key_error = True
167 167
         assert key_error
168 168
 
@@ -186,7 +186,7 @@ class TestTasksApiUnit(object):
186 186
         try:
187 187
             response_json['11111111-1111-1111-1111-111111111116']
188 188
             key_error = False
189
-        except KeyError as ex:
189
+        except KeyError:
190 190
             key_error = True
191 191
         assert key_error is False
192 192
         assert response_json['subtask_errors'][

+ 1
- 1
python/tests/unit/test_validation_rule_mtu_rational.py View File

@@ -54,7 +54,7 @@ class TestMtu(object):
54 54
         validator = MtuRational()
55 55
         message_list = validator.execute(site_design, orchestrator=orch)
56 56
 
57
-        regex = re.compile('MTU must be between \d+ and \d+')
57
+        regex = re.compile(r'MTU must be between \d+ and \d+')
58 58
         regex_1 = re.compile('MTU must be <= the parent Network Link')
59 59
 
60 60
         for msg in message_list:

+ 2
- 2
python/tests/unit/test_validation_rule_network_bond.py View File

@@ -55,8 +55,8 @@ class TestRationalNetworkLinkBond(object):
55 55
         validator = RationalNetworkBond()
56 56
         message_list = validator.execute(site_design, orchestrator=orch)
57 57
 
58
-        regex = re.compile('Down delay \S+ is less than mon rate \S+')
59
-        regex_1 = re.compile('Up delay \S+ is less than mon rate \S+')
58
+        regex = re.compile(r'Down delay \S+ is less than mon rate \S+')
59
+        regex_1 = re.compile(r'Up delay \S+ is less than mon rate \S+')
60 60
 
61 61
         for msg in message_list:
62 62
             msg = msg.to_dict()

+ 2
- 2
python/tests/unit/test_validation_rule_unique_network.py View File

@@ -56,10 +56,10 @@ class TestUniqueNetwork(object):
56 56
         message_list = validator.execute(site_design, orchestrator=orch)
57 57
 
58 58
         regex = re.compile(
59
-            'Allowed network .+ duplicated on NetworkLink .+ and NetworkLink .+'
59
+            r'Allowed network .+ duplicated on NetworkLink .+ and NetworkLink .+'
60 60
         )
61 61
         regex_1 = re.compile(
62
-            'Interface \S+ attached to network \S+ not allowed on interface link'
62
+            r'Interface \S+ attached to network \S+ not allowed on interface link'
63 63
         )
64 64
 
65 65
         assert len(message_list) >= 2

Loading…
Cancel
Save