fix unittest issues caused by neutron rbac changes

neutron recently merged a commit enabling secure rbacs by default [1].
However this commit breaks the unittests of neutron-dynamic-routing.
To fix this we run multiple calls as admin, to allow them to succeed.

[1]: 670cc383e0

Closes-Bug: 2019097
Change-Id: Iadc9b819ce4aaf6029e77f53ce0616aa70119c70
This commit is contained in:
Felix Huettner 2023-05-10 12:14:20 +02:00
parent dd16db1bdf
commit bf54f03ce5
3 changed files with 24 additions and 17 deletions

View File

@ -105,7 +105,8 @@ class BgpEntityCreationMixin(object):
with self.network(name=name, **kwargs) as gw_network: with self.network(name=name, **kwargs) as gw_network:
if external: if external:
self._update('networks', gw_network['network']['id'], self._update('networks', gw_network['network']['id'],
{'network': {external_net.EXTERNAL: True}}) {'network': {external_net.EXTERNAL: True}},
as_admin=True)
yield gw_network yield gw_network
@contextlib.contextmanager @contextlib.contextmanager
@ -152,11 +153,13 @@ class BgpEntityCreationMixin(object):
with self.subnet(ext_net, with self.subnet(ext_net,
cidr=gw_prefix, cidr=gw_prefix,
subnetpool_id=ext_subnetpool_id, subnetpool_id=ext_subnetpool_id,
ip_version=gw_ip_net.version),\ ip_version=gw_ip_net.version,
as_admin=True),\
self.subnet(int_net, self.subnet(int_net,
cidr=tenant_prefix, cidr=tenant_prefix,
subnetpool_id=int_subnetpool_id, subnetpool_id=int_subnetpool_id,
ip_version=tenant_ip_net.version) as int_subnet: ip_version=tenant_ip_net.version,
as_admin=True) as int_subnet:
ext_gw_info = {'network_id': gw_net_id} ext_gw_info = {'network_id': gw_net_id}
with self.router(external_gateway_info=ext_gw_info, with self.router(external_gateway_info=ext_gw_info,
distributed=distributed, distributed=distributed,
@ -421,7 +424,7 @@ class BgpTests(BgpEntityCreationMixin):
with self.subnetpool_with_address_scope(4, with self.subnetpool_with_address_scope(4,
prefixes=['8.0.0.0/8']) as sp,\ prefixes=['8.0.0.0/8']) as sp,\
self.gw_network(name='test-net', tenant_id=_uuid(), self.gw_network(name='test-net', tenant_id=_uuid(),
shared=True) as network: shared=True, as_admin=True) as network:
network_id = network['network']['id'] network_id = network['network']['id']
with self.bgp_speaker(sp['ip_version'], 1234, with self.bgp_speaker(sp['ip_version'], 1234,
networks=[network_id]) as speaker: networks=[network_id]) as speaker:
@ -651,11 +654,13 @@ class BgpTests(BgpEntityCreationMixin):
with self.subnet(network=net1, with self.subnet(network=net1,
cidr=None, cidr=None,
subnetpool_id=subnetpool_id, subnetpool_id=subnetpool_id,
ip_version=6) as ext_subnet,\ ip_version=6,
as_admin=True) as ext_subnet,\
self.subnet(network=net2, self.subnet(network=net2,
cidr=None, cidr=None,
subnetpool_id=subnetpool_id, subnetpool_id=subnetpool_id,
ip_version=6) as int_subnet,\ ip_version=6,
as_admin=True) as int_subnet,\
self.router() as router: self.router() as router:
router_id = router['id'] router_id = router['id']
@ -727,11 +732,13 @@ class BgpTests(BgpEntityCreationMixin):
with self.subnet(cidr=None, with self.subnet(cidr=None,
subnetpool_id=ext_pool_id, subnetpool_id=ext_pool_id,
network=ext_net, network=ext_net,
ip_version=6) as ext_subnet,\ ip_version=6,
as_admin=True) as ext_subnet,\
self.subnet(cidr=None, self.subnet(cidr=None,
subnetpool_id=int_pool_id, subnetpool_id=int_pool_id,
network=int_net, network=int_net,
ip_version=6) as int_subnet,\ ip_version=6,
as_admin=True) as int_subnet,\
self.router() as router: self.router() as router:
router_id = router['id'] router_id = router['id']
int_subnet_id = int_subnet['subnet']['id'] int_subnet_id = int_subnet['subnet']['id']

View File

@ -65,7 +65,7 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
with self.bgp_speaker(4, 1234) as ri: with self.bgp_speaker(4, 1234) as ri:
bgp_speaker_id = ri['id'] bgp_speaker_id = ri['id']
helpers.register_bgp_dragent(host='host1') helpers.register_bgp_dragent(host='host1')
agent = self._list('agents')['agents'][0] agent = self._list('agents', as_admin=True)['agents'][0]
agent_id = agent['id'] agent_id = agent['id']
data = {'bgp_speaker_id': bgp_speaker_id} data = {'bgp_speaker_id': bgp_speaker_id}
@ -75,7 +75,7 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
self.assertEqual(exc.HTTPCreated.code, res.status_int) self.assertEqual(exc.HTTPCreated.code, res.status_int)
req_show = self.new_show_request('agents', agent_id, self.fmt, req_show = self.new_show_request('agents', agent_id, self.fmt,
'bgp-drinstances') 'bgp-drinstances', as_admin=True)
res = req_show.get_response(self.ext_api) res = req_show.get_response(self.ext_api)
self.assertEqual(exc.HTTPOk.code, res.status_int) self.assertEqual(exc.HTTPOk.code, res.status_int)
res = self.deserialize(self.fmt, res) res = self.deserialize(self.fmt, res)
@ -102,7 +102,7 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
with self.bgp_speaker(4, 1234) as ri: with self.bgp_speaker(4, 1234) as ri:
bgp_speaker_id = ri['id'] bgp_speaker_id = ri['id']
self._register_l3_agent(host='host1') # Register wrong agent self._register_l3_agent(host='host1') # Register wrong agent
agent = self._list('agents')['agents'][0] agent = self._list('agents', as_admin=True)['agents'][0]
data = {'bgp_speaker_id': bgp_speaker_id} data = {'bgp_speaker_id': bgp_speaker_id}
req = self.new_create_request( req = self.new_create_request(
'agents', data, self.fmt, 'agents', data, self.fmt,
@ -117,7 +117,7 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
with self.bgp_speaker(4, 1234) as ri: with self.bgp_speaker(4, 1234) as ri:
bgp_speaker_id = ri['id'] bgp_speaker_id = ri['id']
helpers.register_bgp_dragent(host='host1') helpers.register_bgp_dragent(host='host1')
agent = self._list('agents')['agents'][0] agent = self._list('agents', as_admin=True)['agents'][0]
data = {'bgp_speaker_id': bgp_speaker_id} data = {'bgp_speaker_id': bgp_speaker_id}
req = self.new_create_request( req = self.new_create_request(
'agents', data, self.fmt, 'agents', data, self.fmt,
@ -137,14 +137,14 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
helpers.register_bgp_dragent(host='host2') helpers.register_bgp_dragent(host='host2')
data = {'bgp_speaker_id': bgp_speaker_id} data = {'bgp_speaker_id': bgp_speaker_id}
agent1 = self._list('agents')['agents'][0] agent1 = self._list('agents', as_admin=True)['agents'][0]
req = self.new_create_request( req = self.new_create_request(
'agents', data, self.fmt, 'agents', data, self.fmt,
agent1['id'], 'bgp-drinstances') agent1['id'], 'bgp-drinstances')
res = req.get_response(self.ext_api) res = req.get_response(self.ext_api)
self.assertEqual(exc.HTTPCreated.code, res.status_int) self.assertEqual(exc.HTTPCreated.code, res.status_int)
agent2 = self._list('agents')['agents'][1] agent2 = self._list('agents', as_admin=True)['agents'][1]
req = self.new_create_request( req = self.new_create_request(
'agents', data, self.fmt, 'agents', data, self.fmt,
agent2['id'], 'bgp-drinstances') agent2['id'], 'bgp-drinstances')
@ -156,7 +156,7 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
with self.bgp_speaker(4, 1) as ri1, self.bgp_speaker(4, 2) as ri2: with self.bgp_speaker(4, 1) as ri1, self.bgp_speaker(4, 2) as ri2:
helpers.register_bgp_dragent(host='host1') helpers.register_bgp_dragent(host='host1')
agent = self._list('agents')['agents'][0] agent = self._list('agents', as_admin=True)['agents'][0]
data = {'bgp_speaker_id': ri1['id']} data = {'bgp_speaker_id': ri1['id']}
req = self.new_create_request( req = self.new_create_request(
'agents', data, self.fmt, 'agents', data, self.fmt,
@ -175,7 +175,7 @@ class BgpDrSchedulingTestCase(test_agent.AgentDBTestMixIn,
"""Test exception while removing an invalid binding.""" """Test exception while removing an invalid binding."""
with self.bgp_speaker(4, 1234) as ri1: with self.bgp_speaker(4, 1234) as ri1:
helpers.register_bgp_dragent(host='host1') helpers.register_bgp_dragent(host='host1')
agent = self._list('agents')['agents'][0] agent = self._list('agents', as_admin=True)['agents'][0]
agent_id = agent['id'] agent_id = agent['id']
self.assertRaises(bgp_dras_ext.DrAgentNotHostingBgpSpeaker, self.assertRaises(bgp_dras_ext.DrAgentNotHostingBgpSpeaker,
self.bgp_plugin.remove_bgp_speaker_from_dragent, self.bgp_plugin.remove_bgp_speaker_from_dragent,

View File

@ -21,7 +21,7 @@ oslo.messaging>=5.29.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.service!=1.28.1,>=1.24.0 # Apache-2.0 oslo.service!=1.28.1,>=1.24.0 # Apache-2.0
oslo.utils>=4.5.0 # Apache-2.0 oslo.utils>=4.5.0 # Apache-2.0
neutron>=14.0.0.0b1 # Apache-2.0 neutron>=23.0.0.0b2 # Apache-2.0
# The comment below indicates this project repo is current with neutron-lib # The comment below indicates this project repo is current with neutron-lib
# and should receive neutron-lib consumption patches as they are released # and should receive neutron-lib consumption patches as they are released