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
This commit is contained in:
parent
f5e17bbc15
commit
4711505066
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue