Fixes bug 928251,remove tenantid in admin commands

This bug was caused by mixing admin commands with tenanted commands.
Now all admin specific commands won't pass the tenant_id when
constructing the url. The non-admin counterparts of these commands are
extracted into separate commands.

Change-Id: I82d75254468ec978da99aa2a612a67e9e39c3f51
This commit is contained in:
rajarammallya 2012-02-14 04:25:59 +05:30
parent 54b6ad3869
commit f500587c83
3 changed files with 69 additions and 13 deletions

View File

@ -111,8 +111,9 @@ def client_category_usage():
client_categories = ['ip_block', 'subnet', 'policy', 'unusable_ip_range',
'unusable_ip_octet', 'allocated_ip', 'ip_address',
'ip_route', 'interface', 'mac_address_range',
'unusable_ip_octet', 'allocated_ip',
'tenant_allocated_ip', 'ip_address', 'ip_route',
'interface', 'tenant_interface', 'mac_address_range',
'allowed_ip']

View File

@ -54,7 +54,9 @@ class Factory(object):
raise AttributeError("%s has no attribute %s" %
(self.__class__.__name__, item))
return cls(self._client(), self._auth_client(), self.tenant_id)
return cls(self._client(),
self._auth_client(),
tenant_id=self.tenant_id)
class Resource(object):
@ -239,6 +241,18 @@ class AllocatedIpClient(BaseClient):
TENANT_ID_REQUIRED = False
def __init__(self, client, auth_client, tenant_id):
self._resource = Resource("allocated_ip_addresses",
"allocated_ip_addresses",
client,
auth_client)
def list(self, used_by_device=None):
return self._resource.all(used_by_device=used_by_device)
class TenantAllocatedIpClient(BaseClient):
def __init__(self, client, auth_client, tenant_id=None):
self._resource = Resource("allocated_ip_addresses",
"allocated_ip_addresses",
@ -312,8 +326,7 @@ class InterfaceClient(BaseClient):
self._resource = Resource("interfaces",
"interface",
client,
auth_client,
tenant_id)
auth_client)
def create(self, vif_id, tenant_id, device_id=None, network_id=None,
network_tenant_id=None):
@ -326,23 +339,32 @@ class InterfaceClient(BaseClient):
return self._resource.create(**request_params)
def show(self, vif_id):
return self._resource.find(vif_id)
def delete(self, vif_id):
return self._resource.delete(vif_id)
class TenantInterfaceClient(BaseClient):
def __init__(self, client, auth_client, tenant_id=None):
self._resource = Resource("interfaces",
"interface",
client,
auth_client,
tenant_id)
def show(self, vif_id):
return self._resource.find(vif_id)
class MacAddressRangeClient(BaseClient):
TENANT_ID_REQUIRED = False
def __init__(self, client, auth_client, tenant_id=None):
def __init__(self, client, auth_client, tenant_id):
self._resource = Resource("mac_address_ranges",
"mac_address_range",
client,
auth_client,
tenant_id)
auth_client)
def create(self, cidr):
return self._resource.create(cidr=cidr)

View File

@ -286,7 +286,10 @@ class TestAllocatedIpAddressCLI(TestBaseCLI):
self.assertEqual([ip1], yaml.load(list_res['out'])['ip_addresses'])
def test_list_with_tenant(self):
class TestTenantAllocatedIpAddressCLI(TestBaseCLI):
def test_list(self):
device1_id, device2_id = uuid.uuid4(), uuid.uuid4()
tenant1_id, tenant2_id = uuid.uuid4(), uuid.uuid4()
block = factory.create_block(cidr="30.1.1.1/24",
@ -307,11 +310,16 @@ class TestAllocatedIpAddressCLI(TestBaseCLI):
tenant_id=self.tenant_id,
used_by_tenant=tenant2_id)
list_res = functional.run("allocated_ip list -t %s" % tenant1_id)
list_res = functional.run("tenant_allocated_ip list -t %s"
% tenant1_id)
self.assertEqual(sorted([tenant1_ip1, tenant1_ip2]),
sorted(yaml.load(list_res['out'])['ip_addresses']))
def test_raises_error_if_no_tenant_id_specified(self):
res = functional.run("tenant_allocated_ip list")
self.assertTrue("Please provide a tenant id" in res['out'])
class TestIpAddressCLI(TestBaseCLI):
@ -405,13 +413,31 @@ class TestInterfaceCLI(TestBaseCLI):
tenant_id=self.tenant_id)
self.assertShows("interface",
iface,
command_name="tenant_interface",
parameters="vif_id=%s" % iface['id'])
self.command("interface delete", is_tenanted=False, vif_id=iface['id'])
self.assertResourceNotFound("interface",
iface,
command_name="tenant_interface",
parameters="vif_id=%s" % iface['id'])
def test_tenant_id_ignored_when_present(self):
network_id = uuid.uuid4()
block = factory.create_block(cidr="20.1.1.0/24",
network_id=network_id,
tenant_id=self.tenant_id)
create_res = self.command("interface create",
is_tenanted=True,
network_id=network_id,
vif_id=uuid.uuid4(),
tenant_id=self.tenant_id)
iface = factory.model('interface', create_res)
self.assertShows("interface",
iface,
command_name="tenant_interface",
parameters="vif_id=%s" % iface['id'])
class TestMacAddressRangeCLI(TestBaseCLI):
@ -438,6 +464,13 @@ class TestMacAddressRangeCLI(TestBaseCLI):
rng,
is_tenanted=False)
def test_tenant_id_ignored_when_present(self):
create_res = self.command("mac_address_range create",
is_tenanted=True,
cidr="ab-bc-cd-12-23-34/2")
rng = factory.model('mac_address_range', create_res)
self.assertShows('mac_address_range', rng, is_tenanted=True)
class TestAllowedIpCLI(TestBaseCLI):