Skip to content

Commit

Permalink
Replace FLAGS with cfg.CONF in other modules, unless tests
Browse files Browse the repository at this point in the history
Replace all the FLAGS with cfg.CONF in cinder/
Large commit was split into several parts

Change-Id: Iacd645997a0c50aa47079c856e1b4e33e3001243
Fixes: bug #1182037
  • Loading branch information
Sergey Vilgelm committed Jun 13, 2013
1 parent 74f25c7 commit 1fcbd01
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 152 deletions.
10 changes: 7 additions & 3 deletions cinder/backup/__init__.py
Expand Up @@ -16,8 +16,12 @@
# Importing full names to not pollute the namespace and cause possible
# collisions with use of 'from cinder.backup import <foo>' elsewhere.

import cinder.flags

from oslo.config import cfg

import cinder.openstack.common.importutils

API = cinder.openstack.common.importutils.import_class(
cinder.flags.FLAGS.backup_api_class)

CONF = cfg.CONF

API = cinder.openstack.common.importutils.import_class(CONF.backup_api_class)
3 changes: 0 additions & 3 deletions cinder/backup/api.py
Expand Up @@ -22,14 +22,11 @@
from cinder.backup import rpcapi as backup_rpcapi
from cinder.db import base
from cinder import exception
from cinder import flags
from cinder.openstack.common import log as logging
import cinder.policy
import cinder.volume


FLAGS = flags.FLAGS

LOG = logging.getLogger(__name__)


Expand Down
19 changes: 10 additions & 9 deletions cinder/backup/manager.py
Expand Up @@ -36,12 +36,12 @@

from cinder import context
from cinder import exception
from cinder import flags
from cinder import manager
from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
from cinder.openstack.common import log as logging


LOG = logging.getLogger(__name__)

backup_manager_opts = [
Expand All @@ -50,8 +50,8 @@
help='Service to use for backups.'),
]

FLAGS = flags.FLAGS
FLAGS.register_opts(backup_manager_opts)
CONF = cfg.CONF
CONF.register_opts(backup_manager_opts)


class BackupManager(manager.SchedulerDependentManager):
Expand All @@ -60,9 +60,10 @@ class BackupManager(manager.SchedulerDependentManager):
RPC_API_VERSION = '1.0'

def __init__(self, service_name=None, *args, **kwargs):
self.service = importutils.import_module(FLAGS.backup_service)
self.az = FLAGS.storage_availability_zone
self.volume_manager = importutils.import_object(FLAGS.volume_manager)
self.service = importutils.import_module(CONF.backup_service)
self.az = CONF.storage_availability_zone
self.volume_manager = importutils.import_object(
CONF.volume_manager)
self.driver = self.volume_manager.driver
super(BackupManager, self).__init__(service_name='backup',
*args, **kwargs)
Expand Down Expand Up @@ -120,7 +121,7 @@ def create_backup(self, context, backup_id):
'volume: %(volume_id)s') % locals())
self.db.backup_update(context, backup_id, {'host': self.host,
'service':
FLAGS.backup_service})
CONF.backup_service})

expected_status = 'backing-up'
actual_status = volume['status']
Expand Down Expand Up @@ -194,7 +195,7 @@ def restore_backup(self, context, backup_id, volume_id):
backup['id'], backup['size'])

