Browse Source

Merge "Avoid doing `raise ex` when only logging"

Zuul 2 months ago
parent
commit
79b615f98c

+ 5
- 6
kuryr_kubernetes/controller/drivers/lbaasv2.py View File

@@ -405,9 +405,9 @@ class LBaaSv2Driver(base.LBaaSDriver):
405 405
             fixed_ips = ['subnet_id=%s' % str(loadbalancer.subnet_id),
406 406
                          'ip_address=%s' % str(loadbalancer.ip)]
407 407
             ports = neutron.list_ports(fixed_ips=fixed_ips)
408
-        except n_exc.NeutronClientException as ex:
408
+        except n_exc.NeutronClientException:
409 409
             LOG.error("Port with fixed ips %s not found!", fixed_ips)
410
-            raise ex
410
+            raise
411 411
 
412 412
         if ports['ports']:
413 413
             return ports['ports'][0]
@@ -802,10 +802,9 @@ class LBaaSv2Driver(base.LBaaSDriver):
802 802
                 l7_rule.id, l7_rule.l7policy_id,
803 803
                 {'rule': {'value': new_value}})
804 804
 
805
-        except n_exc.NeutronClientException as ex:
806
-            LOG.error("Failed to update l7_rule- id=%s ",
807
-                      l7_rule.id)
808
-            raise ex
805
+        except n_exc.NeutronClientException:
806
+            LOG.exception("Failed to update l7_rule- id=%s ", l7_rule.id)
807
+            raise
809 808
 
810 809
     def is_pool_used_by_other_l7policies(self, l7policy, pool):
811 810
         lbaas = clients.get_loadbalancer_client()

+ 4
- 4
kuryr_kubernetes/controller/drivers/namespace_security_groups.py View File

@@ -115,10 +115,10 @@ class NamespacePodSecurityGroupsDriver(base.PodSecurityGroupsDriver):
115 115
                         "security_group_id": sg['id']
116 116
                     }
117 117
                 })
118
-        except n_exc.NeutronClientException as ex:
119
-            LOG.error("Error creating security group for the namespace "
120
-                      "%s: %s", namespace, ex)
121
-            raise ex
118
+        except n_exc.NeutronClientException:
119
+            LOG.exception("Error creating security group for the namespace "
120
+                          "%s", namespace)
121
+            raise
122 122
         return {'sgId': sg['id']}
123 123
 
124 124
     def delete_sg(self, sg_id):

+ 4
- 4
kuryr_kubernetes/controller/drivers/namespace_subnet.py View File

@@ -138,10 +138,10 @@ class NamespacePodSubnetDriver(default_subnet.DefaultPodSubnetDriver):
138 138
             # connect the subnet to the router
139 139
             neutron.add_interface_router(router_id,
140 140
                                          {"subnet_id": neutron_subnet['id']})
141
-        except n_exc.NeutronClientException as ex:
142
-            LOG.error("Error creating neutron resources for the namespace "
143
-                      "%s: %s", namespace, ex)
144
-            raise ex
141
+        except n_exc.NeutronClientException:
142
+            LOG.exception("Error creating neutron resources for the namespace "
143
+                          "%s", namespace)
144
+            raise
145 145
         return {'netId': neutron_net['id'],
146 146
                 'routerId': router_id,
147 147
                 'subnetId': neutron_subnet['id'],

+ 4
- 4
kuryr_kubernetes/controller/drivers/nested_macvlan_vif.py View File

@@ -142,7 +142,7 @@ class NestedMacvlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
142 142
                 port_id,
143 143
                 {'port': {'allowed_address_pairs': address_pairs}}
144 144
             )
145
-        except n_exc.NeutronClientException as ex:
146
-            LOG.error("Error happened during updating Neutron "
147
-                      "port %s: %s", port_id, ex)
148
-            raise ex
145
+        except n_exc.NeutronClientException:
146
+            LOG.exception("Error happened during updating Neutron port %s",
147
+                          port_id)
148
+            raise

+ 2
- 2
kuryr_kubernetes/controller/drivers/nested_vif.py View File

@@ -40,10 +40,10 @@ class NestedPodVIFDriver(neutron_vif.NeutronPodVIFDriver):
40 40
             fixed_ips = ['subnet_id=%s' % str(node_subnet_id),
41 41
                          'ip_address=%s' % str(node_fixed_ip)]
42 42
             ports = neutron.list_ports(fixed_ips=fixed_ips)
43
-        except n_exc.NeutronClientException as ex:
43
+        except n_exc.NeutronClientException:
44 44
             LOG.error("Parent vm port with fixed ips %s not found!",
45 45
                       fixed_ips)
46
-            raise ex
46
+            raise
47 47
 
48 48
         if ports['ports']:
49 49
             return ports['ports'][0]

+ 20
- 21
kuryr_kubernetes/controller/drivers/nested_vlan_vif.py View File

