Merge "NSX|V3 migration: Fix _fixup_res_dict for api_replay"
This commit is contained in:
commit
01fa17cddc
@ -25,12 +25,9 @@ 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()
|
||||
attr_info = lib_attrs.RESOURCES[attr_name]
|
||||
attr_ops = lib_attrs.AttributeInfo(attr_info)
|
||||
|
@ -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=(
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user