backup_service = backup['service']
configured_service = FLAGS.backup_service
configured_service = CONF.backup_service
if backup_service != configured_service:
err = _('restore_backup aborted, the backup service currently'
' configured [%(configured_service)s] is not the'
Expand Down Expand Up @@ -239,7 +240,7 @@ def delete_backup(self, context, backup_id):

backup_service = backup['service']
if backup_service is not None:
configured_service = FLAGS.backup_service
configured_service = CONF.backup_service
if backup_service != configured_service:
err = _('delete_backup aborted, the backup service currently'
' configured [%(configured_service)s] is not the'
Expand Down
10 changes: 6 additions & 4 deletions cinder/backup/rpcapi.py
Expand Up @@ -19,15 +19,17 @@
Client side of the volume backup RPC API.
"""

from cinder import flags

from oslo.config import cfg

from cinder.openstack.common import log as logging
from cinder.openstack.common import rpc
import cinder.openstack.common.rpc.proxy


LOG = logging.getLogger(__name__)
CONF = cfg.CONF

FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)


class BackupAPI(cinder.openstack.common.rpc.proxy.RpcProxy):
Expand All @@ -42,7 +44,7 @@ class BackupAPI(cinder.openstack.common.rpc.proxy.RpcProxy):

def __init__(self):
super(BackupAPI, self).__init__(
topic=FLAGS.backup_topic,
topic=CONF.backup_topic,
default_version=self.BASE_RPC_API_VERSION)

def create_backup(self, ctxt, host, backup_id, volume_id):
Expand Down
22 changes: 11 additions & 11 deletions cinder/backup/services/swift.py
Expand Up @@ -42,11 +42,11 @@

from cinder.db import base
from cinder import exception
from cinder import flags
from cinder.openstack.common import log as logging
from cinder.openstack.common import timeutils
from swiftclient import client as swift


LOG = logging.getLogger(__name__)

swiftbackup_service_opts = [
Expand All @@ -70,8 +70,8 @@
help='Compression algorithm (None to disable)'),
]

FLAGS = flags.FLAGS
FLAGS.register_opts(swiftbackup_service_opts)
CONF = cfg.CONF
CONF.register_opts(swiftbackup_service_opts)


class SwiftBackupService(base.Base):
Expand All @@ -98,14 +98,14 @@ def _get_compressor(self, algorithm):

def __init__(self, context, db_driver=None):
self.context = context
self.swift_url = '%s%s' % (FLAGS.backup_swift_url,
self.swift_url = '%s%s' % (CONF.backup_swift_url,
self.context.project_id)
self.az = FLAGS.storage_availability_zone
self.data_block_size_bytes = FLAGS.backup_swift_object_size
self.swift_attempts = FLAGS.backup_swift_retry_attempts
self.swift_backoff = FLAGS.backup_swift_retry_backoff
self.az = CONF.storage_availability_zone
self.data_block_size_bytes = CONF.backup_swift_object_size
self.swift_attempts = CONF.backup_swift_retry_attempts
self.swift_backoff = CONF.backup_swift_retry_backoff
self.compressor = \
self._get_compressor(FLAGS.backup_compression_algorithm)
self._get_compressor(CONF.backup_compression_algorithm)
self.conn = swift.Connection(None, None, None,
retries=self.swift_attempts,
preauthurl=self.swift_url,
Expand Down Expand Up @@ -133,7 +133,7 @@ def _create_container(self, context, backup):
LOG.debug(_('_create_container started, container: %(container)s,'
'backup: %(backup_id)s') % locals())
if container is None:
container = FLAGS.backup_swift_container
container = CONF.backup_swift_container
self.db.backup_update(context, backup_id, {'container': container})
if not self._check_container_exists(container):
self.conn.put_container(container)
Expand Down Expand Up @@ -236,7 +236,7 @@ def backup(self, backup, volume_file):
break
LOG.debug(_('reading chunk of data from volume'))
if self.compressor is not None:
algorithm = FLAGS.backup_compression_algorithm.lower()
algorithm = CONF.backup_compression_algorithm.lower()
obj[object_name]['compression'] = algorithm
data_size_bytes = len(data)
data = self.compressor.compress(data)
Expand Down
46 changes: 24 additions & 22 deletions cinder/brick/iscsi/iscsi.py
Expand Up @@ -19,18 +19,20 @@
Helper code for the iSCSI volume driver.
"""


import os
import re

from oslo.config import cfg

from cinder import exception
from cinder import flags
from cinder.openstack.common import fileutils
from cinder.openstack.common import log as logging
from cinder import utils
from cinder.volume import utils as volume_utils


LOG = logging.getLogger(__name__)

iscsi_helper_opt = [cfg.StrOpt('iscsi_helper',
Expand Down Expand Up @@ -59,9 +61,9 @@
)
]

FLAGS = flags.FLAGS
FLAGS.register_opts(iscsi_helper_opt)
FLAGS.import_opt('volume_name_template', 'cinder.db')
CONF = cfg.CONF
CONF.register_opts(iscsi_helper_opt)
CONF.import_opt('volume_name_template', 'cinder.db')


class TargetAdmin(object):
Expand Down Expand Up @@ -133,7 +135,7 @@ def create_iscsi_target(self, name, tid, lun, path,
# Note(jdg) tid and lun aren't used by TgtAdm but remain for
# compatibility

fileutils.ensure_tree(FLAGS.volumes_dir)
fileutils.ensure_tree(CONF.volumes_dir)

vol_id = name.split(':')[1]
if chap_auth is None:
Expand All @@ -151,7 +153,7 @@ def create_iscsi_target(self, name, tid, lun, path,
""" % (name, path, chap_auth)

LOG.info(_('Creating iscsi_target for: %s') % vol_id)
volumes_dir = FLAGS.volumes_dir
volumes_dir = CONF.volumes_dir
volume_path = os.path.join(volumes_dir, vol_id)

f = open(volume_path, 'w+')
Expand All @@ -177,7 +179,7 @@ def create_iscsi_target(self, name, tid, lun, path,
os.unlink(volume_path)
raise exception.ISCSITargetCreateFailed(volume_id=vol_id)

iqn = '%s%s' % (FLAGS.iscsi_target_prefix, vol_id)
iqn = '%s%s' % (CONF.iscsi_target_prefix, vol_id)
tid = self._get_target(iqn)
if tid is None:
LOG.error(_("Failed to create iscsi target for volume "
Expand All @@ -192,10 +194,10 @@ def create_iscsi_target(self, name, tid, lun, path,

def remove_iscsi_target(self, tid, lun, vol_id, **kwargs):
LOG.info(_('Removing iscsi_target for: %s') % vol_id)
vol_uuid_file = FLAGS.volume_name_template % vol_id
volume_path = os.path.join(FLAGS.volumes_dir, vol_uuid_file)
vol_uuid_file = CONF.volume_name_template % vol_id
volume_path = os.path.join(CONF.volumes_dir, vol_uuid_file)
if os.path.isfile(volume_path):
iqn = '%s%s' % (FLAGS.iscsi_target_prefix,
iqn = '%s%s' % (CONF.iscsi_target_prefix,
vol_uuid_file)
else:
raise exception.ISCSITargetRemoveFailed(volume_id=vol_id)
Expand Down Expand Up @@ -232,10 +234,10 @@ def __init__(self, execute=utils.execute):
super(IetAdm, self).__init__('ietadm', execute)

def _iotype(self, path):
if FLAGS.iscsi_iotype == 'auto':
if CONF.iscsi_iotype == 'auto':
return 'blockio' if volume_utils.is_block(path) else 'fileio'
else:
return FLAGS.iscsi_iotype
return CONF.iscsi_iotype

def create_iscsi_target(self, name, tid, lun, path,
chap_auth=None, **kwargs):
Expand All @@ -249,7 +251,7 @@ def create_iscsi_target(self, name, tid, lun, path,
(type, username, password) = chap_auth.split()
self._new_auth(tid, type, username, password, **kwargs)

conf_file = FLAGS.iet_conf
conf_file = CONF.iet_conf
if os.path.exists(conf_file):
try:
volume_conf = """
Expand All @@ -274,8 +276,8 @@ def remove_iscsi_target(self, tid, lun, vol_id, **kwargs):
LOG.info(_('Removing iscsi_target for volume: %s') % vol_id)
self._delete_logicalunit(tid, lun, **kwargs)
self._delete_target(tid, **kwargs)
vol_uuid_file = FLAGS.volume_name_template % vol_id
conf_file = FLAGS.iet_conf
vol_uuid_file = CONF.volume_name_template % vol_id
conf_file = CONF.iet_conf
if os.path.exists(conf_file):
with utils.temporary_chown(conf_file):
try:
Expand Down Expand Up @@ -387,8 +389,8 @@ def create_iscsi_target(self, name, tid, lun, path,
(chap_auth_userid, chap_auth_password) = chap_auth.split(' ')[1:]

extra_args = []
if FLAGS.lio_initiator_iqns:
extra_args.append(FLAGS.lio_initiator_iqns)
if CONF.lio_initiator_iqns:
extra_args.append(CONF.lio_initiator_iqns)

try:
command_args = ['rtstool',
Expand All @@ -407,7 +409,7 @@ def create_iscsi_target(self, name, tid, lun, path,

raise exception.ISCSITargetCreateFailed(volume_id=vol_id)

iqn = '%s%s' % (FLAGS.iscsi_target_prefix, vol_id)
iqn = '%s%s' % (CONF.iscsi_target_prefix, vol_id)
tid = self._get_target(iqn)
if tid is None:
LOG.error(_("Failed to create iscsi target for volume "
Expand All @@ -419,7 +421,7 @@ def create_iscsi_target(self, name, tid, lun, path,
def remove_iscsi_target(self, tid, lun, vol_id, **kwargs):
LOG.info(_('Removing iscsi_target: %s') % vol_id)
vol_uuid_name = 'volume-%s' % vol_id
iqn = '%s%s' % (FLAGS.iscsi_target_prefix, vol_uuid_name)
iqn = '%s%s' % (CONF.iscsi_target_prefix, vol_uuid_name)

try:
self._execute('rtstool',
Expand Down Expand Up @@ -462,11 +464,11 @@ def initialize_connection(self, volume, connector):


def get_target_admin():
if FLAGS.iscsi_helper == 'tgtadm':
if CONF.iscsi_helper == 'tgtadm':
return TgtAdm()
elif FLAGS.iscsi_helper == 'fake':
elif CONF.iscsi_helper == 'fake':
return FakeIscsiHelper()
elif FLAGS.iscsi_helper == 'lioadm':
elif CONF.iscsi_helper == 'lioadm':
return LioAdm()
else:
return IetAdm()
8 changes: 4 additions & 4 deletions cinder/exception.py
Expand Up @@ -27,10 +27,10 @@
from oslo.config import cfg
import webob.exc

from cinder import flags
from cinder.openstack.common import exception as com_exception
from cinder.openstack.common import log as logging


LOG = logging.getLogger(__name__)

exc_log_opts = [
Expand All @@ -39,8 +39,8 @@
help='make exception message format errors fatal'),
]

FLAGS = flags.FLAGS
FLAGS.register_opts(exc_log_opts)
CONF = cfg.CONF
CONF.register_opts(exc_log_opts)


class ConvertedException(webob.exc.WSGIHTTPException):
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, message=None, **kwargs):
LOG.exception(_('Exception in string format operation'))
for name, value in kwargs.iteritems():
LOG.error("%s: %s" % (name, value))
if FLAGS.fatal_exception_format_errors:
if CONF.fatal_exception_format_errors:
raise e
else:
# at least get the core message out if something happened
Expand Down

0 comments on commit 1fcbd01

Please sign in to comment.