summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Lee <aaron.lee@rackspace.com>2012-02-16 11:41:48 -0600
committerAaron Lee <aaron.lee@rackspace.com>2012-02-16 12:26:38 -0600
commit471150506653e697fc5a663d4d8b09ef5fbef19b (patch)
treebde5c76e7361ab51aaf1710caa980792876a00ba
parentf5e17bbc155203feb8bba4f34ed93d22b1b8e95b (diff)
downloadnova-471150506653e697fc5a663d4d8b09ef5fbef19b.tar.gz
nova-471150506653e697fc5a663d4d8b09ef5fbef19b.tar.xz
nova-471150506653e697fc5a663d4d8b09ef5fbef19b.zip
removed unused method and added another test
get_network_id_by_cidr is not used, I'm removing it and it's tests. get_tenant_id_by_net_id relies on catching exceptions as part of the happy path. I expanded the tests to try to exemplify that. Change-Id: Iaf973da1d176ba8ea89d0fd762e796936d056d0f
-rw-r--r--nova/network/quantum/melange_ipam_lib.py18
-rw-r--r--nova/network/quantum/nova_ipam_lib.py9
-rw-r--r--nova/tests/test_melange_ipam_lib.py39
3 files changed, 23 insertions, 43 deletions
diff --git a/nova/network/quantum/melange_ipam_lib.py b/nova/network/quantum/melange_ipam_lib.py
index c884f9694..3502c58e3 100644
--- a/nova/network/quantum/melange_ipam_lib.py
+++ b/nova/network/quantum/melange_ipam_lib.py
@@ -87,18 +87,6 @@ class QuantumMelangeIPAMLib(object):
vif_ref['address'])
return [ip['address'] for ip in ips]
- def get_network_id_by_cidr(self, context, cidr, project_id):
- """Find the Quantum UUID associated with a IPv4 CIDR
- address for the specified tenant.
- """
- tenant_id = project_id or FLAGS.quantum_default_tenant_id
- all_blocks = self.m_conn.get_blocks(tenant_id)
- for b in all_blocks['ip_blocks']:
- LOG.debug("block: %s" % b)
- if b['cidr'] == cidr:
- return b['network_id']
- raise exception.NotFound(_("No network found for cidr %s" % cidr))
-
def delete_subnets_by_net_id(self, context, net_id, project_id):
"""Find Melange block associated with the Quantum UUID,
then tell Melange to delete that block.
@@ -164,10 +152,12 @@ class QuantumMelangeIPAMLib(object):
def get_tenant_id_by_net_id(self, context, net_id, vif_id, project_id):
ipam_tenant_id = None
tenant_ids = [FLAGS.quantum_default_tenant_id, project_id, None]
+ # This is confusing, if there are IPs for the given net, vif,
+ # tenant trifecta we assume that is the tenant for that network
for tid in tenant_ids:
try:
- ips = self.m_conn.get_allocated_ips(net_id, vif_id, tid)
- except Exception, e:
+ self.m_conn.get_allocated_ips(net_id, vif_id, tid)
+ except KeyError:
continue
ipam_tenant_id = tid
break
diff --git a/nova/network/quantum/nova_ipam_lib.py b/nova/network/quantum/nova_ipam_lib.py
index 19520ef51..e49efc2ec 100644
--- a/nova/network/quantum/nova_ipam_lib.py
+++ b/nova/network/quantum/nova_ipam_lib.py
@@ -80,15 +80,6 @@ class QuantumNovaIPAMLib(object):
"uuid": quantum_net_id}
db.network_update(admin_context, network['id'], net)
- def get_network_id_by_cidr(self, context, cidr, project_id):
- """ Grabs Quantum network UUID based on IPv4 CIDR. """
- admin_context = context.elevated()
- network = db.network_get_by_cidr(admin_context, cidr)
- if not network:
- raise Exception(_("No network with fixed_range = %s" %
- cidr))
- return network['uuid']
-
def delete_subnets_by_net_id(self, context, net_id, project_id):
"""Deletes a network based on Quantum UUID. Uses FlatManager
delete_network to avoid duplication.
diff --git a/nova/tests/test_melange_ipam_lib.py b/nova/tests/test_melange_ipam_lib.py
index 031c1f109..ce678ec83 100644
--- a/nova/tests/test_melange_ipam_lib.py
+++ b/nova/tests/test_melange_ipam_lib.py
@@ -53,22 +53,6 @@ class MelangeIpamLibTestCase(test.TestCase):
'address': 'vif_ref_address'})
self.assertEqual(ips[0], 'ip_address')
- def test_get_network_id_by_cidr_finds_block(self):
- self.m_conn.get_blocks('tenant_id').AndReturn(self._block_list())
-
- self.mox.ReplayAll()
-
- net_id = self.ipam.get_network_id_by_cidr('context', 'cidr',
- 'tenant_id')
- self.assertEqual(net_id, 'network_id')
-
- def test_get_network_id_by_cidr_raises_on_not_found(self):
- self.m_conn.get_blocks('tenant_id').AndReturn({'ip_blocks': []})
- self.mox.ReplayAll()
- self.assertRaises(exception.NotFound,
- self.ipam.get_network_id_by_cidr,
- 'context', 'cidr', 'tenant_id')
-
def test_delete_subnets_by_net_id_deletes_block(self):
context = self.mox.CreateMockAnything()
context.elevated().AndReturn('elevated')
@@ -142,14 +126,29 @@ class MelangeIpamLibTestCase(test.TestCase):
self.mox.ReplayAll()
self.ipam.get_project_and_global_net_ids(context, 'project_id')
- def test_get_tenant_id_by_net_id(self):
+ def test_get_tenant_id_by_net_id_returns_id(self):
FLAGS.quantum_default_tenant_id = 'qdti'
self.m_conn.get_allocated_ips('net_id', 'vif_id',
- None).AndReturn('tenant_id')
+ 'qdti').AndReturn({})
self.mox.ReplayAll()
- self.ipam.get_tenant_id_by_net_id('context', 'net_id', 'vif_id',
- 'project_id')
+ value = self.ipam.get_tenant_id_by_net_id('context', 'net_id',
+ 'vif_id', 'project_id')
+ self.assertEqual(value, 'qdti')
+
+ def test_get_tenant_id_by_net_id_returns_none_if_none_found(self):
+ FLAGS.quantum_default_tenant_id = 'qdti'
+
+ self.m_conn.get_allocated_ips('net_id', 'vif_id',
+ 'qdti').AndRaise(KeyError())
+ self.m_conn.get_allocated_ips('net_id', 'vif_id',
+ 'project_id').AndRaise(KeyError())
+ self.m_conn.get_allocated_ips('net_id', 'vif_id',
+ None).AndRaise(KeyError())
+ self.mox.ReplayAll()
+ value = self.ipam.get_tenant_id_by_net_id('context', 'net_id',
+ 'vif_id', 'project_id')
+ self.assertEqual(value, None)
def test_get_subnets_by_net_id(self):
ips = [{'ip_block': {'network_id': 'network_id',