Ties quantum, melange, and nova network model
get_instance_nw_info() now returns network model, and keeps the network info cache up to date. virt shim and translation in place for virts to get at the old stuff Change-Id: I070ea7d8564af6c644059d1c209542d250d19ddb
This commit is contained in:
@@ -113,6 +113,7 @@ class BaseTestCase(test.TestCase):
|
||||
notification_driver='nova.notifier.test_notifier',
|
||||
network_manager='nova.network.manager.FlatManager')
|
||||
self.compute = utils.import_object(FLAGS.compute_manager)
|
||||
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
self.context = context.RequestContext(self.user_id,
|
||||
@@ -463,6 +464,12 @@ class ComputeTestCase(BaseTestCase):
|
||||
|
||||
def test_rebuild(self):
|
||||
"""Ensure instance can be rebuilt"""
|
||||
def fake_get_nw_info(cls, ctxt, instance):
|
||||
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
|
||||
spectacular=True)
|
||||
|
||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
instance = self._create_fake_instance()
|
||||
instance_uuid = instance['uuid']
|
||||
|
||||
@@ -878,6 +885,12 @@ class ComputeTestCase(BaseTestCase):
|
||||
instance = self._create_fake_instance()
|
||||
instance_uuid = instance['uuid']
|
||||
|
||||
def fake_get_nw_info(cls, ctxt, instance):
|
||||
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
|
||||
spectacular=True)
|
||||
|
||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
self.mox.StubOutWithMock(self.compute.network_api,
|
||||
"allocate_for_instance")
|
||||
self.compute.network_api.allocate_for_instance(mox.IgnoreArg(),
|
||||
@@ -1002,6 +1015,13 @@ class ComputeTestCase(BaseTestCase):
|
||||
|
||||
def test_resize_instance_notification(self):
|
||||
"""Ensure notifications on instance migrate/resize"""
|
||||
def fake_get_nw_info(cls, ctxt, instance):
|
||||
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
|
||||
spectacular=True)
|
||||
|
||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
instance_uuid = instance['uuid']
|
||||
context = self.context.elevated()
|
||||
@@ -1212,6 +1232,14 @@ class ComputeTestCase(BaseTestCase):
|
||||
|
||||
def test_pre_live_migration_works_correctly(self):
|
||||
"""Confirm setup_compute_volume is called when volume is mounted."""
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
|
||||
def stupid(*args, **kwargs):
|
||||
return fake_network.fake_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
self.stubs.Set(nova.compute.manager.ComputeManager,
|
||||
'_get_instance_nw_info', stupid)
|
||||
# creating instance testdata
|
||||
inst_ref = self._create_fake_instance({'host': 'dummy'})
|
||||
c = context.get_admin_context()
|
||||
@@ -1220,16 +1248,13 @@ class ComputeTestCase(BaseTestCase):
|
||||
# creating mocks
|
||||
self.mox.StubOutWithMock(self.compute.driver, 'pre_live_migration')
|
||||
self.compute.driver.pre_live_migration({'block_device_mapping': []})
|
||||
dummy_nw_info = [[None, {'ips':'1.1.1.1'}]]
|
||||
self.mox.StubOutWithMock(self.compute, '_get_instance_nw_info')
|
||||
self.compute._get_instance_nw_info(c, mox.IsA(inst_ref)
|
||||
).AndReturn(dummy_nw_info)
|
||||
nw_info = fake_network.fake_get_instance_nw_info(self.stubs)
|
||||
self.mox.StubOutWithMock(self.compute.driver, 'plug_vifs')
|
||||
self.compute.driver.plug_vifs(mox.IsA(inst_ref), dummy_nw_info)
|
||||
self.compute.driver.plug_vifs(mox.IsA(inst_ref), nw_info)
|
||||
self.mox.StubOutWithMock(self.compute.driver,
|
||||
'ensure_filtering_rules_for_instance')
|
||||
self.compute.driver.ensure_filtering_rules_for_instance(
|
||||
mox.IsA(inst_ref), dummy_nw_info)
|
||||
mox.IsA(inst_ref), nw_info)
|
||||
|
||||
# start test
|
||||
self.mox.ReplayAll()
|
||||
@@ -2239,11 +2264,10 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
fixed_address):
|
||||
called['associate'] = True
|
||||
|
||||
nw_info = fake_network.fake_get_instance_nw_info(self.stubs, 1)
|
||||
|
||||
def fake_get_nw_info(cls, ctxt, instance):
|
||||
self.assertTrue(ctxt.is_admin)
|
||||
return nw_info
|
||||
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
|
||||
spectacular=True)
|
||||
|
||||
self.stubs.Set(nova.network.API, 'associate_floating_ip',
|
||||
fake_associate_ip_network_api)
|
||||
@@ -2968,7 +2992,14 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.assertTrue(self.compute_api.get_lock(self.context, instance))
|
||||
|
||||
def test_add_remove_security_group(self):
|
||||
def fake_get_nw_info(cls, ctxt, instance):
|
||||
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
|
||||
spectacular=True)
|
||||
|
||||
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
|
||||
fake_get_nw_info)
|
||||
instance = self._create_fake_instance()
|
||||
|
||||
self.compute.run_instance(self.context, instance['uuid'])
|
||||
instance = self.compute_api.get(self.context, instance['uuid'])
|
||||
security_group_name = self._create_group()['name']
|
||||
|
||||
@@ -106,16 +106,16 @@ class SubnetTests(test.TestCase):
|
||||
|
||||
route1 = fake_network_cache_model.new_route()
|
||||
|
||||
self.assertEqual(subnet['cidr'], '255.255.255.0')
|
||||
self.assertEqual(subnet['cidr'], '10.10.0.0/24')
|
||||
self.assertEqual(subnet['dns'],
|
||||
[fake_network_cache_model.new_ip(dict(address='1.2.3.4')),
|
||||
fake_network_cache_model.new_ip(dict(address='2.3.4.5'))])
|
||||
self.assertEqual(subnet['gateway']['address'], '192.168.1.1')
|
||||
self.assertEqual(subnet['gateway']['address'], '10.10.0.1')
|
||||
self.assertEqual(subnet['ips'],
|
||||
[fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.100')),
|
||||
dict(address='10.10.0.2')),
|
||||
fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.101'))])
|
||||
dict(address='10.10.0.3'))])
|
||||
self.assertEqual(subnet['routes'], [route1])
|
||||
self.assertEqual(subnet['version'], 4)
|
||||
|
||||
@@ -159,9 +159,9 @@ class SubnetTests(test.TestCase):
|
||||
dict(address='192.168.1.102')))
|
||||
self.assertEqual(subnet['ips'],
|
||||
[fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.100')),
|
||||
dict(address='10.10.0.2')),
|
||||
fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.101')),
|
||||
dict(address='10.10.0.3')),
|
||||
fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.102'))])
|
||||
|
||||
@@ -172,9 +172,9 @@ class SubnetTests(test.TestCase):
|
||||
dict(address='192.168.1.102')))
|
||||
self.assertEqual(subnet['ips'],
|
||||
[fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.100')),
|
||||
dict(address='10.10.0.2')),
|
||||
fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.101')),
|
||||
dict(address='10.10.0.3')),
|
||||
fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.102'))])
|
||||
|
||||
@@ -262,9 +262,9 @@ class VIFTests(test.TestCase):
|
||||
def test_vif_get_fixed_ips(self):
|
||||
vif = fake_network_cache_model.new_vif()
|
||||
fixed_ips = vif.fixed_ips()
|
||||
ips = [fake_network_cache_model.new_ip(dict(address='192.168.1.100')),
|
||||
ips = [fake_network_cache_model.new_ip(dict(address='10.10.0.2')),
|
||||
fake_network_cache_model.new_ip(
|
||||
dict(address='192.168.1.101'))] * 2
|
||||
dict(address='10.10.0.3'))] * 2
|
||||
self.assertEqual(fixed_ips, ips)
|
||||
|
||||
def test_vif_get_floating_ips(self):
|
||||
@@ -279,9 +279,9 @@ class VIFTests(test.TestCase):
|
||||
ip_dict = {
|
||||
'network_id': 1,
|
||||
'ips': [fake_network_cache_model.new_ip(
|
||||
{'address': '192.168.1.100'}),
|
||||
{'address': '10.10.0.2'}),
|
||||
fake_network_cache_model.new_ip(
|
||||
{'address': '192.168.1.101'})] * 2,
|
||||
{'address': '10.10.0.3'})] * 2,
|
||||
'network_label': 'public'}
|
||||
self.assertEqual(labeled_ips, ip_dict)
|
||||
|
||||
@@ -303,9 +303,9 @@ class NetworkInfoTests(test.TestCase):
|
||||
fake_network_cache_model.new_vif(
|
||||
{'address':'bb:bb:bb:bb:bb:bb'})])
|
||||
self.assertEqual(ninfo.fixed_ips(),
|
||||
[fake_network_cache_model.new_ip({'address': '192.168.1.100'}),
|
||||
[fake_network_cache_model.new_ip({'address': '10.10.0.2'}),
|
||||
fake_network_cache_model.new_ip(
|
||||
{'address': '192.168.1.101'})] * 4)
|
||||
{'address': '10.10.0.3'})] * 4)
|
||||
|
||||
def test_get_floating_ips(self):
|
||||
vif = fake_network_cache_model.new_vif()
|
||||
@@ -321,6 +321,6 @@ class NetworkInfoTests(test.TestCase):
|
||||
{'address':'bb:bb:bb:bb:bb:bb'})])
|
||||
deserialized = model.NetworkInfo.hydrate(ninfo)
|
||||
self.assertEqual(ninfo.fixed_ips(),
|
||||
[fake_network_cache_model.new_ip({'address': '192.168.1.100'}),
|
||||
[fake_network_cache_model.new_ip({'address': '10.10.0.2'}),
|
||||
fake_network_cache_model.new_ip(
|
||||
{'address': '192.168.1.101'})] * 4)
|
||||
{'address': '10.10.0.3'})] * 4)
|
||||
|
||||
@@ -275,32 +275,42 @@ class QuantumNovaIPAMTestCase(QuantumNovaTestCase):
|
||||
self.net_man.driver.update_dhcp_hostfile_with_text = func
|
||||
self.net_man.driver.restart_dhcp = func2
|
||||
self.net_man.driver.kill_dhcp = func1
|
||||
nw_info = self.net_man.allocate_for_instance(ctx,
|
||||
nw_info = self.net_man.allocate_for_instance(ctx.elevated(),
|
||||
instance_id=instance_ref['id'], host="",
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
project_id=project_id)
|
||||
|
||||
self.assertEquals(len(nw_info), 2)
|
||||
|
||||
cidrs = ['10.', '192.']
|
||||
addrs = ['10.', '192.']
|
||||
cidrs_v6 = ['2001:1dba:', '2001:1db8:']
|
||||
addrs_v6 = ['2001:1dba:', '2001:1db8:']
|
||||
|
||||
def check_for_startswith(choices, choice):
|
||||
for v in choices:
|
||||
if choice.startswith(v):
|
||||
choices.remove(v)
|
||||
return True
|
||||
return False
|
||||
|
||||
# we don't know which order the NICs will be in until we
|
||||
# introduce the notion of priority
|
||||
# v4 cidr
|
||||
self.assertTrue(nw_info[0][0]['cidr'].startswith("10."))
|
||||
self.assertTrue(nw_info[1][0]['cidr'].startswith("192."))
|
||||
|
||||
# v4 address
|
||||
self.assertTrue(nw_info[0][1]['ips'][0]['ip'].startswith("10."))
|
||||
self.assertTrue(nw_info[1][1]['ips'][0]['ip'].startswith("192."))
|
||||
|
||||
# v6 cidr
|
||||
self.assertTrue(nw_info[0][0]['cidr_v6'].startswith("2001:1dba:"))
|
||||
self.assertTrue(nw_info[1][0]['cidr_v6'].startswith("2001:1db8:"))
|
||||
|
||||
# v6 address
|
||||
self.assertTrue(
|
||||
nw_info[0][1]['ip6s'][0]['ip'].startswith("2001:1dba:"))
|
||||
self.assertTrue(
|
||||
nw_info[1][1]['ip6s'][0]['ip'].startswith("2001:1db8:"))
|
||||
for vif in nw_info:
|
||||
for subnet in vif['network']['subnets']:
|
||||
cidr = subnet['cidr'].lower()
|
||||
if subnet['version'] == 4:
|
||||
# v4 cidr
|
||||
self.assertTrue(check_for_startswith(cidrs, cidr))
|
||||
# v4 address
|
||||
address = subnet['ips'][0]['address']
|
||||
self.assertTrue(check_for_startswith(addrs, address))
|
||||
else:
|
||||
# v6 cidr
|
||||
self.assertTrue(check_for_startswith(cidrs_v6, cidr))
|
||||
# v6 address
|
||||
address = subnet['ips'][0]['address']
|
||||
self.assertTrue(check_for_startswith(addrs_v6, address))
|
||||
|
||||
self.net_man.deallocate_for_instance(ctx,
|
||||
instance_id=instance_ref['id'],
|
||||
@@ -342,33 +352,34 @@ class QuantumNovaIPAMTestCase(QuantumNovaTestCase):
|
||||
|
||||
self.assertEquals(len(nw_info), 2)
|
||||
|
||||
cidrs = ['9.', '192.']
|
||||
addrs = ['9.', '192.']
|
||||
cidrs_v6 = ['2001:1dbb:', '2001:1db9:']
|
||||
addrs_v6 = ['2001:1dbb:', '2001:1db9:']
|
||||
|
||||
def check_for_startswith(choices, choice):
|
||||
for v in choices:
|
||||
if choice.startswith(v):
|
||||
choices.remove(v)
|
||||
return True
|
||||
|
||||
# we don't know which order the NICs will be in until we
|
||||
# introduce the notion of priority
|
||||
# v4 cidr
|
||||
self.assertTrue(nw_info[0][0]['cidr'].startswith("9.") or
|
||||
nw_info[1][0]['cidr'].startswith("9."))
|
||||
self.assertTrue(nw_info[0][0]['cidr'].startswith("192.") or
|
||||
nw_info[1][0]['cidr'].startswith("192."))
|
||||
|
||||
# v4 address
|
||||
self.assertTrue(nw_info[0][1]['ips'][0]['ip'].startswith("9.") or
|
||||
nw_info[1][1]['ips'][0]['ip'].startswith("9."))
|
||||
self.assertTrue(nw_info[0][1]['ips'][0]['ip'].startswith("192.") or
|
||||
nw_info[1][1]['ips'][0]['ip'].startswith("192."))
|
||||
|
||||
# v6 cidr
|
||||
self.assertTrue(nw_info[0][0]['cidr_v6'].startswith("2001:1dbb:") or
|
||||
nw_info[1][0]['cidr_v6'].startswith("2001:1dbb:"))
|
||||
self.assertTrue(nw_info[0][0]['cidr_v6'].startswith("2001:1db9:") or
|
||||
nw_info[1][0]['cidr_v6'].startswith("2001:1db9:"))
|
||||
|
||||
# v6 address
|
||||
self.assertTrue(
|
||||
nw_info[0][1]['ip6s'][0]['ip'].startswith("2001:1dbb:") or
|
||||
nw_info[1][1]['ip6s'][0]['ip'].startswith("2001:1dbb:"))
|
||||
self.assertTrue(
|
||||
nw_info[0][1]['ip6s'][0]['ip'].startswith("2001:1db9:") or
|
||||
nw_info[1][1]['ip6s'][0]['ip'].startswith("2001:1db9:"))
|
||||
for vif in nw_info:
|
||||
for subnet in vif['network']['subnets']:
|
||||
cidr = subnet['cidr'].lower()
|
||||
if subnet['version'] == 4:
|
||||
# v4 cidr
|
||||
self.assertTrue(check_for_startswith(cidrs, cidr))
|
||||
# v4 address
|
||||
address = subnet['ips'][0]['address']
|
||||
self.assertTrue(check_for_startswith(addrs, address))
|
||||
else:
|
||||
# v6 cidr
|
||||
self.assertTrue(check_for_startswith(cidrs_v6, cidr))
|
||||
# v6 address
|
||||
address = subnet['ips'][0]['address']
|
||||
self.assertTrue(check_for_startswith(addrs_v6, address))
|
||||
|
||||
self.net_man.deallocate_for_instance(ctx,
|
||||
instance_id=instance_ref['id'],
|
||||
@@ -402,7 +413,7 @@ class QuantumNovaMACGenerationTestCase(QuantumNovaTestCase):
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
project_id=project_id,
|
||||
requested_networks=requested_networks)
|
||||
self.assertEqual(nw_info[0][1]['mac'], fake_mac)
|
||||
self.assertEqual(nw_info[0]['address'], fake_mac)
|
||||
|
||||
def test_melange_mac_address_creation(self):
|
||||
self.flags(use_melange_mac_generation=True)
|
||||
@@ -423,7 +434,7 @@ class QuantumNovaMACGenerationTestCase(QuantumNovaTestCase):
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
project_id=project_id,
|
||||
requested_networks=requested_networks)
|
||||
self.assertEqual(nw_info[0][1]['mac'], fake_mac)
|
||||
self.assertEqual(nw_info[0]['address'], fake_mac)
|
||||
|
||||
|
||||
class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase):
|
||||
@@ -460,7 +471,7 @@ class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase):
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
project_id=project_id,
|
||||
requested_networks=requested_networks)
|
||||
self.assertEqual(nw_info[0][1]['mac'], fake_mac)
|
||||
self.assertEqual(nw_info[0]['address'], fake_mac)
|
||||
|
||||
def test_port_securty_negative(self):
|
||||
self.flags(use_melange_mac_generation=True)
|
||||
@@ -494,4 +505,4 @@ class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase):
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
project_id=project_id,
|
||||
requested_networks=requested_networks)
|
||||
self.assertEqual(nw_info[0][1]['mac'], fake_mac)
|
||||
self.assertEqual(nw_info[0]['address'], fake_mac)
|
||||
|
||||
@@ -414,13 +414,8 @@ def usage_from_instance(instance_ref, network_info=None, **kw):
|
||||
state_description=instance_ref['task_state'] \
|
||||
if instance_ref['task_state'] else '')
|
||||
|
||||
# NOTE(jkoelker) This nastyness can go away once compute uses the
|
||||
# network model
|
||||
if network_info is not None:
|
||||
fixed_ips = []
|
||||
for network, info in network_info:
|
||||
fixed_ips.extend([ip['ip'] for ip in info['ips']])
|
||||
usage_info['fixed_ips'] = fixed_ips
|
||||
usage_info['fixed_ips'] = network_info.fixed_ips()
|
||||
|
||||
usage_info.update(kw)
|
||||
return usage_info
|
||||
|
||||
Reference in New Issue
Block a user