Browse Source

Merge "BCF-11054-Fix-Router-Create-External-Gateway"

Zuul 6 months ago
parent
commit
a6e7548753

+ 20
- 13
networking_bigswitch/plugins/bigswitch/l3_router_plugin.py View File

@@ -168,25 +168,14 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
168 168
         with db.context_manager.reader.using(context):
169 169
             mapped_router = self._map_tenant_name(router)
170 170
             mapped_router = self._map_state_and_status(mapped_router)
171
-            # populate external tenant_id if it is absent for external network,
172
-            # This is a new work flow in kilo that user can specify external
173
-            # network when creating a router
174
-            if (mapped_router and mapped_router.get('external_gateway_info')):
175
-                ext_gw_info = mapped_router.get('external_gateway_info')
176
-                ext_net_id = ext_gw_info.get('network_id')
177
-                ext_tenant_id = ext_gw_info.get("tenant_id")
178
-                if ext_net_id and (not ext_tenant_id):
179
-                    ext_net = self.get_network(context, ext_net_id)
180
-                    if ext_net:
181
-                        mapped_router['external_gateway_info']['tenant_id'] = (
182
-                            ext_net.get('tenant_id'))
183 171
 
172
+            # Does not handle external gateway and some other information
184 173
             self.servers.rest_create_router(mapped_router['tenant_id'],
185 174
                                             mapped_router)
186 175
 
187 176
     @log_helper.log_method_call
188 177
     def router_after_create_callback(self, resource, event, trigger, **kwargs):
189
-        """Create tenant policies for the given router
178
+        """Update external gateway and create tenant policies
190 179
 
191 180
         :param resource:
192 181
         :param event:
@@ -201,6 +190,24 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base,
201 190
         default_policy_dict = self._get_tenant_default_router_policy(tenant_id)
202 191
 
203 192
         with db.context_manager.writer.using(context):
193
+            mapped_router = self._map_tenant_name(router)
194
+            mapped_router = self._map_state_and_status(mapped_router)
195
+            # populate external tenant_id if it is absent for external network,
196
+            # This is a new work flow in kilo that user can specify external
197
+            # network when creating a router
198
+            if mapped_router and mapped_router.get('external_gateway_info'):
199
+                ext_gw_info = mapped_router.get('external_gateway_info')
200
+                ext_net_id = ext_gw_info.get('network_id')
201
+                ext_tenant_id = ext_gw_info.get("tenant_id")
202
+                if ext_net_id and (not ext_tenant_id):
203
+                    ext_net = self.get_network(context, ext_net_id)
204
+                    if ext_net:
205
+                        mapped_router['external_gateway_info']['tenant_id'] = (
206
+                            ext_net.get('tenant_id'))
207
+            # update router that was created in before_create callback
208
+            self.servers.rest_update_router(
209
+                mapped_router['tenant_id'], mapped_router, mapped_router['id'])
210
+
204 211
             # post router creation, create default policy if missing
205 212
             tenantpolicy_dict = super(L3RestProxy, self).create_default_policy(
206 213
                 context, tenant_id, default_policy_dict)

+ 2
- 2
networking_bigswitch/tests/unit/bigswitch/test_router_db.py View File

@@ -113,8 +113,8 @@ class RouterDBTestCase(RouterDBTestBase,
113 113
             router_req = self.new_create_request('routers', data, self.fmt)
114 114
             res = router_req.get_response(self.ext_api)
115 115
             router = self.deserialize(self.fmt, res)
116
-            self.assertEqual(
117
-                False,
116
+            # external tenant_id should be patched
117
+            self.assertTrue(
118 118
                 'tenant_id' in router['router']['external_gateway_info'])
119 119
 
120 120
     def test_router_add_interface_port(self):

Loading…
Cancel
Save