Change agent and Ipam code to use project_id

Changed all agent code to use project_id, removing some
leftover code from previous cycles.

Changed Ipam code to use project instead of tenant where
possible.

Changed auto-allocate DB code to use project instead of
tenant where possible.

Blueprint: https://blueprints.launchpad.net/neutron/+spec/keystone-v3

Signed-off-by: Brian Haley <haleyb.dev@gmail.com>
Change-Id: Id5fbb4aa96e6ae2653107ded8d83334c65695419
This commit is contained in:
Brian Haley committed 2026-01-09 17:29:34 -05:00
1 parent 644d2b767d
commit d2120f3dbe
18 files changed
+127 -138

No files matched your search

-8
View File
@@ -170,14 +170,6 @@ class NetModel(DictModel):
def namespace(self):
return self._ns_name
# TODO(ralonsoh): remove in Z+.
@property
def project_id(self):
try:
return self['project_id']
except KeyError:
return self['tenant_id']
class DhcpBase(metaclass=abc.ABCMeta):
+1 -1
View File
@@ -138,7 +138,7 @@ class MetadataProxyHandler(
"ports": ports})
num_ports = len(ports)
if num_ports == 1:
return ports[0]['device_id'], ports[0]['tenant_id']
return ports[0]['device_id'], ports[0]['project_id']
if num_ports == 0:
LOG.warning("No port found in network %s with IP address %s",
network_id, remote_address)
-3
View File
@@ -238,11 +238,8 @@ class DhcpRpcCallback:
# NOTE(kevinbenton): we sort these because the agent builds tags
# based on position in the list and has to restart the process if
# the order changes.
# TODO(ralonsoh): in Z+, remove "tenant_id" parameter. DHCP agents
# should read only "project_id".
ret = {'id': network.id,
'project_id': network.project_id,
'tenant_id': network.project_id,
'admin_state_up': network.admin_state_up,
'subnets': sorted(subnets, key=operator.itemgetter('id')),
'non_local_subnets': sorted(nonlocal_subnets,
+2 -2
View File
@@ -145,7 +145,7 @@ class AgentAvailabilityZoneMixin(az_ext.AvailabilityZonePluginBase):
# it is not visible via API.
return [{'state': v,
'name': k[0], 'resource': k[1],
'tenant_id': context.tenant_id}
'tenant_id': context.project_id}
for k, v in self._list_availability_zones(
context, filters).items()
if not filter_states or v in filter_states]
@@ -153,7 +153,7 @@ class AgentAvailabilityZoneMixin(az_ext.AvailabilityZonePluginBase):
# visible via API.
return [{'state': v,
'name': k[0], 'resource': k[1],
'tenant_id': context.tenant_id}
'tenant_id': context.project_id}
for k, v in self._list_availability_zones(
context, filters).items()]
+3 -3
View File
@@ -342,8 +342,8 @@ class DbBasePluginCommon:
def _is_network_shared(self, context, rbac_entries):
# The shared attribute for a network now reflects if the network
# is shared to the calling tenant via an RBAC entry.
matches = ('*',) + ((context.tenant_id,) if context else ())
# is shared to the calling project via an RBAC entry.
matches = ('*',) + ((context.project_id,) if context else ())
for entry in rbac_entries:
if (entry.action == rbac_db_models.ACCESS_SHARED and
entry.target_project in matches):
@@ -351,7 +351,7 @@ class DbBasePluginCommon:
return False
def _make_subnet_args(self, detail, subnet, subnetpool_id):
args = {'project_id': detail.tenant_id,
args = {'project_id': detail.project_id,
'id': detail.subnet_id,
'name': subnet['name'],
'network_id': subnet['network_id'],
+2 -2
View File
@@ -195,13 +195,13 @@ def remove_reservation(context, reservation_id, set_dirty=False):
if not reservation:
# TODO(salv-orlando): Raise here and then handle the exception?
return
tenant_id = reservation.project_id
project_id = reservation.project_id
resources = [delta.resource for delta in reservation.resource_deltas]
reservation.delete()
if set_dirty:
# quota_usage for all resource involved in this reservation must
# be marked as dirty
set_resources_quota_usage_dirty(context, resources, tenant_id)
set_resources_quota_usage_dirty(context, resources, project_id)
return 1
@@ -82,7 +82,7 @@ class NeutronDbSubnet(ipam_base.Subnet):
cidr=subnet_request.subnet_cidr,
allocation_pools=pools,
gateway_ip=subnet_request.gateway_ip,
tenant_id=subnet_request.tenant_id,
project_id=subnet_request.project_id,
subnet_id=subnet_request.subnet_id)
@classmethod
@@ -108,7 +108,7 @@ class NeutronDbSubnet(ipam_base.Subnet):
cidr=neutron_subnet_obj.cidr,
allocation_pools=pools,
gateway_ip=neutron_subnet_obj.gateway_ip,
tenant_id=neutron_subnet_obj.tenant_id,
project_id=neutron_subnet_obj.project_id,
subnet_id=neutron_subnet_id)
@classmethod
@@ -117,7 +117,7 @@ class NeutronDbSubnet(ipam_base.Subnet):
return plugin._get_subnet_object(context, id)
def __init__(self, internal_id, ctx, cidr=None,
allocation_pools=None, gateway_ip=None, tenant_id=None,
allocation_pools=None, gateway_ip=None, project_id=None,
subnet_id=None):
# NOTE: In theory it could have been possible to grant the IPAM
# driver direct access to the database. While this is possible,
@@ -128,7 +128,7 @@ class NeutronDbSubnet(ipam_base.Subnet):
self._cidr = cidr
self._pools = allocation_pools
self._gateway_ip = gateway_ip
self._tenant_id = tenant_id
self._project_id = project_id
self._subnet_id = subnet_id
self.subnet_manager = ipam_db_api.IpamSubnetManager(internal_id,
self._subnet_id)
@@ -305,7 +305,7 @@ class NeutronDbSubnet(ipam_base.Subnet):
def get_details(self):
"""Return subnet data as a SpecificSubnetRequest"""
return ipam_req.SpecificSubnetRequest(
self._tenant_id, self.subnet_manager.neutron_id,
self._project_id, self.subnet_manager.neutron_id,
self._cidr, self._gateway_ip, self._pools)
+10 -10
View File
@@ -35,13 +35,13 @@ class SubnetRequest(metaclass=abc.ABCMeta):
that is common to any type of request. This class shouldn't be
instantiated on its own. Rather, a subclass of this class should be used.
"""
def __init__(self, tenant_id, subnet_id,
def __init__(self, project_id, subnet_id,
gateway_ip=None, allocation_pools=None,
set_gateway_ip=True):
"""Initialize and validate
:param tenant_id: The tenant id who will own the subnet
:type tenant_id: str uuid
:param project_id: The project id who will own the subnet
:type project_id: str uuid
:param subnet_id: Neutron's subnet ID
:type subnet_id: str uuid
:param gateway_ip: An IP to reserve for the subnet gateway.
@@ -57,7 +57,7 @@ class SubnetRequest(metaclass=abc.ABCMeta):
be assigned.
:type set_gateway_ip: boolean
"""
self._tenant_id = tenant_id
self._project_id = project_id
self._subnet_id = subnet_id
self._gateway_ip = None
self._set_gateway_ip = set_gateway_ip
@@ -93,8 +93,8 @@ class SubnetRequest(metaclass=abc.ABCMeta):
"allocation pool version"))
@property
def tenant_id(self):
return self._tenant_id
def project_id(self):
return self._project_id
@property
def subnet_id(self):
@@ -154,7 +154,7 @@ class AnySubnetRequest(SubnetRequest):
WILDCARDS = {constants.IPv4: '0.0.0.0',
constants.IPv6: '::'}
def __init__(self, tenant_id, subnet_id, version, prefixlen,
def __init__(self, project_id, subnet_id, version, prefixlen,
gateway_ip=None, allocation_pools=None,
set_gateway_ip=True):
"""Initialize AnySubnetRequest
@@ -165,7 +165,7 @@ class AnySubnetRequest(SubnetRequest):
:type prefixlen: int
"""
super().__init__(
tenant_id=tenant_id,
project_id=project_id,
subnet_id=subnet_id,
gateway_ip=gateway_ip,
allocation_pools=allocation_pools,
@@ -189,7 +189,7 @@ class SpecificSubnetRequest(SubnetRequest):
allocation, even overlapping ones. This can be expanded on by future
blueprints.
"""
def __init__(self, tenant_id, subnet_id, subnet_cidr,
def __init__(self, project_id, subnet_id, subnet_cidr,
gateway_ip=None, allocation_pools=None,
set_gateway_ip=True):
"""Initialize SpecificSubnetRequest
@@ -200,7 +200,7 @@ class SpecificSubnetRequest(SubnetRequest):
:type subnet: netaddr.IPNetwork or convertible to one
"""
super().__init__(
tenant_id=tenant_id,
project_id=project_id,
subnet_id=subnet_id,
gateway_ip=gateway_ip,
allocation_pools=allocation_pools,
+11 -11
View File
@@ -92,13 +92,13 @@ class SubnetAllocator(driver.Pool):
def _num_quota_units_in_prefixlen(self, prefixlen, quota_unit):
return math.pow(2, quota_unit - prefixlen)
def _allocations_used_by_tenant(self, quota_unit):
def _allocations_used_by_project(self, quota_unit):
subnetpool_id = self._subnetpool['id']
tenant_id = self._subnetpool['tenant_id']
project_id = self._subnetpool['project_id']
with db_api.CONTEXT_READER.using(self._context):
qry = self._context.session.query(models_v2.Subnet.cidr)
allocations = qry.filter_by(subnetpool_id=subnetpool_id,
tenant_id=tenant_id)
project_id=project_id)
value = 0
for allocation in allocations:
prefixlen = netaddr.IPNetwork(allocation.cidr).prefixlen
@@ -106,13 +106,13 @@ class SubnetAllocator(driver.Pool):
quota_unit)
return value
def _check_subnetpool_tenant_quota(self, tenant_id, prefixlen):
def _check_subnetpool_project_quota(self, project_id, prefixlen):
quota_unit = self._sp_helper.ip_version_subnetpool_quota_unit(
self._subnetpool['ip_version'])
quota = self._subnetpool.get('default_quota')
if quota:
used = self._allocations_used_by_tenant(quota_unit)
used = self._allocations_used_by_project(quota_unit)
requested_units = self._num_quota_units_in_prefixlen(prefixlen,
quota_unit)
@@ -122,7 +122,7 @@ class SubnetAllocator(driver.Pool):
def _allocate_any_subnet(self, request):
with db_api.CONTEXT_WRITER.using(self._context):
self._lock_subnetpool()
self._check_subnetpool_tenant_quota(request.tenant_id,
self._check_subnetpool_project_quota(request.project_id,
request.prefixlen)
prefix_pool = self._get_available_prefix_list()
for prefix in prefix_pool:
@@ -134,7 +134,7 @@ class SubnetAllocator(driver.Pool):
pools = ipam_utils.generate_pools(subnet.cidr,
gateway_ip)
return IpamSubnet(request.tenant_id,
return IpamSubnet(request.project_id,
request.subnet_id,
subnet.cidr,
gateway_ip=gateway_ip,
@@ -148,13 +148,13 @@ class SubnetAllocator(driver.Pool):
def _allocate_specific_subnet(self, request):
with db_api.CONTEXT_WRITER.using(self._context):
self._lock_subnetpool()
self._check_subnetpool_tenant_quota(request.tenant_id,
self._check_subnetpool_project_quota(request.project_id,
request.prefixlen)
cidr = request.subnet_cidr
available = self._get_available_prefix_list()
matched = netaddr.all_matching_cidrs(cidr, available)
if len(matched) == 1 and matched[0].prefixlen <= cidr.prefixlen:
return IpamSubnet(request.tenant_id,
return IpamSubnet(request.project_id,
request.subnet_id,
cidr,
gateway_ip=request.gateway_ip,
@@ -200,7 +200,7 @@ class SubnetAllocator(driver.Pool):
class IpamSubnet(driver.Subnet):
def __init__(self,
tenant_id,
project_id,
subnet_id,
cidr,
gateway_ip=None,
@@ -208,7 +208,7 @@ class IpamSubnet(driver.Subnet):
set_gateway_ip=True,
):
self._req = ipam_req.SpecificSubnetRequest(
tenant_id,
project_id,
subnet_id,
cidr,
gateway_ip=gateway_ip,
+55 -55
View File
@@ -99,7 +99,7 @@ class AutoAllocatedTopologyMixin:
resources.NETWORK, events.PRECOMMIT_CREATE)
return new
# TODO(armax): if a tenant modifies auto allocated resources under
# TODO(armax): if a project modifies auto allocated resources under
# the hood the behavior of the get_auto_allocated_topology API is
# undetermined. Consider adding callbacks to deal with the following
# situations:
@@ -129,26 +129,26 @@ class AutoAllocatedTopologyMixin:
net_res[api_const.IS_DEFAULT] = net_db.external.is_default
return net_res
def get_auto_allocated_topology(self, context, tenant_id, fields=None):
"""Return tenant's network associated to auto-allocated topology.
def get_auto_allocated_topology(self, context, project_id, fields=None):
"""Return project's network associated to auto-allocated topology.
The topology will be provisioned upon return, if network is missing.
"""
fields = fields or []
tenant_id = self._validate(context, tenant_id)
project_id = self._validate(context, project_id)
if CHECK_REQUIREMENTS in fields:
# for dry-run requests, simply validates that subsequent
# requests can be fulfilled based on a set of requirements
# such as existence of default networks, pools, etc.
return self._check_requirements(context, tenant_id)
return self._check_requirements(context, project_id)
if fields:
raise n_exc.BadRequest(resource='auto_allocate',
msg=_("Unrecognized field"))
# Check for an existent topology
network_id = self._get_auto_allocated_network(context, tenant_id)
network_id = self._get_auto_allocated_network(context, project_id)
if network_id:
return self._response(network_id, tenant_id, fields=fields)
return self._response(network_id, project_id, fields=fields)
# See if we indeed have an external network to connect to, otherwise
# we will fail fast
default_external_network = self._get_default_external_network(
@@ -156,12 +156,12 @@ class AutoAllocatedTopologyMixin:
# If we reach this point, then we got some work to do!
network_id = self._build_topology(
context, tenant_id, default_external_network)
return self._response(network_id, tenant_id, fields=fields)
context, project_id, default_external_network)
return self._response(network_id, project_id, fields=fields)
def delete_auto_allocated_topology(self, context, tenant_id):
tenant_id = self._validate(context, tenant_id)
topology = self._get_auto_allocated_topology(context, tenant_id)
def delete_auto_allocated_topology(self, context, project_id):
project_id = self._validate(context, project_id)
topology = self._get_auto_allocated_topology(context, project_id)
if topology:
subnets = self.core_plugin.get_subnets(
context,
@@ -170,29 +170,29 @@ class AutoAllocatedTopologyMixin:
context, network_id=topology['network_id'],
router_id=topology['router_id'], subnets=subnets)
def _build_topology(self, context, tenant_id, default_external_network):
def _build_topology(self, context, project_id, default_external_network):
"""Build the network topology and returns its network UUID."""
try:
subnets = self._provision_tenant_private_network(
context, tenant_id)
subnets = self._provision_project_private_network(
context, project_id)
network_id = subnets[0]['network_id']
router = self._provision_external_connectivity(
context, default_external_network, subnets, tenant_id)
context, default_external_network, subnets, project_id)
network_id = self._save(
context, tenant_id, network_id, router['id'], subnets)
context, project_id, network_id, router['id'], subnets)
return network_id
except exceptions.UnknownProvisioningError as e:
# Clean partially provisioned topologies, and reraise the
# error. If it can be retried, so be it.
LOG.error("Unknown error while provisioning topology for "
"tenant %(tenant_id)s. Reason: %(reason)s",
{'tenant_id': tenant_id, 'reason': e})
"project %(project_id)s. Reason: %(reason)s",
{'project_id': project_id, 'reason': e})
self._cleanup(
context, network_id=e.network_id,
router_id=e.router_id, subnets=e.subnets)
raise e.error
def _check_requirements(self, context, tenant_id):
def _check_requirements(self, context, project_id):
"""Raise if requirements are not met."""
self._get_default_external_network(context)
try:
@@ -201,39 +201,39 @@ class AutoAllocatedTopologyMixin:
raise exceptions.AutoAllocationFailure(
reason=_("No default subnetpools defined"))
return {'id': 'dry-run=pass',
'tenant_id': tenant_id,
'project_id': tenant_id}
'tenant_id': project_id,
'project_id': project_id}
def _validate(self, context, tenant_id):
"""Validate and return the tenant to be associated to the topology."""
if tenant_id == 'None':
def _validate(self, context, project_id):
"""Validate and return the project to be associated to the topology."""
if project_id == 'None':
# NOTE(HenryG): the client might be sending us astray by
# passing no tenant; this is really meant to be the tenant
# passing no project; this is really meant to be the project
# issuing the request, therefore let's get it from the context
tenant_id = context.tenant_id
project_id = context.project_id
if not context.is_admin and tenant_id != context.tenant_id:
if not context.is_admin and project_id != context.project_id:
raise n_exc.NotAuthorized()
return tenant_id
return project_id
def _get_auto_allocated_topology(self, context, tenant_id):
def _get_auto_allocated_topology(self, context, project_id):
"""Return the auto allocated topology record if present or None."""
return auto_allocate_obj.AutoAllocatedTopology.get_object(
context, project_id=tenant_id)
context, project_id=project_id)
def _get_auto_allocated_network(self, context, tenant_id):
"""Get the auto allocated network for the tenant."""
network = self._get_auto_allocated_topology(context, tenant_id)
def _get_auto_allocated_network(self, context, project_id):
"""Get the auto allocated network for the project."""
network = self._get_auto_allocated_topology(context, project_id)
if network:
return network['network_id']
@staticmethod
def _response(network_id, tenant_id, fields=None):
def _response(network_id, project_id, fields=None):
"""Build response for auto-allocated network."""
res = {
'id': network_id,
'tenant_id': tenant_id
'tenant_id': project_id
}
return db_utils.resource_fields(res, fields)
@@ -270,14 +270,14 @@ class AutoAllocatedTopologyMixin:
return available_pools
def _provision_tenant_private_network(self, context, tenant_id):
"""Create a tenant private network/subnets."""
def _provision_project_private_network(self, context, project_id):
"""Create a project private network/subnets."""
network = None
try:
network_args = {
'name': 'auto_allocated_network',
'admin_state_up': False,
'tenant_id': tenant_id,
'tenant_id': project_id,
'shared': False
}
network = p_utils.create_network(
@@ -287,7 +287,7 @@ class AutoAllocatedTopologyMixin:
subnet_args = {
'name': 'auto_allocated_subnet_v%s' % pool['ip_version'],
'network_id': network['id'],
'tenant_id': tenant_id,
'tenant_id': project_id,
'ip_version': pool['ip_version'],
'subnetpool_id': pool['id'],
}
@@ -296,27 +296,27 @@ class AutoAllocatedTopologyMixin:
return subnets
except (n_exc.SubnetAllocationError, ValueError,
n_exc.BadRequest, n_exc.NotFound) as e:
LOG.error("Unable to auto allocate topology for tenant "
"%(tenant_id)s due to missing or unmet "
LOG.error("Unable to auto allocate topology for project "
"%(project_id)s due to missing or unmet "
"requirements. Reason: %(reason)s",
{'tenant_id': tenant_id, 'reason': e})
{'project_id': project_id, 'reason': e})
if network:
self._cleanup(context, network['id'])
raise exceptions.AutoAllocationFailure(
reason=_("Unable to provide tenant private network"))
reason=_("Unable to provide project private network"))
except Exception as e:
network_id = network['id'] if network else None
raise exceptions.UnknownProvisioningError(e, network_id=network_id)
def _provision_external_connectivity(self, context,
default_external_network, subnets,
tenant_id):
"""Uplink tenant subnet(s) to external network."""
project_id):
"""Uplink project subnet(s) to external network."""
router_args = {
'name': 'auto_allocated_router',
l3_apidef.EXTERNAL_GW_INFO: {
'network_id': default_external_network},
'tenant_id': tenant_id,
'tenant_id': project_id,
'admin_state_up': True
}
router = None
@@ -330,10 +330,10 @@ class AutoAllocatedTopologyMixin:
attached_subnets.append(subnet)
return router
except n_exc.BadRequest as e:
LOG.error("Unable to auto allocate topology for tenant "
"%(tenant_id)s because of router errors. "
LOG.error("Unable to auto allocate topology for project "
"%(project_id)s because of router errors. "
"Reason: %(reason)s",
{'tenant_id': tenant_id, 'reason': e})
{'project_id': project_id, 'reason': e})
router_id = router['id'] if router else None
self._cleanup(context,
network_id=subnets[0]['network_id'],
@@ -346,24 +346,24 @@ class AutoAllocatedTopologyMixin:
e, network_id=subnets[0]['network_id'],
router_id=router_id, subnets=subnets)
def _save(self, context, tenant_id, network_id, router_id, subnets):
def _save(self, context, project_id, network_id, router_id, subnets):
"""Save auto-allocated topology, or revert in case of DB errors."""
try:
auto_allocate_obj.AutoAllocatedTopology(
context, project_id=tenant_id, network_id=network_id,
context, project_id=project_id, network_id=network_id,
router_id=router_id).create()
self.core_plugin.update_network(
context, network_id,
{'network': {'admin_state_up': True}})
except obj_exc.NeutronDbObjectDuplicateEntry:
LOG.debug("Multiple auto-allocated networks detected for "
"tenant %s. Attempting clean up for network %s "
"project %s. Attempting clean up for network %s "
"and router %s.",
tenant_id, network_id, router_id)
project_id, network_id, router_id)
self._cleanup(
context, network_id=network_id,
router_id=router_id, subnets=subnets)
network_id = self._get_auto_allocated_network(context, tenant_id)
network_id = self._get_auto_allocated_network(context, project_id)
except Exception as e:
raise exceptions.UnknownProvisioningError(
e, network_id=network_id,
+4 -4
View File
@@ -39,8 +39,8 @@ def _get_ports_attached_to_sg(context, sg_id):
return [port for (port,) in ports]
def _get_ports_filter_in_tenant(context, tenant_id):
"""Return a list of ports filter under a tenant"""
def _get_ports_filter_in_project(context, project_id):
"""Return a list of ports filter under a project"""
try:
sg_id = sg_db.SecurityGroupPortBinding.security_group_id
@@ -49,7 +49,7 @@ def _get_ports_filter_in_tenant(context, tenant_id):
sg_db.SecurityGroupPortBinding.port_id).join(
sg_db.SecurityGroup,
sg_db.SecurityGroup.id == sg_id).filter(
sg_db.SecurityGroup.project_id == tenant_id).all()
sg_db.SecurityGroup.project_id == project_id).all()
return list({port for (port,) in ports})
except orm_exc.NoResultFound:
return []
@@ -79,7 +79,7 @@ def _get_ports_being_logged(context, sg_log):
port_ids = _get_ports_attached_to_sg(context, resource_id)
# both 'resource_id' and 'target_id' aren't specified in a log_resource
else:
port_ids = _get_ports_filter_in_tenant(context, sg_log['project_id'])
port_ids = _get_ports_filter_in_project(context, sg_log['project_id'])
# list of validated ports's being logged
validated_port_ids = []
@@ -208,7 +208,6 @@ class TestDhcpRpcCallback(base.BaseTestCase):
non_local_subnets = []
ret = {'id': network.id,
'project_id': network.project_id,
'tenant_id': network.project_id,
'admin_state_up': network.admin_state_up,
'ports': ports,
'subnets': sorted(subnets, key=operator.itemgetter('id')),
@@ -95,7 +95,7 @@ class TestNeutronDbIpamPool(testlib_api.SqlTestCase,
gateway_ip_address = netaddr.IPAddress(gateway_ip)
if cidr:
cidr_ip_network = netaddr.IPNetwork(cidr)
self.assertEqual(project_id, ipam_subnet_details.tenant_id)
self.assertEqual(project_id, ipam_subnet_details.project_id)
self.assertEqual(gateway_ip_address, ipam_subnet_details.gateway_ip)
self.assertEqual(cidr_ip_network, ipam_subnet_details.subnet_cidr)
self.assertEqual(allocation_pools,
+2 -2
View File
@@ -42,7 +42,7 @@ class TestIpamSubnetRequests(IpamSubnetRequestTestCase):
def test_subnet_request(self):
pool = ipam_req.SubnetRequest(self.project_id,
self.subnet_id)
self.assertEqual(self.project_id, pool.tenant_id)
self.assertEqual(self.project_id, pool.project_id)
self.assertEqual(self.subnet_id, pool.subnet_id)
self.assertIsNone(pool.gateway_ip)
self.assertIsNone(pool.allocation_pools)
@@ -395,7 +395,7 @@ class TestSubnetRequestFactory(IpamSubnetRequestTestCase):
subnetpool)
self.assertIsInstance(request,
ipam_req.SpecificSubnetRequest)
self.assertEqual(self.project_id, request.tenant_id)
self.assertEqual(self.project_id, request.project_id)
self.assertEqual(self.subnet_id, request.subnet_id)
self.assertIsNone(request.gateway_ip)
self.assertIsNone(request.allocation_pools)
+2 -2
View File
@@ -165,12 +165,12 @@ class TestSubnetAllocation(testlib_api.SqlTestCase):
self.assertEqual(netaddr.IPAddress('2210::ffff:ffff:ffff:ffff'),
detail.gateway_ip)
def test__allocation_value_for_tenant_no_allocations(self):
def test__allocation_value_for_project_no_allocations(self):
sp = self._create_subnet_pool(self.plugin, self.ctx, 'test-sp',
['10.1.0.0/16', '192.168.1.0/24'],
21, 4)
sa = subnet_alloc.SubnetAllocator(sp, self.ctx)
value = sa._allocations_used_by_tenant(32)
value = sa._allocations_used_by_project(32)
self.assertEqual(0, value)
def test_subnetpool_default_quota_exceeded(self):
@@ -3797,7 +3797,7 @@ class TestML2PluggableIPAM(test_ipam.UseIpamMixin, TestMl2SubnetsV2):
request.subnet_cidr = netaddr.IPNetwork(cidr)
request.allocation_pools = []
request.gateway_ip = netaddr.IPAddress(gateway_ip)
request.tenant_id = self._project_id
request.project_id = self._project_id
ipam_subnet = mock.Mock()
ipam_subnet.get_details.return_value = request
@@ -308,7 +308,7 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
n_exc.BadRequest(resource='router', msg='doh!'))
self.assertRaises(exceptions.AutoAllocationFailure,
self.mixin._provision_external_connectivity,
self.ctx, 'ext_net_foo', subnets, 'tenant_foo')
self.ctx, 'ext_net_foo', subnets, 'project_foo')
# expect no subnets to be unplugged
mock_cleanup.assert_called_once_with(
self.ctx, network_id='network_foo',
@@ -324,7 +324,7 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
n_exc.BadRequest(resource='router', msg='doh!'))
self.assertRaises(exceptions.AutoAllocationFailure,
self.mixin._provision_external_connectivity,
self.ctx, 'ext_net_foo', subnets, 'tenant_foo')
self.ctx, 'ext_net_foo', subnets, 'project_foo')
# expected router_id to be None
mock_cleanup.assert_called_once_with(
self.ctx, network_id='network_foo',
@@ -341,7 +341,7 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
self.mixin.get_auto_allocated_topology,
self.ctx, mock.ANY, fields=['foo'])
def test__provision_tenant_private_network_handles_subnet_errors(self):
def test__provision_project_private_network_handles_subnet_errors(self):
network_id = uuidutils.generate_uuid()
self.mixin._core_plugin.create_network.return_value = (
{'id': network_id})
@@ -353,7 +353,7 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
[{'ip_version': constants.IP_VERSION_4,
'id': uuidutils.generate_uuid()}])
self.assertRaises(exceptions.AutoAllocationFailure,
self.mixin._provision_tenant_private_network,
self.mixin._provision_project_private_network,
self.ctx, 'foo_project')
g.assert_called_once_with(self.ctx, network_id)
@@ -376,21 +376,21 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
provisioning_exception = exceptions.UnknownProvisioningError(
db_exc.DBError)
self._test__build_topology(
'_provision_tenant_private_network',
'_provision_project_private_network',
provisioning_exception)
def test__build_topology_provisioning_error_network_only(self):
provisioning_exception = exceptions.UnknownProvisioningError(
Exception, network_id='foo')
self._test__build_topology(
'_provision_tenant_private_network',
'_provision_project_private_network',
provisioning_exception)
def test__build_topology_error_only_network_again(self):
provisioning_exception = exceptions.UnknownProvisioningError(
AttributeError, network_id='foo')
with mock.patch.object(self.mixin,
'_provision_tenant_private_network') as f:
'_provision_project_private_network') as f:
f.return_value = [{'network_id': 'foo'}]
self._test__build_topology(
'_provision_external_connectivity',
@@ -400,7 +400,7 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
provisioning_exception = exceptions.UnknownProvisioningError(
KeyError, network_id='foo_n', router_id='foo_r')
with mock.patch.object(self.mixin,
'_provision_tenant_private_network') as f:
'_provision_project_private_network') as f:
f.return_value = [{'network_id': 'foo_n'}]
self._test__build_topology(
'_provision_external_connectivity',
@@ -411,7 +411,7 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
db_exc.DBConnectionError,
network_id='foo_n', router_id='foo_r', subnets=[{'id': 'foo_s'}])
with mock.patch.object(self.mixin,
'_provision_tenant_private_network') as f,\
'_provision_project_private_network') as f,\
mock.patch.object(self.mixin,
'_provision_external_connectivity') as g:
f.return_value = [{'network_id': 'foo_n'}]
@@ -442,11 +442,11 @@ class AutoAllocateTestCase(testlib_api.SqlTestCase):
self.assertIsNone(e.router_id)
self.assertIsNone(e.subnets)
def test__provision_tenant_private_network_with_provisioning_error(self):
def test__provision_project_private_network_with_provisioning_error(self):
self.mixin._core_plugin.create_network.side_effect = Exception
with testtools.ExpectedException(
exceptions.UnknownProvisioningError) as e:
self.mixin._provision_tenant_private_network(
self.mixin._provision_project_private_network(
self.ctx, 'foo_project')
self.assertIsNone(e.network_id)
+17 -16
View File
@@ -35,27 +35,27 @@ class NeutronKeystoneContextTestCase(base.BaseTestCase):
self.request.headers['X_AUTH_TOKEN'] = 'testauthtoken'
def test_no_user_id(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
response = self.request.get_response(self.middleware)
self.assertEqual('401 Unauthorized', response.status)
def test_with_user_id(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual('testuserid', self.context.user_id)
def test_with_tenant_id(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
def test_with_project_id(self):
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'test_user_id'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual('testtenantid', self.context.tenant_id)
self.assertEqual('testtenantid', self.context.project_id)
self.assertEqual('testprojectid', self.context.tenant_id)
self.assertEqual('testprojectid', self.context.project_id)
def test_roles_no_admin(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_ROLES'] = 'role1, role2 , role3,role4,role5'
response = self.request.get_response(self.middleware)
@@ -65,7 +65,7 @@ class NeutronKeystoneContextTestCase(base.BaseTestCase):
self.assertFalse(self.context.is_admin)
def test_roles_with_admin(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_ROLES'] = ('role1, role2 , role3,role4,role5,'
'AdMiN')
@@ -75,35 +75,36 @@ class NeutronKeystoneContextTestCase(base.BaseTestCase):
'AdMiN'], self.context.roles)
self.assertTrue(self.context.is_admin)
def test_with_user_tenant_name(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
def test_with_user_project_name(self):
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_PROJECT_NAME'] = 'testtenantname'
self.request.headers['X_PROJECT_NAME'] = 'testprojectname'
self.request.headers['X_USER_NAME'] = 'testusername'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual('testuserid', self.context.user_id)
self.assertEqual('testusername', self.context.user_name)
self.assertEqual('testtenantid', self.context.tenant_id)
self.assertEqual('testtenantname', self.context.project_name)
self.assertEqual('testprojectid', self.context.tenant_id)
self.assertEqual('testprojectid', self.context.project_id)
self.assertEqual('testprojectname', self.context.project_name)
def test_request_id_extracted_from_env(self):
req_id = 'dummy-request-id'
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.environ[request_id.ENV_REQUEST_ID] = req_id
self.request.get_response(self.middleware)
self.assertEqual(req_id, self.context.request_id)
def test_with_auth_token(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
response = self.request.get_response(self.middleware)
self.assertEqual('200 OK', response.status)
self.assertEqual('testauthtoken', self.context.auth_token)
def test_without_auth_token(self):
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
self.request.headers['X_PROJECT_ID'] = 'testprojectid'
self.request.headers['X_USER_ID'] = 'testuserid'
del self.request.headers['X_AUTH_TOKEN']
self.request.get_response(self.middleware)