Convert fixed_ips to using instance_uuid.
This should be the second last blueprint finish-uuid-conversion change. Change-Id: Idd47c5ed3c30af24d60eb23b8e3881d61b4c7976
This commit is contained in:
@@ -274,9 +274,9 @@ class FixedIpCommands(object):
|
||||
sys.exit(2)
|
||||
|
||||
instances = db.instance_get_all(context.get_admin_context())
|
||||
instances_by_id = {}
|
||||
instances_by_uuid = {}
|
||||
for instance in instances:
|
||||
instances_by_id[instance['id']] = instance
|
||||
instances_by_uuid[instance['uuid']] = instance
|
||||
|
||||
print "%-18s\t%-15s\t%-15s\t%s" % (_('network'),
|
||||
_('IP address'),
|
||||
@@ -304,8 +304,8 @@ class FixedIpCommands(object):
|
||||
network = all_networks.get(fixed_ip['network_id'])
|
||||
if network:
|
||||
has_ip = True
|
||||
if fixed_ip.get('instance_id'):
|
||||
instance = instances_by_id.get(fixed_ip['instance_id'])
|
||||
if fixed_ip.get('instance_uuid'):
|
||||
instance = instances_by_uuid.get(fixed_ip['instance_uuid'])
|
||||
if instance:
|
||||
hostname = instance['hostname']
|
||||
host = instance['host']
|
||||
@@ -414,16 +414,11 @@ class FloatingIpCommands(object):
|
||||
instance_id = None
|
||||
if floating_ip['fixed_ip_id']:
|
||||
fixed_ip = db.fixed_ip_get(ctxt, floating_ip['fixed_ip_id'])
|
||||
try:
|
||||
instance = db.instance_get(ctxt, fixed_ip['instance_id'])
|
||||
instance_id = instance.get('uuid', "none")
|
||||
except exception.InstanceNotFound:
|
||||
msg = _('Missing instance %s')
|
||||
instance_id = msg % fixed_ip['instance_id']
|
||||
instance_uuid = fixed_ip['instance_uuid']
|
||||
|
||||
print "%s\t%s\t%s\t%s\t%s" % (floating_ip['project_id'],
|
||||
floating_ip['address'],
|
||||
instance_id,
|
||||
instance_uuid,
|
||||
floating_ip['pool'],
|
||||
floating_ip['interface'])
|
||||
|
||||
|
||||
@@ -334,14 +334,14 @@ class DbApiTestCase(test.TestCase):
|
||||
values = {'address': 'baz',
|
||||
'network_id': 1,
|
||||
'allocated': True,
|
||||
'instance_id': instance['id'],
|
||||
'instance_uuid': instance['uuid'],
|
||||
'virtual_interface_id': vif['id']}
|
||||
fixed_address = db.fixed_ip_create(ctxt, values)
|
||||
data = db.network_get_associated_fixed_ips(ctxt, 1)
|
||||
self.assertEqual(len(data), 1)
|
||||
record = data[0]
|
||||
self.assertEqual(record['address'], fixed_address)
|
||||
self.assertEqual(record['instance_id'], instance['id'])
|
||||
self.assertEqual(record['instance_uuid'], instance['uuid'])
|
||||
self.assertEqual(record['network_id'], 1)
|
||||
self.assertEqual(record['instance_created'], instance['created_at'])
|
||||
self.assertEqual(record['instance_updated'], instance['updated_at'])
|
||||
@@ -360,25 +360,25 @@ class DbApiTestCase(test.TestCase):
|
||||
new = time = timeout + datetime.timedelta(seconds=5)
|
||||
# should deallocate
|
||||
values = {'allocated': False,
|
||||
'instance_id': instance['id'],
|
||||
'instance_uuid': instance['uuid'],
|
||||
'network_id': net['id'],
|
||||
'updated_at': old}
|
||||
db.fixed_ip_create(ctxt, values)
|
||||
# still allocated
|
||||
values = {'allocated': True,
|
||||
'instance_id': instance['id'],
|
||||
'instance_uuid': instance['uuid'],
|
||||
'network_id': net['id'],
|
||||
'updated_at': old}
|
||||
db.fixed_ip_create(ctxt, values)
|
||||
# wrong network
|
||||
values = {'allocated': False,
|
||||
'instance_id': instance['id'],
|
||||
'instance_uuid': instance['uuid'],
|
||||
'network_id': None,
|
||||
'updated_at': old}
|
||||
db.fixed_ip_create(ctxt, values)
|
||||
# too new
|
||||
values = {'allocated': False,
|
||||
'instance_id': instance['id'],
|
||||
'instance_uuid': instance['uuid'],
|
||||
'network_id': None,
|
||||
'updated_at': new}
|
||||
db.fixed_ip_create(ctxt, values)
|
||||
@@ -830,27 +830,27 @@ class TestIpAllocation(test.TestCase):
|
||||
def test_fixed_ip_associate_fails_if_ip_not_in_network(self):
|
||||
self.assertRaises(exception.FixedIpNotFoundForNetwork,
|
||||
db.fixed_ip_associate,
|
||||
self.ctxt, None, None)
|
||||
self.ctxt, None, self.instance.uuid)
|
||||
|
||||
def test_fixed_ip_associate_fails_if_ip_in_use(self):
|
||||
address = self.create_fixed_ip(instance_id=self.instance.id)
|
||||
address = self.create_fixed_ip(instance_uuid=self.instance.uuid)
|
||||
self.assertRaises(exception.FixedIpAlreadyInUse,
|
||||
db.fixed_ip_associate,
|
||||
self.ctxt, address, self.instance.id)
|
||||
self.ctxt, address, self.instance.uuid)
|
||||
|
||||
def test_fixed_ip_associate_succeeds(self):
|
||||
address = self.create_fixed_ip(network_id=self.network.id)
|
||||
db.fixed_ip_associate(self.ctxt, address, self.instance.id,
|
||||
db.fixed_ip_associate(self.ctxt, address, self.instance.uuid,
|
||||
network_id=self.network.id)
|
||||
fixed_ip = db.fixed_ip_get_by_address(self.ctxt, address)
|
||||
self.assertEqual(fixed_ip.instance_id, self.instance.id)
|
||||
self.assertEqual(fixed_ip.instance_uuid, self.instance.uuid)
|
||||
|
||||
def test_fixed_ip_associate_succeeds_and_sets_network(self):
|
||||
address = self.create_fixed_ip()
|
||||
db.fixed_ip_associate(self.ctxt, address, self.instance.id,
|
||||
db.fixed_ip_associate(self.ctxt, address, self.instance.uuid,
|
||||
network_id=self.network.id)
|
||||
fixed_ip = db.fixed_ip_get_by_address(self.ctxt, address)
|
||||
self.assertEqual(fixed_ip.instance_id, self.instance.id)
|
||||
self.assertEqual(fixed_ip.instance_uuid, self.instance.uuid)
|
||||
self.assertEqual(fixed_ip.network_id, self.network.id)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user