fix reference to tenant id.

Administrator can create resource, even if the tenant of resource is
different from the one of authentication. For example, administrator
can operate 'quantum net-create' command with different tenant
between the authentication tenant(--os-tenant-name) and --tenant-id.

In this case, quota cannot be restricted with the resource tenant,
because it is restricted with --os-tenant-name.

This patch fixes this problem.

Fixes: bug #1179729

Change-Id: I8ce893bb583d52f81c661082372d725bebf9c1be
This commit is contained in:
fujioka yuuichi 2013-05-14 09:01:17 +09:00
parent 2a0e7f2fa7
commit 84f65f387c
2 changed files with 31 additions and 1 deletions

View File

@ -138,7 +138,7 @@ class DbQuotaDriver(object):
# Grab and return the quotas (without usages)
quotas = DbQuotaDriver.get_tenant_quotas(
context, sub_resources, context.tenant_id)
context, sub_resources, tenant_id)
return dict((k, v) for k, v in quotas.items())

View File

@ -9,9 +9,11 @@ from quantum.common import config
from quantum.common import exceptions
from quantum import context
from quantum.db import api as db
from quantum.db import quota_db
from quantum import manager
from quantum.plugins.linuxbridge.db import l2network_db_v2
from quantum import quota
from quantum.tests import base
from quantum.tests.unit import test_api_v2
from quantum.tests.unit import test_extensions
from quantum.tests.unit import testlib_api
@ -341,3 +343,31 @@ class QuotaExtensionCfgTestCase(QuotaExtensionTestCase):
class QuotaExtensionCfgTestCaseXML(QuotaExtensionCfgTestCase):
fmt = 'xml'
class TestDbQuotaDriver(base.BaseTestCase):
"""Test for quantum.db.quota_db.DbQuotaDriver."""
def test_get_tenant_quotas_arg(self):
"""Call quantum.db.quota_db.DbQuotaDriver._get_quotas."""
driver = quota_db.DbQuotaDriver()
ctx = context.Context('', 'bar')
foo_quotas = {'network': 5}
default_quotas = {'network': 10}
target_tenant = 'foo'
with mock.patch.object(quota_db.DbQuotaDriver,
'get_tenant_quotas',
return_value=foo_quotas) as get_tenant_quotas:
quotas = driver._get_quotas(ctx,
target_tenant,
default_quotas,
['network'])
self.assertEqual(quotas, foo_quotas)
get_tenant_quotas.assert_called_once_with(ctx,
default_quotas,
target_tenant)