diff --git a/vmware_nsx/api_replay/utils.py b/vmware_nsx/api_replay/utils.py index 723e24c5a7..8917213b07 100644 --- a/vmware_nsx/api_replay/utils.py +++ b/vmware_nsx/api_replay/utils.py @@ -25,13 +25,10 @@ LOG = logging.getLogger(__name__) def _fixup_res_dict(context, attr_name, res_dict, check_allow_post=True): # This method is a replacement of _fixup_res_dict which is used in - # neutron.plugin.common.utils. All this mock does is insert a uuid + # neutron_lib.plugin.utils. All this mock does is insert a uuid # for the id field if one is not found ONLY if running in api_replay_mode. if cfg.CONF.api_replay_mode and 'id' not in res_dict: - # exclude gateway ports from this - if (attr_name != 'ports' or - res_dict.get('device_owner') != 'network:router_gateway'): - res_dict['id'] = uuidutils.generate_uuid() + res_dict['id'] = uuidutils.generate_uuid() attr_info = lib_attrs.RESOURCES[attr_name] attr_ops = lib_attrs.AttributeInfo(attr_info) try: diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 1ae85a091d..f9bd635957 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -2386,7 +2386,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, def _update_router_wrapper(self, context, router_id, router): if cfg.CONF.api_replay_mode: # NOTE(arosen): the mock.patch here is needed for api_replay_mode - with mock.patch("neutron.plugins.common.utils._fixup_res_dict", + with mock.patch("neutron_lib.plugins.utils._fixup_res_dict", side_effect=api_replay_utils._fixup_res_dict): return super(NsxV3Plugin, self).update_router( context, router_id, router) @@ -2674,7 +2674,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, interface_info): if cfg.CONF.api_replay_mode: # NOTE(arosen): the mock.patch here is needed for api_replay_mode - with mock.patch("neutron.plugins.common.utils._fixup_res_dict", + with mock.patch("neutron_lib.plugins.utils._fixup_res_dict", side_effect=api_replay_utils._fixup_res_dict): return super(NsxV3Plugin, self).add_router_interface( context, router_id, interface_info) @@ -2922,7 +2922,7 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base, def _create_floating_ip_wrapper(self, context, floatingip): if cfg.CONF.api_replay_mode: # NOTE(arosen): the mock.patch here is needed for api_replay_mode - with mock.patch("neutron.plugins.common.utils._fixup_res_dict", + with mock.patch("neutron_lib.plugins.utils._fixup_res_dict", side_effect=api_replay_utils._fixup_res_dict): return super(NsxV3Plugin, self).create_floatingip( context, floatingip, initial_status=( diff --git a/vmware_nsx/tests/unit/nsx_v3/test_api_replay.py b/vmware_nsx/tests/unit/nsx_v3/test_api_replay.py index 157624e0c8..4c372b4067 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_api_replay.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_api_replay.py @@ -21,7 +21,7 @@ from neutron_lib.plugins import directory from oslo_config import cfg -class TestApiReplay(test_plugin.NsxV3PluginTestCaseMixin): +class TestApiReplay(test_plugin.L3NatTest): def setUp(self, plugin=None, ext_mgr=None, service_plugins=None): # enables api_replay_mode for these tests @@ -61,3 +61,34 @@ class TestApiReplay(test_plugin.NsxV3PluginTestCaseMixin): id=specified_port_id) port = self.deserialize(self.fmt, port_res) self.assertEqual(specified_port_id, port['port']['id']) + + def _create_router(self, fmt, tenant_id, name=None, + admin_state_up=None, + arg_list=None, **kwargs): + data = {'router': {'tenant_id': tenant_id}} + if name: + data['router']['name'] = name + if admin_state_up: + data['router']['admin_state_up'] = admin_state_up + for arg in (('admin_state_up', 'tenant_id') + (arg_list or ())): + # Arg must be present and not empty + if kwargs.get(arg): + data['router'][arg] = kwargs[arg] + router_req = self.new_create_request('routers', data, fmt) + return router_req.get_response(self.ext_api) + + def test_create_update_router(self): + specified_router_id = '555e762b-d7a1-4b44-b09b-2a34ada56c9f' + router_res = self._create_router(self.fmt, + 'test-tenant', + 'test-rtr', + arg_list=('id',), + id=specified_router_id) + router = self.deserialize(self.fmt, router_res) + self.assertEqual(specified_router_id, router['router']['id']) + + # This part tests _fixup_res_dict as well + body = self._update('routers', specified_router_id, + {'router': {'name': 'new_name'}}) + body = self._show('routers', specified_router_id) + self.assertEqual(body['router']['name'], 'new_name')