@@ -81,9 +81,9 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
81 81
         bulk_port_rq = {'ports': [port_rq for _ in range(len(subports_info))]}
82 82
         try:
83 83
             ports = neutron.create_port(bulk_port_rq).get('ports')
84
-        except n_exc.NeutronClientException as ex:
85
-            LOG.error("Error creating bulk ports: %s", bulk_port_rq)
86
-            raise ex
84
+        except n_exc.NeutronClientException:
85
+            LOG.exception("Error creating bulk ports: %s", bulk_port_rq)
86
+            raise
87 87
         for index, port in enumerate(ports):
88 88
             subports_info[index]['port_id'] = port['id']
89 89
 
@@ -91,14 +91,14 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
91 91
             try:
92 92
                 neutron.trunk_add_subports(trunk_id,
93 93
                                            {'sub_ports': subports_info})
94
-            except n_exc.Conflict as ex:
94
+            except n_exc.Conflict:
95 95
                 LOG.error("vlan ids already in use on trunk")
96 96
                 for port in ports:
97 97
                     neutron.delete_port(port['id'])
98
-                raise ex
99
-        except n_exc.NeutronClientException as ex:
100
-            LOG.error("Error happened during subport addition to trunk")
101
-            raise ex
98
+                raise
99
+        except n_exc.NeutronClientException:
100
+            LOG.exception("Error happened during subport addition to trunk")
101
+            raise
102 102
 
103 103
         vifs = []
104 104
         for index, port in enumerate(ports):
@@ -185,17 +185,17 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
185 185
         while True:
186 186
             try:
187 187
                 vlan_id = self._get_vlan_id(trunk_id)
188
-            except n_exc.NeutronClientException as ex:
188
+            except n_exc.NeutronClientException:
189 189
                 LOG.error("Getting VlanID for subport on "
190 190
                           "trunk %s failed!!", trunk_id)
191
-                raise ex
191
+                raise
192 192
             subport = [{'segmentation_id': vlan_id,
193 193
                         'port_id': subport,
194 194
                        'segmentation_type': 'vlan'}]
195 195
             try:
196 196
                 neutron.trunk_add_subports(trunk_id,
197 197
                                            {'sub_ports': subport})
198
-            except n_exc.Conflict as ex:
198
+            except n_exc.Conflict:
199 199
                 if retry_count < DEFAULT_MAX_RETRY_COUNT:
200 200
                     LOG.error("vlanid already in use on trunk, "
201 201
                               "%s. Retrying...", trunk_id)
@@ -205,12 +205,12 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
205 205
                 else:
206 206
                     LOG.error(
207 207
                         "MAX retry count reached. Failed to add subport")
208
-                    raise ex
208
+                    raise
209 209
 
210
-            except n_exc.NeutronClientException as ex:
211
-                LOG.error("Error happened during subport "
212
-                          "addition to trunk, %s", trunk_id)
213
-                raise ex
210
+            except n_exc.NeutronClientException:
211
+                LOG.exception("Error happened during subport "
212
+                              "addition to trunk %s", trunk_id)
213
+                raise
214 214
             return vlan_id
215 215
 
216 216
     def _remove_subports(self, neutron, trunk_id, subports_id):
@@ -220,11 +220,10 @@ class NestedVlanPodVIFDriver(nested_vif.NestedPodVIFDriver):
220 220
         try:
221 221
             neutron.trunk_remove_subports(trunk_id,
222 222
                                           {'sub_ports': subports_body})
223
-        except n_exc.NeutronClientException as ex:
224
-            LOG.error(
225
-                "Error happened during subport removal from "
226
-                "trunk, %s", trunk_id)
227
-            raise ex
223
+        except n_exc.NeutronClientException:
224
+            LOG.exception("Error happened during subport removal from "
225
+                          "trunk %s", trunk_id)
226
+            raise
228 227
 
229 228
     def _remove_subport(self, neutron, trunk_id, subport_id):
230 229
         self._remove_subports(neutron, trunk_id, [subport_id])

+ 3
- 3
kuryr_kubernetes/controller/drivers/neutron_vif.py View File

@@ -51,9 +51,9 @@ class NeutronPodVIFDriver(base.PodVIFDriver):
51 51
         bulk_port_rq = {'ports': [rq for _ in range(num_ports)]}
52 52
         try:
53 53
             ports = neutron.create_port(bulk_port_rq).get('ports')
54
-        except n_exc.NeutronClientException as ex:
55
-            LOG.error("Error creating bulk ports: %s", bulk_port_rq)
56
-            raise ex
54
+        except n_exc.NeutronClientException:
55
+            LOG.exception("Error creating bulk ports: %s", bulk_port_rq)
56
+            raise
57 57
 
58 58
         vif_plugin = self._get_vif_plugin(ports[0])
59 59
 

+ 4
- 3
kuryr_kubernetes/controller/drivers/public_ip.py View File

@@ -133,9 +133,10 @@ class FipPubIpDriver(BasePubIpDriver):
133 133
 
