summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorTrey Morris <treyemorris@gmail.com>2012-01-09 11:52:53 -0600
committerTrey Morris <treyemorris@gmail.com>2012-02-01 13:29:14 -0600
commit73fd7abacd3bc5492b0335b3bb71c16b4a9d30e2 (patch)
tree571ee661373cfc18b1ca1135e2b8c36d6758c641 /nova/tests
parentfced0f58bcbaef6fff76c6719e27e7d100aa721b (diff)
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
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/ec2/test_cloud.py20
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py28
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py246
-rw-r--r--nova/tests/api/openstack/fakes.py19
-rw-r--r--nova/tests/fake_network.py89
-rw-r--r--nova/tests/fake_network_cache_model.py11
-rw-r--r--nova/tests/integrated/integrated_helpers.py1
-rw-r--r--nova/tests/integrated/test_servers.py5
-rw-r--r--nova/tests/test_compute.py49
-rw-r--r--nova/tests/test_metadata.py10
-rw-r--r--nova/tests/test_network_info.py32
-rw-r--r--nova/tests/test_quantum.py105
12 files changed, 297 insertions, 318 deletions
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index cb085e751..442a1d0d6 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -91,6 +91,10 @@ class CloudTestCase(test.TestCase):
self.flags(connection_type='fake',
stub_network=True)
+ def dumb(*args, **kwargs):
+ pass
+
+ self.stubs.Set(utils, 'usage_from_instance', dumb)
# set up our cloud
self.cloud = cloud.CloudController()
@@ -198,20 +202,15 @@ class CloudTestCase(test.TestCase):
{'host': self.network.host})
project_id = self.context.project_id
type_id = inst['instance_type_id']
- ips = self.network.allocate_for_instance(self.context,
+ nw_info = self.network.allocate_for_instance(self.context,
instance_id=inst['id'],
instance_uuid='',
host=inst['host'],
vpn=None,
instance_type_id=type_id,
project_id=project_id)
- # TODO(jkoelker) Make this mas bueno
- self.assertTrue(ips)
- self.assertTrue('ips' in ips[0][1])
- self.assertTrue(ips[0][1]['ips'])
- self.assertTrue('ip' in ips[0][1]['ips'][0])
- fixed = ips[0][1]['ips'][0]['ip']
+ fixed_ips = nw_info.fixed_ips()
ec2_id = ec2utils.id_to_ec2_id(inst['id'])
self.cloud.associate_address(self.context,
@@ -221,7 +220,7 @@ class CloudTestCase(test.TestCase):
public_ip=address)
self.cloud.release_address(self.context,
public_ip=address)
- self.network.deallocate_fixed_ip(self.context, fixed)
+ self.network.deallocate_fixed_ip(self.context, fixed_ips[0]['address'])
db.instance_destroy(self.context, inst['id'])
db.floating_ip_destroy(self.context, address)
@@ -1229,6 +1228,11 @@ class CloudTestCase(test.TestCase):
self.stubs.UnsetAll()
self.stubs.Set(fake._FakeImageService, 'show', fake_show)
+
+ def dumb(*args, **kwargs):
+ pass
+
+ self.stubs.Set(utils, 'usage_from_instance', dumb)
# NOTE(comstud): Make 'cast' behave like a 'call' which will
# ensure that operations complete
self.stubs.Set(rpc, 'cast', rpc.call)
diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
index a8dddf08f..2c94e385c 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -24,6 +24,7 @@ from nova import network
from nova import compute
from nova import rpc
from nova import test
+from nova.tests import fake_network
from nova.tests.api.openstack import fakes
from nova import utils
@@ -58,7 +59,7 @@ def network_api_get_floating_ips_by_project(self, context):
def compute_api_get(self, context, instance_id):
- return dict(uuid=FAKE_UUID)
+ return dict(uuid=FAKE_UUID, id=instance_id, instance_type_id=1, host='bob')
def network_api_allocate(self, context):
@@ -81,23 +82,6 @@ def network_api_disassociate(self, context, floating_address):
pass
-def network_get_instance_nw_info(self, context, instance):
- info = {
- 'label': 'fake',
- 'gateway': 'fake',
- 'dhcp_server': 'fake',
- 'broadcast': 'fake',
- 'mac': 'fake',
- 'vif_uuid': 'fake',
- 'rxtx_cap': 'fake',
- 'dns': [],
- 'ips': [{'ip': '10.0.0.1'}],
- 'should_create_bridge': False,
- 'should_create_vlan': False}
-
- return [['ignore', info]]
-
-
def fake_instance_get(context, instance_id):
return {
"id": 1,
@@ -137,8 +121,12 @@ class FloatingIpTest(test.TestCase):
network_api_release)
self.stubs.Set(network.api.API, "disassociate_floating_ip",
network_api_disassociate)
- self.stubs.Set(network.api.API, "get_instance_nw_info",
- network_get_instance_nw_info)
+
+ fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
+ spectacular=True)
+
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ spectacular=True)
self.stubs.Set(db, 'instance_get',
fake_instance_get)
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index c6c7fcc43..64693b4ec 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -39,6 +39,7 @@ import nova.image.fake
import nova.rpc
import nova.scheduler.api
from nova import test
+from nova.tests import fake_network
from nova.tests.api.openstack import fakes
from nova import utils
@@ -65,12 +66,13 @@ def fake_gen_uuid():
def return_server_by_id(context, id):
- return fakes.stub_instance(id)
+ return fakes.stub_instance(id, project_id='fake_project')
def return_server_by_uuid(context, uuid):
id = 1
- return fakes.stub_instance(id, uuid=uuid)
+ return fakes.stub_instance(id, uuid=uuid,
+ project_id='fake_project')
def return_server_with_attributes(**kwargs):
@@ -131,7 +133,8 @@ def return_servers_from_child_zones(*args, **kwargs):
for server_id in xrange(5):
server = Server()
server._info = fakes.stub_instance(
- server_id, reservation_id="child")
+ server_id, reservation_id="child",
+ project_id='fake_project')
servers_list.append(server)
zones.append(("Zone%d" % zone, servers_list))
@@ -165,11 +168,9 @@ class ServersControllerTest(test.TestCase):
self.maxDiff = None
super(ServersControllerTest, self).setUp()
self.flags(verbose=True, use_ipv6=False)
- fakes.stub_out_networking(self.stubs)
fakes.stub_out_rate_limiting(self.stubs)
fakes.stub_out_key_pair_funcs(self.stubs)
fakes.stub_out_image_service(self.stubs)
- fakes.stub_out_nw_api(self.stubs)
self.stubs.Set(nova.db, 'instance_get_all_by_filters',
return_servers)
self.stubs.Set(nova.db, 'instance_get', return_server_by_id)
@@ -186,13 +187,8 @@ class ServersControllerTest(test.TestCase):
self.controller = servers.Controller()
self.ips_controller = ips.Controller()
- def nw_info(*args, **kwargs):
- return []
-
- floaters = nw_info
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- floaters)
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ spectacular=True)
def test_get_server_by_uuid(self):
"""
@@ -229,11 +225,12 @@ class ServersControllerTest(test.TestCase):
uuid = FAKE_UUID
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % uuid)
res_dict = self.controller.show(req, uuid)
+
expected_server = {
"server": {
"id": uuid,
"user_id": "fake",
- "tenant_id": "fake",
+ "tenant_id": "fake_project",
"updated": "2010-11-11T11:00:00Z",
"created": "2010-10-10T12:00:00Z",
"progress": 0,
@@ -262,6 +259,10 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {
"seq": "1",
@@ -326,6 +327,10 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {
"seq": "1",
@@ -393,6 +398,10 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {
"seq": "1",
@@ -443,67 +452,13 @@ class ServersControllerTest(test.TestCase):
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
self.assertEqual(res_dict['server']['name'], 'server1')
- def test_get_server_by_id_with_addresses(self):
- self.flags(use_ipv6=True)
- privates = ['192.168.0.3', '192.168.0.4']
- publics = ['172.19.0.1', '172.19.0.2']
- public6s = ['b33f::fdee:ddff:fecc:bbaa']
-
- def nw_info(*args, **kwargs):
- return [(None, {'label': 'public',
- 'ips': [dict(ip=ip) for ip in publics],
- 'ip6s': [dict(ip=ip) for ip in public6s]}),
- (None, {'label': 'private',
- 'ips': [dict(ip=ip) for ip in privates]})]
-
- def floaters(*args, **kwargs):
- return []
-
- new_return_server = return_server_with_attributes()
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- floaters)
- self.stubs.Set(nova.db, 'instance_get', new_return_server)
-
- req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID)
- res_dict = self.controller.show(req, FAKE_UUID)
-
- self.assertEqual(res_dict['server']['id'], FAKE_UUID)
- self.assertEqual(res_dict['server']['name'], 'server1')
- addresses = res_dict['server']['addresses']
- expected = {
- 'private': [
- {'addr': '192.168.0.3', 'version': 4},
- {'addr': '192.168.0.4', 'version': 4},
- ],
- 'public': [
- {'addr': '172.19.0.1', 'version': 4},
- {'addr': '172.19.0.2', 'version': 4},
- {'addr': 'b33f::fdee:ddff:fecc:bbaa', 'version': 6},
- ],
- }
- self.assertDictMatch(addresses, expected)
-
- def test_get_server_addresses_from_nwinfo(self):
+ def test_get_server_addresses_from_nw_info(self):
self.flags(use_ipv6=True)
- privates = ['192.168.0.3', '192.168.0.4']
- publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
-
- public6s = ['b33f::fdee:ddff:fecc:bbaa']
-
- def nw_info(*args, **kwargs):
- return [(None, {'label': 'public',
- 'ips': [dict(ip=ip) for ip in publics],
- 'ip6s': [dict(ip=ip) for ip in public6s]}),
- (None, {'label': 'private',
- 'ips': [dict(ip=ip) for ip in privates]})]
-
- def floaters(*args, **kwargs):
- return []
-
new_return_server = return_server_with_attributes_by_uuid()
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, nw_info)
+ fake_network.fake_get_instance_nw_info(self.stubs, num_networks=2,
+ spectacular=True)
+ floaters = []
fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
floaters)
self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
@@ -513,16 +468,10 @@ class ServersControllerTest(test.TestCase):
expected = {
'addresses': {
- 'private': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 4, 'addr': '192.168.0.4'},
- ],
- 'public': [
- {'version': 4, 'addr': '172.19.0.1'},
- {'version': 4, 'addr': '1.2.3.4'},
- {'version': 4, 'addr': '172.19.0.2'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
}
self.assertDictMatch(res_dict, expected)
@@ -580,39 +529,21 @@ class ServersControllerTest(test.TestCase):
self.assertDictMatch(res_dict, expected)
def test_get_server_addresses_with_floating_from_nwinfo(self):
- ips = dict(privates=['192.168.0.3', '192.168.0.4'],
- publics=['172.19.0.1', '1.2.3.4', '172.19.0.2'])
-
- def nw_info(*args, **kwargs):
- return [(None, {'label': 'private',
- 'ips': [dict(ip=ip)
- for ip in ips['privates']]})]
-
- def floaters(*args, **kwargs):
- # NOTE(jkoelker) floaters will get called multiple times
- # this makes sure it will only return data
- # once
- pubs = list(ips['publics'])
- ips['publics'] = []
- return pubs
-
new_return_server = return_server_with_attributes_by_uuid()
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- floaters)
self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ floating_ips_per_fixed_ip=1,
+ spectacular=True)
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/ips' % FAKE_UUID)
res_dict = self.ips_controller.index(req, FAKE_UUID)
expected = {
'addresses': {
- 'private': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 4, 'addr': '192.168.0.4'},
- {'version': 4, 'addr': '172.19.0.1'},
- {'version': 4, 'addr': '1.2.3.4'},
- {'version': 4, 'addr': '172.19.0.2'},
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'},
+ {'version': 4, 'addr': '10.10.10.100'},
],
},
}
@@ -620,37 +551,25 @@ class ServersControllerTest(test.TestCase):
def test_get_server_addresses_single_network_from_nwinfo(self):
self.flags(use_ipv6=True)
- privates = ['192.168.0.3', '192.168.0.4']
- publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
- public6s = ['b33f::fdee:ddff:fecc:bbaa']
-
- def nw_info(*args, **kwargs):
- return [(None, {'label': 'public',
- 'ips': [dict(ip=ip) for ip in publics],
- 'ip6s': [dict(ip=ip) for ip in public6s]}),
- (None, {'label': 'private',
- 'ips': [dict(ip=ip) for ip in privates]})]
def floaters(*args, **kwargs):
return []
new_return_server = return_server_with_attributes_by_uuid()
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, nw_info)
+ fake_network.fake_get_instance_nw_info(self.stubs, num_networks=1)
fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
floaters)
self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
- url = '/v2/fake/servers/%s/ips/public' % FAKE_UUID
+ url = '/v2/fake/servers/%s/ips/test0' % FAKE_UUID
req = fakes.HTTPRequest.blank(url)
- res_dict = self.ips_controller.show(req, FAKE_UUID, 'public')
+ res_dict = self.ips_controller.show(req, FAKE_UUID, 'test0')
expected = {
- 'public': [
- {'version': 4, 'addr': '172.19.0.1'},
- {'version': 4, 'addr': '1.2.3.4'},
- {'version': 4, 'addr': '172.19.0.2'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
}
self.assertDictMatch(res_dict, expected)
@@ -1215,7 +1134,8 @@ class ServersControllerTest(test.TestCase):
def test_rebuild_instance_with_access_ipv6_bad_format(self):
def fake_get_instance(*args, **kwargs):
- return fakes.stub_instance(1, vm_state=vm_states.ACTIVE)
+ return fakes.stub_instance(1, vm_state=vm_states.ACTIVE,
+ project_id='fake_project')
self.stubs.Set(nova.db, 'instance_get', fake_get_instance)
# proper local hrefs must start with 'http://localhost/v2/'
@@ -1493,7 +1413,6 @@ class ServersControllerCreateTest(test.TestCase):
def queue_get_for(context, *args):
return 'network_topic'
- fakes.stub_out_networking(self.stubs)
fakes.stub_out_rate_limiting(self.stubs)
fakes.stub_out_key_pair_funcs(self.stubs)
fakes.stub_out_image_service(self.stubs)
@@ -2672,13 +2591,10 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {},
"config_drive": None,
@@ -2744,13 +2660,10 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {},
"config_drive": None,
@@ -2824,13 +2737,10 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {},
"config_drive": None,
@@ -2891,13 +2801,10 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {},
"config_drive": None,
@@ -2956,13 +2863,10 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
- ],
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ ]
},
"metadata": {},
"config_drive": None,
@@ -3023,12 +2927,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
]
},
"metadata": {},
@@ -3095,12 +2996,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'private': [
- {'version': 4, 'addr': '172.19.0.1'}
- ],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ 'test0': [
+ {'version': 4, 'addr': '192.168.0.100'},
+ {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
]
},
"metadata": {
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index b5966b460..358ca414d 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -40,6 +40,7 @@ from nova import context
from nova.db.sqlalchemy import models
from nova import exception as exc
import nova.image.fake
+from nova.tests import fake_network
from nova.tests.glance import stubs as glance_stubs
from nova import utils
from nova import wsgi
@@ -180,15 +181,9 @@ class stub_out_compute_api_backup(object):
return dict(id='123', status='ACTIVE', name=name, properties=props)
-def stub_out_nw_api_get_instance_nw_info(stubs, func=None):
- def get_instance_nw_info(self, context, instance):
- return [(None, {'label': 'public',
- 'ips': [{'ip': '192.168.0.3'}],
- 'ip6s': []})]
-
- if func is None:
- func = get_instance_nw_info
- stubs.Set(nova.network.API, 'get_instance_nw_info', func)
+def stub_out_nw_api_get_instance_nw_info(stubs, num_networks=1, func=None):
+ fake_network.stub_out_nw_api_get_instance_nw_info(stubs,
+ spectacular=True)
def stub_out_nw_api_get_floating_ips_by_fixed_address(stubs, func=None):
@@ -208,8 +203,7 @@ def stub_out_nw_api(stubs, cls=None, private=None, publics=None):
class Fake:
def get_instance_nw_info(*args, **kwargs):
- return [(None, {'label': 'private',
- 'ips': [{'ip': private}]})]
+ pass
def get_floating_ips_by_fixed_address(*args, **kwargs):
return publics
@@ -217,6 +211,7 @@ def stub_out_nw_api(stubs, cls=None, private=None, publics=None):
if cls is None:
cls = Fake
stubs.Set(nova.network, 'API', cls)
+ fake_network.stub_out_nw_api_get_instance_nw_info(stubs, spectacular=True)
def _make_image_fixtures():
@@ -473,7 +468,6 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
auto_disk_config=False, display_name=None,
include_fake_metadata=True,
power_state=None, nw_cache=None):
-
if include_fake_metadata:
metadata = [models.InstanceMetadata(key='seq', value=id)]
else:
@@ -518,6 +512,7 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
"ephemeral_gb": 0,
"hostname": "",
"host": host,
+ "instance_type_id": 1,
"instance_type": dict(inst_type),
"user_data": "",
"reservation_id": reservation_id,
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py
index 2c950c143..08712a302 100644
--- a/nova/tests/fake_network.py
+++ b/nova/tests/fake_network.py
@@ -20,7 +20,10 @@ from nova import db
from nova import exception
from nova import flags
from nova import utils
+import nova.compute.utils
from nova.network import manager as network_manager
+from nova.network.quantum import nova_ipam_lib
+from nova.tests import fake_network_cache_model
HOST = "testhost"
@@ -199,7 +202,6 @@ def vifs(n):
'address': 'DE:AD:BE:EF:00:%02x' % x,
'uuid': '00000000-0000-0000-0000-00000000000000%02d' % x,
'network_id': x,
- 'network': FakeModel(**fake_network(x)),
'instance_id': 0}
@@ -253,7 +255,8 @@ def ipv4_like(ip, match_string):
def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
- floating_ips_per_fixed_ip=0):
+ floating_ips_per_fixed_ip=0,
+ spectacular=False):
# stubs is the self.stubs from the test
# ips_per_vif is the number of ips each vif will have
# num_floating_ips is number of float ips for each fixed ip
@@ -261,22 +264,37 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
network.db = db
# reset the fixed and floating ip generators
- global floating_ip_id, fixed_ip_id
+ global floating_ip_id, fixed_ip_id, fixed_ips
floating_ip_id = floating_ip_ids()
fixed_ip_id = fixed_ip_ids()
+ fixed_ips = []
networks = [fake_network(x) for x in xrange(num_networks)]
def fixed_ips_fake(*args, **kwargs):
- return [next_fixed_ip(i, floating_ips_per_fixed_ip)
- for i in xrange(num_networks) for j in xrange(ips_per_vif)]
-
- def floating_ips_fake(*args, **kwargs):
+ global fixed_ips
+ ips = [next_fixed_ip(i, floating_ips_per_fixed_ip)
+ for i in xrange(num_networks) for j in xrange(ips_per_vif)]
+ fixed_ips = ips
+ return ips
+
+ def floating_ips_fake(context, address):
+ for ip in fixed_ips:
+ if address == ip['address']:
+ return ip['floating_ips']
return []
def virtual_interfaces_fake(*args, **kwargs):
return [vif for vif in vifs(num_networks)]
+ def vif_by_uuid_fake(context, uuid):
+ return {'id': 1,
+ 'address': 'DE:AD:BE:EF:00:01',
+ 'uuid': uuid,
+ 'network_id': 1,
+ 'network': None,
+ 'instance_id': 0}
+
def instance_type_fake(*args, **kwargs):
return flavor
@@ -289,25 +307,68 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
def update_cache_fake(*args, **kwargs):
pass
+ def get_subnets_by_net_id(self, context, project_id, network_uuid,
+ vif_uuid):
+ subnet_v4 = dict(
+ cidr='192.168.0.0/24',
+ dns1='1.2.3.4',
+ dns2='2.3.4.5',
+ gateway='192.168.0.1')
+
+ subnet_v6 = dict(
+ cidr='fe80::/64',
+ gateway='fe80::def')
+ return [subnet_v4, subnet_v6]
+
+ def get_network_by_uuid(context, uuid):
+ return dict(id=1,
+ cidr_v6='fe80::/64',
+ bridge='br0',
+ label='public')
+
+ def get_v4_fake(*args, **kwargs):
+ ips = fixed_ips_fake(*args, **kwargs)
+ return [ip['address'] for ip in ips]
+
stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
stubs.Set(db, 'floating_ip_get_by_fixed_address', floating_ips_fake)
+ stubs.Set(db, 'virtual_interface_get_by_uuid', vif_by_uuid_fake)
+ stubs.Set(db, 'network_get_by_uuid', get_network_by_uuid)
stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake)
stubs.Set(db, 'instance_type_get', instance_type_fake)
stubs.Set(db, 'network_get', network_get_fake)
stubs.Set(db, 'instance_info_cache_update', update_cache_fake)
- context = nova.context.RequestContext('testuser', 'testproject',
- is_admin=False)
- return network.get_instance_nw_info(context, 0, 0, 0, None)
+ stubs.Set(nova_ipam_lib.QuantumNovaIPAMLib, 'get_subnets_by_net_id',
+ get_subnets_by_net_id)
+ stubs.Set(nova_ipam_lib.QuantumNovaIPAMLib, 'get_v4_ips_by_interface',
+ get_v4_fake)
+ class FakeContext(nova.context.RequestContext):
+ def is_admin(self):
+ return True
+
+ nw_model = network.get_instance_nw_info(
+ FakeContext('fakeuser', 'fake_project'),
+ 0, 0, 0, None)
+ if spectacular:
+ return nw_model
+ return nova.compute.utils.legacy_network_info(nw_model)
-def stub_out_nw_api_get_instance_nw_info(stubs, func=None):
+
+def stub_out_nw_api_get_instance_nw_info(stubs, func=None,
+ num_networks=1,
+ ips_per_vif=1,
+ floating_ips_per_fixed_ip=0,
+ spectacular=False):
import nova.network
def get_instance_nw_info(self, context, instance):
- return [(None, {'label': 'public',
- 'ips': [{'ip': '192.168.0.3'}],
- 'ip6s': []})]
+ return fake_get_instance_nw_info(stubs, num_networks=num_networks,
+ ips_per_vif=ips_per_vif,
+ floating_ips_per_fixed_ip=floating_ips_per_fixed_ip,
+ spectacular=spectacular)
+
if func is None:
func = get_instance_nw_info
stubs.Set(nova.network.API, 'get_instance_nw_info', func)
diff --git a/nova/tests/fake_network_cache_model.py b/nova/tests/fake_network_cache_model.py
index c85b1b025..32ace8bdc 100644
--- a/nova/tests/fake_network_cache_model.py
+++ b/nova/tests/fake_network_cache_model.py
@@ -38,14 +38,13 @@ def new_route(route_dict=None):
def new_subnet(subnet_dict=None):
new_subnet = dict(
- cidr='255.255.255.0',
+ cidr='10.10.0.0/24',
dns=[new_ip(dict(address='1.2.3.4')),
new_ip(dict(address='2.3.4.5'))],
- gateway=new_ip(dict(address='192.168.1.1')),
- ips=[new_ip(dict(address='192.168.1.100')),
- new_ip(dict(address='192.168.1.101'))],
- routes=[new_route()],
- version=4)
+ gateway=new_ip(dict(address='10.10.0.1')),
+ ips=[new_ip(dict(address='10.10.0.2')),
+ new_ip(dict(address='10.10.0.3'))],
+ routes=[new_route()])
subnet_dict = subnet_dict or {}
new_subnet.update(subnet_dict)
return model.Subnet(**new_subnet)
diff --git a/nova/tests/integrated/integrated_helpers.py b/nova/tests/integrated/integrated_helpers.py
index a98c94f65..6cacb8da8 100644
--- a/nova/tests/integrated/integrated_helpers.py
+++ b/nova/tests/integrated/integrated_helpers.py
@@ -134,5 +134,4 @@ class _IntegratedTestBase(test.TestCase):
# Set a valid server name
server_name = self.get_unused_server_name()
server['name'] = server_name
-
return server
diff --git a/nova/tests/integrated/test_servers.py b/nova/tests/integrated/test_servers.py
index 42deee413..810461f66 100644
--- a/nova/tests/integrated/test_servers.py
+++ b/nova/tests/integrated/test_servers.py
@@ -29,10 +29,10 @@ LOG = logging.getLogger('nova.tests.integrated')
class ServersTest(integrated_helpers._IntegratedTestBase):
- def _wait_for_state_change(self, server, status):
+ def _wait_for_state_change(self, server, from_status):
for i in xrange(0, 50):
server = self.api.get_server(server['id'])
- if server['status'] != status:
+ if server['status'] != from_status:
break
time.sleep(.1)
@@ -129,7 +129,6 @@ class ServersTest(integrated_helpers._IntegratedTestBase):
self.assertTrue(created_server_id in server_ids)
found_server = self._wait_for_state_change(found_server, 'BUILD')
-
# It should be available...
# TODO(justinsb): Mock doesn't yet do this...
self.assertEqual('ACTIVE', found_server['status'])
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 10f01c1a7..0ce9a4ea5 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -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']
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index ff6720312..1e6d44581 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -61,12 +61,6 @@ class MetadataTestCase(test.TestCase):
'root_device_name': '/dev/sda1',
'hostname': 'test'})
- def fake_get_instance_nw_info(self, context, instance):
- return [(None, {'label': 'public',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': [{'ip': 'fe80::beef'}]})]
-
def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip):
return ['1.2.3.4', '5.6.7.8']
@@ -76,8 +70,8 @@ class MetadataTestCase(test.TestCase):
def instance_get_list(*args, **kwargs):
return [self.instance]
- self.stubs.Set(network.API, 'get_instance_nw_info',
- fake_get_instance_nw_info)
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ spectacular=True)
self.stubs.Set(network.API, 'get_floating_ips_by_fixed_address',
fake_get_floating_ips_by_fixed_address)
self.stubs.Set(api, 'instance_get', instance_get)
diff --git a/nova/tests/test_network_info.py b/nova/tests/test_network_info.py
index 7627c29f6..83fea8a64 100644
--- a/nova/tests/test_network_info.py
+++ b/nova/tests/test_network_info.py
@@ -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)
diff --git a/nova/tests/test_quantum.py b/nova/tests/test_quantum.py
index bd35454ab..32f30fbf6 100644
--- a/nova/tests/test_quantum.py
+++ b/nova/tests/test_quantum.py
@@ -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)
- # 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."))
+ cidrs = ['10.', '192.']
+ addrs = ['10.', '192.']
+ cidrs_v6 = ['2001:1dba:', '2001:1db8:']
+ addrs_v6 = ['2001:1dba:', '2001:1db8:']
- # 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:"))
+ def check_for_startswith(choices, choice):
+ for v in choices:
+ if choice.startswith(v):
+ choices.remove(v)
+ return True
+ return False
- # 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:"))
+ # we don't know which order the NICs will be in until we
+ # introduce the notion of priority
+ 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)