diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 400e6949..d99aed31 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -190,6 +190,15 @@ class BaseTestCase(test.TestCase): class ComputeTestCase(BaseTestCase): + def setUp(self): + def fake_get_nw_info(cls, ctxt, instance): + self.assertTrue(ctxt.is_admin) + return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1, + spectacular=True) + + super(ComputeTestCase, self).setUp() + self.stubs.Set(nova.network.API, 'get_instance_nw_info', + fake_get_nw_info) def test_wrap_instance_fault(self): inst_uuid = "fake_uuid" @@ -966,38 +975,66 @@ class ComputeTestCase(BaseTestCase): def test_finish_resize(self): """Contrived test to ensure finish_resize doesn't raise anything""" + nw_info = fake_network.fake_get_instance_nw_info(self.stubs, + spectacular=True) + def fake(*args, **kwargs): pass + def fake_nw_info(*args, **kwargs): + return nw_info + + # NOTE(jkoelker) There is a bit of a stubbing issue here. + # fake_network stubs out a bunch of stuff which + # this functional test expects to be acting on + # the db or the stubs it sets. + self.stubs.UnsetAll() + self.stubs.SmartUnsetAll() + self.setUp() + self.stubs.Set(self.compute.driver, 'finish_migration', fake) - self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake) + self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', + fake_nw_info) + fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, + func=fake_nw_info) context = self.context.elevated() + instance = self._create_fake_instance() self.compute.prep_resize(context, instance['uuid'], 1, filter_properties={}) migration_ref = db.migration_get_by_instance_and_status(context, instance['uuid'], 'pre-migrating') - try: - self.compute.finish_resize(context, instance['uuid'], - int(migration_ref['id']), {}) - except KeyError, e: - # Only catch key errors. We want other reasons for the test to - # fail to actually error out so we don't obscure anything - self.fail() - + self.compute.finish_resize(context, instance['uuid'], + int(migration_ref['id']), {}) self.compute.terminate_instance(self.context, instance['uuid']) def test_finish_resize_handles_error(self): """Make sure we don't leave the instance in RESIZE on error""" + nw_info = fake_network.fake_get_instance_nw_info(self.stubs, + spectacular=True) + def throw_up(*args, **kwargs): raise Exception() def fake(*args, **kwargs): pass + def fake_nw_info(*args, **kwargs): + return nw_info + + # NOTE(jkoelker) There is a bit of a stubbing issue here. + # fake_network stubs out a bunch of stuff which + # this functional test expects to be acting on + # the db or the stubs it sets. + self.stubs.UnsetAll() + self.stubs.SmartUnsetAll() + self.setUp() + self.stubs.Set(self.compute.driver, 'finish_migration', throw_up) self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake) + fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, + func=fake_nw_info) context = self.context.elevated() instance = self._create_fake_instance() self.compute.prep_resize(context, instance['uuid'], 1, @@ -1123,13 +1160,32 @@ class ComputeTestCase(BaseTestCase): def test_finish_revert_resize(self): """Ensure that the flavor is reverted to the original on revert""" - context = self.context.elevated() - instance = self._create_fake_instance() - instance_uuid = instance['uuid'] + nw_info = fake_network.fake_get_instance_nw_info(self.stubs, + spectacular=True) def fake(*args, **kwargs): pass + def fake_nw_info(*args, **kwargs): + return nw_info + + # NOTE(jkoelker) There is a bit of a stubbing issue here. + # fake_network stubs out a bunch of stuff which + # this functional test expects to be acting on + # the db or the stubs it sets. + self.stubs.UnsetAll() + self.stubs.SmartUnsetAll() + self.setUp() + + self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', + fake_nw_info) + fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, + func=fake_nw_info) + + context = self.context.elevated() + instance = self._create_fake_instance() + instance_uuid = instance['uuid'] + self.stubs.Set(self.compute.driver, 'finish_migration', fake) self.stubs.Set(self.compute.driver, 'finish_revert_migration', fake) self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake) @@ -1450,7 +1506,14 @@ class ComputeTestCase(BaseTestCase): class ComputeAPITestCase(BaseTestCase): def setUp(self): + def fake_get_nw_info(cls, ctxt, instance): + self.assertTrue(ctxt.is_admin) + return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1, + spectacular=True) + super(ComputeAPITestCase, self).setUp() + self.stubs.Set(nova.network.API, 'get_instance_nw_info', + fake_get_nw_info) self.compute_api = compute.API() self.fake_image = { 'id': 1, @@ -2267,17 +2330,9 @@ class ComputeAPITestCase(BaseTestCase): fixed_address): called['associate'] = True - def fake_get_nw_info(cls, ctxt, instance): - self.assertTrue(ctxt.is_admin) - 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) - self.stubs.Set(nova.network.API, 'get_instance_nw_info', - fake_get_nw_info) - instance = self._create_fake_instance() instance_uuid = instance['uuid'] address = '0.1.2.3' @@ -2995,12 +3050,6 @@ 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']) diff --git a/nova/tests/test_compute_utils.py b/nova/tests/test_compute_utils.py index 71463fbc..8e35d190 100644 --- a/nova/tests/test_compute_utils.py +++ b/nova/tests/test_compute_utils.py @@ -29,6 +29,7 @@ import nova.image.fake from nova.compute import utils as compute_utils from nova.compute import instance_types from nova.notifier import test_notifier +from nova.tests import fake_network LOG = logging.getLogger('nova.tests.compute_utils') @@ -39,7 +40,15 @@ flags.DECLARE('stub_network', 'nova.compute.manager') class UsageInfoTestCase(test.TestCase): def setUp(self): + def fake_get_nw_info(cls, ctxt, instance): + self.assertTrue(ctxt.is_admin) + return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1, + spectacular=True) + super(UsageInfoTestCase, self).setUp() + self.stubs.Set(nova.network.API, 'get_instance_nw_info', + fake_get_nw_info) + self.flags(connection_type='fake', stub_network=True, notification_driver='nova.notifier.test_notifier', diff --git a/nova/tests/test_notifier.py b/nova/tests/test_notifier.py index 00f367f4..b13f203a 100644 --- a/nova/tests/test_notifier.py +++ b/nova/tests/test_notifier.py @@ -16,6 +16,7 @@ import stubout import nova +import nova.notifier.no_op_notifier from nova import log import nova.notifier.api from nova.notifier.api import notify @@ -26,6 +27,7 @@ class NotifierTestCase(test.TestCase): """Test case for notifications""" def setUp(self): super(NotifierTestCase, self).setUp() + self.flags(notification_driver='nova.notifier.no_op_notifier') self.stubs = stubout.StubOutForTesting() def tearDown(self):