diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-02-06 23:59:01 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-02-06 23:59:01 +0000 |
| commit | d52ea46f558ef5e8d2cda238d89b420e9a5d7932 (patch) | |
| tree | 09fda7fda6ab08a1b03425b9bd96f1770901f817 /nova/tests | |
| parent | 724961063323d811405c3933fb5d16fb5b83bb12 (diff) | |
| parent | 9b1b65a4395511b07e15a521de3a3a66c4bdcfaa (diff) | |
Merge "Fix _poll_bandwidth_usage if no network on vif"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/test_compute.py | 101 | ||||
| -rw-r--r-- | nova/tests/test_compute_utils.py | 9 | ||||
| -rw-r--r-- | nova/tests/test_notifier.py | 2 | ||||
| -rw-r--r-- | nova/tests/test_quota.py | 3 |
4 files changed, 88 insertions, 27 deletions
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 400e6949f..d99aed310 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 71463fbc0..8e35d1905 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 00f367f49..b13f203a4 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): diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index 8ed38cc92..23660333a 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -46,7 +46,8 @@ class QuotaTestCase(test.TestCase): quota_cores=4, quota_volumes=2, quota_gigabytes=20, - quota_floating_ips=1) + quota_floating_ips=1, + network_manager='nova.network.manager.FlatDHCPManager') self.network = self.network = self.start_service('network') self.user_id = 'admin' |
