diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2011-08-03 12:22:58 -0700 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2011-08-03 12:22:58 -0700 |
| commit | 8efe41aaa4993d0aa9ad381d202ba7b7d025939e (patch) | |
| tree | 49e3cbd02da6fcc1ac1ca46aa15841fd9bc2b870 | |
| parent | d7f704876f5cfab165c855170468274e57935d15 (diff) | |
| download | nova-8efe41aaa4993d0aa9ad381d202ba7b7d025939e.tar.gz nova-8efe41aaa4993d0aa9ad381d202ba7b7d025939e.tar.xz nova-8efe41aaa4993d0aa9ad381d202ba7b7d025939e.zip | |
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
| -rw-r--r-- | nova/test.py | 8 | ||||
| -rw-r--r-- | nova/tests/hyperv_unittest.py | 5 | ||||
| -rw-r--r-- | nova/tests/test_auth.py | 4 | ||||
| -rw-r--r-- | nova/tests/test_host_filter.py | 12 | ||||
| -rw-r--r-- | nova/tests/test_ipv6.py | 3 | ||||
| -rw-r--r-- | nova/tests/test_libvirt.py | 23 | ||||
| -rw-r--r-- | nova/tests/test_network.py | 2 | ||||
| -rw-r--r-- | nova/tests/test_quota.py | 42 | ||||
| -rw-r--r-- | nova/tests/test_rpc.py | 2 | ||||
| -rw-r--r-- | nova/tests/test_rpc_amqp.py | 24 | ||||
| -rw-r--r-- | nova/tests/test_service.py | 1 | ||||
| -rw-r--r-- | 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() |
