From 899dbbf71b681e92d5f1d1f11389825f85b98491 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 3 Aug 2011 12:22:58 -0700 Subject: [PATCH] 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/tests/hyperv_unittest.py | 5 +---- nova/tests/test_auth.py | 4 ++-- nova/tests/test_host_filter.py | 12 +++--------- nova/tests/test_libvirt.py | 23 +++++++++-------------- nova/tests/test_network.py | 2 -- nova/tests/test_rpc.py | 2 -- nova/tests/test_rpc_amqp.py | 24 ++++++++++++++++++++++-- nova/tests/test_xenapi.py | 12 ++++++------ 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/nova/tests/hyperv_unittest.py b/nova/tests/hyperv_unittest.py index 0ea19695..d346d0a7 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 7c0f783b..2e24b7d6 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 438f3e52..3a1389a4 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_libvirt.py b/nova/tests/test_libvirt.py index cf25ce21..f8b86698 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 28f50d32..2ca8b64f 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_rpc.py b/nova/tests/test_rpc.py index 2d243617..ba9c0a85 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 d29f7ae3..2215a908 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_xenapi.py b/nova/tests/test_xenapi.py index a795b3c7..1ba2bf35 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()