Switch from FLAGS to CONF in tests

Use the global CONF variable instead of FLAGS. This is purely a cleanup
since FLAGS is already just another reference to CONF.

We leave the nova.flags imports until a later cleanup commit since
removing them may cause unpredictable problems due to config options not
being registered.

Change-Id: Ic0168188dfe214fc81af04c8a9644d2d9f31600d
This commit is contained in:
Mark McLoughlin 2012-11-04 21:32:53 +00:00
parent 827998fd9a
commit ffdf02175e
21 changed files with 173 additions and 184 deletions

View File

@ -49,8 +49,8 @@ test_opts = [
help='should we use everything for testing'),
]
FLAGS = flags.FLAGS
FLAGS.register_opts(test_opts)
CONF = config.CONF
CONF.register_opts(test_opts)
LOG = logging.getLogger(__name__)
@ -66,7 +66,7 @@ class TestCase(testtools.TestCase):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
fake_flags.set_defaults(FLAGS)
fake_flags.set_defaults(CONF)
config.parse_args([], default_config_files=[])
# NOTE(vish): We need a better method for creating fixtures for tests
@ -93,7 +93,7 @@ class TestCase(testtools.TestCase):
super(TestCase, self).tearDown()
finally:
# Reset any overridden flags
FLAGS.reset()
CONF.reset()
# Unstub modules
for name, mod in self._modules.iteritems():
@ -131,7 +131,7 @@ class TestCase(testtools.TestCase):
def flags(self, **kw):
"""Override flag variables for a test."""
for k, v in kw.iteritems():
FLAGS.set_override(k, v)
CONF.set_override(k, v)
def start_service(self, name, host=None, **kwargs):
host = host and host or uuid.uuid4().hex

View File

@ -31,6 +31,7 @@ setattr(__builtin__, '_', lambda x: x)
import os
import shutil
from nova import config
from nova.db.sqlalchemy.session import get_engine
from nova import flags
from nova.openstack.common import log as logging
@ -40,8 +41,8 @@ import eventlet
eventlet.monkey_patch(os=False)
FLAGS = flags.FLAGS
FLAGS.use_stderr = False
CONF = config.CONF
CONF.set_override('use_stderr', False)
logging.setup('nova')
@ -49,7 +50,7 @@ _DB = None
def reset_db():
if FLAGS.sql_connection == "sqlite://":
if CONF.sql_connection == "sqlite://":
engine = get_engine()
engine.dispose()
conn = engine.connect()
@ -58,8 +59,8 @@ def reset_db():
else:
setup()
else:
shutil.copyfile(os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db),
os.path.join(FLAGS.state_path, FLAGS.sqlite_db))
shutil.copyfile(os.path.join(CONF.state_path, CONF.sqlite_clean_db),
os.path.join(CONF.state_path, CONF.sqlite_db))
def setup():
@ -70,41 +71,41 @@ def setup():
from nova.db import migration
from nova.network import manager as network_manager
from nova.tests import fake_flags
fake_flags.set_defaults(FLAGS)
fake_flags.set_defaults(CONF)
if FLAGS.sql_connection == "sqlite://":
if CONF.sql_connection == "sqlite://":
if migration.db_version() > migration.INIT_VERSION:
return
else:
testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
testdb = os.path.join(CONF.state_path, CONF.sqlite_db)
if os.path.exists(testdb):
return
migration.db_sync()
ctxt = context.get_admin_context()
network = network_manager.VlanManager()
bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
bridge_interface = CONF.flat_interface or CONF.vlan_interface
network.create_networks(ctxt,
label='test',
cidr=FLAGS.fixed_range,
multi_host=FLAGS.multi_host,
num_networks=FLAGS.num_networks,
network_size=FLAGS.network_size,
cidr_v6=FLAGS.fixed_range_v6,
gateway=FLAGS.gateway,
gateway_v6=FLAGS.gateway_v6,
bridge=FLAGS.flat_network_bridge,
cidr=CONF.fixed_range,
multi_host=CONF.multi_host,
num_networks=CONF.num_networks,
network_size=CONF.network_size,
cidr_v6=CONF.fixed_range_v6,
gateway=CONF.gateway,
gateway_v6=CONF.gateway_v6,
bridge=CONF.flat_network_bridge,
bridge_interface=bridge_interface,
vpn_start=FLAGS.vpn_start,
vlan_start=FLAGS.vlan_start,
dns1=FLAGS.flat_network_dns)
vpn_start=CONF.vpn_start,
vlan_start=CONF.vlan_start,
dns1=CONF.flat_network_dns)
for net in db.network_get_all(ctxt):
network.set_network_host(ctxt, net)
if FLAGS.sql_connection == "sqlite://":
if CONF.sql_connection == "sqlite://":
global _DB
engine = get_engine()
conn = engine.connect()
_DB = "".join(line for line in conn.connection.iterdump())
else:
cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
cleandb = os.path.join(CONF.state_path, CONF.sqlite_clean_db)
shutil.copyfile(testdb, cleandb)

View File

