From 113fe431d61899b8402181d1016ab29479330636 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 2 Aug 2011 13:34:29 -0500 Subject: Get instance by UUID instead of id. --- nova/compute/manager.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index a2d84cd76..c7c88a1fb 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -648,37 +648,38 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock - def rescue_instance(self, context, instance_id): + def rescue_instance(self, context, instance_uuid): """Rescue an instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get(context, instance_id) - LOG.audit(_('instance %s: rescuing'), instance_id, context=context) + instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) + LOG.audit(_('instance %s: rescuing'), instance_uuid, context=context) self.db.instance_set_state(context, - instance_id, + instance_uuid, power_state.NOSTATE, 'rescuing') _update_state = lambda result: self._update_state_callback( - self, context, instance_id, result) + self, context, instance_uuid, result) network_info = self._get_instance_nw_info(context, instance_ref) self.driver.rescue(instance_ref, _update_state, network_info) - self._update_state(context, instance_id) + self._update_state(context, instance_uuid) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock - def unrescue_instance(self, context, instance_id): + def unrescue_instance(self, context, instance_uuid): """Rescue an instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get(context, instance_id) - LOG.audit(_('instance %s: unrescuing'), instance_id, context=context) + instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) + LOG.audit(_('instance %s: unrescuing'), instance_uuid, + context=context) self.db.instance_set_state(context, - instance_id, + instance_uuid, power_state.NOSTATE, 'unrescuing') _update_state = lambda result: self._update_state_callback( - self, context, instance_id, result) + self, context, instance_uuid, result) network_info = self._get_instance_nw_info(context, instance_ref) self.driver.unrescue(instance_ref, _update_state, network_info) - self._update_state(context, instance_id) + self._update_state(context, instance_uuid) @staticmethod def _update_state_callback(self, context, instance_id, result): -- cgit From 4d500af8bdb4eda2d6040b54c217905cd7ed8bff Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 09:56:37 -0700 Subject: fix use of FLAGS in openstack API servers tests to use the new way --- nova/tests/api/openstack/test_servers.py | 35 +++++++++++++------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 4d42972c1..e927e6612 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -26,7 +26,6 @@ import webob from nova import context from nova import db from nova import exception -from nova import flags from nova import test from nova import utils import nova.api.openstack @@ -46,10 +45,6 @@ from nova.tests.api.openstack import common from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS -FLAGS.verbose = True - - FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' @@ -269,8 +264,6 @@ class ServersTest(test.TestCase): self.sent_to_glance = {} fakes.stub_out_glance_add_image(self.stubs, self.sent_to_glance) - self.allow_admin = FLAGS.allow_admin_api - self.webreq = common.webob_factory('/v1.0/servers') def test_get_server_by_id(self): @@ -767,7 +760,7 @@ class ServersTest(test.TestCase): self.assertEquals(ip.getAttribute('addr'), private) def test_get_server_by_id_with_addresses_v1_1(self): - FLAGS.use_ipv6 = True + self.flags(use_ipv6=True) interfaces = [ { 'network': {'label': 'network_1'}, @@ -811,7 +804,7 @@ class ServersTest(test.TestCase): self.assertEqual(addresses, expected) def test_get_server_by_id_with_addresses_v1_1_ipv6_disabled(self): - FLAGS.use_ipv6 = False + self.flags(use_ipv6=False) interfaces = [ { 'network': {'label': 'network_1'}, @@ -854,7 +847,7 @@ class ServersTest(test.TestCase): self.assertEqual(addresses, expected) def test_get_server_addresses_v1_1(self): - FLAGS.use_ipv6 = True + self.flags(use_ipv6=True) interfaces = [ { 'network': {'label': 'network_1'}, @@ -905,7 +898,7 @@ class ServersTest(test.TestCase): self.assertEqual(res_dict, expected) def test_get_server_addresses_single_network_v1_1(self): - FLAGS.use_ipv6 = True + self.flags(use_ipv6=True) interfaces = [ { 'network': {'label': 'network_1'}, @@ -2329,7 +2322,7 @@ class ServersTest(test.TestCase): """ req = self.webreq('/1/migrate', 'POST') - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) self.resize_called = False def resize_mock(*args): @@ -2344,7 +2337,7 @@ class ServersTest(test.TestCase): def test_migrate_server_no_admin_api_fails(self): req = self.webreq('/1/migrate', 'POST') - FLAGS.allow_admin_api = False + self.flags(allow_admin_api=False) res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 404) @@ -2425,7 +2418,7 @@ class ServersTest(test.TestCase): def test_create_backup(self): """The happy path for creating backups""" - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = { 'createBackup': { @@ -2445,7 +2438,7 @@ class ServersTest(test.TestCase): def test_create_backup_v1_1(self): """The happy path for creating backups through v1.1 api""" - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = { 'createBackup': { @@ -2465,7 +2458,7 @@ class ServersTest(test.TestCase): def test_create_backup_admin_api_off(self): """The happy path for creating backups""" - FLAGS.allow_admin_api = False + self.flags(allow_admin_api=False) body = { 'createBackup': { @@ -2483,7 +2476,7 @@ class ServersTest(test.TestCase): self.assertEqual(501, response.status_int) def test_create_backup_with_metadata(self): - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = { 'createBackup': { @@ -2504,7 +2497,7 @@ class ServersTest(test.TestCase): def test_create_backup_no_name(self): """Name is required for backups""" - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = { 'createBackup': { @@ -2522,7 +2515,7 @@ class ServersTest(test.TestCase): def test_create_backup_no_rotation(self): """Rotation is required for backup requests""" - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = { 'createBackup': { @@ -2541,7 +2534,7 @@ class ServersTest(test.TestCase): def test_create_backup_no_backup_type(self): """Backup Type (daily or weekly) is required for backup requests""" - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = { 'createBackup': { @@ -2558,7 +2551,7 @@ class ServersTest(test.TestCase): self.assertEqual(400, response.status_int) def test_create_backup_bad_entity(self): - FLAGS.allow_admin_api = True + self.flags(allow_admin_api=True) body = {'createBackup': 'go'} req = webob.Request.blank('/v1.0/images') -- cgit From d7f704876f5cfab165c855170468274e57935d15 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 10:11:20 -0700 Subject: more cleanup of API tests regarding FLAGS --- nova/test.py | 6 ++++++ nova/tests/api/openstack/test_accounts.py | 6 +----- nova/tests/api/openstack/test_adminapi.py | 5 +---- nova/tests/api/openstack/test_extensions.py | 2 -- nova/tests/api/openstack/test_flavors_extra_specs.py | 3 --- nova/tests/api/openstack/test_images.py | 8 +------- nova/tests/api/openstack/test_servers.py | 1 + nova/tests/api/openstack/test_users.py | 7 +------ nova/tests/api/openstack/test_zones.py | 2 +- 9 files changed, 12 insertions(+), 28 deletions(-) diff --git a/nova/test.py b/nova/test.py index 549aa6fcf..804dc8c37 100644 --- a/nova/test.py +++ b/nova/test.py @@ -100,6 +100,7 @@ class TestCase(unittest.TestCase): self.injected = [] self._services = [] self._original_flags = FLAGS.FlagValuesDict() + self._original_flags_verbosity = FLAGS.verbose def tearDown(self): """Runs after each test method to tear down test environment.""" @@ -157,6 +158,11 @@ class TestCase(unittest.TestCase): FLAGS.Reset() for k, v in self._original_flags.iteritems(): setattr(FLAGS, k, v) + FLAGS.verbose = self._original_flags_verbosity + + def set_flags_verbosity(self, verbose=True): + """Set the FLAGS verbosity for a test""" + FLAGS.verbose = verbose def start_service(self, name, host=None, **kwargs): host = host and host or uuid.uuid4().hex diff --git a/nova/tests/api/openstack/test_accounts.py b/nova/tests/api/openstack/test_accounts.py index 89dbf5213..b1ca546d2 100644 --- a/nova/tests/api/openstack/test_accounts.py +++ b/nova/tests/api/openstack/test_accounts.py @@ -18,17 +18,12 @@ import json import webob -from nova import flags from nova import test from nova.api.openstack import accounts from nova.auth.manager import User from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS -FLAGS.verbose = True - - def fake_init(self): self.manager = fakes.FakeAuthManager() @@ -41,6 +36,7 @@ class AccountsTest(test.TestCase): def setUp(self): super(AccountsTest, self).setUp() self.flags(allow_admin_api=True) + self.set_flags_verbosity(True) self.stubs.Set(accounts.Controller, '__init__', fake_init) self.stubs.Set(accounts.Controller, '_check_admin', diff --git a/nova/tests/api/openstack/test_adminapi.py b/nova/tests/api/openstack/test_adminapi.py index b83de40cf..9d03a7f9d 100644 --- a/nova/tests/api/openstack/test_adminapi.py +++ b/nova/tests/api/openstack/test_adminapi.py @@ -18,12 +18,9 @@ import webob -from nova import flags from nova import test from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS - class AdminAPITest(test.TestCase): @@ -31,7 +28,7 @@ class AdminAPITest(test.TestCase): super(AdminAPITest, self).setUp() fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) - self.allow_admin = FLAGS.allow_admin_api + self.set_flags_verbosity(True) def test_admin_enabled(self): self.flags(allow_admin_api=True) diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index 47c37225c..409fa0e71 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -21,7 +21,6 @@ import webob from xml.etree import ElementTree from nova import context -from nova import flags from nova import test from nova.api import openstack from nova.api.openstack import extensions @@ -29,7 +28,6 @@ from nova.api.openstack import flavors from nova.api.openstack import wsgi from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS NS = "{http://docs.openstack.org/compute/api/v1.1}" ATOMNS = "{http://www.w3.org/2005/Atom}" response_body = "Try to say this Mr. Knox, sir..." diff --git a/nova/tests/api/openstack/test_flavors_extra_specs.py b/nova/tests/api/openstack/test_flavors_extra_specs.py index d386958db..ccd1b0d9f 100644 --- a/nova/tests/api/openstack/test_flavors_extra_specs.py +++ b/nova/tests/api/openstack/test_flavors_extra_specs.py @@ -21,15 +21,12 @@ import webob import os.path -from nova import flags from nova import test from nova.api import openstack from nova.api.openstack import extensions from nova.tests.api.openstack import fakes import nova.wsgi -FLAGS = flags.FLAGS - def return_create_flavor_extra_specs(context, flavor_id, extra_specs): return stub_flavor_extra_specs() diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 942c0b333..38cfc287c 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -34,7 +34,6 @@ import webob from glance import client as glance_client from nova import context from nova import exception -from nova import flags from nova import test from nova import utils import nova.api.openstack @@ -42,9 +41,6 @@ from nova.api.openstack import images from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS - - class _BaseImageServiceTests(test.TestCase): """Tasks to test for all image services""" @@ -328,8 +324,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): def setUp(self): """Run before each test.""" super(ImageControllerWithGlanceServiceTest, self).setUp() - self.orig_image_service = FLAGS.image_service - FLAGS.image_service = 'nova.image.glance.GlanceImageService' + self.flags(image_service='nova.image.glance.GlanceImageService') self.stubs = stubout.StubOutForTesting() fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) @@ -342,7 +337,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): def tearDown(self): """Run after each test.""" self.stubs.UnsetAll() - FLAGS.image_service = self.orig_image_service super(ImageControllerWithGlanceServiceTest, self).tearDown() def _applicable_fixture(self, fixture, user_id): diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index e927e6612..796c494d4 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -230,6 +230,7 @@ class ServersTest(test.TestCase): def setUp(self): self.maxDiff = None super(ServersTest, self).setUp() + self.set_flags_verbosity(True) fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) diff --git a/nova/tests/api/openstack/test_users.py b/nova/tests/api/openstack/test_users.py index 705c02f6b..649538f11 100644 --- a/nova/tests/api/openstack/test_users.py +++ b/nova/tests/api/openstack/test_users.py @@ -17,7 +17,6 @@ import json import webob -from nova import flags from nova import test from nova import utils from nova.api.openstack import users @@ -25,10 +24,6 @@ from nova.auth.manager import User, Project from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS -FLAGS.verbose = True - - def fake_init(self): self.manager = fakes.FakeAuthManager() @@ -41,6 +36,7 @@ class UsersTest(test.TestCase): def setUp(self): super(UsersTest, self).setUp() self.flags(allow_admin_api=True) + self.set_flags_verbosity(True) self.stubs.Set(users.Controller, '__init__', fake_init) self.stubs.Set(users.Controller, '_check_admin', @@ -56,7 +52,6 @@ class UsersTest(test.TestCase): fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_auth(self.stubs) - self.allow_admin = FLAGS.allow_admin_api fakemgr = fakes.FakeAuthManager() fakemgr.add_user(User('id1', 'guy1', 'acc1', 'secret1', False)) fakemgr.add_user(User('id2', 'guy2', 'acc2', 'secret2', True)) diff --git a/nova/tests/api/openstack/test_zones.py b/nova/tests/api/openstack/test_zones.py index 3deb844aa..442ee4313 100644 --- a/nova/tests/api/openstack/test_zones.py +++ b/nova/tests/api/openstack/test_zones.py @@ -29,7 +29,6 @@ from nova.scheduler import api FLAGS = flags.FLAGS -FLAGS.verbose = True def zone_get(context, zone_id): @@ -96,6 +95,7 @@ class ZonesTest(test.TestCase): def setUp(self): super(ZonesTest, self).setUp() self.flags(allow_admin_api=True) + self.set_flags_verbosity(True) fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) -- cgit From 8efe41aaa4993d0aa9ad381d202ba7b7d025939e Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 12:22:58 -0700 Subject: switch FLAGS.* = in tests to self.flags(...) remove unused cases of FLAGS from tests modified test.TestCase's flags() to allow multiple overrides added missing license to test_rpc_amqp.py --- nova/test.py | 8 +++----- nova/tests/hyperv_unittest.py | 5 +---- nova/tests/test_auth.py | 4 ++-- nova/tests/test_host_filter.py | 12 +++--------- nova/tests/test_ipv6.py | 3 --- nova/tests/test_libvirt.py | 23 +++++++++-------------- nova/tests/test_network.py | 2 -- nova/tests/test_quota.py | 42 +++++++++++++++++------------------------- nova/tests/test_rpc.py | 2 -- nova/tests/test_rpc_amqp.py | 24 ++++++++++++++++++++++-- nova/tests/test_service.py | 1 - nova/tests/test_xenapi.py | 12 ++++++------ 12 files changed, 63 insertions(+), 75 deletions(-) diff --git a/nova/test.py b/nova/test.py index 804dc8c37..fa5a662fd 100644 --- a/nova/test.py +++ b/nova/test.py @@ -142,11 +142,9 @@ class TestCase(unittest.TestCase): def flags(self, **kw): """Override flag variables for a test.""" for k, v in kw.iteritems(): - if k in self.flag_overrides: - self.reset_flags() - raise Exception( - 'trying to override already overriden flag: %s' % k) - self.flag_overrides[k] = getattr(FLAGS, k) + # Store original flag value if it's not been overriden yet + if k not in self.flag_overrides: + self.flag_overrides[k] = getattr(FLAGS, k) setattr(FLAGS, k, v) def reset_flags(self): diff --git a/nova/tests/hyperv_unittest.py b/nova/tests/hyperv_unittest.py index 0ea196950..d346d0a70 100644 --- a/nova/tests/hyperv_unittest.py +++ b/nova/tests/hyperv_unittest.py @@ -21,13 +21,9 @@ import random from nova import context from nova import db -from nova import flags from nova import test from nova.virt import hyperv -FLAGS = flags.FLAGS -FLAGS.connection_type = 'hyperv' - class HyperVTestCase(test.TestCase): """Test cases for the Hyper-V driver""" @@ -36,6 +32,7 @@ class HyperVTestCase(test.TestCase): self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) + self.flags(connection_type='hyperv') def test_create_destroy(self): """Create a VM and destroy it""" diff --git a/nova/tests/test_auth.py b/nova/tests/test_auth.py index 7c0f783bb..2e24b7d6e 100644 --- a/nova/tests/test_auth.py +++ b/nova/tests/test_auth.py @@ -83,9 +83,9 @@ class user_and_project_generator(object): class _AuthManagerBaseTestCase(test.TestCase): def setUp(self): - FLAGS.auth_driver = self.auth_driver super(_AuthManagerBaseTestCase, self).setUp() - self.flags(connection_type='fake') + self.flags(auth_driver=self.auth_driver, + connection_type='fake') self.manager = manager.AuthManager(new=True) self.manager.mc.cache = {} diff --git a/nova/tests/test_host_filter.py b/nova/tests/test_host_filter.py index 438f3e522..3a1389a49 100644 --- a/nova/tests/test_host_filter.py +++ b/nova/tests/test_host_filter.py @@ -19,12 +19,9 @@ Tests For Scheduler Host Filters. import json from nova import exception -from nova import flags from nova import test from nova.scheduler import host_filter -FLAGS = flags.FLAGS - class FakeZoneManager: pass @@ -57,9 +54,9 @@ class HostFilterTestCase(test.TestCase): 'host_name-label': 'xs-%s' % multiplier} def setUp(self): - self.old_flag = FLAGS.default_host_filter - FLAGS.default_host_filter = \ - 'nova.scheduler.host_filter.AllHostsFilter' + super(HostFilterTestCase, self).setUp() + default_host_filter = 'nova.scheduler.host_filter.AllHostsFilter' + self.flags(default_host_filter=default_host_filter) self.instance_type = dict(name='tiny', memory_mb=50, vcpus=10, @@ -76,9 +73,6 @@ class HostFilterTestCase(test.TestCase): states['host%02d' % (x + 1)] = {'compute': self._host_caps(x)} self.zone_manager.service_states = states - def tearDown(self): - FLAGS.default_host_filter = self.old_flag - def test_choose_filter(self): # Test default filter ... hf = host_filter.choose_host_filter() diff --git a/nova/tests/test_ipv6.py b/nova/tests/test_ipv6.py index 11dc2ec98..d123df6f1 100644 --- a/nova/tests/test_ipv6.py +++ b/nova/tests/test_ipv6.py @@ -16,15 +16,12 @@ """Test suite for IPv6.""" -from nova import flags from nova import ipv6 from nova import log as logging from nova import test LOG = logging.getLogger('nova.tests.test_ipv6') -FLAGS = flags.FLAGS - import sys diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index cf25ce215..f8b866985 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -38,7 +38,6 @@ from nova.virt.libvirt import firewall libvirt = None FLAGS = flags.FLAGS -flags.DECLARE('instances_path', 'nova.compute.manager') def _concurrency(wait, done, target): @@ -93,6 +92,7 @@ def _setup_networking(instance_id, ip='1.2.3.4'): class CacheConcurrencyTestCase(test.TestCase): def setUp(self): super(CacheConcurrencyTestCase, self).setUp() + self.flags(instances_path='nova.compute.manager') def fake_exists(fname): basedir = os.path.join(FLAGS.instances_path, '_base') @@ -158,7 +158,7 @@ class LibvirtConnTestCase(test.TestCase): self.context = context.RequestContext(self.user_id, self.project_id) self.network = utils.import_object(FLAGS.network_manager) self.context = context.get_admin_context() - FLAGS.instances_path = '' + self.flags(instances_path='') self.call_libvirt_dependant_setup = False self.test_ip = '10.11.12.13' @@ -322,7 +322,7 @@ class LibvirtConnTestCase(test.TestCase): if not self.lazy_load_library_exists(): return - FLAGS.image_service = 'nova.image.fake.FakeImageService' + self.flags(image_service='nova.image.fake.FakeImageService') # Start test image_service = utils.import_object(FLAGS.image_service) @@ -357,7 +357,7 @@ class LibvirtConnTestCase(test.TestCase): if not self.lazy_load_library_exists(): return - FLAGS.image_service = 'nova.image.fake.FakeImageService' + self.flags(image_service='nova.image.fake.FakeImageService') # Start test image_service = utils.import_object(FLAGS.image_service) @@ -521,7 +521,7 @@ class LibvirtConnTestCase(test.TestCase): 'disk.local')] for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems(): - FLAGS.libvirt_type = libvirt_type + self.flags(libvirt_type=libvirt_type) conn = connection.LibvirtConnection(True) uri = conn.get_uri() @@ -546,9 +546,9 @@ class LibvirtConnTestCase(test.TestCase): # checking against that later on. This way we make sure the # implementation doesn't fiddle around with the FLAGS. testuri = 'something completely different' - FLAGS.libvirt_uri = testuri + self.flags(libvirt_uri=testuri) for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems(): - FLAGS.libvirt_type = libvirt_type + self.flags(libvirt_type=libvirt_type) conn = connection.LibvirtConnection(True) uri = conn.get_uri() self.assertEquals(uri, testuri) @@ -556,8 +556,7 @@ class LibvirtConnTestCase(test.TestCase): def test_update_available_resource_works_correctly(self): """Confirm compute_node table is updated successfully.""" - org_path = FLAGS.instances_path = '' - FLAGS.instances_path = '.' + self.flags(instances_path='.') # Prepare mocks def getVersion(): @@ -604,12 +603,10 @@ class LibvirtConnTestCase(test.TestCase): self.assertTrue(compute_node['hypervisor_version'] > 0) db.service_destroy(self.context, service_ref['id']) - FLAGS.instances_path = org_path def test_update_resource_info_no_compute_record_found(self): """Raise exception if no recorde found on services table.""" - org_path = FLAGS.instances_path = '' - FLAGS.instances_path = '.' + self.flags(instances_path='.') self.create_fake_libvirt_mock() self.mox.ReplayAll() @@ -618,8 +615,6 @@ class LibvirtConnTestCase(test.TestCase): conn.update_available_resource, self.context, 'dummy') - FLAGS.instances_path = org_path - def test_ensure_filtering_rules_for_instance_timeout(self): """ensure_filtering_fules_for_instance() finishes with timeout.""" # Skip if non-libvirt environment diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 28f50d328..2ca8b64f4 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -17,7 +17,6 @@ from nova import db from nova import exception -from nova import flags from nova import log as logging from nova import test from nova.network import manager as network_manager @@ -26,7 +25,6 @@ from nova.network import manager as network_manager import mox -FLAGS = flags.FLAGS LOG = logging.getLogger('nova.tests.network') diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index 92393b536..f4b481ebe 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -114,9 +114,7 @@ class QuotaTestCase(test.TestCase): db.quota_destroy_all_by_project(self.context, self.project_id) def test_unlimited_instances(self): - FLAGS.quota_instances = 2 - FLAGS.quota_ram = -1 - FLAGS.quota_cores = -1 + self.flags(quota_instances=2, quota_ram=-1, quota_cores=-1) instance_type = self._get_instance_type('m1.small') num_instances = quota.allowed_instances(self.context, 100, instance_type) @@ -130,9 +128,7 @@ class QuotaTestCase(test.TestCase): self.assertEqual(num_instances, 101) def test_unlimited_ram(self): - FLAGS.quota_instances = -1 - FLAGS.quota_ram = 2 * 2048 - FLAGS.quota_cores = -1 + self.flags(quota_instances=-1, quota_ram=2 * 2048, quota_cores=-1) instance_type = self._get_instance_type('m1.small') num_instances = quota.allowed_instances(self.context, 100, instance_type) @@ -146,9 +142,7 @@ class QuotaTestCase(test.TestCase): self.assertEqual(num_instances, 101) def test_unlimited_cores(self): - FLAGS.quota_instances = -1 - FLAGS.quota_ram = -1 - FLAGS.quota_cores = 2 + self.flags(quota_instances=-1, quota_ram=-1, quota_cores=2) instance_type = self._get_instance_type('m1.small') num_instances = quota.allowed_instances(self.context, 100, instance_type) @@ -162,8 +156,7 @@ class QuotaTestCase(test.TestCase): self.assertEqual(num_instances, 101) def test_unlimited_volumes(self): - FLAGS.quota_volumes = 10 - FLAGS.quota_gigabytes = -1 + self.flags(quota_volumes=10, quota_gigabytes=-1) volumes = quota.allowed_volumes(self.context, 100, 1) self.assertEqual(volumes, 10) db.quota_create(self.context, self.project_id, 'volumes', None) @@ -173,8 +166,7 @@ class QuotaTestCase(test.TestCase): self.assertEqual(volumes, 101) def test_unlimited_gigabytes(self): - FLAGS.quota_volumes = -1 - FLAGS.quota_gigabytes = 10 + self.flags(quota_volumes=-1, quota_gigabytes=10) volumes = quota.allowed_volumes(self.context, 100, 1) self.assertEqual(volumes, 10) db.quota_create(self.context, self.project_id, 'gigabytes', None) @@ -184,7 +176,7 @@ class QuotaTestCase(test.TestCase): self.assertEqual(volumes, 101) def test_unlimited_floating_ips(self): - FLAGS.quota_floating_ips = 10 + self.flags(quota_floating_ips=10) floating_ips = quota.allowed_floating_ips(self.context, 100) self.assertEqual(floating_ips, 10) db.quota_create(self.context, self.project_id, 'floating_ips', None) @@ -194,7 +186,7 @@ class QuotaTestCase(test.TestCase): self.assertEqual(floating_ips, 101) def test_unlimited_metadata_items(self): - FLAGS.quota_metadata_items = 10 + self.flags(quota_metadata_items=10) items = quota.allowed_metadata_items(self.context, 100) self.assertEqual(items, 10) db.quota_create(self.context, self.project_id, 'metadata_items', None) @@ -286,49 +278,49 @@ class QuotaTestCase(test.TestCase): metadata=metadata) def test_default_allowed_injected_files(self): - FLAGS.quota_max_injected_files = 55 + self.flags(quota_max_injected_files=55) self.assertEqual(quota.allowed_injected_files(self.context, 100), 55) def test_overridden_allowed_injected_files(self): - FLAGS.quota_max_injected_files = 5 + self.flags(quota_max_injected_files=5) db.quota_create(self.context, self.project_id, 'injected_files', 77) self.assertEqual(quota.allowed_injected_files(self.context, 100), 77) def test_unlimited_default_allowed_injected_files(self): - FLAGS.quota_max_injected_files = -1 + self.flags(quota_max_injected_files=-1) self.assertEqual(quota.allowed_injected_files(self.context, 100), 100) def test_unlimited_db_allowed_injected_files(self): - FLAGS.quota_max_injected_files = 5 + self.flags(quota_max_injected_files=5) db.quota_create(self.context, self.project_id, 'injected_files', None) self.assertEqual(quota.allowed_injected_files(self.context, 100), 100) def test_default_allowed_injected_file_content_bytes(self): - FLAGS.quota_max_injected_file_content_bytes = 12345 + self.flags(quota_max_injected_file_content_bytes=12345) limit = quota.allowed_injected_file_content_bytes(self.context, 23456) self.assertEqual(limit, 12345) def test_overridden_allowed_injected_file_content_bytes(self): - FLAGS.quota_max_injected_file_content_bytes = 12345 + self.flags(quota_max_injected_file_content_bytes=12345) db.quota_create(self.context, self.project_id, 'injected_file_content_bytes', 5678) limit = quota.allowed_injected_file_content_bytes(self.context, 23456) self.assertEqual(limit, 5678) def test_unlimited_default_allowed_injected_file_content_bytes(self): - FLAGS.quota_max_injected_file_content_bytes = -1 + self.flags(quota_max_injected_file_content_bytes=-1) limit = quota.allowed_injected_file_content_bytes(self.context, 23456) self.assertEqual(limit, 23456) def test_unlimited_db_allowed_injected_file_content_bytes(self): - FLAGS.quota_max_injected_file_content_bytes = 12345 + self.flags(quota_max_injected_file_content_bytes=12345) db.quota_create(self.context, self.project_id, 'injected_file_content_bytes', None) limit = quota.allowed_injected_file_content_bytes(self.context, 23456) self.assertEqual(limit, 23456) def _create_with_injected_files(self, files): - FLAGS.image_service = 'nova.image.fake.FakeImageService' + self.flags(image_service='nova.image.fake.FakeImageService') api = compute.API(image_service=self.StubImageService()) inst_type = instance_types.get_instance_type_by_name('m1.small') api.create(self.context, min_count=1, max_count=1, @@ -336,7 +328,7 @@ class QuotaTestCase(test.TestCase): injected_files=files) def test_no_injected_files(self): - FLAGS.image_service = 'nova.image.fake.FakeImageService' + self.flags(image_service='nova.image.fake.FakeImageService') api = compute.API(image_service=self.StubImageService()) inst_type = instance_types.get_instance_type_by_name('m1.small') api.create(self.context, instance_type=inst_type, image_href='3') diff --git a/nova/tests/test_rpc.py b/nova/tests/test_rpc.py index 2d2436175..ba9c0a859 100644 --- a/nova/tests/test_rpc.py +++ b/nova/tests/test_rpc.py @@ -20,13 +20,11 @@ Unit Tests for remote procedure calls using queue """ from nova import context -from nova import flags from nova import log as logging from nova import rpc from nova import test -FLAGS = flags.FLAGS LOG = logging.getLogger('nova.tests.rpc') diff --git a/nova/tests/test_rpc_amqp.py b/nova/tests/test_rpc_amqp.py index d29f7ae32..2215a908b 100644 --- a/nova/tests/test_rpc_amqp.py +++ b/nova/tests/test_rpc_amqp.py @@ -1,12 +1,32 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2010 Openstack, LLC. +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Tests For RPC AMQP. +""" + from nova import context -from nova import flags from nova import log as logging from nova import rpc from nova.rpc import amqp from nova import test -FLAGS = flags.FLAGS LOG = logging.getLogger('nova.tests.rpc') diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py index bbf47b50f..8f92406ff 100644 --- a/nova/tests/test_service.py +++ b/nova/tests/test_service.py @@ -33,7 +33,6 @@ from nova import manager from nova import wsgi from nova.compute import manager as compute_manager -FLAGS = flags.FLAGS flags.DEFINE_string("fake_manager", "nova.tests.test_service.FakeManager", "Manager for testing") diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index a795b3c74..1ba2bf356 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -71,9 +71,9 @@ class XenAPIVolumeTestCase(test.TestCase): self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) - FLAGS.target_host = '127.0.0.1' - FLAGS.xenapi_connection_url = 'test_url' - FLAGS.xenapi_connection_password = 'test_pass' + self.flags(target_host='127.0.0.1', + xenapi_connection_url='test_url', + xenapi_connection_password='test_pass') db_fakes.stub_out_db_instance_api(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() @@ -719,9 +719,9 @@ class XenAPIMigrateInstance(test.TestCase): def setUp(self): super(XenAPIMigrateInstance, self).setUp() self.stubs = stubout.StubOutForTesting() - FLAGS.target_host = '127.0.0.1' - FLAGS.xenapi_connection_url = 'test_url' - FLAGS.xenapi_connection_password = 'test_pass' + self.flags(target_host='127.0.0.1', + xenapi_connection_url='test_url', + xenapi_connection_password='test_pass') db_fakes.stub_out_db_instance_api(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() -- cgit From 25655e0bcea99ea27108d954104138a09f922f30 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 12:26:51 -0700 Subject: fix test_s3 FLAGS uses --- nova/tests/api/openstack/__init__.py | 3 --- nova/tests/image/test_s3.py | 10 +--------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/nova/tests/api/openstack/__init__.py b/nova/tests/api/openstack/__init__.py index bfb424afe..458434a81 100644 --- a/nova/tests/api/openstack/__init__.py +++ b/nova/tests/api/openstack/__init__.py @@ -22,14 +22,11 @@ import webob.dec from nova import test from nova import context -from nova import flags from nova.api.openstack.limits import RateLimitingMiddleware from nova.api.openstack.common import limited from nova.tests.api.openstack import fakes from webob import Request -FLAGS = flags.FLAGS - @webob.dec.wsgify def simple_wsgi(req): diff --git a/nova/tests/image/test_s3.py b/nova/tests/image/test_s3.py index 231e109f8..f1ceeb7fe 100644 --- a/nova/tests/image/test_s3.py +++ b/nova/tests/image/test_s3.py @@ -16,12 +16,9 @@ # under the License. from nova import context -from nova import flags from nova import test from nova.image import s3 -FLAGS = flags.FLAGS - ami_manifest_xml = """ @@ -59,15 +56,10 @@ ami_manifest_xml = """ class TestS3ImageService(test.TestCase): def setUp(self): super(TestS3ImageService, self).setUp() - self.orig_image_service = FLAGS.image_service - FLAGS.image_service = 'nova.image.fake.FakeImageService' + self.flags(image_service='nova.image.fake.FakeImageService') self.image_service = s3.S3ImageService() self.context = context.RequestContext(None, None) - def tearDown(self): - super(TestS3ImageService, self).tearDown() - FLAGS.image_service = self.orig_image_service - def _assertEqualList(self, list0, list1, keys): self.assertEqual(len(list0), len(list1)) key = keys[0] -- cgit From ff5dbc6d985d11ef937baa930ee96c93cbd8ccf9 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 14:06:56 -0700 Subject: fix more tests that use FLAGS setting --- nova/tests/integrated/integrated_helpers.py | 4 +--- nova/tests/integrated/test_extensions.py | 5 ----- nova/tests/integrated/test_login.py | 4 ---- nova/tests/integrated/test_servers.py | 5 ----- nova/tests/integrated/test_volumes.py | 5 ----- nova/tests/integrated/test_xml.py | 5 ----- 6 files changed, 1 insertion(+), 27 deletions(-) diff --git a/nova/tests/integrated/integrated_helpers.py b/nova/tests/integrated/integrated_helpers.py index 47bd8c1e4..049ddbc60 100644 --- a/nova/tests/integrated/integrated_helpers.py +++ b/nova/tests/integrated/integrated_helpers.py @@ -23,7 +23,6 @@ import random import string from nova import exception -from nova import flags from nova import service from nova import test # For the flags from nova.auth import manager @@ -32,8 +31,6 @@ from nova.log import logging from nova.tests.integrated.api import client -FLAGS = flags.FLAGS - LOG = logging.getLogger('nova.tests.integrated') @@ -151,6 +148,7 @@ class _IntegratedTestBase(test.TestCase): f = self._get_flags() self.flags(**f) + self.set_flags_verbosity(True) def fake_get_image_service(image_href): image_id = int(str(image_href).split('/')[-1]) diff --git a/nova/tests/integrated/test_extensions.py b/nova/tests/integrated/test_extensions.py index 0d4ee8cab..c22cf0be0 100644 --- a/nova/tests/integrated/test_extensions.py +++ b/nova/tests/integrated/test_extensions.py @@ -17,7 +17,6 @@ import os -from nova import flags from nova.log import logging from nova.tests.integrated import integrated_helpers @@ -25,10 +24,6 @@ from nova.tests.integrated import integrated_helpers LOG = logging.getLogger('nova.tests.integrated') -FLAGS = flags.FLAGS -FLAGS.verbose = True - - class ExtensionsTest(integrated_helpers._IntegratedTestBase): def _get_flags(self): f = super(ExtensionsTest, self)._get_flags() diff --git a/nova/tests/integrated/test_login.py b/nova/tests/integrated/test_login.py index a5180b6bc..06359a52f 100644 --- a/nova/tests/integrated/test_login.py +++ b/nova/tests/integrated/test_login.py @@ -17,7 +17,6 @@ import unittest -from nova import flags from nova.log import logging from nova.tests.integrated import integrated_helpers from nova.tests.integrated.api import client @@ -25,9 +24,6 @@ from nova.tests.integrated.api import client LOG = logging.getLogger('nova.tests.integrated') -FLAGS = flags.FLAGS -FLAGS.verbose = True - class LoginTest(integrated_helpers._IntegratedTestBase): def test_login(self): diff --git a/nova/tests/integrated/test_servers.py b/nova/tests/integrated/test_servers.py index 67b3c485a..150279a95 100644 --- a/nova/tests/integrated/test_servers.py +++ b/nova/tests/integrated/test_servers.py @@ -18,7 +18,6 @@ import time import unittest -from nova import flags from nova.log import logging from nova.tests.integrated import integrated_helpers from nova.tests.integrated.api import client @@ -27,10 +26,6 @@ from nova.tests.integrated.api import client LOG = logging.getLogger('nova.tests.integrated') -FLAGS = flags.FLAGS -FLAGS.verbose = True - - class ServersTest(integrated_helpers._IntegratedTestBase): def test_get_servers(self): """Simple check that listing servers works.""" diff --git a/nova/tests/integrated/test_volumes.py b/nova/tests/integrated/test_volumes.py index e9fb3c4d1..d3e936462 100644 --- a/nova/tests/integrated/test_volumes.py +++ b/nova/tests/integrated/test_volumes.py @@ -18,7 +18,6 @@ import unittest import time -from nova import flags from nova.log import logging from nova.tests.integrated import integrated_helpers from nova.tests.integrated.api import client @@ -28,10 +27,6 @@ from nova.volume import driver LOG = logging.getLogger('nova.tests.integrated') -FLAGS = flags.FLAGS -FLAGS.verbose = True - - class VolumesTest(integrated_helpers._IntegratedTestBase): def setUp(self): super(VolumesTest, self).setUp() diff --git a/nova/tests/integrated/test_xml.py b/nova/tests/integrated/test_xml.py index fde32f797..74baaacc2 100644 --- a/nova/tests/integrated/test_xml.py +++ b/nova/tests/integrated/test_xml.py @@ -15,7 +15,6 @@ # License for the specific language governing permissions and limitations # under the License. -from nova import flags from nova.log import logging from nova.tests.integrated import integrated_helpers from nova.api.openstack import common @@ -24,10 +23,6 @@ from nova.api.openstack import common LOG = logging.getLogger('nova.tests.integrated') -FLAGS = flags.FLAGS -FLAGS.verbose = True - - class XmlTests(integrated_helpers._IntegratedTestBase): """"Some basic XML sanity checks.""" -- cgit From 4f9f56d8e9917f5db0c5f76653d7ee3a2db52a5f Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 14:08:22 -0700 Subject: fix scheduler tests that set FLAGS --- nova/tests/scheduler/test_scheduler.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 6a56a57db..f60eb6433 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -962,13 +962,10 @@ class ZoneRedirectTest(test.TestCase): self.stubs.Set(db, 'zone_get_all', zone_get_all) self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get_by_uuid) - - self.enable_zone_routing = FLAGS.enable_zone_routing - FLAGS.enable_zone_routing = True + self.flags(enable_zone_routing=True) def tearDown(self): self.stubs.UnsetAll() - FLAGS.enable_zone_routing = self.enable_zone_routing super(ZoneRedirectTest, self).tearDown() def test_trap_found_locally(self): @@ -998,7 +995,7 @@ class ZoneRedirectTest(test.TestCase): self.assertEquals(e.results['magic'], 'found me') def test_routing_flags(self): - FLAGS.enable_zone_routing = False + self.flags(enable_zone_routing=False) decorator = FakeRerouteCompute("foo") self.assertRaises(exception.InstanceNotFound, decorator(go_boom), None, None, 1) -- cgit From 3765fca2cfd323c047141a27df248d9617d71ad0 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 14:11:37 -0700 Subject: dist scheduler flag setting fixes --- nova/tests/scheduler/test_host_filter.py | 11 ++--------- nova/tests/scheduler/test_least_cost_scheduler.py | 23 +++++++++-------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/nova/tests/scheduler/test_host_filter.py b/nova/tests/scheduler/test_host_filter.py index b1892dab4..b016923c4 100644 --- a/nova/tests/scheduler/test_host_filter.py +++ b/nova/tests/scheduler/test_host_filter.py @@ -19,12 +19,9 @@ Tests For Scheduler Host Filters. import json from nova import exception -from nova import flags from nova import test from nova.scheduler import host_filter -FLAGS = flags.FLAGS - class FakeZoneManager: pass @@ -57,9 +54,8 @@ class HostFilterTestCase(test.TestCase): 'host_name-label': 'xs-%s' % multiplier} def setUp(self): - self.old_flag = FLAGS.default_host_filter - FLAGS.default_host_filter = \ - 'nova.scheduler.host_filter.AllHostsFilter' + default_host_filter = 'nova.scheduler.host_filter.AllHostsFilter' + self.flags(default_host_filter=default_host_filter) self.instance_type = dict(name='tiny', memory_mb=50, vcpus=10, @@ -98,9 +94,6 @@ class HostFilterTestCase(test.TestCase): host09['xpu_arch'] = 'fermi' host09['xpu_info'] = 'Tesla 2150' - def tearDown(self): - FLAGS.default_host_filter = self.old_flag - def test_choose_filter(self): # Test default filter ... hf = host_filter.choose_host_filter() diff --git a/nova/tests/scheduler/test_least_cost_scheduler.py b/nova/tests/scheduler/test_least_cost_scheduler.py index 49791053e..fbe6b2f77 100644 --- a/nova/tests/scheduler/test_least_cost_scheduler.py +++ b/nova/tests/scheduler/test_least_cost_scheduler.py @@ -16,13 +16,11 @@ Tests For Least Cost Scheduler """ -from nova import flags from nova import test from nova.scheduler import least_cost from nova.tests.scheduler import test_zone_aware_scheduler MB = 1024 * 1024 -FLAGS = flags.FLAGS class FakeHost(object): @@ -95,10 +93,9 @@ class LeastCostSchedulerTestCase(test.TestCase): self.assertWeights(expected, num, request_spec, hosts) def test_noop_cost_fn(self): - FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.noop_cost_fn', - ] - FLAGS.noop_cost_fn_weight = 1 + self.flags(least_cost_scheduler_cost_functions=[ + 'nova.scheduler.least_cost.noop_cost_fn'], + noop_cost_fn_weight=1) num = 1 request_spec = {} @@ -109,10 +106,9 @@ class LeastCostSchedulerTestCase(test.TestCase): self.assertWeights(expected, num, request_spec, hosts) def test_cost_fn_weights(self): - FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.noop_cost_fn', - ] - FLAGS.noop_cost_fn_weight = 2 + self.flags(least_cost_scheduler_cost_functions=[ + 'nova.scheduler.least_cost.noop_cost_fn'], + noop_cost_fn_weight=2) num = 1 request_spec = {} @@ -123,10 +119,9 @@ class LeastCostSchedulerTestCase(test.TestCase): self.assertWeights(expected, num, request_spec, hosts) def test_compute_fill_first_cost_fn(self): - FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.compute_fill_first_cost_fn', - ] - FLAGS.compute_fill_first_cost_fn_weight = 1 + self.flags(least_cost_scheduler_cost_functions=[ + 'nova.scheduler.least_cost.compute_fill_first_cost_fn'], + compute_fill_first_cost_fn_weight=1) num = 1 instance_type = {'memory_mb': 1024} -- cgit From 544eecd0adc2c774e512f5c364f6952fb3fd1155 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 14:13:37 -0700 Subject: fix test_cloud FLAGS setting --- nova/tests/test_cloud.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 8c1a74c70..e891fa197 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -99,11 +99,9 @@ class CloudTestCase(test.TestCase): """Makes sure describe regions runs without raising an exception""" result = self.cloud.describe_regions(self.context) self.assertEqual(len(result['regionInfo']), 1) - regions = FLAGS.region_list - FLAGS.region_list = ["one=test_host1", "two=test_host2"] + self.flags(region_list=["one=test_host1", "two=test_host2"]) result = self.cloud.describe_regions(self.context) self.assertEqual(len(result['regionInfo']), 2) - FLAGS.region_list = regions def test_describe_addresses(self): """Makes sure describe addresses runs without raising an exception""" -- cgit From bd0a2ed74764de262a828fd086fa0e08493b2cec Mon Sep 17 00:00:00 2001 From: "matt.dietz@rackspace.com" <> Date: Wed, 3 Aug 2011 17:39:51 -0500 Subject: Fixes lp819397 --- nova/tests/test_xenapi.py | 7 +++++++ nova/virt/xenapi/vmops.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index a795b3c74..26a36b231 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -754,12 +754,18 @@ class XenAPIMigrateInstance(test.TestCase): def test_finish_migrate(self): instance = db.instance_create(self.context, self.values) self.called = False + self.fake_vm_start_called = False + + def fake_vm_start(*args, **kwargs): + self.fake_vm_start_called = True def fake_vdi_resize(*args, **kwargs): self.called = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) + self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) + stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) conn = xenapi_conn.get_connection(False) @@ -781,6 +787,7 @@ class XenAPIMigrateInstance(test.TestCase): dict(base_copy='hurr', cow='durr'), network_info, resize_instance=True) self.assertEqual(self.called, True) + self.assertEqual(self.fake_vm_start_called, True) def test_finish_migrate_no_local_storage(self): tiny_type_id = \ diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index b3b812a48..3b9f35034 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -122,7 +122,7 @@ class VMOps(object): network_info) if resize_instance: self.resize_instance(instance, vdi_uuid) - self._spawn(instance, vm_ref) + self._start(instance, vm_ref=vm_ref) def _start(self, instance, vm_ref=None): """Power on a VM instance""" -- cgit From dbbc07750c2624b61af4f824d29c99bffe5f722f Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 4 Aug 2011 09:40:51 -0500 Subject: Fixed rescue and unrescue. --- nova/compute/manager.py | 25 ++++++++++++------------- nova/exception.py | 3 ++- nova/virt/xenapi/vmops.py | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 8780ad921..cf4ee229d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -648,38 +648,37 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock - def rescue_instance(self, context, instance_uuid): + def rescue_instance(self, context, instance_id): """Rescue an instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) - LOG.audit(_('instance %s: rescuing'), instance_uuid, context=context) + instance_ref = self.db.instance_get(context, instance_id) + LOG.audit(_('instance %s: rescuing'), instance_id, context=context) self.db.instance_set_state(context, - instance_uuid, + instance_id, power_state.NOSTATE, 'rescuing') _update_state = lambda result: self._update_state_callback( - self, context, instance_uuid, result) + self, context, instance_id, result) network_info = self._get_instance_nw_info(context, instance_ref) self.driver.rescue(context, instance_ref, _update_state, network_info) - self._update_state(context, instance_uuid) + self._update_state(context, instance_id) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock - def unrescue_instance(self, context, instance_uuid): + def unrescue_instance(self, context, instance_id): """Rescue an instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) - LOG.audit(_('instance %s: unrescuing'), instance_uuid, - context=context) + instance_ref = self.db.instance_get(context, instance_id) + LOG.audit(_('instance %s: unrescuing'), instance_id, context=context) self.db.instance_set_state(context, - instance_uuid, + instance_id, power_state.NOSTATE, 'unrescuing') _update_state = lambda result: self._update_state_callback( - self, context, instance_uuid, result) + self, context, instance_id, result) network_info = self._get_instance_nw_info(context, instance_ref) self.driver.unrescue(instance_ref, _update_state, network_info) - self._update_state(context, instance_uuid) + self._update_state(context, instance_id) @staticmethod def _update_state_callback(self, context, instance_id, result): diff --git a/nova/exception.py b/nova/exception.py index 68e6ac937..8503f8e3e 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -122,7 +122,8 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, LOG.exception(_('Uncaught exception')) #logging.error(traceback.extract_stack(exc_traceback)) raise Error(str(e)) - raise + # Don't mask the real exception. + raise Exception(e) return wraps(f)(wrapped) return inner diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index b3b812a48..9979a0165 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -935,7 +935,8 @@ class VMOps(object): self.spawn_rescue(context, instance, network_info) rescue_vm_ref = VMHelper.lookup(self._session, instance.name) - vbd_ref = self._session.get_xenapi().VM.get_VBDs(vm_ref)[0] + #NOTE(jk0): Find the root partition, not swap. + vbd_ref = self._session.get_xenapi().VM.get_VBDs(vm_ref)[1] vdi_ref = self._session.get_xenapi().VBD.get_record(vbd_ref)["VDI"] rescue_vbd_ref = VMHelper.create_vbd(self._session, rescue_vm_ref, vdi_ref, 1, False) -- cgit From 5e1d63cf3b16f78f02e9c2642f60a43402a933a9 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 4 Aug 2011 10:41:42 -0400 Subject: Updates to the XenServer glance plugin so that it obtains the set of existing headers and sends them along with the request to PUT a snapshotted image into glance. --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index 86e837849..17a5dbbfb 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -248,6 +248,19 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port, os_type, using chunked-transfer-encoded HTTP. """ conn = httplib.HTTPConnection(glance_host, glance_port) + + # NOTE(dprince): We need to resend any existing Glance meta/property + # headers so they are preserved in Glance. We obtain them here with a + # HEAD request. + conn.request('HEAD', '/v1/images/%s' % image_id) + resp = conn.getresponse() + if resp.status != httplib.OK: + raise Exception("Unexpected response from Glance %i" % resp.status) + headers = {} + for header, value in resp.getheaders(): + if header.lower().startswith("x-image-meta-property-"): + headers[header.lower()] = value + # NOTE(sirp): httplib under python2.4 won't accept a file-like object # to request conn.putrequest('PUT', '/v1/images/%s' % image_id) @@ -260,7 +273,7 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port, os_type, # 2. We're currently uploading a vanilla tarball. In order to be OVF/OVA # compliant, we'll need to embed a minimal OVF manifest as the first # file. - headers = { + ovf_headers = { 'content-type': 'application/octet-stream', 'transfer-encoding': 'chunked', 'x-image-meta-is-public': 'True', @@ -271,7 +284,9 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port, os_type, # If we have an auth_token, set an x-auth-token header if auth_token: - headers['x-auth-token'] = auth_token + ovf_headers['x-auth-token'] = auth_token + + headers.update(ovf_headers) for header, value in headers.iteritems(): conn.putheader(header, value) -- cgit From 4eed25b0f01b510d0d90e864eef7f285964ab293 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 4 Aug 2011 11:11:12 -0400 Subject: The OSAPI v1.0 image create POST request should store the instance_id as a Glance property. --- nova/api/openstack/images.py | 8 ++++++-- nova/tests/api/openstack/test_images.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 0834adfa5..c76738d30 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -116,13 +116,17 @@ class ControllerV10(Controller): try: image_name = image["name"] - server_id = image["serverId"] + instance_id = image["serverId"] except KeyError as missing_key: msg = _("Image entity requires %s") % missing_key raise webob.exc.HTTPBadRequest(explanation=msg) context = req.environ["nova.context"] - image = self._compute_service.snapshot(context, server_id, image_name) + props = {'instance_id': instance_id} + image = self._compute_service.snapshot(context, + instance_id, + image_name, + extra_properties=props) return dict(image=self.get_builder(req).build(image, detail=True)) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 942c0b333..6486a069c 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1031,6 +1031,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): req.headers["content-type"] = "application/json" response = req.get_response(fakes.wsgi_app()) self.assertEqual(200, response.status_int) + image_meta = json.loads(response.body)['image'] + self.assertEqual(123, image_meta['serverId']) + self.assertEqual('Snapshot 1', image_meta['name']) def test_create_snapshot_no_name(self): """Name is required for snapshots""" -- cgit From 8fd335e309ea48d1460ee4d04105e429575f47f6 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 4 Aug 2011 10:03:15 -0700 Subject: fix up new test_server_actions.py file for flags verbosity change --- nova/tests/api/openstack/test_server_actions.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py index fc08a2d53..baec5f3d1 100644 --- a/nova/tests/api/openstack/test_server_actions.py +++ b/nova/tests/api/openstack/test_server_actions.py @@ -8,7 +8,6 @@ import webob from nova import context from nova import db -from nova import flags from nova import utils from nova.api.openstack import create_instance_helper from nova.compute import instance_types @@ -19,10 +18,6 @@ from nova.tests.api.openstack import common from nova.tests.api.openstack import fakes -FLAGS = flags.FLAGS -FLAGS.verbose = True - - def return_server_by_id(context, id): return _get_instance() @@ -102,6 +97,7 @@ class ServerActionsTest(test.TestCase): def setUp(self): self.maxDiff = None super(ServerActionsTest, self).setUp() + self.set_flags_verbosity(True) self.stubs = stubout.StubOutForTesting() fakes.FakeAuthManager.reset_fake_data() fakes.FakeAuthDatabase.data = {} -- cgit From 24b308ebb4f7fff5520383248170bfb7d51c6755 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 4 Aug 2011 10:17:55 -0700 Subject: test_host_filter setUp needs to call its super --- nova/tests/scheduler/test_host_filter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nova/tests/scheduler/test_host_filter.py b/nova/tests/scheduler/test_host_filter.py index b016923c4..7e664d3f9 100644 --- a/nova/tests/scheduler/test_host_filter.py +++ b/nova/tests/scheduler/test_host_filter.py @@ -54,6 +54,7 @@ class HostFilterTestCase(test.TestCase): 'host_name-label': 'xs-%s' % multiplier} def setUp(self): + super(HostFilterTestCase, self).setUp() default_host_filter = 'nova.scheduler.host_filter.AllHostsFilter' self.flags(default_host_filter=default_host_filter) self.instance_type = dict(name='tiny', -- cgit From 7f35619377593b5bb30425984999e8bb9ed2bdb2 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 4 Aug 2011 10:34:36 -0700 Subject: fix pep8 issues that are in trunk --- nova/compute/manager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 94bac9be4..9f566dea7 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -167,10 +167,12 @@ class ComputeManager(manager.SchedulerDependentManager): 'nova-compute restart.'), locals()) self.reboot_instance(context, instance['id']) elif drv_state == power_state.RUNNING: - try: # Hyper-V and VMWareAPI drivers will raise and exception + # Hyper-V and VMWareAPI drivers will raise and exception + try: self.driver.ensure_filtering_rules_for_instance(instance) except NotImplementedError: - LOG.warning(_('Hypervisor driver does not support firewall rules')) + LOG.warning(_('Hypervisor driver does not ' + 'support firewall rules')) def _update_state(self, context, instance_id, state=None): """Update the state of an instance from the driver info.""" -- cgit From ca79470843ff351623d07378ab553b2548cb8dc0 Mon Sep 17 00:00:00 2001 From: Mandell Degerness Date: Thu, 4 Aug 2011 10:43:16 -0700 Subject: Fix to nova-ajax-console-proxy to use the new syntax. create_consumer and create_connection abstractions were added recently. --- Authors | 1 + bin/nova-ajax-console-proxy | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Authors b/Authors index 0e5931462..b216873df 100644 --- a/Authors +++ b/Authors @@ -64,6 +64,7 @@ Kirill Shileev Koji Iida Lorin Hochstein Lvov Maxim +Mandell Degerness Mark Washenberger Masanori Itoh Matt Dietz diff --git a/bin/nova-ajax-console-proxy b/bin/nova-ajax-console-proxy index 21cf68007..2329581a2 100755 --- a/bin/nova-ajax-console-proxy +++ b/bin/nova-ajax-console-proxy @@ -114,11 +114,11 @@ class AjaxConsoleProxy(object): AjaxConsoleProxy.tokens[kwargs['token']] = \ {'args': kwargs, 'last_activity': time.time()} - conn = rpc.Connection.instance(new=True) - consumer = rpc.TopicAdapterConsumer( - connection=conn, - proxy=TopicProxy, - topic=FLAGS.ajax_console_proxy_topic) + conn = rpc.create_connection(new=True) + consumer = rpc.create_consumer( + conn, + FLAGS.ajax_console_proxy_topic, + TopicProxy) def delete_expired_tokens(): now = time.time() -- cgit From 7f35b6ee93ea2192a8c81a7c17e2e74694a397a1 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 4 Aug 2011 12:07:07 -0700 Subject: remove set_flags_verbosity.. it's not needed --- nova/test.py | 5 ----- nova/tests/api/openstack/test_accounts.py | 3 +-- nova/tests/api/openstack/test_adminapi.py | 2 +- nova/tests/api/openstack/test_server_actions.py | 2 +- nova/tests/api/openstack/test_servers.py | 2 +- nova/tests/api/openstack/test_users.py | 3 +-- nova/tests/api/openstack/test_zones.py | 3 +-- nova/tests/integrated/integrated_helpers.py | 2 +- 8 files changed, 7 insertions(+), 15 deletions(-) diff --git a/nova/test.py b/nova/test.py index fa5a662fd..ff85deeda 100644 --- a/nova/test.py +++ b/nova/test.py @@ -156,11 +156,6 @@ class TestCase(unittest.TestCase): FLAGS.Reset() for k, v in self._original_flags.iteritems(): setattr(FLAGS, k, v) - FLAGS.verbose = self._original_flags_verbosity - - def set_flags_verbosity(self, verbose=True): - """Set the FLAGS verbosity for a test""" - FLAGS.verbose = verbose def start_service(self, name, host=None, **kwargs): host = host and host or uuid.uuid4().hex diff --git a/nova/tests/api/openstack/test_accounts.py b/nova/tests/api/openstack/test_accounts.py index b1ca546d2..707a2599f 100644 --- a/nova/tests/api/openstack/test_accounts.py +++ b/nova/tests/api/openstack/test_accounts.py @@ -35,8 +35,7 @@ def fake_admin_check(self, req): class AccountsTest(test.TestCase): def setUp(self): super(AccountsTest, self).setUp() - self.flags(allow_admin_api=True) - self.set_flags_verbosity(True) + self.flags(verbose=True, allow_admin_api=True) self.stubs.Set(accounts.Controller, '__init__', fake_init) self.stubs.Set(accounts.Controller, '_check_admin', diff --git a/nova/tests/api/openstack/test_adminapi.py b/nova/tests/api/openstack/test_adminapi.py index 9d03a7f9d..c9e66dc4c 100644 --- a/nova/tests/api/openstack/test_adminapi.py +++ b/nova/tests/api/openstack/test_adminapi.py @@ -28,7 +28,7 @@ class AdminAPITest(test.TestCase): super(AdminAPITest, self).setUp() fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) - self.set_flags_verbosity(True) + self.flags(verbose=True) def test_admin_enabled(self): self.flags(allow_admin_api=True) diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py index baec5f3d1..562cefe90 100644 --- a/nova/tests/api/openstack/test_server_actions.py +++ b/nova/tests/api/openstack/test_server_actions.py @@ -97,7 +97,7 @@ class ServerActionsTest(test.TestCase): def setUp(self): self.maxDiff = None super(ServerActionsTest, self).setUp() - self.set_flags_verbosity(True) + self.flags(verbose=True) self.stubs = stubout.StubOutForTesting() fakes.FakeAuthManager.reset_fake_data() fakes.FakeAuthDatabase.data = {} diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index bb411af10..0477f6d92 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -230,7 +230,7 @@ class ServersTest(test.TestCase): def setUp(self): self.maxDiff = None super(ServersTest, self).setUp() - self.set_flags_verbosity(True) + self.flags(verbose=True) fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) diff --git a/nova/tests/api/openstack/test_users.py b/nova/tests/api/openstack/test_users.py index 649538f11..1d133f9ab 100644 --- a/nova/tests/api/openstack/test_users.py +++ b/nova/tests/api/openstack/test_users.py @@ -35,8 +35,7 @@ def fake_admin_check(self, req): class UsersTest(test.TestCase): def setUp(self): super(UsersTest, self).setUp() - self.flags(allow_admin_api=True) - self.set_flags_verbosity(True) + self.flags(verbose=True, allow_admin_api=True) self.stubs.Set(users.Controller, '__init__', fake_init) self.stubs.Set(users.Controller, '_check_admin', diff --git a/nova/tests/api/openstack/test_zones.py b/nova/tests/api/openstack/test_zones.py index 442ee4313..4a46a5764 100644 --- a/nova/tests/api/openstack/test_zones.py +++ b/nova/tests/api/openstack/test_zones.py @@ -94,8 +94,7 @@ def zone_select(context, specs): class ZonesTest(test.TestCase): def setUp(self): super(ZonesTest, self).setUp() - self.flags(allow_admin_api=True) - self.set_flags_verbosity(True) + self.flags(verbose=True, allow_admin_api=True) fakes.stub_out_networking(self.stubs) fakes.stub_out_rate_limiting(self.stubs) diff --git a/nova/tests/integrated/integrated_helpers.py b/nova/tests/integrated/integrated_helpers.py index 049ddbc60..fb2f88502 100644 --- a/nova/tests/integrated/integrated_helpers.py +++ b/nova/tests/integrated/integrated_helpers.py @@ -148,7 +148,7 @@ class _IntegratedTestBase(test.TestCase): f = self._get_flags() self.flags(**f) - self.set_flags_verbosity(True) + self.flags(verbose=True) def fake_get_image_service(image_href): image_id = int(str(image_href).split('/')[-1]) -- cgit From b02fb7f6a3c35673122d7f409d8c999cc9fbae46 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 4 Aug 2011 12:21:09 -0700 Subject: remove storing original flags verbosity --- nova/test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/test.py b/nova/test.py index ff85deeda..5760d7a82 100644 --- a/nova/test.py +++ b/nova/test.py @@ -100,7 +100,6 @@ class TestCase(unittest.TestCase): self.injected = [] self._services = [] self._original_flags = FLAGS.FlagValuesDict() - self._original_flags_verbosity = FLAGS.verbose def tearDown(self): """Runs after each test method to tear down test environment.""" -- cgit From cae90fb1d5a798673416e51c5cf1f7db6cbd6c23 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 4 Aug 2011 14:30:12 -0500 Subject: Fixed rescue and unrescue. --- nova/compute/manager.py | 10 ++++------ nova/virt/xenapi/vmops.py | 4 ++-- nova/virt/xenapi_conn.py | 8 ++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index cf4ee229d..c6af0dfbe 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -651,16 +651,15 @@ class ComputeManager(manager.SchedulerDependentManager): def rescue_instance(self, context, instance_id): """Rescue an instance on this host.""" context = context.elevated() + self._update_state(context, instance_id) instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_('instance %s: rescuing'), instance_id, context=context) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'rescuing') - _update_state = lambda result: self._update_state_callback( - self, context, instance_id, result) network_info = self._get_instance_nw_info(context, instance_ref) - self.driver.rescue(context, instance_ref, _update_state, network_info) + self.driver.rescue(context, instance_ref, None, network_info) self._update_state(context, instance_id) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @@ -668,16 +667,15 @@ class ComputeManager(manager.SchedulerDependentManager): def unrescue_instance(self, context, instance_id): """Rescue an instance on this host.""" context = context.elevated() + self._update_state(context, instance_id) instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_('instance %s: unrescuing'), instance_id, context=context) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'unrescuing') - _update_state = lambda result: self._update_state_callback( - self, context, instance_id, result) network_info = self._get_instance_nw_info(context, instance_ref) - self.driver.unrescue(instance_ref, _update_state, network_info) + self.driver.unrescue(instance_ref, None, network_info) self._update_state(context, instance_id) @staticmethod diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 9979a0165..5badbac31 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -914,7 +914,7 @@ class VMOps(object): True) self._wait_with_callback(instance.id, task, callback) - def rescue(self, context, instance, callback, network_info): + def rescue(self, context, instance, _callback, network_info): """Rescue the specified instance. - shutdown the instance VM. @@ -943,7 +943,7 @@ class VMOps(object): self._session.call_xenapi("Async.VBD.plug", rescue_vbd_ref) - def unrescue(self, instance, callback): + def unrescue(self, instance, _callback): """Unrescue the specified instance. - unplug the instance VM's disk from the rescue VM. diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 39afbd650..9dcbb3cf9 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -242,13 +242,13 @@ class XenAPIConnection(driver.ComputeDriver): """resume the specified instance""" self._vmops.resume(instance, callback) - def rescue(self, context, instance, callback, network_info): + def rescue(self, context, instance, _callback, network_info): """Rescue the specified instance""" - self._vmops.rescue(context, instance, callback, network_info) + self._vmops.rescue(context, instance, _callback, network_info) - def unrescue(self, instance, callback, network_info): + def unrescue(self, instance, _callback, network_info): """Unrescue the specified instance""" - self._vmops.unrescue(instance, callback) + self._vmops.unrescue(instance, _callback) def poll_rescued_instances(self, timeout): """Poll for rescued instances""" -- cgit From 12404f486a825dc8afdc45db0b10347a3a782e6d Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 4 Aug 2011 14:41:54 -0500 Subject: Removed temporary debugging raise. --- nova/exception.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nova/exception.py b/nova/exception.py index 8503f8e3e..68e6ac937 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -122,8 +122,7 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, LOG.exception(_('Uncaught exception')) #logging.error(traceback.extract_stack(exc_traceback)) raise Error(str(e)) - # Don't mask the real exception. - raise Exception(e) + raise return wraps(f)(wrapped) return inner -- cgit From b8d4004e9de28dae47c6a1772a0caac965f7a69f Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 4 Aug 2011 15:16:42 -0500 Subject: Fixed rescue unit tests. --- nova/tests/test_xenapi.py | 6 ++++++ nova/virt/xenapi/vmops.py | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index a795b3c74..1bc55027a 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -170,6 +170,10 @@ def reset_network(*args): pass +def _find_rescue_vbd_ref(*args): + pass + + class XenAPIVMTestCase(test.TestCase): """Unit tests for VM operations.""" def setUp(self): @@ -189,6 +193,8 @@ class XenAPIVMTestCase(test.TestCase): stubs.stubout_stream_disk(self.stubs) stubs.stubout_is_vdi_pv(self.stubs) self.stubs.Set(vmops.VMOps, 'reset_network', reset_network) + self.stubs.Set(vmops.VMOps, '_find_rescue_vbd_ref', + _find_rescue_vbd_ref) stubs.stub_out_vm_methods(self.stubs) glance_stubs.stubout_glance_client(self.stubs) fake_utils.stub_out_utils_execute(self.stubs) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 5badbac31..81c6c6967 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -743,6 +743,14 @@ class VMOps(object): except self.XenAPI.Failure, exc: LOG.exception(exc) + def _find_rescue_vbd_ref(self, vm_ref, rescue_vm_ref): + """Find and return the rescue VM's vbd_ref.""" + vbd_ref = self._session.get_xenapi().VM.get_VBDs(vm_ref)[1] + vdi_ref = self._session.get_xenapi().VBD.get_record(vbd_ref)["VDI"] + + return VMHelper.create_vbd(self._session, rescue_vm_ref, vdi_ref, 1, + False) + def _shutdown_rescue(self, rescue_vm_ref): """Shutdown a rescue instance.""" self._session.call_xenapi("Async.VM.hard_shutdown", rescue_vm_ref) @@ -934,12 +942,7 @@ class VMOps(object): instance._rescue = True self.spawn_rescue(context, instance, network_info) rescue_vm_ref = VMHelper.lookup(self._session, instance.name) - - #NOTE(jk0): Find the root partition, not swap. - vbd_ref = self._session.get_xenapi().VM.get_VBDs(vm_ref)[1] - vdi_ref = self._session.get_xenapi().VBD.get_record(vbd_ref)["VDI"] - rescue_vbd_ref = VMHelper.create_vbd(self._session, rescue_vm_ref, - vdi_ref, 1, False) + rescue_vbd_ref = self._find_rescue_vbd_ref(vm_ref, rescue_vm_ref) self._session.call_xenapi("Async.VBD.plug", rescue_vbd_ref) -- cgit From eca23b1ad18a8626dd68cded4d488ca1aa779f69 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 4 Aug 2011 15:22:36 -0500 Subject: Removed debugging code. --- nova/compute/manager.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index c6af0dfbe..cf4ee229d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -651,15 +651,16 @@ class ComputeManager(manager.SchedulerDependentManager): def rescue_instance(self, context, instance_id): """Rescue an instance on this host.""" context = context.elevated() - self._update_state(context, instance_id) instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_('instance %s: rescuing'), instance_id, context=context) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'rescuing') + _update_state = lambda result: self._update_state_callback( + self, context, instance_id, result) network_info = self._get_instance_nw_info(context, instance_ref) - self.driver.rescue(context, instance_ref, None, network_info) + self.driver.rescue(context, instance_ref, _update_state, network_info) self._update_state(context, instance_id) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @@ -667,15 +668,16 @@ class ComputeManager(manager.SchedulerDependentManager): def unrescue_instance(self, context, instance_id): """Rescue an instance on this host.""" context = context.elevated() - self._update_state(context, instance_id) instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_('instance %s: unrescuing'), instance_id, context=context) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'unrescuing') + _update_state = lambda result: self._update_state_callback( + self, context, instance_id, result) network_info = self._get_instance_nw_info(context, instance_ref) - self.driver.unrescue(instance_ref, None, network_info) + self.driver.unrescue(instance_ref, _update_state, network_info) self._update_state(context, instance_id) @staticmethod -- cgit From 475963efeae1b12ae7474508559fb904bc9c1675 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 4 Aug 2011 15:31:18 -0500 Subject: Added more informative docstring. --- nova/virt/xenapi/vmops.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 81c6c6967..69f1af75a 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -744,7 +744,10 @@ class VMOps(object): LOG.exception(exc) def _find_rescue_vbd_ref(self, vm_ref, rescue_vm_ref): - """Find and return the rescue VM's vbd_ref.""" + """Find and return the rescue VM's vbd_ref. + + We use the second VBD here because swap is first with the root file + system coming in second.""" vbd_ref = self._session.get_xenapi().VM.get_VBDs(vm_ref)[1] vdi_ref = self._session.get_xenapi().VBD.get_record(vbd_ref)["VDI"] -- cgit