Consume neutron-lib Context class project_id change
Use the project_id keyword in all calls to the neutron-lib Context class. Requires a bump of neutron-lib to 3.17.0 which contains the dependent change. Change-Id: Ied15540f210bbd307acefe85bb4431b6972ea7d8
This commit is contained in:
@@ -420,7 +420,7 @@ class FieldCheck(policy.Check):
|
||||
{'field': self.field, 'target_dict': target_dict})
|
||||
return
|
||||
project_id = target_dict.get('project_id')
|
||||
ctx = (context.Context(tenant_id=project_id) if project_id
|
||||
ctx = (context.Context(project_id=project_id) if project_id
|
||||
else context.get_admin_context())
|
||||
plugin = directory.get_plugin()
|
||||
network = plugin.get_network(ctx, target_network_id)
|
||||
|
@@ -1338,7 +1338,7 @@ class TestPortsV2(NeutronDbPluginV2TestCase):
|
||||
def test_get_ports_count(self):
|
||||
with self.port(), self.port(), self.port(), self.port() as p:
|
||||
tenid = p['port']['tenant_id']
|
||||
ctx = context.Context(user_id=None, tenant_id=tenid,
|
||||
ctx = context.Context(user_id=None, project_id=tenid,
|
||||
is_admin=False)
|
||||
pl = directory.get_plugin()
|
||||
count = pl.get_ports_count(ctx, filters={'tenant_id': [tenid]})
|
||||
@@ -3369,7 +3369,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
def test_create_subnet_with_network_different_tenant(self):
|
||||
with self.network(shared=False, tenant_id='tenant1') as network:
|
||||
ctx = context.Context(user_id='non_admin',
|
||||
tenant_id='tenant2',
|
||||
project_id='tenant2',
|
||||
is_admin=False)
|
||||
data = {'subnet': {'network_id': network['network']['id'],
|
||||
'cidr': '10.0.2.0/24',
|
||||
@@ -5364,7 +5364,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
gateway_ip='10.0.2.1',
|
||||
cidr='10.0.2.0/24'):
|
||||
project_id = network['network']['project_id']
|
||||
ctx = context.Context(user_id=None, tenant_id=project_id,
|
||||
ctx = context.Context(user_id=None, project_id=project_id,
|
||||
is_admin=False)
|
||||
pl = directory.get_plugin()
|
||||
count = pl.get_subnets_count(
|
||||
@@ -5385,7 +5385,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
self.subnet(network=network,
|
||||
gateway_ip='10.0.2.1',
|
||||
cidr='10.0.2.0/24'):
|
||||
ctx = context.Context(user_id=None, tenant_id=project_id,
|
||||
ctx = context.Context(user_id=None, project_id=project_id,
|
||||
is_admin=True)
|
||||
pl = directory.get_plugin()
|
||||
count = pl.get_subnets_count(
|
||||
@@ -5409,7 +5409,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
||||
gateway_ip='10.0.2.1',
|
||||
cidr='10.0.2.0/24'):
|
||||
project_id = network['network']['project_id']
|
||||
ctx = context.Context(user_id=None, tenant_id=project_id,
|
||||
ctx = context.Context(user_id=None, project_id=project_id,
|
||||
is_admin=False)
|
||||
pl = directory.get_plugin()
|
||||
count = pl.get_subnets_count(ctx,
|
||||
|
@@ -39,7 +39,7 @@ class TestIsSessionActive(testlib_api.SqlTestCase,
|
||||
super().setUp()
|
||||
|
||||
def test_is_session_active(self):
|
||||
context = n_context.Context(user_id=None, tenant_id=None,
|
||||
context = n_context.Context(user_id=None, project_id=None,
|
||||
is_admin=True, overwrite=False)
|
||||
self.assertFalse(db_api.is_session_active(context.session))
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
|
@@ -44,7 +44,7 @@ class IpamTestCase(testlib_api.SqlTestCase, testlib_api.MySQLTestCaseMixin):
|
||||
self.setup_coreplugin(DB_PLUGIN_KLASS)
|
||||
self.plugin = base_plugin.NeutronDbPluginV2()
|
||||
self.cxt = context.Context(user_id=None,
|
||||
tenant_id=None,
|
||||
project_id=None,
|
||||
is_admin=True,
|
||||
overwrite=False)
|
||||
self.tenant_id = uuidutils.generate_uuid()
|
||||
|
@@ -41,7 +41,7 @@ class NetworkRBACTestCase(testlib_api.SqlTestCase):
|
||||
l3_dvrscheduler_db, '_notify_l3_agent_new_port').start()
|
||||
self.plugin_l3 = l3_router_plugin.L3RouterPlugin()
|
||||
self.ctx = context.Context(user_id=None,
|
||||
tenant_id=None,
|
||||
project_id=None,
|
||||
is_admin=True,
|
||||
overwrite=False)
|
||||
self.project_1 = uuidutils.generate_uuid()
|
||||
@@ -140,11 +140,11 @@ class NetworkRBACTestCase(testlib_api.SqlTestCase):
|
||||
action=constants.ACCESS_SHARED)
|
||||
|
||||
ctx_1 = context.Context(user_id=None,
|
||||
tenant_id=self.project_1,
|
||||
project_id=self.project_1,
|
||||
is_admin=False,
|
||||
overwrite=False)
|
||||
ctx_2 = context.Context(user_id=None,
|
||||
tenant_id=self.project_2,
|
||||
project_id=self.project_2,
|
||||
is_admin=False,
|
||||
overwrite=False)
|
||||
|
||||
|
@@ -32,7 +32,7 @@ class SegmentAllocation(testlib_api.SqlTestCase,
|
||||
self.skipTest('No allocation class defined')
|
||||
super().setUp()
|
||||
self.context = context.Context(user_id='usier_id',
|
||||
tenant_id='tenant_id')
|
||||
project_id='tenant_id')
|
||||
self.segid_field = (
|
||||
self.segment_allocation_class.get_segmentation_id().name)
|
||||
self.is_vlan = ('physical_network' in
|
||||
|
@@ -28,7 +28,7 @@ class TestReservationSql(testlib_api.SqlTestCase,
|
||||
testlib_api.MySQLTestCaseMixin):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.context = context.Context(user_id=None, tenant_id=None,
|
||||
self.context = context.Context(user_id=None, project_id=None,
|
||||
is_admin=True, overwrite=False)
|
||||
|
||||
def _create_test_reservation(self, exp):
|
||||
|
@@ -126,20 +126,20 @@ class TestDbQuotaDriver(testlib_api.SqlTestCase,
|
||||
|
||||
def test_get_default_quotas(self):
|
||||
defaults = {RESOURCE: TestResource(RESOURCE, 4)}
|
||||
user_ctx = context.Context(user_id=PROJECT, tenant_id=PROJECT)
|
||||
user_ctx = context.Context(user_id=PROJECT, project_id=PROJECT)
|
||||
self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2)
|
||||
quotas = self.plugin.get_default_quotas(user_ctx, defaults, PROJECT)
|
||||
self.assertEqual(4, quotas[RESOURCE])
|
||||
|
||||
def test_get_project_quotas(self):
|
||||
user_ctx = context.Context(user_id=PROJECT, tenant_id=PROJECT)
|
||||
user_ctx = context.Context(user_id=PROJECT, project_id=PROJECT)
|
||||
self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2)
|
||||
quotas = self.plugin.get_project_quotas(user_ctx, {}, PROJECT)
|
||||
self.assertEqual(2, quotas[RESOURCE])
|
||||
|
||||
def test_get_project_quotas_different_project(self):
|
||||
user_ctx = context.Context(user_id=PROJECT,
|
||||
tenant_id='another_project')
|
||||
project_id='another_project')
|
||||
self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 2)
|
||||
# It is appropriate to use assertFalse here as the expected return
|
||||
# value is an empty dict (the defaults passed in the statement below
|
||||
|
@@ -78,7 +78,7 @@ class TestDbQuotaDriverNoLock(test_driver.TestDbQuotaDriver):
|
||||
|
||||
def test_get_detailed_project_quotas_resource(self):
|
||||
user_ctx = context.Context(user_id=self.project_1,
|
||||
tenant_id=self.project_1)
|
||||
project_id=self.project_1)
|
||||
tracked_resource = quota_resource.TrackedResource(
|
||||
'network', models_v2.Network, 'quota_network')
|
||||
res = {'network': tracked_resource}
|
||||
@@ -108,7 +108,7 @@ class TestDbQuotaDriverNoLock(test_driver.TestDbQuotaDriver):
|
||||
resources = self._create_tracked_resources()
|
||||
for project_id in self.projects:
|
||||
user_ctx = context.Context(user_id=project_id,
|
||||
tenant_id=project_id)
|
||||
project_id=project_id)
|
||||
self.plugin.update_quota_limit(
|
||||
user_ctx, project_id, 'network', 101)
|
||||
self.plugin.update_quota_limit(user_ctx, project_id, 'subnet', 102)
|
||||
@@ -134,7 +134,7 @@ class TestDbQuotaDriverNoLock(test_driver.TestDbQuotaDriver):
|
||||
'port': {'limit': 103, 'used': 1, 'reserved': 0}}
|
||||
for project_id in self.projects:
|
||||
user_ctx = context.Context(user_id=project_id,
|
||||
tenant_id=project_id)
|
||||
project_id=project_id)
|
||||
returned = self.plugin.get_detailed_project_quotas(
|
||||
user_ctx, resources, project_id)
|
||||
self.assertEqual(reference, returned)
|
||||
|
@@ -564,10 +564,10 @@ class SecurityGroupDbMixinTestCase(testlib_api.SqlTestCase):
|
||||
|
||||
def _create_environment(self):
|
||||
self.sg = copy.deepcopy(FAKE_SECGROUP)
|
||||
self.user_ctx = context.Context(user_id='user1', tenant_id='tenant_1',
|
||||
is_admin=False, overwrite=False)
|
||||
self.admin_ctx = context.Context(user_id='user2', tenant_id='tenant_2',
|
||||
is_admin=True, overwrite=False)
|
||||
self.user_ctx = context.Context(user_id='user1',
|
||||
project_id='tenant_1', is_admin=False, overwrite=False)
|
||||
self.admin_ctx = context.Context(user_id='user2',
|
||||
project_id='tenant_2', is_admin=True, overwrite=False)
|
||||
self.sg_user = self.mixin.create_security_group(
|
||||
self.user_ctx, {'security_group': {'name': 'name',
|
||||
'tenant_id': 'tenant_1',
|
||||
|
@@ -64,7 +64,7 @@ class TestRBACObjectMixin:
|
||||
|
||||
for idx in range(3):
|
||||
project = 'project_%s' % idx
|
||||
ctx_no_admin = context.Context(user_id='user', tenant_id=project,
|
||||
ctx_no_admin = context.Context(user_id='user', project_id=project,
|
||||
is_admin=False)
|
||||
objects = self._parent_class.get_objects(ctx_no_admin)
|
||||
self.assertEqual([_obj_shared.id], [_obj.id for _obj in objects])
|
||||
|
@@ -15,7 +15,7 @@ requests>=2.32.3 # Apache-2.0
|
||||
Jinja2>=2.10 # BSD License (3 clause)
|
||||
keystonemiddleware>=5.1.0 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
neutron-lib>=3.16.0 # Apache-2.0
|
||||
neutron-lib>=3.17.0 # Apache-2.0
|
||||
python-neutronclient>=7.8.0 # Apache-2.0
|
||||
tenacity>=6.0.0 # Apache-2.0
|
||||
SQLAlchemy>=1.4.23 # MIT
|
||||
|
Reference in New Issue
Block a user