134 134
         try:
135 135
             response = neutron.create_floatingip(request)
136
-        except n_exc.NeutronClientException as ex:
137
-            LOG.error("Failed to create floating IP - netid=%s ", pub_net_id)
138
-            raise ex
136
+        except n_exc.NeutronClientException:
137
+            LOG.exception("Failed to create floating IP - netid=%s ",
138
+                          pub_net_id)
139
+            raise
139 140
         return response['floatingip']['id'], response[
140 141
             'floatingip']['floating_ip_address']
141 142
 

+ 2
- 2
kuryr_kubernetes/controller/drivers/sriov.py View File

@@ -74,10 +74,10 @@ class SriovVIFDriver(neutron_vif.NeutronPodVIFDriver):
74 74
         """Returns an appropriate physnet for exact subnet_id from mapping"""
75 75
         try:
76 76
             physnet = self._physnet_mapping[subnet_id]
77
-        except KeyError as ex:
77
+        except KeyError:
78 78
             LOG.error("No mapping for subnet {} in {}".format(
79 79
                 subnet_id, self._physnet_mapping))
80
-            raise ex
80
+            raise
81 81
         return physnet
82 82
 
83 83
     def _get_remaining_sriov_vfs(self, pod):

+ 2
- 2
kuryr_kubernetes/controller/drivers/vif_pool.py View File

@@ -184,10 +184,10 @@ class BaseVIFPool(base.VIFPoolDriver):
184 184
 
185 185
         try:
186 186
             return self._get_port_from_pool(pool_key, pod, subnets)
187
-        except exceptions.ResourceNotReady as ex:
187
+        except exceptions.ResourceNotReady:
188 188
             LOG.warning("Ports pool does not have available ports!")
189 189
             eventlet.spawn(self._populate_pool, pool_key, pod, subnets)
190
-            raise ex
190
+            raise
191 191
 
192 192
     def _get_port_from_pool(self, pool_key, pod, subnets):
193 193
         raise NotImplementedError()

+ 14
- 14
kuryr_kubernetes/controller/managers/pool.py View File

@@ -157,22 +157,22 @@ class RequestHandler(BaseHTTPRequestHandler):
157 157
             project_id = drv_project.get_project({})
158 158
             security_groups = drv_sg.get_security_groups({}, project_id)
159 159
             subnets = drv_subnets.get_subnets([], project_id)
160
-        except TypeError as ex:
160
+        except TypeError:
161 161
             LOG.error("Invalid driver type")
162
-            raise ex
162
+            raise
163 163
 
164 164
         for trunk_ip in trunk_ips:
165 165
             try:
166 166
                 drv_vif_pool.force_populate_pool(
167 167
                     trunk_ip, project_id, subnets, security_groups, num_ports)
168
-            except n_exc.Conflict as ex:
168
+            except n_exc.Conflict:
169 169
                 LOG.error("VLAN Id conflict (already in use) at trunk %s",
170 170
                           trunk_ip)
171
-                raise ex
172
-            except n_exc.NeutronClientException as ex:
173
-                LOG.error("Error happened during subports addition at trunk: "
174
-                          " %s", trunk_ip)
175
-                raise ex
171
+                raise
172
+            except n_exc.NeutronClientException:
173
+                LOG.exception("Error happened during subports addition at "
174
+                              "trunk: %s", trunk_ip)
175
+                raise
176 176
 
177 177
     def _delete_subports(self, trunk_ips):
178 178
         try:
@@ -181,9 +181,9 @@ class RequestHandler(BaseHTTPRequestHandler):
181 181
             drv_vif_pool.set_vif_driver(drv_vif)
182 182
 
183 183
             drv_vif_pool.free_pool(trunk_ips)
184
-        except TypeError as ex:
184
+        except TypeError:
185 185
             LOG.error("Invalid driver type")
186
-            raise ex
186
+            raise
187 187
 
188 188
     def _list_pools(self):
189 189
         try:
@@ -192,9 +192,9 @@ class RequestHandler(BaseHTTPRequestHandler):
192 192
             drv_vif_pool.set_vif_driver(drv_vif)
193 193
 
194 194
             available_pools = drv_vif_pool.list_pools()
195
-        except TypeError as ex:
195
+        except TypeError:
196 196
             LOG.error("Invalid driver type")
197
-            raise ex
197
+            raise
198 198
 
199 199
         pools_info = ""
200 200
         for pool_key, pool_items in available_pools.items():
@@ -211,9 +211,9 @@ class RequestHandler(BaseHTTPRequestHandler):
211 211
             drv_vif_pool.set_vif_driver(drv_vif)
212 212
 
213 213
             pool = drv_vif_pool.show_pool(pool_key)
214
-        except TypeError as ex:
214
+        except TypeError:
215 215
             LOG.error("Invalid driver type")
216
-            raise ex
216
+            raise
217 217
 
218 218
         if pool:
219 219
             pool_info = ""

Loading…
Cancel
Save