summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2012-01-04 11:10:10 -0600
committerJason Kölker <jason@koelker.net>2012-01-16 10:52:56 -0600
commitbb867ce3948ddc23cf928ca3dda100a1a977896a (patch)
tree2931f3ea721e452bed8304fd192024394972b602 /nova/tests
parent46f90f7cb79a01104376919c56e70a6324fe89af (diff)
Implement BP untie-nova-network-models
Fixes LP853979 Remove the FK references for network data. Remove unused db functions that used the FK's Update db functions to not joinload Update notification to optionally take network_info if compute has it Update EC2 Api to use the network cache, falling back to rpc.call Remove test_instance_get_project_vpn_joins which tests calls not used Change-Id: I1a01ccc5ebcf7efeafe014af62be893325bb0825
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/ec2/test_cloud.py53
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py45
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py248
-rw-r--r--nova/tests/api/openstack/fakes.py50
-rw-r--r--nova/tests/db/fakes.py8
-rw-r--r--nova/tests/fake_network.py67
-rw-r--r--nova/tests/test_compute_utils.py2
-rw-r--r--nova/tests/test_db_api.py13
-rw-r--r--nova/tests/test_libvirt.py11
-rw-r--r--nova/tests/test_linux_net.py99
-rw-r--r--nova/tests/test_metadata.py4
-rw-r--r--nova/tests/test_network.py61
-rw-r--r--nova/tests/test_xenapi.py9
-rw-r--r--nova/tests/vmwareapi/db_fakes.py6
14 files changed, 411 insertions, 265 deletions
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index d4e4d7d1a..ffdb74c8c 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -58,32 +58,42 @@ class AjaxProxyManager(manager.SchedulerDependentManager):
return None
-def get_fake_fixed_ips():
- vif = {'address': 'aa:bb:cc:dd:ee:ff'}
- network = {'label': 'private',
- 'project_id': 'fake',
- 'cidr_v6': 'fe80:b33f::/64'}
- floating_ips = [{'address': '1.2.3.4'},
- {'address': '5.6.7.8'}]
- fixed_ip1 = {'address': '192.168.0.3',
- 'floating_ips': floating_ips,
- 'virtual_interface': vif,
- 'network': network}
- fixed_ip2 = {'address': '192.168.0.4',
- 'network': network}
- return [fixed_ip1, fixed_ip2]
-
-
-def get_instances_with_fixed_ips(orig_func, *args, **kwargs):
- """Kludge fixed_ips into instance(s) without having to create DB
+def get_fake_cache():
+ def _ip(ip, fixed=True, floats=None):
+ ip_dict = {'address': ip, 'type': 'fixed'}
+ if not fixed:
+ ip_dict['type'] = 'floating'
+ if fixed and floats:
+ ip_dict['floating_ips'] = [_ip(f, fixed=False) for f in floats]
+ return ip_dict
+
+ info = [{'address': 'aa:bb:cc:dd:ee:ff',
+ 'id': 1,
+ 'network': {'bridge': 'br0',
+ 'id': 1,
+ 'label': 'private',
+ 'subnets': [{'cidr': '192.168.0.0/24',
+ 'ips': [_ip('192.168.0.3',
+ floats=['1.2.3.4',
+ '5.6.7.8']),
+ _ip('192.168.0.4')]}]}}]
+ if FLAGS.use_ipv6:
+ ipv6_addr = 'fe80:b33f::a8bb:ccff:fedd:eeff'
+ info[0]['network']['subnets'].append({'cidr': 'fe80:b33f::/64',
+ 'ips': [_ip(ipv6_addr)]})
+ return info
+
+
+def get_instances_with_cached_ips(orig_func, *args, **kwargs):
+ """Kludge the cache into instance(s) without having to create DB
entries
"""
instances = orig_func(*args, **kwargs)
if isinstance(instances, list):
for instance in instances:
- instance['fixed_ips'] = get_fake_fixed_ips()
+ instance['info_cache'] = {'network_info': get_fake_cache()}
else:
- instances['fixed_ips'] = get_fake_fixed_ips()
+ instances['info_cache'] = {'network_info': get_fake_cache()}
return instances
@@ -136,7 +146,7 @@ class CloudTestCase(test.TestCase):
orig_func = getattr(self.cloud.compute_api, func_name)
def fake_get(*args, **kwargs):
- return get_instances_with_fixed_ips(orig_func, *args, **kwargs)
+ return get_instances_with_cached_ips(orig_func, *args, **kwargs)
self.stubs.Set(self.cloud.compute_api, func_name, fake_get)
def _create_key(self, name):
@@ -177,7 +187,6 @@ class CloudTestCase(test.TestCase):
def test_release_address(self):
address = "10.10.10.10"
- allocate = self.cloud.allocate_address
db.floating_ip_create(self.context,
{'address': address,
'pool': 'nova',
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 fe5444419..27c980f00 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -21,6 +21,7 @@ from nova.api.openstack.compute.contrib import floating_ips
from nova import context
from nova import db
from nova import network
+from nova import compute
from nova import rpc
from nova import test
from nova.tests.api.openstack import fakes
@@ -29,28 +30,35 @@ from nova import utils
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+def network_api_get_fixed_ip(self, context, id):
+ if id is None:
+ return None
+ return {'address': '10.0.0.1', 'id': id, 'instance_id': 1}
+
+
def network_api_get_floating_ip(self, context, id):
- return {'id': 1, 'address': '10.10.10.10',
- 'pool': 'nova',
- 'fixed_ip': None}
+ return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
+ 'fixed_ip_id': None}
def network_api_get_floating_ip_by_address(self, context, address):
- return {'id': 1, 'address': '10.10.10.10',
- 'pool': 'nova',
- 'fixed_ip': {'address': '10.0.0.1',
- 'instance': {'uuid': FAKE_UUID}}}
+ return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
+ 'fixed_ip_id': 10}
def network_api_get_floating_ips_by_project(self, context):
return [{'id': 1,
'address': '10.10.10.10',
'pool': 'nova',
- 'fixed_ip': {'address': '10.0.0.1',
- 'instance': {'uuid': FAKE_UUID}}},
+ 'fixed_ip_id': 20},
{'id': 2,
'pool': 'nova', 'interface': 'eth0',
- 'address': '10.10.10.11'}]
+ 'address': '10.10.10.11',
+ 'fixed_ip_id': None}]
+
+
+def compute_api_get(self, context, instance_id):
+ return dict(uuid=FAKE_UUID)
def network_api_allocate(self, context):
@@ -120,6 +128,10 @@ class FloatingIpTest(test.TestCase):
def setUp(self):
super(FloatingIpTest, self).setUp()
+ self.stubs.Set(network.api.API, "get_fixed_ip",
+ network_api_get_fixed_ip)
+ self.stubs.Set(compute.api.API, "get",
+ compute_api_get)
self.stubs.Set(network.api.API, "get_floating_ip",
network_api_get_floating_ip)
self.stubs.Set(network.api.API, "get_floating_ip_by_address",
@@ -149,6 +161,8 @@ class FloatingIpTest(test.TestCase):
floating_ip_address = self._create_floating_ip()
floating_ip = db.floating_ip_get_by_address(self.context,
floating_ip_address)
+ floating_ip['fixed_ip'] = None
+ floating_ip['instance'] = None
view = floating_ips._translate_floating_ip_view(floating_ip)
self.assertTrue('floating_ip' in view)
self.assertTrue(view['floating_ip']['id'])
@@ -188,11 +202,14 @@ class FloatingIpTest(test.TestCase):
def test_show_associated_floating_ip(self):
def get_floating_ip(self, context, id):
- return {'id': 1, 'address': '10.10.10.10',
- 'pool': 'nova',
- 'fixed_ip': {'address': '10.0.0.1',
- 'instance': {'uuid': FAKE_UUID}}}
+ return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova',
+ 'fixed_ip_id': 11}
+
+ def get_fixed_ip(self, context, id):
+ return {'address': '10.0.0.1', 'instance_id': 1}
+
self.stubs.Set(network.api.API, "get_floating_ip", get_floating_ip)
+ self.stubs.Set(network.api.API, "get_fixed_ip", get_fixed_ip)
req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/1')
res_dict = self.controller.show(req, 1)
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 77c89d47d..80ac9baa6 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -102,11 +102,11 @@ def return_server_with_uuid_and_state(vm_state, task_state):
def return_servers(context, *args, **kwargs):
- servers = []
+ servers_list = []
for i in xrange(5):
server = fakes.stub_instance(i, 'fake', 'fake', uuid=get_fake_uuid(i))
- servers.append(server)
- return servers
+ servers_list.append(server)
+ return servers_list
def return_servers_by_reservation(context, reservation_id=""):
@@ -127,14 +127,14 @@ def return_servers_from_child_zones(*args, **kwargs):
zones = []
for zone in xrange(3):
- servers = []
+ servers_list = []
for server_id in xrange(5):
server = Server()
server._info = fakes.stub_instance(
server_id, reservation_id="child")
- servers.append(server)
+ servers_list.append(server)
- zones.append(("Zone%d" % zone, servers))
+ zones.append(("Zone%d" % zone, servers_list))
return zones
@@ -146,10 +146,6 @@ def instance_update(context, instance_id, values):
return fakes.stub_instance(instance_id, name=values.get('display_name'))
-def instance_addresses(context, instance_id):
- return None
-
-
def fake_compute_api(cls, req, id):
return True
@@ -188,16 +184,20 @@ class ServersControllerTest(test.TestCase):
self.stubs.Set(nova.db, 'instance_add_security_group',
return_security_group)
self.stubs.Set(nova.db, 'instance_update', instance_update)
- self.stubs.Set(nova.db, 'instance_get_fixed_addresses',
- instance_addresses)
- self.stubs.Set(nova.db, 'instance_get_floating_address',
- instance_addresses)
self.config_drive = None
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)
+
def test_get_server_by_uuid(self):
"""
The steps involved with resolving a UUID are pretty complicated;
@@ -451,8 +451,22 @@ class ServersControllerTest(test.TestCase):
self.flags(use_ipv6=True)
privates = ['192.168.0.3', '192.168.0.4']
publics = ['172.19.0.1', '172.19.0.2']
- new_return_server = return_server_with_attributes(
- public_ips=publics, private_ips=privates)
+ 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)
@@ -467,46 +481,35 @@ class ServersControllerTest(test.TestCase):
{'addr': '192.168.0.4', 'version': 4},
],
'public': [
- {'addr': 'b33f::fdee:ddff:fecc:bbaa', 'version': 6},
{'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_by_id_with_addresses_ipv6_disabled(self):
- # ipv6 flag is off by default
+ def test_get_server_addresses_from_nwinfo(self):
+ self.flags(use_ipv6=True)
+
privates = ['192.168.0.3', '192.168.0.4']
- publics = ['172.19.0.1', '172.19.0.2']
- new_return_server = return_server_with_attributes(
- public_ips=publics, private_ips=privates)
- self.stubs.Set(nova.db, 'instance_get', new_return_server)
+ publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
- req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID)
- res_dict = self.controller.show(req, FAKE_UUID)
+ public6s = ['b33f::fdee:ddff:fecc:bbaa']
- 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},
- ],
- }
- self.assertDictMatch(addresses, expected)
+ 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 test_get_server_addresses(self):
- self.flags(use_ipv6=True)
+ def floaters(*args, **kwargs):
+ return []
- privates = ['192.168.0.3', '192.168.0.4']
- publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
- new_return_server = return_server_with_attributes_by_uuid(
- public_ips=publics, private_ips=privates)
+ 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)
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/ips' % FAKE_UUID)
@@ -519,21 +522,88 @@ class ServersControllerTest(test.TestCase):
{'version': 4, 'addr': '192.168.0.4'},
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'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'},
],
},
}
self.assertDictMatch(res_dict, expected)
- def test_get_server_addresses_with_floating(self):
- privates = ['192.168.0.3', '192.168.0.4']
- publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
- new_return_server = return_server_with_attributes_by_uuid(
- public_ips=publics, private_ips=privates,
- public_ips_are_floating=True)
+ def test_get_server_addresses_from_cache(self):
+ pub0 = ('172.19.0.1', '172.19.0.2',)
+ pub1 = ('1.2.3.4',)
+ pub2 = ('b33f::fdee:ddff:fecc:bbaa',)
+ priv0 = ('192.168.0.3', '192.168.0.4',)
+
+ def _ip(ip):
+ return {'address': ip, 'type': 'fixed'}
+
+ nw_cache = [
+ {'address': 'aa:aa:aa:aa:aa:aa',
+ 'id': 1,
+ 'network': {'bridge': 'br0',
+ 'id': 1,
+ 'label': 'public',
+ 'subnets': [{'cidr': '172.19.0.0/24',
+ 'ips': [_ip(ip) for ip in pub0]},
+ {'cidr': '1.2.3.0/16',
+ 'ips': [_ip(ip) for ip in pub1]},
+ {'cidr': 'b33f::/64',
+ 'ips': [_ip(ip) for ip in pub2]}]}},
+ {'address': 'bb:bb:bb:bb:bb:bb',
+ 'id': 2,
+ 'network': {'bridge': 'br1',
+ 'id': 2,
+ 'label': 'private',
+ 'subnets': [{'cidr': '192.168.0.0/24',
+ 'ips': [_ip(ip) for ip in priv0]}]}}]
+
+ kwargs = {'nw_cache': nw_cache}
+ new_return_server = return_server_with_attributes_by_uuid(**kwargs)
+ self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
+
+ 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'},
+ ],
+ 'public': [
+ {'version': 4, 'addr': '172.19.0.1'},
+ {'version': 4, 'addr': '172.19.0.2'},
+ {'version': 4, 'addr': '1.2.3.4'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ ],
+ },
+ }
+ 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)
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/ips' % FAKE_UUID)
@@ -552,12 +622,26 @@ class ServersControllerTest(test.TestCase):
}
self.assertDictMatch(res_dict, expected)
- def test_get_server_addresses_single_network(self):
+ 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']
- new_return_server = return_server_with_attributes_by_uuid(
- public_ips=publics, private_ips=privates)
+ 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)
+ 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
@@ -566,10 +650,10 @@ class ServersControllerTest(test.TestCase):
expected = {
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'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'},
],
}
self.assertDictMatch(res_dict, expected)
@@ -1523,24 +1607,6 @@ class ServersControllerCreateTest(test.TestCase):
flavor_ref = 'http://localhost/fake/flavors/3'
access_ipv4 = '1.2.3.4'
access_ipv6 = 'fead::1234'
- expected_flavor = {
- "id": "3",
- "links": [
- {
- "rel": "bookmark",
- "href": 'http://localhost/fake/flavors/3',
- },
- ],
- }
- expected_image = {
- "id": image_uuid,
- "links": [
- {
- "rel": "bookmark",
- "href": 'http://localhost/fake/images/%s' % image_uuid,
- },
- ],
- }
body = {
'server': {
'name': 'server_test',
@@ -2390,10 +2456,26 @@ class ServersViewBuilderTest(test.TestCase):
image_ref="5",
uuid="deadbeef-feed-edee-beef-d0ea7beefedd",
display_name="test_server",
- public_ips=["192.168.0.3"],
- private_ips=["172.19.0.1"],
include_fake_metadata=False)
+ privates = ['172.19.0.1']
+ publics = ['192.168.0.3']
+ 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 []
+
+ 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.uuid = self.instance['uuid']
self.view_builder = views.servers.ViewBuilder()
self.request = fakes.HTTPRequest.blank("/v2")
@@ -2485,8 +2567,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
],
},
"metadata": {},
@@ -2557,8 +2639,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
],
},
"metadata": {},
@@ -2637,8 +2719,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
],
},
"metadata": {},
@@ -2704,8 +2786,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
],
},
"metadata": {},
@@ -2769,8 +2851,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
],
},
"metadata": {},
@@ -2836,8 +2918,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
]
},
"metadata": {},
@@ -2908,8 +2990,8 @@ class ServersViewBuilderTest(test.TestCase):
{'version': 4, 'addr': '172.19.0.1'}
],
'public': [
- {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '192.168.0.3'},
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
]
},
"metadata": {
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 9fa1749ef..728b180a8 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -466,35 +466,14 @@ class FakeRateLimiter(object):
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
-def create_fixed_ips(project_id, publics, privates, publics_are_floating):
- if publics is None:
- publics = []
- if privates is None:
- privates = []
-
- fixed_ips = []
- private_vif = dict(address='aa:bb:cc:dd:ee:ff')
- private_net = dict(label='private', project_id=project_id, cidr_v6=None)
-
- for private in privates:
- entry = dict(address=private, network=private_net,
- virtual_interface=private_vif, floating_ips=[])
- if publics_are_floating:
- for public in publics:
- entry['floating_ips'].append(dict(address=public))
- # Only add them once
- publics = []
- fixed_ips.append(entry)
-
- if not publics_are_floating:
- public_vif = dict(address='ff:ee:dd:cc:bb:aa')
- public_net = dict(label='public', project_id=project_id,
- cidr_v6='b33f::/64')
- for public in publics:
- entry = dict(address=public, network=public_net,
- virtual_interface=public_vif, floating_ips=[])
- fixed_ips.append(entry)
- return fixed_ips
+def create_info_cache(nw_cache):
+ if nw_cache is None:
+ return {}
+
+ if not isinstance(nw_cache, basestring):
+ nw_cache = utils.dumps(nw_cache)
+
+ return {"info_cache": {"network_info": nw_cache}}
def stub_instance(id, user_id='fake', project_id='fake', host=None,
@@ -502,10 +481,9 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
reservation_id="", uuid=FAKE_UUID, image_ref="10",
flavor_id="1", name=None, key_name='',
access_ipv4=None, access_ipv6=None, progress=0,
- auto_disk_config=False, public_ips=None, private_ips=None,
- public_ips_are_floating=False, display_name=None,
+ auto_disk_config=False, display_name=None,
include_fake_metadata=True,
- power_state=None):
+ power_state=None, nw_cache=None):
if include_fake_metadata:
metadata = [models.InstanceMetadata(key='seq', value=id)]
@@ -522,14 +500,13 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
else:
key_data = ''
- fixed_ips = create_fixed_ips(project_id, public_ips, private_ips,
- public_ips_are_floating)
-
# ReservationID isn't sent back, hack it in there.
server_name = name or "server%s" % id
if reservation_id != "":
server_name = "reservation_%s" % (reservation_id, )
+ info_cache = create_info_cache(nw_cache)
+
instance = {
"id": int(id),
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
@@ -569,8 +546,9 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
"progress": progress,
"auto_disk_config": auto_disk_config,
"name": "instance-%s" % id,
- "fixed_ips": fixed_ips,
"shutdown_terminate": True,
"disable_terminate": False}
+ instance.update(info_cache)
+
return instance
diff --git a/nova/tests/db/fakes.py b/nova/tests/db/fakes.py
index 45045989c..f24f020a6 100644
--- a/nova/tests/db/fakes.py
+++ b/nova/tests/db/fakes.py
@@ -441,12 +441,6 @@ def stub_out_db_instance_api(stubs, injected=True):
else:
return [FakeModel(flat_network_fields)]
- def fake_instance_get_fixed_addresses(context, instance_id):
- return [FakeModel(fixed_ip_fields).address]
-
- def fake_instance_get_fixed_addresses_v6(context, instance_id):
- return [FakeModel(fixed_ip_fields).address]
-
def fake_fixed_ip_get_by_instance(context, instance_id):
return [FakeModel(fixed_ip_fields)]
@@ -455,8 +449,6 @@ def stub_out_db_instance_api(stubs, injected=True):
fake_instance_type_get_all,
fake_instance_type_get_by_name,
fake_instance_type_get,
- fake_instance_get_fixed_addresses,
- fake_instance_get_fixed_addresses_v6,
fake_network_get_all_by_instance,
fake_fixed_ip_get_by_instance]
stub_out(stubs, funcs)
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py
index 07f07f461..071990bd6 100644
--- a/nova/tests/fake_network.py
+++ b/nova/tests/fake_network.py
@@ -71,6 +71,36 @@ class FakeNetworkManager(network_manager.NetworkManager):
"""
class FakeDB:
+ vifs = [{'id': 0,
+ 'instance_id': 0,
+ 'network_id': 1,
+ 'address': 'DC:AD:BE:FF:EF:01'},
+ {'id': 1,
+ 'instance_id': 20,
+ 'network_id': 21,
+ 'address': 'DC:AD:BE:FF:EF:02'},
+ {'id': 2,
+ 'instance_id': 30,
+ 'network_id': 31,
+ 'address': 'DC:AD:BE:FF:EF:03'}]
+
+ floating_ips = [dict(address='172.16.1.1',
+ fixed_ip_id=100),
+ dict(address='172.16.1.2',
+ fixed_ip_id=200),
+ dict(address='173.16.1.2',
+ fixed_ip_id=210)]
+
+ fixed_ips = [dict(id=100,
+ address='172.16.0.1',
+ virtual_interface_id=0),
+ dict(id=200,
+ address='172.16.0.2',
+ virtual_interface_id=1),
+ dict(id=210,
+ address='173.16.0.2',
+ virtual_interface_id=2)]
+
def fixed_ip_get_by_instance(self, context, instance_id):
return [dict(address='10.0.0.0'), dict(address='10.0.0.1'),
dict(address='10.0.0.2')]
@@ -96,26 +126,7 @@ class FakeNetworkManager(network_manager.NetworkManager):
return True
def virtual_interface_get_all(self, context):
- floats = [{'address': '172.16.1.1'},
- {'address': '172.16.1.2'},
- {'address': '173.16.1.2'}]
-
- vifs = [{'instance_id': 0,
- 'network_id': 1,
- 'address': 'DC:AD:BE:FF:EF:01',
- 'fixed_ips': [{'address': '172.16.0.1',
- 'floating_ips': [floats[0]]}]},
- {'instance_id': 20,
- 'network_id': 21,
- 'address': 'DC:AD:BE:FF:EF:02',
- 'fixed_ips': [{'address': '172.16.0.2',
- 'floating_ips': [floats[1]]}]},
- {'instance_id': 30,
- 'network_id': 31,
- 'address': 'DC:AD:BE:FF:EF:03',
- 'fixed_ips': [{'address': '173.16.0.2',
- 'floating_ips': [floats[2]]}]}]
- return vifs
+ return self.vifs
def instance_get_id_to_uuid_mapping(self, context, ids):
# NOTE(jkoelker): This is just here until we can rely on UUIDs
@@ -124,6 +135,10 @@ class FakeNetworkManager(network_manager.NetworkManager):
mapping[id] = str(utils.gen_uuid())
return mapping
+ def fixed_ips_by_virtual_interface(self, context, vif_id):
+ return [ip for ip in self.fixed_ips
+ if ip['virtual_interface_id'] == vif_id]
+
def __init__(self):
self.db = self.FakeDB()
self.deallocate_called = None
@@ -285,3 +300,15 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
self.project_id = 1
return network.get_instance_nw_info(FakeContext(), 0, 0, 0, None)
+
+
+def stub_out_nw_api_get_instance_nw_info(stubs, func=None):
+ import nova.network
+
+ 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)
diff --git a/nova/tests/test_compute_utils.py b/nova/tests/test_compute_utils.py
index b452ec665..7ba03063f 100644
--- a/nova/tests/test_compute_utils.py
+++ b/nova/tests/test_compute_utils.py
@@ -86,7 +86,7 @@ class UsageInfoTestCase(test.TestCase):
type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
self.assertEquals(str(payload['instance_type_id']), str(type_id))
for attr in ('display_name', 'created_at', 'launched_at',
- 'state', 'state_description', 'fixed_ips',
+ 'state', 'state_description',
'bandwidth', 'audit_period_beginning',
'audit_period_ending'):
self.assertTrue(attr in payload,
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 524a2811f..356be7a58 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -67,19 +67,6 @@ class DbApiTestCase(test.TestCase):
self.project_id)
self.assertEqual(instance['id'], result['id'])
- def test_instance_get_project_vpn_joins(self):
- values = {'instance_type_id': FLAGS.default_instance_type,
- 'image_ref': FLAGS.vpn_image_id,
- 'project_id': self.project_id,
- }
- instance = db.instance_create(self.context, values)
- _setup_networking(instance['id'])
- result = db.instance_get_project_vpn(self.context.elevated(),
- self.project_id)
- self.assertEqual(instance['id'], result['id'])
- self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address,
- '1.2.1.2')
-
def test_instance_get_all_by_filters(self):
args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
inst1 = db.instance_create(self.context, args)
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 8334e6f94..1490f9173 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -1328,17 +1328,22 @@ class IptablesFirewallTestCase(test.TestCase):
return '', ''
print cmd, kwargs
+ network_info = _fake_network_info(self.stubs, 1)
+
def get_fixed_ips(*args, **kwargs):
ips = []
for network, info in network_info:
ips.extend(info['ips'])
- return [ip['ip'] for ip in ips]
+ return [ip['ip'] for ip in ips]
+
+ def nw_info(*args, **kwargs):
+ return network_info
from nova.network import linux_net
linux_net.iptables_manager.execute = fake_iptables_execute
- network_info = _fake_network_info(self.stubs, 1)
- self.stubs.Set(db, 'instance_get_fixed_addresses', get_fixed_ips)
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ nw_info)
self.fw.prepare_instance_filter(instance_ref, network_info)
self.fw.apply_instance_filter(instance_ref, network_info)
diff --git a/nova/tests/test_linux_net.py b/nova/tests/test_linux_net.py
index c8f8cbe06..21c5284a5 100644
--- a/nova/tests/test_linux_net.py
+++ b/nova/tests/test_linux_net.py
@@ -19,6 +19,7 @@ import os
import mox
+from nova import context
from nova import db
from nova import flags
from nova import log as logging
@@ -102,8 +103,7 @@ fixed_ips = [{'id': 0,
'instance_id': 0,
'allocated': True,
'virtual_interface_id': 0,
- 'virtual_interface': addresses[0],
- 'instance': instances[0],
+ 'instance_id': 0,
'floating_ips': []},
{'id': 1,
'network_id': 1,
@@ -111,8 +111,7 @@ fixed_ips = [{'id': 0,
'instance_id': 0,
'allocated': True,
'virtual_interface_id': 1,
- 'virtual_interface': addresses[1],
- 'instance': instances[0],
+ 'instance_id': 0,
'floating_ips': []},
{'id': 2,
'network_id': 1,
@@ -120,8 +119,7 @@ fixed_ips = [{'id': 0,
'instance_id': 1,
'allocated': True,
'virtual_interface_id': 2,
- 'virtual_interface': addresses[2],
- 'instance': instances[1],
+ 'instance_id': 1,
'floating_ips': []},
{'id': 3,
'network_id': 0,
@@ -129,8 +127,7 @@ fixed_ips = [{'id': 0,
'instance_id': 1,
'allocated': True,
'virtual_interface_id': 3,
- 'virtual_interface': addresses[3],
- 'instance': instances[1],
+ 'instance_id': 1,
'floating_ips': []},
{'id': 4,
'network_id': 0,
@@ -138,8 +135,7 @@ fixed_ips = [{'id': 0,
'instance_id': 0,
'allocated': True,
'virtual_interface_id': 4,
- 'virtual_interface': addresses[4],
- 'instance': instances[0],
+ 'instance_id': 0,
'floating_ips': []},
{'id': 5,
'network_id': 1,
@@ -147,8 +143,7 @@ fixed_ips = [{'id': 0,
'instance_id': 1,
'allocated': True,
'virtual_interface_id': 5,
- 'virtual_interface': addresses[5],
- 'instance': instances[1],
+ 'instance_id': 1,
'floating_ips': []}]
@@ -156,37 +151,31 @@ vifs = [{'id': 0,
'address': 'DE:AD:BE:EF:00:00',
'uuid': '00000000-0000-0000-0000-0000000000000000',
'network_id': 0,
- 'network': networks[0],
'instance_id': 0},
{'id': 1,
'address': 'DE:AD:BE:EF:00:01',
'uuid': '00000000-0000-0000-0000-0000000000000001',
'network_id': 1,
- 'network': networks[1],
'instance_id': 0},
{'id': 2,
'address': 'DE:AD:BE:EF:00:02',
'uuid': '00000000-0000-0000-0000-0000000000000002',
'network_id': 1,
- 'network': networks[1],
'instance_id': 1},
{'id': 3,
'address': 'DE:AD:BE:EF:00:03',
'uuid': '00000000-0000-0000-0000-0000000000000003',
'network_id': 0,
- 'network': networks[0],
'instance_id': 1},
{'id': 4,
'address': 'DE:AD:BE:EF:00:04',
'uuid': '00000000-0000-0000-0000-0000000000000004',
'network_id': 0,
- 'network': networks[0],
'instance_id': 0},
{'id': 5,
'address': 'DE:AD:BE:EF:00:05',
'uuid': '00000000-0000-0000-0000-0000000000000005',
'network_id': 1,
- 'network': networks[1],
'instance_id': 1}]
@@ -197,10 +186,20 @@ class LinuxNetworkTestCase(test.TestCase):
network_driver = FLAGS.network_driver
self.driver = utils.import_object(network_driver)
self.driver.db = db
+ self.context = context.RequestContext('testuser', 'testproject',
+ is_admin=True)
def test_update_dhcp_for_nw00(self):
self.flags(use_single_default_gateway=True)
+ def get_vif(_context, vif_id):
+ return vifs[vif_id]
+
+ def get_instance(_context, instance_id):
+ return instances[instance_id]
+
+ self.stubs.Set(db, 'virtual_interface_get', get_vif)
+ self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
self.mox.StubOutWithMock(self.driver, 'write_to_file')
@@ -236,10 +235,19 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
- self.driver.update_dhcp(None, "eth0", networks[0])
+ self.driver.update_dhcp(self.context, "eth0", networks[0])
def test_update_dhcp_for_nw01(self):
self.flags(use_single_default_gateway=True)
+
+ def get_vif(_context, vif_id):
+ return vifs[vif_id]
+
+ def get_instance(_context, instance_id):
+ return instances[instance_id]
+
+ self.stubs.Set(db, 'virtual_interface_get', get_vif)
+ self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
self.mox.StubOutWithMock(self.driver, 'write_to_file')
@@ -275,10 +283,19 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
- self.driver.update_dhcp(None, "eth0", networks[0])
+ self.driver.update_dhcp(self.context, "eth0", networks[0])
def test_get_dhcp_hosts_for_nw00(self):
self.flags(use_single_default_gateway=True)
+
+ def get_vif(_context, vif_id):
+ return vifs[vif_id]
+
+ def get_instance(_context, instance_id):
+ return instances[instance_id]
+
+ self.stubs.Set(db, 'virtual_interface_get', get_vif)
+ self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
db.network_get_associated_fixed_ips(mox.IgnoreArg(),
@@ -288,16 +305,25 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
expected = \
- "10.0.0.1,fake_instance00.novalocal,"\
+ "DE:AD:BE:EF:00:00,fake_instance00.novalocal,"\
"192.168.0.100,net:NW-i00000000-0\n"\
- "10.0.0.4,fake_instance01.novalocal,"\
+ "DE:AD:BE:EF:00:03,fake_instance01.novalocal,"\
"192.168.1.101,net:NW-i00000001-0"
- actual_hosts = self.driver.get_dhcp_hosts(None, networks[1])
+ actual_hosts = self.driver.get_dhcp_hosts(self.context, networks[1])
self.assertEquals(actual_hosts, expected)
def test_get_dhcp_hosts_for_nw01(self):
self.flags(use_single_default_gateway=True)
+
+ def get_vif(_context, vif_id):
+ return vifs[vif_id]
+
+ def get_instance(_context, instance_id):
+ return instances[instance_id]
+
+ self.stubs.Set(db, 'virtual_interface_get', get_vif)
+ self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
db.network_get_associated_fixed_ips(mox.IgnoreArg(),
@@ -307,15 +333,19 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
expected = \
- "10.0.0.2,fake_instance00.novalocal,"\
+ "DE:AD:BE:EF:00:01,fake_instance00.novalocal,"\
"192.168.1.100,net:NW-i00000000-1\n"\
- "10.0.0.3,fake_instance01.novalocal,"\
+ "DE:AD:BE:EF:00:02,fake_instance01.novalocal,"\
"192.168.0.101,net:NW-i00000001-1"
- actual_hosts = self.driver.get_dhcp_hosts(None, networks[0])
+ actual_hosts = self.driver.get_dhcp_hosts(self.context, networks[0])
self.assertEquals(actual_hosts, expected)
def test_get_dhcp_opts_for_nw00(self):
+ def get_instance(_context, instance_id):
+ return instances[instance_id]
+
+ self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
@@ -337,11 +367,16 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
expected_opts = 'NW-i00000001-0,3'
- actual_opts = self.driver.get_dhcp_opts(None, networks[0])
+ actual_opts = self.driver.get_dhcp_opts(self.context, networks[0])
self.assertEquals(actual_opts, expected_opts)
def test_get_dhcp_opts_for_nw01(self):
+ def get_instance(_context, instance_id):
+ print instance_id
+ return instances[instance_id]
+
+ self.stubs.Set(db, 'instance_get', get_instance)
self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips')
self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance')
@@ -363,18 +398,20 @@ class LinuxNetworkTestCase(test.TestCase):
self.mox.ReplayAll()
expected_opts = "NW-i00000000-1,3"
- actual_opts = self.driver.get_dhcp_opts(None, networks[1])
+ actual_opts = self.driver.get_dhcp_opts(self.context, networks[1])
self.assertEquals(actual_opts, expected_opts)
def test_dhcp_opts_not_default_gateway_network(self):
expected = "NW-i00000000-0,3"
- actual = self.driver._host_dhcp_opts(fixed_ips[0])
+ actual = self.driver._host_dhcp_opts(fixed_ips[0], instances[0])
self.assertEquals(actual, expected)
def test_host_dhcp_without_default_gateway_network(self):
- expected = ("10.0.0.1,fake_instance00.novalocal,192.168.0.100")
- actual = self.driver._host_dhcp(fixed_ips[0])
+ expected = ','.join(['DE:AD:BE:EF:00:00',
+ 'fake_instance00.novalocal',
+ '192.168.0.100'])
+ actual = self.driver._host_dhcp(fixed_ips[0], vifs[0], instances[0])
self.assertEquals(actual, expected)
def test_linux_bridge_driver_plug(self):
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index 257bc28c8..ff6720312 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -76,16 +76,12 @@ class MetadataTestCase(test.TestCase):
def instance_get_list(*args, **kwargs):
return [self.instance]
- def floating_get(*args, **kwargs):
- return '99.99.99.99'
-
self.stubs.Set(network.API, 'get_instance_nw_info',
fake_get_instance_nw_info)
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)
self.stubs.Set(api, 'instance_get_all_by_filters', instance_get_list)
- self.stubs.Set(api, 'instance_get_floating_address', floating_get)
self.app = handler.MetadataRequestHandler()
network_manager = fake_network.FakeNetworkManager()
self.stubs.Set(self.app.compute_api.network_api,
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index 2776f3664..8f8efc991 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -35,15 +35,6 @@ LOG = logging.getLogger('nova.tests.network')
HOST = "testhost"
-class FakeModel(dict):
- """Represent a model from the db"""
- def __init__(self, *args, **kwargs):
- self.update(kwargs)
-
- def __getattr__(self, name):
- return self[name]
-
-
networks = [{'id': 0,
'uuid': "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
'label': 'test0',
@@ -85,7 +76,6 @@ networks = [{'id': 0,
'project_id': 'fake_project',
'vpn_public_address': '192.168.1.2'}]
-
fixed_ips = [{'id': 0,
'network_id': 0,
'address': '192.168.0.100',
@@ -118,19 +108,16 @@ vifs = [{'id': 0,
'address': 'DE:AD:BE:EF:00:00',
'uuid': '00000000-0000-0000-0000-0000000000000000',
'network_id': 0,
- 'network': FakeModel(**networks[0]),
'instance_id': 0},
{'id': 1,
'address': 'DE:AD:BE:EF:00:01',
'uuid': '00000000-0000-0000-0000-0000000000000001',
'network_id': 1,
- 'network': FakeModel(**networks[1]),
'instance_id': 0},
{'id': 2,
'address': 'DE:AD:BE:EF:00:02',
'uuid': '00000000-0000-0000-0000-0000000000000002',
'network_id': 2,
- 'network': None,
'instance_id': 0}]
@@ -196,6 +183,7 @@ class FlatNetworkTestCase(test.TestCase):
self.assertDictListMatch(info['ips'], check)
def test_validate_networks(self):
+ self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'network_get_all_by_uuids')
self.mox.StubOutWithMock(db, "fixed_ip_get_by_address")
@@ -203,11 +191,13 @@ class FlatNetworkTestCase(test.TestCase):
"192.168.1.100")]
db.network_get_all_by_uuids(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks)
+ db.network_get(mox.IgnoreArg(),
+ mox.IgnoreArg()).AndReturn(networks[1])
- fixed_ips[1]['network'] = FakeModel(**networks[1])
- fixed_ips[1]['instance'] = None
+ ip = fixed_ips[1].copy()
+ ip['instance_id'] = None
db.fixed_ip_get_by_address(mox.IgnoreArg(),
- mox.IgnoreArg()).AndReturn(fixed_ips[1])
+ mox.IgnoreArg()).AndReturn(ip)
self.mox.ReplayAll()
self.network.validate_networks(self.context, requested_networks)
@@ -448,6 +438,10 @@ class VlanNetworkTestCase(test.TestCase):
cidr='192.168.0.1/24', network_size=100)
def test_validate_networks(self):
+ def network_get(_context, network_id):
+ return networks[network_id]
+
+ self.stubs.Set(db, 'network_get', network_get)
self.mox.StubOutWithMock(db, 'network_get_all_by_uuids')
self.mox.StubOutWithMock(db, "fixed_ip_get_by_address")
@@ -457,8 +451,8 @@ class VlanNetworkTestCase(test.TestCase):
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks)
- fixed_ips[1]['network'] = FakeModel(**networks[1])
- fixed_ips[1]['instance'] = None
+ fixed_ips[1]['network_id'] = networks[1]['id']
+ fixed_ips[1]['instance_id'] = None
db.fixed_ip_get_by_address(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(fixed_ips[1])
@@ -613,14 +607,20 @@ class VlanNetworkTestCase(test.TestCase):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
- 'network': {'multi_host': False, 'host': 'jibberjabber'}}
+ 'network_id': 'blah'}
+
+ def fake4_network(*args, **kwargs):
+ return {'multi_host': False, 'host': 'jibberjabber'}
# fixed ip with local host
def fake5(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
- 'network': {'multi_host': False, 'host': 'testhost'}}
+ 'network_id': 'blahblah'}
+
+ def fake5_network(*args, **kwargs):
+ return {'multi_host': False, 'host': 'testhost'}
def fake6(*args, **kwargs):
self.local = False
@@ -643,6 +643,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call remotely
self.local = True
self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake4)
+ self.stubs.Set(self.network.db, 'network_get', fake4_network)
self.stubs.Set(rpc, 'cast', fake6)
self.network.associate_floating_ip(ctxt, mox.IgnoreArg(),
mox.IgnoreArg())
@@ -651,6 +652,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call locally
self.local = False
self.stubs.Set(self.network.db, 'fixed_ip_get_by_address', fake5)
+ self.stubs.Set(self.network.db, 'network_get', fake5_network)
self.stubs.Set(self.network, '_associate_floating_ip', fake7)
self.network.associate_floating_ip(ctxt, mox.IgnoreArg(),
mox.IgnoreArg())
@@ -682,14 +684,21 @@ class VlanNetworkTestCase(test.TestCase):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
- 'network': {'multi_host': False, 'host': 'jibberjabber'}}
+ 'network_id': 'blah'}
+
+ def fake4_network(*args, **kwargs):
+ return {'multi_host': False,
+ 'host': 'jibberjabber'}
# fixed ip with local host
def fake5(*args, **kwargs):
return {'address': '10.0.0.1',
'pool': 'nova',
'interface': 'eth0',
- 'network': {'multi_host': False, 'host': 'testhost'}}
+ 'network_id': 'blahblah'}
+
+ def fake5_network(*args, **kwargs):
+ return {'multi_host': False, 'host': 'testhost'}
def fake6(*args, **kwargs):
self.local = False
@@ -711,6 +720,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call remotely
self.local = True
self.stubs.Set(self.network.db, 'fixed_ip_get', fake4)
+ self.stubs.Set(self.network.db, 'network_get', fake4_network)
self.stubs.Set(rpc, 'cast', fake6)
self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg())
self.assertFalse(self.local)
@@ -718,6 +728,7 @@ class VlanNetworkTestCase(test.TestCase):
# does not raise and makes call locally
self.local = False
self.stubs.Set(self.network.db, 'fixed_ip_get', fake5)
+ self.stubs.Set(self.network.db, 'network_get', fake5_network)
self.stubs.Set(self.network, '_disassociate_floating_ip', fake7)
self.network.disassociate_floating_ip(ctxt, mox.IgnoreArg())
self.assertTrue(self.local)
@@ -752,6 +763,11 @@ class VlanNetworkTestCase(test.TestCase):
"""Makes sure that we cannot deallocaate or disassociate
a public ip of other project"""
+ def network_get(_context, network_id):
+ return networks[network_id]
+
+ self.stubs.Set(db, 'network_get', network_get)
+
context1 = context.RequestContext('user', 'project1')
context2 = context.RequestContext('user', 'project2')
@@ -789,6 +805,7 @@ class VlanNetworkTestCase(test.TestCase):
float_addr)
# Clean up the ip addresses
+ self.network.disassociate_floating_ip(context1, float_addr)
self.network.deallocate_floating_ip(context1, float_addr)
self.network.deallocate_fixed_ip(context1, fix_addr)
db.floating_ip_destroy(context1.elevated(), float_addr)
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 77cde2a02..180400af4 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -1411,14 +1411,19 @@ class XenAPIDom0IptablesFirewallTestCase(test.TestCase):
instance_ref = db.instance_get(admin_ctxt, instance_ref['id'])
src_instance_ref = db.instance_get(admin_ctxt, src_instance_ref['id'])
+ network_info = fake_network.fake_get_instance_nw_info(self.stubs, 1)
+
def get_fixed_ips(*args, **kwargs):
ips = []
for _n, info in network_info:
ips.extend(info['ips'])
return [ip['ip'] for ip in ips]
- network_info = fake_network.fake_get_instance_nw_info(self.stubs, 1)
- self.stubs.Set(db, 'instance_get_fixed_addresses', get_fixed_ips)
+ def nw_info(*args, **kwargs):
+ return network_info
+
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ nw_info)
self.fw.prepare_instance_filter(instance_ref, network_info)
self.fw.apply_instance_filter(instance_ref, network_info)
diff --git a/nova/tests/vmwareapi/db_fakes.py b/nova/tests/vmwareapi/db_fakes.py
index c745944c7..599ba271c 100644
--- a/nova/tests/vmwareapi/db_fakes.py
+++ b/nova/tests/vmwareapi/db_fakes.py
@@ -96,10 +96,6 @@ def stub_out_db_instance_api(stubs):
"""Stubs out the db.instance_action_create method."""
pass
- def fake_instance_get_fixed_addresses(context, instance_id):
- """Stubs out the db.instance_get_fixed_address method."""
- return '10.10.10.10'
-
def fake_instance_type_get_all(context, inactive=0, filters=None):
return INSTANCE_TYPES.values()
@@ -109,7 +105,5 @@ def stub_out_db_instance_api(stubs):
stubs.Set(db, 'instance_create', fake_instance_create)
stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance)
stubs.Set(db, 'instance_action_create', fake_instance_action_create)
- stubs.Set(db, 'instance_get_fixed_addresses',
- fake_instance_get_fixed_addresses)
stubs.Set(db, 'instance_type_get_all', fake_instance_type_get_all)
stubs.Set(db, 'instance_type_get_by_name', fake_instance_type_get_by_name)