diff options
author | Jason Koelker <jason@koelker.net> | 2011-09-20 16:13:12 -0500 |
---|---|---|
committer | Jason Kölker <jason@koelker.net> | 2011-09-25 12:24:52 -0500 |
commit | 8be1c68f809b55088c1ad00ef86cb13b0103aab0 (patch) | |
tree | 7d5a5be076d679d70d84b2afcbf73828b17e6d50 /nova/tests/api/openstack | |
parent | bca7dd3e1d8bec758faf511338617f6d4121e0b8 (diff) | |
download | nova-8be1c68f809b55088c1ad00ef86cb13b0103aab0.tar.gz |
* Rework osapi to use network API not FK backref
* Fixes lp854585
Change-Id: I270794a08a1bfafe7af427cd31f1f60df1faa4ba
Diffstat (limited to 'nova/tests/api/openstack')
-rw-r--r-- | nova/tests/api/openstack/contrib/test_createserverext.py | 26 | ||||
-rw-r--r-- | nova/tests/api/openstack/contrib/test_volumes.py | 13 | ||||
-rw-r--r-- | nova/tests/api/openstack/fakes.py | 42 | ||||
-rw-r--r-- | nova/tests/api/openstack/test_server_actions.py | 1 | ||||
-rw-r--r-- | nova/tests/api/openstack/test_servers.py | 389 |
5 files changed, 254 insertions, 217 deletions
diff --git a/nova/tests/api/openstack/contrib/test_createserverext.py b/nova/tests/api/openstack/contrib/test_createserverext.py index dfd6142caf..d2fac26c78 100644 --- a/nova/tests/api/openstack/contrib/test_createserverext.py +++ b/nova/tests/api/openstack/contrib/test_createserverext.py @@ -18,10 +18,8 @@ import base64 import datetime import json -import unittest from xml.dom import minidom -import stubout import webob from nova import db @@ -91,6 +89,11 @@ class CreateserverextTest(test.TestCase): def tearDown(self): super(CreateserverextTest, self).tearDown() + def _make_stub_method(self, canned_return): + def stub_method(*args, **kwargs): + return canned_return + return stub_method + def _setup_mock_compute_api(self): class MockComputeAPI(nova.compute.API): @@ -126,18 +129,19 @@ class CreateserverextTest(test.TestCase): def set_admin_password(self, *args, **kwargs): pass - def make_stub_method(canned_return): - def stub_method(*args, **kwargs): - return canned_return - return stub_method - compute_api = MockComputeAPI() - self.stubs.Set(nova.compute, 'API', make_stub_method(compute_api)) + self.stubs.Set(nova.compute, 'API', + self._make_stub_method(compute_api)) self.stubs.Set( nova.api.openstack.create_instance_helper.CreateInstanceHelper, - '_get_kernel_ramdisk_from_image', make_stub_method((1, 1))) + '_get_kernel_ramdisk_from_image', + self._make_stub_method((1, 1))) + return compute_api + def _setup_mock_network_api(self): + fakes.stub_out_nw_api(self.stubs) + def _create_security_group_request_dict(self, security_groups): server = {} server['name'] = 'new-server-test' @@ -179,6 +183,7 @@ class CreateserverextTest(test.TestCase): def _run_create_instance_with_mock_compute_api(self, request): compute_api = self._setup_mock_compute_api() + self._setup_mock_network_api() response = request.get_response(fakes.wsgi_app()) return compute_api, response @@ -391,6 +396,7 @@ class CreateserverextTest(test.TestCase): return_security_group_get_by_name) self.stubs.Set(nova.db.api, 'instance_add_security_group', return_instance_add_security_group) + self._setup_mock_network_api() body_dict = self._create_security_group_request_dict(security_groups) request = self._get_create_request_json(body_dict) response = request.get_response(fakes.wsgi_app()) @@ -398,6 +404,7 @@ class CreateserverextTest(test.TestCase): def test_get_server_by_id_verify_security_groups_json(self): self.stubs.Set(nova.db.api, 'instance_get', return_server_by_id) + self._setup_mock_network_api() req = webob.Request.blank('/v1.1/123/os-create-server-ext/1') req.headers['Content-Type'] = 'application/json' response = req.get_response(fakes.wsgi_app()) @@ -409,6 +416,7 @@ class CreateserverextTest(test.TestCase): def test_get_server_by_id_verify_security_groups_xml(self): self.stubs.Set(nova.db.api, 'instance_get', return_server_by_id) + self._setup_mock_network_api() req = webob.Request.blank('/v1.1/123/os-create-server-ext/1') req.headers['Accept'] = 'application/xml' response = req.get_response(fakes.wsgi_app()) diff --git a/nova/tests/api/openstack/contrib/test_volumes.py b/nova/tests/api/openstack/contrib/test_volumes.py index ec69c1fd1b..f61e25d126 100644 --- a/nova/tests/api/openstack/contrib/test_volumes.py +++ b/nova/tests/api/openstack/contrib/test_volumes.py @@ -18,10 +18,8 @@ import json import webob import nova -from nova import context from nova import flags from nova import test -from nova.api.openstack.contrib.volumes import BootFromVolumeController from nova.compute import instance_types from nova.tests.api.openstack import fakes from nova.tests.api.openstack.test_servers import fake_gen_uuid @@ -47,11 +45,22 @@ def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs): }] +def fake_get_instance_nw_info(cls, context, instance): + return [(None, {'label': 'public', + 'ips': [{'ip': '10.0.0.1'}], + 'ip6s': []})] + + +def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip): + return ['172.16.0.1'] + + class BootFromVolumeTest(test.TestCase): def setUp(self): super(BootFromVolumeTest, self).setUp() self.stubs.Set(nova.compute.API, 'create', fake_compute_api_create) + fakes.stub_out_nw_api(self.stubs) def test_create_root_volume(self): body = dict(server=dict( diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 3a567f0cc4..a1c956324a 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -15,16 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -import copy -import random -import string - import webob import webob.dec from paste import urlmap from glance import client as glance_client -from glance.common import exception as glance_exc from nova import context from nova import exception as exc @@ -39,8 +34,6 @@ from nova.api.openstack import versions from nova.api.openstack import limits from nova.auth.manager import User, Project import nova.image.fake -from nova.image import glance -from nova.tests import fake_flags from nova.tests.glance import stubs as glance_stubs @@ -177,6 +170,41 @@ def stub_out_compute_api_backup(stubs): stubs.Set(nova.compute.API, 'backup', backup) +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_floating_ips_by_fixed_address(stubs, func=None): + def get_floating_ips_by_fixed_address(self, context, fixed_ip): + return ['1.2.3.4'] + + if func is None: + func = get_floating_ips_by_fixed_address + stubs.Set(nova.network.API, 'get_floating_ips_by_fixed_address', func) + + +def stub_out_nw_api(stubs, cls=None): + class Fake: + def get_instance_nw_info(*args, **kwargs): + pass + + def get_floating_ips_by_fixed_address(*args, **kwargs): + pass + + if cls is None: + cls = Fake + stubs.Set(nova.network, 'API', cls) + stub_out_nw_api_get_floating_ips_by_fixed_address(stubs) + stub_out_nw_api_get_instance_nw_info(stubs) + + def _make_image_fixtures(): NOW_GLANCE_FORMAT = "2010-10-11T10:30:22" diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py index 251b5d1265..3811fcf0f6 100644 --- a/nova/tests/api/openstack/test_server_actions.py +++ b/nova/tests/api/openstack/test_server_actions.py @@ -474,6 +474,7 @@ class ServerActionsTestV11(test.TestCase): self.stubs.Set(nova.db.api, 'instance_update', instance_update) fakes.stub_out_glance(self.stubs) + fakes.stub_out_nw_api(self.stubs) fakes.stub_out_compute_api_snapshot(self.stubs) service_class = 'nova.image.glance.GlanceImageService' self.service = utils.import_object(service_class) diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index c8d62d71a2..29be7a8120 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -35,7 +35,6 @@ from nova import utils import nova.api.openstack from nova.api.openstack import create_instance_helper from nova.api.openstack import servers -from nova.api.openstack import wsgi from nova.api.openstack import xmlutil import nova.compute.api from nova.compute import instance_types @@ -43,7 +42,6 @@ from nova.compute import task_states from nova.compute import vm_states import nova.db.api import nova.scheduler.api -from nova.db.sqlalchemy.models import Instance from nova.db.sqlalchemy.models import InstanceMetadata import nova.image.fake import nova.rpc @@ -74,18 +72,6 @@ def return_server_by_uuid(context, uuid): return stub_instance(id, uuid=uuid) -def return_virtual_interface_by_instance(interfaces): - def _return_virtual_interface_by_instance(context, instance_id): - return interfaces - return _return_virtual_interface_by_instance - - -def return_virtual_interface_instance_nonexistant(interfaces): - def _return_virtual_interface_by_instance(context, instance_id): - raise exception.InstanceNotFound(instance_id=instance_id) - return _return_virtual_interface_by_instance - - def return_server_with_attributes(**kwargs): def _return_server(context, id): return stub_instance(id, **kwargs) @@ -260,6 +246,7 @@ class ServersTest(test.TestCase): 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(utils, 'gen_uuid', fake_gen_uuid) self.stubs.Set(nova.db.api, 'instance_get_all_by_filters', return_servers) @@ -324,29 +311,26 @@ class ServersTest(test.TestCase): def test_get_server_by_id_v1_1(self): image_bookmark = "http://localhost/fake/images/10" - flavor_ref = "http://localhost/v1.1/fake/flavors/1" - flavor_id = "1" flavor_bookmark = "http://localhost/fake/flavors/1" - public_ip = '192.168.0.3' private_ip = '172.19.0.1' - interfaces = [ - { - 'network': {'label': 'public'}, - 'fixed_ips': [ - {'address': public_ip}, - ], - }, - { - 'network': {'label': 'private'}, - 'fixed_ips': [ - {'address': private_ip}, - ], - }, - ] - new_return_server = return_server_with_attributes( - interfaces=interfaces) - self.stubs.Set(nova.db.api, 'instance_get', new_return_server) + + nw_info = [(None, {'label': 'public', + 'ips': [{'ip': public_ip}], + 'ip6s': []}), + (None, {'label': 'private', + 'ips': [{'ip': private_ip}], + 'ip6s': []})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) req = webob.Request.blank('/v1.1/fake/servers/1') res = req.get_response(fakes.wsgi_app()) @@ -423,23 +407,23 @@ class ServersTest(test.TestCase): flavor_bookmark = "http://localhost/fake/flavors/1" public_ip = '192.168.0.3' private_ip = '172.19.0.1' - interfaces = [ - { - 'network': {'label': 'public'}, - 'fixed_ips': [ - {'address': public_ip}, - ], - }, - { - 'network': {'label': 'private'}, - 'fixed_ips': [ - {'address': private_ip}, - ], - }, - ] - new_return_server = return_server_with_attributes( - interfaces=interfaces) - self.stubs.Set(nova.db.api, 'instance_get', new_return_server) + + nw_info = [(None, {'label': 'public', + 'ips': [{'ip': public_ip}], + 'ip6s': []}), + (None, {'label': 'private', + 'ips': [{'ip': private_ip}], + 'ip6s': []})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) req = webob.Request.blank('/v1.1/fake/servers/1') req.headers['Accept'] = 'application/xml' @@ -529,29 +513,28 @@ class ServersTest(test.TestCase): def test_get_server_with_active_status_by_id_v1_1(self): image_bookmark = "http://localhost/fake/images/10" - flavor_ref = "http://localhost/v1.1/fake/flavors/1" - flavor_id = "1" flavor_bookmark = "http://localhost/fake/flavors/1" private_ip = "192.168.0.3" public_ip = "1.2.3.4" - interfaces = [ - { - 'network': {'label': 'public'}, - 'fixed_ips': [ - {'address': public_ip}, - ], - }, - { - 'network': {'label': 'private'}, - 'fixed_ips': [ - {'address': private_ip}, - ], - }, - ] + nw_info = [(None, {'label': 'public', + 'ips': [{'ip': public_ip}], + 'ip6s': []}), + (None, {'label': 'private', + 'ips': [{'ip': private_ip}], + 'ip6s': []})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) new_return_server = return_server_with_attributes( - interfaces=interfaces, vm_state=vm_states.ACTIVE, - progress=100) + vm_state=vm_states.ACTIVE, progress=100) self.stubs.Set(nova.db.api, 'instance_get', new_return_server) req = webob.Request.blank('/v1.1/fake/servers/1') @@ -626,28 +609,29 @@ class ServersTest(test.TestCase): def test_get_server_with_id_image_ref_by_id_v1_1(self): image_ref = "10" image_bookmark = "http://localhost/fake/images/10" - flavor_ref = "http://localhost/v1.1/fake/flavors/1" flavor_id = "1" flavor_bookmark = "http://localhost/fake/flavors/1" private_ip = "192.168.0.3" public_ip = "1.2.3.4" - interfaces = [ - { - 'network': {'label': 'public'}, - 'fixed_ips': [ - {'address': public_ip}, - ], - }, - { - 'network': {'label': 'private'}, - 'fixed_ips': [ - {'address': private_ip}, - ], - }, - ] + nw_info = [(None, {'label': 'public', + 'ips': [{'ip': public_ip}], + 'ip6s': []}), + (None, {'label': 'private', + 'ips': [{'ip': private_ip}], + 'ip6s': []})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) new_return_server = return_server_with_attributes( - interfaces=interfaces, vm_state=vm_states.ACTIVE, + vm_state=vm_states.ACTIVE, image_ref=image_ref, flavor_id=flavor_id, progress=100) self.stubs.Set(nova.db.api, 'instance_get', new_return_server) @@ -857,26 +841,24 @@ class ServersTest(test.TestCase): def test_get_server_by_id_with_addresses_v1_1(self): self.flags(use_ipv6=True) - interfaces = [ - { - 'network': {'label': 'network_1'}, - 'fixed_ips': [ - {'address': '192.168.0.3'}, - {'address': '192.168.0.4'}, - ], - }, - { - 'network': {'label': 'network_2'}, - 'fixed_ips': [ - {'address': '172.19.0.1'}, - {'address': '172.19.0.2'}, - ], - 'fixed_ipv6': '2001:4860::12', - }, - ] - new_return_server = return_server_with_attributes( - interfaces=interfaces) - self.stubs.Set(nova.db.api, 'instance_get', new_return_server) + nw_info = [(None, {'label': 'network_1', + 'ips': [{'ip': '192.168.0.3'}, + {'ip': '192.168.0.4'}], + 'ip6s': []}), + (None, {'label': 'network_2', + 'ips': [{'ip': '172.19.0.1'}, + {'ip': '172.19.0.2'}], + 'ip6s': [{'ip': '2001:4860::12'}]})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) req = webob.Request.blank('/v1.1/fake/servers/1') res = req.get_response(fakes.wsgi_app()) @@ -897,30 +879,33 @@ class ServersTest(test.TestCase): ], } - self.assertEqual(addresses, expected) + self.assertTrue('network_1' in addresses) + self.assertTrue('network_2' in addresses) + + for network in ('network_1', 'network_2'): + for ip in expected[network]: + self.assertTrue(ip in addresses[network]) def test_get_server_by_id_with_addresses_v1_1_ipv6_disabled(self): self.flags(use_ipv6=False) - interfaces = [ - { - 'network': {'label': 'network_1'}, - 'fixed_ips': [ - {'address': '192.168.0.3'}, - {'address': '192.168.0.4'}, - ], - }, - { - 'network': {'label': 'network_2'}, - 'fixed_ips': [ - {'address': '172.19.0.1'}, - {'address': '172.19.0.2'}, - ], - 'fixed_ipv6': '2001:4860::12', - }, - ] - new_return_server = return_server_with_attributes( - interfaces=interfaces) - self.stubs.Set(nova.db.api, 'instance_get', new_return_server) + nw_info = [(None, {'label': 'network_1', + 'ips': [{'ip': '192.168.0.3'}, + {'ip': '192.168.0.4'}], + 'ip6s': []}), + (None, {'label': 'network_2', + 'ips': [{'ip': '172.19.0.1'}, + {'ip': '172.19.0.2'}], + 'ip6s': [{'ip': '2001:4860::12'}]})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) req = webob.Request.blank('/v1.1/fake/servers/1') res = req.get_response(fakes.wsgi_app()) @@ -940,37 +925,36 @@ class ServersTest(test.TestCase): ], } - self.assertEqual(addresses, expected) + self.assertTrue('network_1' in addresses) + self.assertTrue('network_2' in addresses) + + for network in ('network_1', 'network_2'): + for ip in expected[network]: + self.assertTrue(ip['version'] != 6) + self.assertTrue(ip in addresses[network]) def test_get_server_addresses_v1_1(self): self.flags(use_ipv6=True) - interfaces = [ - { - 'network': {'label': 'network_1'}, - 'fixed_ips': [ - {'address': '192.168.0.3'}, - {'address': '192.168.0.4'}, - ], - }, - { - 'network': {'label': 'network_2'}, - 'fixed_ips': [ - { - 'address': '172.19.0.1', - 'floating_ips': [ - {'address': '1.2.3.4'}, - ], - }, - {'address': '172.19.0.2'}, - ], - 'fixed_ipv6': '2001:4860::12', - }, - ] - - _return_vifs = return_virtual_interface_by_instance(interfaces) - self.stubs.Set(nova.db.api, - 'virtual_interface_get_by_instance', - _return_vifs) + nw_info = [(None, {'label': 'network_1', + 'ips': [{'ip': '192.168.0.3'}, + {'ip': '192.168.0.4'}], + 'ip6s': []}), + (None, {'label': 'network_2', + 'ips': [{'ip': '172.19.0.1'}, + {'ip': '172.19.0.2'}], + 'ip6s': [{'ip': '2001:4860::12'}]})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + if fixed_ip == '172.19.0.1': + return ['1.2.3.4'] + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) req = webob.Request.blank('/v1.1/fake/servers/1/ips') res = req.get_response(fakes.wsgi_app()) @@ -991,36 +975,36 @@ class ServersTest(test.TestCase): }, } - self.assertEqual(res_dict, expected) + self.assertTrue('addresses' in res_dict) + self.assertTrue('network_1' in res_dict['addresses']) + self.assertTrue('network_2' in res_dict['addresses']) + + for network in ('network_1', 'network_2'): + for ip in expected['addresses'][network]: + self.assertTrue(ip in res_dict['addresses'][network]) def test_get_server_addresses_single_network_v1_1(self): self.flags(use_ipv6=True) - interfaces = [ - { - 'network': {'label': 'network_1'}, - 'fixed_ips': [ - {'address': '192.168.0.3'}, - {'address': '192.168.0.4'}, - ], - }, - { - 'network': {'label': 'network_2'}, - 'fixed_ips': [ - { - 'address': '172.19.0.1', - 'floating_ips': [ - {'address': '1.2.3.4'}, - ], - }, - {'address': '172.19.0.2'}, - ], - 'fixed_ipv6': '2001:4860::12', - }, - ] - _return_vifs = return_virtual_interface_by_instance(interfaces) - self.stubs.Set(nova.db.api, - 'virtual_interface_get_by_instance', - _return_vifs) + nw_info = [(None, {'label': 'network_1', + 'ips': [{'ip': '192.168.0.3'}, + {'ip': '192.168.0.4'}], + 'ip6s': []}), + (None, {'label': 'network_2', + 'ips': [{'ip': '172.19.0.1'}, + {'ip': '172.19.0.2'}], + 'ip6s': [{'ip': '2001:4860::12'}]})] + + def get_nw_info(*args, **kwargs): + return nw_info + + def get_floats(self, context, fixed_ip): + if fixed_ip == '172.19.0.1': + return ['1.2.3.4'] + return [] + + fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info) + fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs, + get_floats) req = webob.Request.blank('/v1.1/fake/servers/1/ips/network_2') res = req.get_response(fakes.wsgi_app()) @@ -1028,30 +1012,32 @@ class ServersTest(test.TestCase): res_dict = json.loads(res.body) expected = { 'network_2': [ + {'version': 6, 'addr': '2001:4860::12'}, {'version': 4, 'addr': '172.19.0.1'}, {'version': 4, 'addr': '1.2.3.4'}, {'version': 4, 'addr': '172.19.0.2'}, - {'version': 6, 'addr': '2001:4860::12'}, ], } - self.assertEqual(res_dict, expected) - def test_get_server_addresses_nonexistant_network_v1_1(self): - _return_vifs = return_virtual_interface_by_instance([]) - self.stubs.Set(nova.db.api, - 'virtual_interface_get_by_instance', - _return_vifs) + self.assertTrue('network_2' in res_dict) + self.assertTrue(len(res_dict['network_2']) == 4) + for ip in expected['network_2']: + self.assertTrue(ip in res_dict['network_2']) + def test_get_server_addresses_nonexistant_network_v1_1(self): req = webob.Request.blank('/v1.1/fake/servers/1/ips/network_0') res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 404) def test_get_server_addresses_nonexistant_server_v1_1(self): - _return_vifs = return_virtual_interface_instance_nonexistant([]) - self.stubs.Set(nova.db.api, - 'virtual_interface_get_by_instance', - _return_vifs) + def fake(*args, **kwargs): + return [] + + def fake_instance_get(*args, **kwargs): + raise nova.exception.InstanceNotFound() + self.stubs.Set(nova.db.api, 'instance_get', fake_instance_get) + self.stubs.Set(nova.network.API, 'get_instance_nw_info', fake) req = webob.Request.blank('/v1.1/fake/servers/600/ips') res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 404) @@ -2745,6 +2731,10 @@ class ServersTest(test.TestCase): class TestServerStatus(test.TestCase): + def setUp(self): + super(TestServerStatus, self).setUp() + fakes.stub_out_nw_api(self.stubs) + def _get_with_state(self, vm_state, task_state=None): new_server = return_server_with_state(vm_state, task_state) self.stubs.Set(nova.db.api, 'instance_get', new_server) @@ -3536,6 +3526,7 @@ class TestServerInstanceCreation(test.TestCase): super(TestServerInstanceCreation, self).setUp() fakes.stub_out_image_service(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) + fakes.stub_out_nw_api(self.stubs) def _setup_mock_compute_api_for_personality(self): @@ -3924,7 +3915,7 @@ class ServersViewBuilderV11Test(test.TestCase): } } - output = self.view_builder.build(self.instance, False) + output = self.view_builder.build(self.instance, {}, False) self.assertDictMatch(output, expected_server) def test_build_server_with_project_id(self): @@ -3947,7 +3938,7 @@ class ServersViewBuilderV11Test(test.TestCase): } view_builder = self._get_view_builder(project_id='fake') - output = view_builder.build(self.instance, False) + output = view_builder.build(self.instance, {}, False) self.assertDictMatch(output, expected_server) def test_build_server_detail(self): @@ -4002,7 +3993,7 @@ class ServersViewBuilderV11Test(test.TestCase): } } - output = self.view_builder.build(self.instance, True) + output = self.view_builder.build(self.instance, {}, True) self.assertDictMatch(output, expected_server) def test_build_server_detail_active_status(self): @@ -4060,7 +4051,7 @@ class ServersViewBuilderV11Test(test.TestCase): } } - output = self.view_builder.build(self.instance, True) + output = self.view_builder.build(self.instance, {}, True) self.assertDictMatch(output, expected_server) def test_build_server_detail_with_accessipv4(self): @@ -4118,7 +4109,7 @@ class ServersViewBuilderV11Test(test.TestCase): } } - output = self.view_builder.build(self.instance, True) + output = self.view_builder.build(self.instance, {}, True) self.assertDictMatch(output, expected_server) def test_build_server_detail_with_accessipv6(self): @@ -4176,7 +4167,7 @@ class ServersViewBuilderV11Test(test.TestCase): } } - output = self.view_builder.build(self.instance, True) + output = self.view_builder.build(self.instance, {}, True) self.assertDictMatch(output, expected_server) def test_build_server_detail_with_metadata(self): @@ -4240,7 +4231,7 @@ class ServersViewBuilderV11Test(test.TestCase): } } - output = self.view_builder.build(self.instance, True) + output = self.view_builder.build(self.instance, {}, True) self.assertDictMatch(output, expected_server) |