@ -29,10 +29,6 @@ from nova.tests import fake_utils
from nova.virt.baremetal import dom
from nova.virt.baremetal import driver
FLAGS = flags.FLAGS
# Same fake_domains is used by different classes,
# but different fake_file is used by different classes for unit test.
fake_domains = [{'status': 1, 'name': 'instance-00000001',

View File

@ -16,8 +16,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova import flags
from nova import config
from nova.openstack.common import cfg
FLAGS = flags.FLAGS
FLAGS.register_opt(cfg.IntOpt('answer', default=42, help='test flag'))
CONF = config.CONF
CONF.register_opt(cfg.IntOpt('answer', default=42, help='test flag'))

View File

@ -16,8 +16,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova import flags
from nova import config
from nova.openstack.common import cfg
FLAGS = flags.FLAGS
FLAGS.register_opt(cfg.IntOpt('runtime_answer', default=54, help='test flag'))
CONF = config.CONF
CONF.register_opt(cfg.IntOpt('runtime_answer', default=54, help='test flag'))

View File

@ -18,6 +18,7 @@ Tests For Scheduler Host Filters.
import httplib
import stubout
from nova import config
from nova import context
from nova import db
from nova import exception
@ -30,7 +31,7 @@ from nova import test
from nova.tests.scheduler import fakes
from nova import utils
CONF = config.CONF
DATA = ''
@ -433,7 +434,7 @@ class HostFiltersTestCase(test.TestCase):
filt_cls = self.class_map['SimpleCIDRAffinityFilter']()
host = fakes.FakeHostState('host1', 'node1', {})
affinity_ip = flags.FLAGS.my_ip.split('.')[0:3]
affinity_ip = CONF.my_ip.split('.')[0:3]
affinity_ip.append('100')
affinity_ip = str.join('.', affinity_ip)

View File

@ -18,14 +18,14 @@
Unit Tests for nova.scheduler.rpcapi
"""
from nova import config
from nova import context
from nova import flags
from nova.openstack.common import rpc
from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import test
FLAGS = flags.FLAGS
CONF = config.CONF
class SchedulerRpcAPITestCase(test.TestCase):
@ -51,7 +51,7 @@ class SchedulerRpcAPITestCase(test.TestCase):
retval = getattr(rpcapi, method)(ctxt, **kwargs)
self.assertEqual(retval, expected_retval)
expected_args = [ctxt, FLAGS.scheduler_topic, expected_msg]
expected_args = [ctxt, CONF.scheduler_topic, expected_msg]
for arg, expected_arg in zip(self.fake_args, expected_args):
self.assertEqual(arg, expected_arg)

View File

@ -39,8 +39,6 @@ from nova import test
from nova.tests.scheduler import fakes
from nova import utils
FLAGS = flags.FLAGS
class SchedulerManagerTestCase(test.TestCase):
"""Test case for scheduler manager"""

View File

@ -43,9 +43,6 @@ from nova.openstack.common import timeutils
from nova import test
FLAGS = flags.FLAGS
class FakeHttplibSocket(object):
"""a fake socket implementation for httplib.HTTPResponse, trivial"""
def __init__(self, response_string):

View File

@ -30,8 +30,6 @@ from nova.openstack.common import timeutils
from nova import test
from nova import utils
FLAGS = flags.FLAGS
CONF = config.CONF
CONF.import_opt('reserved_host_memory_mb', 'nova.compute.resource_tracker')
CONF.import_opt('reserved_host_disk_mb', 'nova.compute.resource_tracker')

View File

@ -23,8 +23,7 @@ from nova.openstack.common import cfg
from nova import test
CONF = config.CONF
FLAGS = flags.FLAGS
FLAGS.register_opt(cfg.StrOpt('flags_unittest',
CONF.register_opt(cfg.StrOpt('flags_unittest',
default='foo',
help='for testing purposes only'))
@ -43,7 +42,7 @@ class FlagsTestCase(test.TestCase):
self.assertEqual(CONF.answer, 256)
def test_getopt_non_interspersed_args(self):
self.assert_('runtime_answer' not in FLAGS)
self.assert_('runtime_answer' not in CONF)
argv = ['flags_test', 'extra_arg', '--runtime_answer=60']
args = config.parse_args(argv, default_config_files=[])
@ -51,42 +50,42 @@ class FlagsTestCase(test.TestCase):
self.assertEqual(argv, args)
def test_runtime_and_unknown_flags(self):
self.assert_('runtime_answer' not in FLAGS)
self.assert_('runtime_answer' not in CONF)
import nova.tests.runtime_flags
self.assert_('runtime_answer' in FLAGS)
self.assertEqual(FLAGS.runtime_answer, 54)
self.assert_('runtime_answer' in CONF)
self.assertEqual(CONF.runtime_answer, 54)
def test_long_vs_short_flags(self):
FLAGS.clear()
FLAGS.register_cli_opt(cfg.StrOpt('duplicate_answer_long',
CONF.clear()
CONF.register_cli_opt(cfg.StrOpt('duplicate_answer_long',
default='val',
help='desc'))
argv = ['flags_test', '--duplicate_answer=60', 'extra_arg']
args = config.parse_args(argv, default_config_files=[])
self.assert_('duplicate_answer' not in FLAGS)
self.assert_(FLAGS.duplicate_answer_long, 60)
self.assert_('duplicate_answer' not in CONF)
self.assert_(CONF.duplicate_answer_long, 60)
FLAGS.clear()
FLAGS.register_cli_opt(cfg.IntOpt('duplicate_answer',
CONF.clear()
CONF.register_cli_opt(cfg.IntOpt('duplicate_answer',
default=60, help='desc'))
args = config.parse_args(argv, default_config_files=[])
self.assertEqual(FLAGS.duplicate_answer, 60)
self.assertEqual(FLAGS.duplicate_answer_long, 'val')
self.assertEqual(CONF.duplicate_answer, 60)
self.assertEqual(CONF.duplicate_answer_long, 'val')
def test_flag_leak_left(self):
self.assertEqual(FLAGS.flags_unittest, 'foo')
self.assertEqual(CONF.flags_unittest, 'foo')
self.flags(flags_unittest='bar')
self.assertEqual(FLAGS.flags_unittest, 'bar')
self.assertEqual(CONF.flags_unittest, 'bar')
def test_flag_leak_right(self):
self.assertEqual(FLAGS.flags_unittest, 'foo')
self.assertEqual(CONF.flags_unittest, 'foo')
self.flags(flags_unittest='bar')
self.assertEqual(FLAGS.flags_unittest, 'bar')
self.assertEqual(CONF.flags_unittest, 'bar')
def test_flag_overrides(self):
self.assertEqual(FLAGS.flags_unittest, 'foo')
self.assertEqual(CONF.flags_unittest, 'foo')
self.flags(flags_unittest='bar')
self.assertEqual(FLAGS.flags_unittest, 'bar')
FLAGS.reset()
self.assertEqual(FLAGS.flags_unittest, 'foo')
self.assertEqual(CONF.flags_unittest, 'bar')
CONF.reset()
self.assertEqual(CONF.flags_unittest, 'foo')

View File

@ -25,6 +25,7 @@ import sys
import uuid
from nova.compute import power_state
from nova import config
from nova import context
from nova import db
from nova import flags
@ -40,6 +41,8 @@ from nova.virt.hyperv import driver as driver_hyperv
from nova.virt.hyperv import vmutils
from nova.virt import images
CONF = config.CONF
class HyperVAPITestCase(basetestcase.BaseTestCase):
"""Unit tests for Hyper-V driver calls."""
@ -148,7 +151,7 @@ class HyperVAPITestCase(basetestcase.BaseTestCase):
self._hypervutils.logout_iscsi_volume_sessions(self._volume_id)
shutil.rmtree(flags.FLAGS.instances_path, True)
shutil.rmtree(CONF.instances_path, True)
fake_image.FakeImageService_reset()
finally:

View File

@ -17,13 +17,14 @@
import os
from nova import config
from nova import flags
from nova.openstack.common import fileutils
from nova import test
from nova.tests import fake_libvirt_utils
from nova.virt.libvirt import imagebackend
FLAGS = flags.FLAGS
CONF = config.CONF
class _ImageTestCase(test.TestCase):
@ -42,9 +43,9 @@ class _ImageTestCase(test.TestCase):
self.NAME = 'fake.vm'
self.TEMPLATE = 'template'
self.PATH = os.path.join(FLAGS.instances_path, self.INSTANCE,
self.PATH = os.path.join(CONF.instances_path, self.INSTANCE,
self.NAME)
self.TEMPLATE_DIR = os.path.join(FLAGS.instances_path,
self.TEMPLATE_DIR = os.path.join(CONF.instances_path,
'_base')
self.TEMPLATE_PATH = os.path.join(self.TEMPLATE_DIR, 'template')

View File

@ -27,6 +27,7 @@ from nova import test
from nova.compute import manager as compute_manager
from nova.compute import vm_states
from nova import config
from nova import db
from nova import flags
from nova.openstack.common import importutils
@ -35,8 +36,7 @@ from nova import utils
from nova.virt.libvirt import imagecache
from nova.virt.libvirt import utils as virtutils
FLAGS = flags.FLAGS
CONF = config.CONF
LOG = log.getLogger(__name__)
@ -147,13 +147,13 @@ class ImageCacheManagerTestCase(test.TestCase):
def test_list_running_instances(self):
all_instances = [{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'inst-1',
'uuid': '123',
'vm_state': '',
'task_state': ''},
{'image_ref': '2',
'host': FLAGS.host,
'host': CONF.host,
'name': 'inst-2',
'uuid': '456',
'vm_state': '',
@ -182,7 +182,7 @@ class ImageCacheManagerTestCase(test.TestCase):
def test_list_resizing_instances(self):
all_instances = [{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'inst-1',
'uuid': '123',
'vm_state': vm_states.RESIZED,
@ -209,7 +209,7 @@ class ImageCacheManagerTestCase(test.TestCase):
self.stubs.Set(virtutils, 'get_disk_backing_file',
lambda x: 'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
found = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name,
found = os.path.join(CONF.instances_path, CONF.base_dir_name,
'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
image_cache_manager = imagecache.ImageCacheManager()
@ -231,7 +231,7 @@ class ImageCacheManagerTestCase(test.TestCase):
lambda x: ('e97222e91fc4241f49a7f520d1dcf446751129b3_'
'10737418240'))
found = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name,
found = os.path.join(CONF.instances_path, CONF.base_dir_name,
'e97222e91fc4241f49a7f520d1dcf446751129b3_'
'10737418240')
@ -252,7 +252,7 @@ class ImageCacheManagerTestCase(test.TestCase):
self.stubs.Set(virtutils, 'get_disk_backing_file',
lambda x: 'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
found = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name,
found = os.path.join(CONF.instances_path, CONF.base_dir_name,
'e97222e91fc4241f49a7f520d1dcf446751129b3_sm')
image_cache_manager = imagecache.ImageCacheManager()
@ -789,13 +789,13 @@ class ImageCacheManagerTestCase(test.TestCase):
# Fake the database call which lists running instances
all_instances = [{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'instance-1',
'uuid': '123',
'vm_state': '',
'task_state': ''},
{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'instance-2',
'uuid': '456',
'vm_state': '',
@ -868,11 +868,11 @@ class ImageCacheManagerTestCase(test.TestCase):
self.flags(instances_path='/tmp/no/such/dir/name/please')
self.flags(image_info_filename_pattern=('$instances_path/_base/'
'%(image)s.info'))
base_filename = os.path.join(FLAGS.instances_path, '_base', hashed)
base_filename = os.path.join(CONF.instances_path, '_base', hashed)
self.assertFalse(virtutils.is_valid_info_file('banana'))
self.assertFalse(virtutils.is_valid_info_file(
os.path.join(FLAGS.instances_path, '_base', '00000001')))
os.path.join(CONF.instances_path, '_base', '00000001')))
self.assertFalse(virtutils.is_valid_info_file(base_filename))
self.assertFalse(virtutils.is_valid_info_file(base_filename + '.sha1'))
self.assertTrue(virtutils.is_valid_info_file(base_filename + '.info'))
@ -889,13 +889,13 @@ class ImageCacheManagerTestCase(test.TestCase):
# Fake the database call which lists running instances
all_instances = [{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'instance-1',
'uuid': '123',
'vm_state': '',
'task_state': ''},
{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'instance-2',
'uuid': '456',
'vm_state': '',
@ -927,19 +927,19 @@ class ImageCacheManagerTestCase(test.TestCase):
def fake_get_all(context):
was['called'] = True
return [{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'instance-1',
'uuid': '123',
'vm_state': '',
'task_state': ''},
{'image_ref': '1',
'host': FLAGS.host,
'host': CONF.host,
'name': 'instance-2',
'uuid': '456',
'vm_state': '',
'task_state': ''}]
self.stubs.Set(db, 'instance_get_all', fake_get_all)
compute = importutils.import_object(FLAGS.compute_manager)
compute = importutils.import_object(CONF.compute_manager)
compute._run_image_cache_manager_pass(None)
self.assertTrue(was['called'])

View File

@ -27,7 +27,6 @@ from nova import flags
from nova.openstack.common import log as logging
from nova import test
FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)

View File

@ -33,6 +33,7 @@ from nova.compute import instance_types
from nova.compute import power_state
from nova.compute import vm_mode
from nova.compute import vm_states
from nova import config
from nova import context
from nova import db
from nova import exception
@ -51,7 +52,7 @@ from nova.virt import driver
from nova.virt import fake
from nova.virt import firewall as base_firewall
from nova.virt import images
from nova.virt.libvirt import config
from nova.virt.libvirt import config as vconfig
from nova.virt.libvirt import driver as libvirt_driver
from nova.virt.libvirt import firewall
from nova.virt.libvirt import imagebackend
@ -69,7 +70,7 @@ except ImportError:
libvirt_driver.libvirt = libvirt
FLAGS = flags.FLAGS
CONF = config.CONF
LOG = logging.getLogger(__name__)
_fake_network_info = fake_network.fake_get_instance_nw_info
@ -267,7 +268,7 @@ class LibvirtVolumeTestCase(test.TestCase):
tree = conf.format_dom()
self.assertEqual(tree.get('type'), 'network')
self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
rbd_name = '%s/%s' % (CONF.rbd_pool, name)
self.assertEqual(tree.find('./source').get('name'), rbd_name)
self.assertEqual(tree.find('./source/auth'), None)
libvirt_driver.disconnect_volume(connection_info, mount_device)
@ -292,7 +293,7 @@ class LibvirtVolumeTestCase(test.TestCase):
tree = conf.format_dom()
self.assertEqual(tree.get('type'), 'network')
self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
rbd_name = '%s/%s' % (CONF.rbd_pool, name)
self.assertEqual(tree.find('./source').get('name'), rbd_name)
self.assertEqual(tree.find('./auth').get('username'), user)
self.assertEqual(tree.find('./auth/secret').get('type'), secret_type)
@ -324,7 +325,7 @@ class LibvirtVolumeTestCase(test.TestCase):
tree = conf.format_dom()
self.assertEqual(tree.get('type'), 'network')
self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
rbd_name = '%s/%s' % (CONF.rbd_pool, name)
self.assertEqual(tree.find('./source').get('name'), rbd_name)
self.assertEqual(tree.find('./auth').get('username'), flags_user)
self.assertEqual(tree.find('./auth/secret').get('type'), secret_type)
@ -351,7 +352,7 @@ class LibvirtVolumeTestCase(test.TestCase):
tree = conf.format_dom()
self.assertEqual(tree.get('type'), 'network')
self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
rbd_name = '%s/%s' % (CONF.rbd_pool, name)
self.assertEqual(tree.find('./source').get('name'), rbd_name)
self.assertEqual(tree.find('./auth'), None)
libvirt_driver.disconnect_volume(connection_info, mount_device)
@ -383,7 +384,7 @@ class LibvirtVolumeTestCase(test.TestCase):
tree = conf.format_dom()
self.assertEqual(tree.get('type'), 'network')
self.assertEqual(tree.find('./source').get('protocol'), 'rbd')
rbd_name = '%s/%s' % (FLAGS.rbd_pool, name)
rbd_name = '%s/%s' % (CONF.rbd_pool, name)
self.assertEqual(tree.find('./source').get('name'), rbd_name)
self.assertEqual(tree.find('./auth').get('username'), flags_user)
self.assertEqual(tree.find('./auth/secret').get('type'), secret_type)
@ -448,11 +449,11 @@ class CacheConcurrencyTestCase(test.TestCase):
# which can cause race conditions with the multiple threads we
# use for tests. So, create the path here so utils.synchronized()
# won't delete it out from under one of the threads.
self.lock_path = os.path.join(FLAGS.instances_path, 'locks')
self.lock_path = os.path.join(CONF.instances_path, 'locks')
fileutils.ensure_tree(self.lock_path)
def fake_exists(fname):
basedir = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
basedir = os.path.join(CONF.instances_path, CONF.base_dir_name)
if fname == basedir or fname == self.lock_path:
return True
return False
@ -647,28 +648,28 @@ class LibvirtConnTestCase(test.TestCase):
self.assertEquals(cfg.os_root, None)
self.assertEquals(len(cfg.devices), 7)
self.assertEquals(type(cfg.devices[0]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(type(cfg.devices[1]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(type(cfg.devices[2]),
config.LibvirtConfigGuestInterface)
vconfig.LibvirtConfigGuestInterface)
self.assertEquals(type(cfg.devices[3]),
config.LibvirtConfigGuestSerial)
vconfig.LibvirtConfigGuestSerial)
self.assertEquals(type(cfg.devices[4]),
config.LibvirtConfigGuestSerial)
vconfig.LibvirtConfigGuestSerial)
self.assertEquals(type(cfg.devices[5]),
config.LibvirtConfigGuestInput)
vconfig.LibvirtConfigGuestInput)
self.assertEquals(type(cfg.devices[6]),
config.LibvirtConfigGuestGraphics)
vconfig.LibvirtConfigGuestGraphics)
self.assertEquals(type(cfg.clock),
config.LibvirtConfigGuestClock)
vconfig.LibvirtConfigGuestClock)
self.assertEquals(cfg.clock.offset, "utc")
self.assertEquals(len(cfg.clock.timers), 2)
self.assertEquals(type(cfg.clock.timers[0]),
config.LibvirtConfigGuestTimer)
vconfig.LibvirtConfigGuestTimer)
self.assertEquals(type(cfg.clock.timers[1]),
config.LibvirtConfigGuestTimer)
vconfig.LibvirtConfigGuestTimer)
self.assertEquals(cfg.clock.timers[0].name, "pit")
self.assertEquals(cfg.clock.timers[0].tickpolicy,
"delay")
@ -691,21 +692,21 @@ class LibvirtConnTestCase(test.TestCase):
self.assertEquals(cfg.os_root, None)
self.assertEquals(len(cfg.devices), 8)
self.assertEquals(type(cfg.devices[0]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(type(cfg.devices[1]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(type(cfg.devices[2]),
config.LibvirtConfigGuestInterface)
vconfig.LibvirtConfigGuestInterface)
self.assertEquals(type(cfg.devices[3]),
config.LibvirtConfigGuestInterface)
vconfig.LibvirtConfigGuestInterface)
self.assertEquals(type(cfg.devices[4]),
config.LibvirtConfigGuestSerial)
vconfig.LibvirtConfigGuestSerial)
self.assertEquals(type(cfg.devices[5]),
config.LibvirtConfigGuestSerial)
vconfig.LibvirtConfigGuestSerial)
self.assertEquals(type(cfg.devices[6]),
config.LibvirtConfigGuestInput)
vconfig.LibvirtConfigGuestInput)
self.assertEquals(type(cfg.devices[7]),
config.LibvirtConfigGuestGraphics)
vconfig.LibvirtConfigGuestGraphics)
def test_get_guest_config_with_root_device_name(self):
self.flags(libvirt_type='uml')
@ -722,11 +723,11 @@ class LibvirtConnTestCase(test.TestCase):
self.assertEquals(cfg.os_root, 'dev/vdb')
self.assertEquals(len(cfg.devices), 3)
self.assertEquals(type(cfg.devices[0]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(type(cfg.devices[1]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(type(cfg.devices[2]),
config.LibvirtConfigGuestConsole)
vconfig.LibvirtConfigGuestConsole)
def test_get_guest_config_with_block_device(self):
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
@ -739,10 +740,10 @@ class LibvirtConnTestCase(test.TestCase):
cfg = conn.get_guest_config(instance_ref, [], None, None, info)
self.assertEquals(type(cfg.devices[2]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(cfg.devices[2].target_dev, 'vdc')
self.assertEquals(type(cfg.devices[3]),
config.LibvirtConfigGuestDisk)
vconfig.LibvirtConfigGuestDisk)
self.assertEquals(cfg.devices[3].target_dev, 'vdd')
def test_get_guest_cpu_config_none(self):
@ -772,7 +773,7 @@ class LibvirtConnTestCase(test.TestCase):
_fake_network_info(self.stubs, 1),
None, None)
self.assertEquals(type(conf.cpu),
config.LibvirtConfigGuestCPU)
vconfig.LibvirtConfigGuestCPU)
self.assertEquals(conf.cpu.mode, "host-model")
self.assertEquals(conf.cpu.model, None)
@ -815,7 +816,7 @@ class LibvirtConnTestCase(test.TestCase):
_fake_network_info(self.stubs, 1),
None, None)
self.assertEquals(type(conf.cpu),
config.LibvirtConfigGuestCPU)
vconfig.LibvirtConfigGuestCPU)
self.assertEquals(conf.cpu.mode, "host-passthrough")
self.assertEquals(conf.cpu.model, None)
@ -834,7 +835,7 @@ class LibvirtConnTestCase(test.TestCase):
_fake_network_info(self.stubs, 1),
None, None)
self.assertEquals(type(conf.cpu),
config.LibvirtConfigGuestCPU)
vconfig.LibvirtConfigGuestCPU)
self.assertEquals(conf.cpu.mode, "host-model")
self.assertEquals(conf.cpu.model, None)
@ -854,7 +855,7 @@ class LibvirtConnTestCase(test.TestCase):
_fake_network_info(self.stubs, 1),
None, None)
self.assertEquals(type(conf.cpu),
config.LibvirtConfigGuestCPU)
vconfig.LibvirtConfigGuestCPU)
self.assertEquals(conf.cpu.mode, "custom")
self.assertEquals(conf.cpu.model, "Penryn")
@ -880,12 +881,12 @@ class LibvirtConnTestCase(test.TestCase):
# Ensure we have a predictable host CPU
def get_host_capabilities_stub(self):
cpu = config.LibvirtConfigGuestCPU()
cpu = vconfig.LibvirtConfigGuestCPU()
cpu.model = "Opteron_G4"
cpu.vendor = "AMD"
caps = config.LibvirtConfigCaps()
caps.host = config.LibvirtConfigCapsHost()
caps = vconfig.LibvirtConfigCaps()
caps.host = vconfig.LibvirtConfigCapsHost()
caps.host.cpu = cpu
return caps
@ -903,7 +904,7 @@ class LibvirtConnTestCase(test.TestCase):
_fake_network_info(self.stubs, 1),
None, None)
self.assertEquals(type(conf.cpu),
config.LibvirtConfigGuestCPU)
vconfig.LibvirtConfigGuestCPU)
self.assertEquals(conf.cpu.mode, None)
self.assertEquals(conf.cpu.model, "Opteron_G4")
self.assertEquals(conf.cpu.vendor, "AMD")
@ -924,7 +925,7 @@ class LibvirtConnTestCase(test.TestCase):
_fake_network_info(self.stubs, 1),
None, None)
self.assertEquals(type(conf.cpu),
config.LibvirtConfigGuestCPU)
vconfig.LibvirtConfigGuestCPU)
self.assertEquals(conf.cpu.mode, None)
self.assertEquals(conf.cpu.model, "Penryn")
@ -1838,9 +1839,9 @@ class LibvirtConnTestCase(test.TestCase):
# This test is supposed to make sure we don't
# override a specifically set uri
#
# Deliberately not just assigning this string to FLAGS.libvirt_uri and
# Deliberately not just assigning this string to CONF.libvirt_uri and
# checking against that later on. This way we make sure the
# implementation doesn't fiddle around with the FLAGS.
# implementation doesn't fiddle around with the CONF.
testuri = 'something completely different'
self.flags(libvirt_uri=testuri)
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
@ -2064,7 +2065,7 @@ class LibvirtConnTestCase(test.TestCase):
def test_live_migration_raises_exception(self):
"""Confirms recover method is called when exceptions are raised."""
# Preparing data
self.compute = importutils.import_object(FLAGS.compute_manager)
self.compute = importutils.import_object(CONF.compute_manager)
instance_dict = {'host': 'fake',
'power_state': power_state.RUNNING,
'vm_state': vm_states.ACTIVE}
@ -2075,8 +2076,8 @@ class LibvirtConnTestCase(test.TestCase):
# Preparing mocks
vdmock = self.mox.CreateMock(libvirt.virDomain)
self.mox.StubOutWithMock(vdmock, "migrateToURI")
_bandwidth = FLAGS.live_migration_bandwidth
vdmock.migrateToURI(FLAGS.live_migration_uri % 'dest',
_bandwidth = CONF.live_migration_bandwidth
vdmock.migrateToURI(CONF.live_migration_uri % 'dest',
mox.IgnoreArg(),
None,
_bandwidth).AndRaise(libvirt.libvirtError('ERR'))
@ -2287,14 +2288,14 @@ class LibvirtConnTestCase(test.TestCase):
conn.spawn(self.context, instance, None, [], 'herp',
network_info=network_info)
path = os.path.join(FLAGS.instances_path, instance.name)
path = os.path.join(CONF.instances_path, instance.name)
if os.path.isdir(path):
shutil.rmtree(path)
path = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
path = os.path.join(CONF.instances_path, CONF.base_dir_name)
if os.path.isdir(path):
shutil.rmtree(os.path.join(FLAGS.instances_path,
FLAGS.base_dir_name))
shutil.rmtree(os.path.join(CONF.instances_path,
CONF.base_dir_name))
def test_get_console_output_file(self):
@ -2384,7 +2385,7 @@ class LibvirtConnTestCase(test.TestCase):
def test_get_host_ip_addr(self):
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
ip = conn.get_host_ip_addr()
self.assertEquals(ip, FLAGS.my_ip)
self.assertEquals(ip, CONF.my_ip)
def test_broken_connection(self):
for (error, domain) in (
@ -2574,14 +2575,14 @@ class LibvirtConnTestCase(test.TestCase):
self.stubs.Set(conn, 'get_instance_disk_info', get_info)
result = conn.get_disk_available_least()
space = fake_libvirt_utils.get_fs_info(FLAGS.instances_path)['free']
space = fake_libvirt_utils.get_fs_info(CONF.instances_path)['free']
self.assertEqual(result, space / 1024 ** 3)
def test_cpu_info(self):
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
def get_host_capabilities_stub(self):
cpu = config.LibvirtConfigCPU()
cpu = vconfig.LibvirtConfigCPU()
cpu.model = "Opteron_G4"
cpu.vendor = "AMD"
cpu.arch = "x86_64"
@ -2590,20 +2591,20 @@ class LibvirtConnTestCase(test.TestCase):
cpu.threads = 1
cpu.sockets = 4
cpu.add_feature(config.LibvirtConfigCPUFeature("extapic"))
cpu.add_feature(config.LibvirtConfigCPUFeature("3dnow"))
cpu.add_feature(vconfig.LibvirtConfigCPUFeature("extapic"))
cpu.add_feature(vconfig.LibvirtConfigCPUFeature("3dnow"))
caps = config.LibvirtConfigCaps()
caps.host = config.LibvirtConfigCapsHost()
caps = vconfig.LibvirtConfigCaps()
caps.host = vconfig.LibvirtConfigCapsHost()
caps.host.cpu = cpu
guest = config.LibvirtConfigGuest()
guest = vconfig.LibvirtConfigGuest()
guest.ostype = vm_mode.HVM
guest.arch = "x86_64"
guest.domtype = ["kvm"]
caps.guests.append(guest)
guest = config.LibvirtConfigGuest()
guest = vconfig.LibvirtConfigGuest()
guest.ostype = vm_mode.HVM
guest.arch = "i686"
guest.domtype = ["kvm"]
@ -3016,15 +3017,15 @@ class LibvirtConnTestCase(test.TestCase):
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
def get_host_capabilities_stub(self):
caps = config.LibvirtConfigCaps()
caps = vconfig.LibvirtConfigCaps()
guest = config.LibvirtConfigGuest()
guest = vconfig.LibvirtConfigGuest()
guest.ostype = 'hvm'
guest.arch = 'x86_64'
guest.domtype = ['kvm', 'qemu']
caps.guests.append(guest)
guest = config.LibvirtConfigGuest()
guest = vconfig.LibvirtConfigGuest()
guest.ostype = 'hvm'
guest.arch = 'i686'
guest.domtype = ['kvm']
@ -4143,7 +4144,7 @@ class LibvirtDriverTestCase(test.TestCase):
_fake_network_info(self.stubs, 1))
def test_cleanup_resize_same_host(self):
ins_ref = self._create_instance({'host': FLAGS.host})
ins_ref = self._create_instance({'host': CONF.host})
def fake_os_path_exists(path):
return True
@ -4159,7 +4160,7 @@ class LibvirtDriverTestCase(test.TestCase):
_fake_network_info(self.stubs, 1))
def test_cleanup_resize_not_same_host(self):
host = 'not' + FLAGS.host
host = 'not' + CONF.host
ins_ref = self._create_instance({'host': host})
def fake_os_path_exists(path):

View File

@ -16,13 +16,14 @@
from lxml import etree
from nova import config
from nova import flags
from nova import test
from nova import utils
from nova.virt.libvirt import config
from nova.virt.libvirt import config as vconfig
from nova.virt.libvirt import vif
FLAGS = flags.FLAGS
CONF = config.CONF
class LibvirtVifTestCase(test.TestCase):
@ -66,7 +67,7 @@ class LibvirtVifTestCase(test.TestCase):
self.stubs.Set(utils, 'execute', fake_execute)
def _get_instance_xml(self, driver):
conf = config.LibvirtConfigGuest()
conf = vconfig.LibvirtConfigGuest()
conf.virt_type = "qemu"
conf.name = "fake-name"
conf.uuid = "fake-uuid"
@ -122,7 +123,7 @@ class LibvirtVifTestCase(test.TestCase):
self.assertEqual(node.get("type"), "bridge")
br_name = node.find("source").get("bridge")
self.assertEqual(br_name, FLAGS.libvirt_ovs_bridge)
self.assertEqual(br_name, CONF.libvirt_ovs_bridge)
mac = node.find("mac").get("address")
self.assertEqual(mac, self.mapping['mac'])
vp = node.find("virtualport")

View File

@ -30,8 +30,6 @@ from nova.virt.powervm import driver as powervm_driver
from nova.virt.powervm import lpar
from nova.virt.powervm import operator
FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)

View File

@ -27,8 +27,6 @@ from nova.virt import driver
from nova.openstack.common import jsonutils
FLAGS = flags.FLAGS
class TestVirtDriver(test.TestCase):
def test_block_device(self):

View File

@ -32,9 +32,6 @@ from nova.virt.vmwareapi import driver
from nova.virt.vmwareapi import fake as vmwareapi_fake
FLAGS = flags.FLAGS
class VMWareAPIVMTestCase(test.TestCase):
"""Unit tests for Vmware API connection calls."""

View File

@ -29,6 +29,7 @@ from nova.compute import instance_types
from nova.compute import power_state
from nova.compute import task_states
from nova.compute import vm_states
from nova import config
from nova import context
from nova import db
from nova import exception
@ -55,7 +56,7 @@ from nova.virt.xenapi import volume_utils
LOG = logging.getLogger(__name__)
FLAGS = flags.FLAGS
CONF = config.CONF
IMAGE_MACHINE = '1'
IMAGE_KERNEL = '2'
@ -173,7 +174,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase):
vol['user_id'] = 'fake'
vol['project_id'] = 'fake'
vol['host'] = 'localhost'
vol['availability_zone'] = FLAGS.node_availability_zone
vol['availability_zone'] = CONF.node_availability_zone
vol['status'] = "creating"
vol['attach_status'] = "detached"
return db.volume_create(self.context, vol)
@ -265,7 +266,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
"""Unit tests for VM operations."""
def setUp(self):
super(XenAPIVMTestCase, self).setUp()
self.network = importutils.import_object(FLAGS.network_manager)
self.network = importutils.import_object(CONF.network_manager)
self.flags(disable_process_locking=True,
instance_name_template='%d',
firewall_driver='nova.virt.xenapi.firewall.'
@ -275,7 +276,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
xenapi_fake.create_local_srs()
xenapi_fake.create_local_pifs()
db_fakes.stub_out_db_instance_api(self.stubs)
xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
xenapi_fake.create_network('fake', CONF.flat_network_bridge)
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
stubs.stubout_get_this_vm_uuid(self.stubs)
stubs.stubout_is_vdi_pv(self.stubs)
@ -511,16 +512,16 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
self.assertEquals(self.vm['HVM_boot_policy'], '')
def _list_vdis(self):
url = FLAGS.xenapi_connection_url
username = FLAGS.xenapi_connection_username
password = FLAGS.xenapi_connection_password
url = CONF.xenapi_connection_url
username = CONF.xenapi_connection_username
password = CONF.xenapi_connection_password
session = xenapi_conn.XenAPISession(url, username, password)
return session.call_xenapi('VDI.get_all')
def _list_vms(self):
url = FLAGS.xenapi_connection_url
username = FLAGS.xenapi_connection_username
password = FLAGS.xenapi_connection_password
url = CONF.xenapi_connection_url
username = CONF.xenapi_connection_username
password = CONF.xenapi_connection_password
session = xenapi_conn.XenAPISession(url, username, password)
return session.call_xenapi('VM.get_all')
@ -772,7 +773,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
self.network.allocate_for_instance(ctxt,
instance_id=2,
instance_uuid='00000000-0000-0000-0000-000000000002',
host=FLAGS.host,
host=CONF.host,
vpn=None,
rxtx_factor=3,
project_id=self.project_id)
@ -1003,7 +1004,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
'Dom0IptablesFirewallDriver')
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
db_fakes.stub_out_db_instance_api(self.stubs)
xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
xenapi_fake.create_network('fake', CONF.flat_network_bridge)
self.user_id = 'fake'
self.project_id = 'fake'
self.context = context.RequestContext(self.user_id, self.project_id)
@ -1702,7 +1703,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase):
stubs.stubout_session(self.stubs, stubs.FakeSessionForFirewallTests,
test_case=self)
self.context = context.RequestContext(self.user_id, self.project_id)
self.network = importutils.import_object(FLAGS.network_manager)
self.network = importutils.import_object(CONF.network_manager)
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
self.fw = self.conn._vmops.firewall_driver
@ -2030,7 +2031,7 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
self.context = context.get_admin_context()
self.conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
self.compute = importutils.import_object(FLAGS.compute_manager)
self.compute = importutils.import_object(CONF.compute_manager)
self.api = compute_api.AggregateAPI()
values = {'name': 'test_aggr',
'availability_zone': 'test_zone',
@ -2548,7 +2549,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
self.metadetails = {"host": "test_host_uuid"}
def fake_aggregate_get_by_host(context, host, key=None):
self.assertEqual(FLAGS.host, host)
self.assertEqual(CONF.host, host)
return [fake_aggregate()]
self.stubs.Set(db, "aggregate_get_by_host",
@ -2565,7 +2566,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
self.metadetails = {"dest_other": "test_host_uuid"}
def fake_aggregate_get_by_host(context, host, key=None):
self.assertEqual(FLAGS.host, host)
self.assertEqual(CONF.host, host)
return [fake_aggregate()]
self.stubs.Set(db, "aggregate_get_by_host",