Remove log translations

Log messages are no longer being translated. This removes all use of
the _LE, _LI, and _LW translation markers to simplify logging and to
avoid confusion with new contributions.

See:
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html
https://review.openstack.org/#/c/446762/

Change-Id: I8eb62d63dab12693534c802623a9a4c406fef46e
This commit is contained in:
lihaijing 2017-03-21 12:40:14 +08:00
parent 976b301db8
commit c09006bc42
11 changed files with 191 additions and 207 deletions

View File

@ -16,7 +16,6 @@ from oslo_log import log as logging
from oslo_utils import units
from fuxi import exceptions
from fuxi.i18n import _LE
LOG = logging.getLogger(__name__)
@ -32,5 +31,5 @@ class BlockerDeviceManager(object):
.read().rstrip('\n')
return (float(nr_sectors) * float(sect_size)) / units.Gi
except IOError as e:
LOG.error(_LE("Failed to read device size. %s"), e)
LOG.error("Failed to read device size. %s", e)
raise exceptions.FuxiException(e.message)

View File

@ -18,7 +18,7 @@ from oslo_log import log as logging
from fuxi.common import constants
from fuxi import exceptions
from fuxi.i18n import _LE
from fuxi.i18n import _
LOG = logging.getLogger(__name__)
@ -52,12 +52,12 @@ class StateMonitor(object):
self.transient_states = self.transient_states[idx:]
return False
else:
msg = _LE("Unexpected state while waiting for volume. "
"Expected Volume: {0}, "
"Expected State: {1}, "
"Reached State: {2}").format(self.expected_obj,
self.desired_state,
current_state)
msg = _("Unexpected state while waiting for volume. "
"Expected Volume: {0}, "
"Expected State: {1}, "
"Reached State: {2}").format(self.expected_obj,
self.desired_state,
current_state)
LOG.error(msg)
raise exceptions.UnexpectedStateException(msg)
@ -68,12 +68,12 @@ class StateMonitor(object):
except cinder_exception.ClientException:
elapsed_time = time.time() - self.start_time
if elapsed_time > self.time_limit:
msg = _LE("Timed out while waiting for volume. "
"Expected Volume: {0}, "
"Expected State: {1}, "
"Elapsed Time: {2}").format(self.expected_obj,
self.desired_state,
elapsed_time)
msg = ("Timed out while waiting for volume. "
"Expected Volume: {0}, "
"Expected State: {1}, "
"Elapsed Time: {2}").format(self.expected_obj,
self.desired_state,
elapsed_time)
LOG.error(msg)
raise exceptions.TimeoutException(msg)
raise
@ -90,12 +90,12 @@ class StateMonitor(object):
except manila_exception.ClientException:
elapsed_time = time.time() - self.start_time
if elapsed_time > self.time_limit:
msg = _LE("Timed out while waiting for share. "
"Expected Share: {0}, "
"Expected State: {1}, "
"Elapsed Time: {2}").format(self.expected_obj,
self.desired_state,
elapsed_time)
msg = ("Timed out while waiting for share. "
"Expected Share: {0}, "
"Expected State: {1}, "
"Elapsed Time: {2}").format(self.expected_obj,
self.desired_state,
elapsed_time)
raise exceptions.TimeoutException(msg)
raise
@ -111,10 +111,10 @@ class StateMonitor(object):
except manila_exception.ClientException:
elapsed_time = time.time() - self.start_time
if elapsed_time > self.time_limit:
msg = _LE("Timed out while waiting for share access. "
"Expected State: {0}, "
"Elapsed Time: {1}").format(self.desired_state,
elapsed_time)
msg = ("Timed out while waiting for share access. "
"Expected State: {0}, "
"Elapsed Time: {1}").format(self.desired_state,
elapsed_time)
raise exceptions.TimeoutException(msg)
raise

View File

@ -25,7 +25,7 @@ from fuxi.common import constants as consts
from fuxi.common import state_monitor
from fuxi.connector import connector
from fuxi import exceptions
from fuxi.i18n import _, _LI, _LW, _LE
from fuxi.i18n import _
from fuxi import utils
CONF = config.CONF
@ -50,7 +50,7 @@ class CinderConnector(connector.Connector):
if not server_id:
server_id = utils.get_instance_uuid()
LOG.info(_LI("Start to connect to volume %s"), volume)
LOG.info("Start to connect to volume %s", volume)
nova_volume = self.novaclient.volumes.create_server_volume(
server_id=server_id,
volume_id=volume.id,
@ -63,15 +63,15 @@ class CinderConnector(connector.Connector):
('available', 'attaching',))
attached_volume = volume_monitor.monitor_cinder_volume()
except nova_exception.ClientException as ex:
LOG.error(_LE("Attaching volume %(vol)s to server %(s)s "
"failed. Error: %(err)s"),
LOG.error("Attaching volume %(vol)s to server %(s)s "
"failed. Error: %(err)s",
{'vol': volume.id, 's': server_id, 'err': ex})
raise
# Get all devices on host after do volume-attach,
# and then find attached device.
LOG.info(_LI("After connected to volume, scan the added "
"block device on host"))
LOG.info("After connected to volume, scan the added "
"block device on host")
curr_devices = bdm.device_scan()
start_time = time.time()
delta_devices = list(set(curr_devices) - set(ori_devices))
@ -83,13 +83,13 @@ class CinderConnector(connector.Connector):
msg = _("Could not detect added device with "
"limited time")
raise exceptions.FuxiException(msg)
LOG.info(_LI("Get extra added block device %s"), delta_devices)
LOG.info("Get extra added block device %s", delta_devices)
for device in delta_devices:
if bdm.get_device_size(device) == volume.size:
device = device.replace('/sys/block', '/dev')
LOG.info(_LI("Find attached device %(dev)s"
" for volume %(at)s %(vol)s"),
LOG.info("Find attached device %(dev)s"
" for volume %(at)s %(vol)s",
{'dev': device, 'at': attached_volume.name,
'vol': volume})
@ -99,35 +99,35 @@ class CinderConnector(connector.Connector):
link_path,
run_as_root=True)
except processutils.ProcessExecutionError as e:
LOG.error(_LE("Error happened when create link file for"
" block device attached by Nova."
" Error: %s"), e)
LOG.error("Error happened when create link file for"
" block device attached by Nova."
" Error: %s", e)
raise
return {'path': link_path}
LOG.warning(_LW("Could not find matched device"))
LOG.warning("Could not find matched device")
raise exceptions.NotFound("Not Found Matched Device")
def disconnect_volume(self, volume, **disconnect_opts):
try:
volume = self.cinderclient.volumes.get(volume.id)
except cinder_exception.ClientException as e:
LOG.error(_LE("Get Volume %s from Cinder failed"), volume.id)
LOG.error("Get Volume %s from Cinder failed", volume.id)
raise
try:
link_path = self.get_device_path(volume)
utils.execute('rm', '-f', link_path, run_as_root=True)
except processutils.ProcessExecutionError as e:
LOG.warning(_LE("Error happened when remove docker volume"
" mountpoint directory. Error: %s"), e)
LOG.warning("Error happened when remove docker volume"
" mountpoint directory. Error: %s", e)
try:
self.novaclient.volumes.delete_server_volume(
utils.get_instance_uuid(),
volume.id)
except nova_exception.ClientException as e:
LOG.error(_LE("Detaching volume %(vol)s failed. Err: %(err)s"),
LOG.error("Detaching volume %(vol)s failed. Err: %(err)s",
{'vol': volume.id, 'err': e})
raise

View File

@ -27,7 +27,6 @@ from fuxi.common import mount
from fuxi.common import state_monitor
from fuxi.connector import connector as fuxi_connector
from fuxi import exceptions
from fuxi.i18n import _LI, _LW, _LE
from fuxi import utils
CONF = cfg.CONF
@ -80,17 +79,17 @@ class CinderConnector(fuxi_connector.Connector):
self.cinderclient = utils.get_cinderclient()
def _get_connection_info(self, volume_id):
LOG.info(_LI("Get connection info for osbrick connector and use it to "
"connect to volume"))
LOG.info("Get connection info for osbrick connector and use it to "
"connect to volume")
try:
conn_info = self.cinderclient.volumes.initialize_connection(
volume_id,
brick_get_connector_properties())
LOG.info(_LI("Get connection information %s"), conn_info)
LOG.info("Get connection information %s", conn_info)
return conn_info
except cinder_exception.ClientException as e:
LOG.error(_LE("Error happened when initialize connection"
" for volume. Error: %s"), e)
LOG.error("Error happened when initialize connection"
" for volume. Error: %s", e)
raise
def _connect_volume(self, volume):
@ -99,15 +98,15 @@ class CinderConnector(fuxi_connector.Connector):
protocol = conn_info['driver_volume_type']
brick_connector = brick_get_connector(protocol)
device_info = brick_connector.connect_volume(conn_info['data'])
LOG.info(_LI("Get device_info after connect to "
"volume %s") % device_info)
LOG.info("Get device_info after connect to "
"volume %s" % device_info)
try:
link_path = os.path.join(consts.VOLUME_LINK_DIR, volume.id)
utils.execute('ln', '-s', os.path.realpath(device_info['path']),
link_path,
run_as_root=True)
except processutils.ProcessExecutionError as e:
LOG.error(_LE("Failed to create link for device. %s"), e)
LOG.error("Failed to create link for device. %s", e)
raise
return {'path': link_path}
@ -116,8 +115,8 @@ class CinderConnector(fuxi_connector.Connector):
link_path = self.get_device_path(volume)
utils.execute('rm', '-f', link_path, run_as_root=True)
except processutils.ProcessExecutionError as e:
LOG.warning(_LE("Error happened when remove docker volume"
" mountpoint directory. Error: %s"), e)
LOG.warning("Error happened when remove docker volume"
" mountpoint directory. Error: %s", e)
conn_info = self._get_connection_info(volume.id)
@ -132,7 +131,7 @@ class CinderConnector(fuxi_connector.Connector):
try:
self.cinderclient.volumes.reserve(volume)
except cinder_exception.ClientException:
LOG.error(_LE("Reserve volume %s failed"), volume)
LOG.error("Reserve volume %s failed", volume)
raise
try:
@ -141,9 +140,9 @@ class CinderConnector(fuxi_connector.Connector):
instance_uuid=None,
mountpoint=mountpoint,
host_name=host_name)
LOG.info(_LI("Attach volume to this server successfully"))
LOG.info("Attach volume to this server successfully")
except Exception:
LOG.error(_LE("Attach volume %s to this server failed"), volume)
LOG.error("Attach volume %s to this server failed", volume)
with excutils.save_and_reraise_exception():
try:
self._disconnect_volume(volume)
@ -165,10 +164,10 @@ class CinderConnector(fuxi_connector.Connector):
try:
self.cinderclient.volumes.detach(volume.id,
attachment_uuid=attachment_uuid)
LOG.info(_LI("Disconnect volume successfully"))
LOG.info("Disconnect volume successfully")
except cinder_exception.ClientException as e:
LOG.error(_LE("Error happened when detach volume %(vol)s from this"
" server. Error: %(err)s"),
LOG.error("Error happened when detach volume %(vol)s from this"
" server. Error: %(err)s",
{'vol': volume, 'err': e})
raise
@ -257,7 +256,7 @@ class ManilaConnector(fuxi_connector.Connector):
def check_access_allowed(self, share):
access_type = self.proto_access_type_map.get(share.share_proto, None)
if not access_type:
LOG.warning(_LW("The share_proto %s is not enabled currently"),
LOG.warning("The share_proto %s is not enabled currently",
share.share_proto)
return False
@ -283,15 +282,15 @@ class ManilaConnector(fuxi_connector.Connector):
access_type = self.proto_access_type_map[share_proto]
access_to = self._get_access_to(access_type)
LOG.info(_LI("Allow machine to access share %(shr)s with "
"access_type %(type)s and access_to %(to)s"),
LOG.info("Allow machine to access share %(shr)s with "
"access_type %(type)s and access_to %(to)s",
{'shr': share, 'type': access_type, 'to': access_to})
self.manilaclient.shares.allow(share, access_type, access_to, 'rw')
except manila_exception.ClientException as e:
LOG.error(_LE("Failed to grant access for server, %s"), e)
LOG.error("Failed to grant access for server, %s", e)
raise
LOG.info(_LI("Waiting share %s access to be active"), share)
LOG.info("Waiting share %s access to be active", share)
state_monitor.StateMonitor(
self.manilaclient, share,
'active',
@ -306,7 +305,7 @@ class ManilaConnector(fuxi_connector.Connector):
'name': share.share_proto
}
path_info = self._get_brick_connector(share).connect_volume(conn_prop)
LOG.info(_LI("Connect share %(s)s successfully, path_info %(pi)s"),
LOG.info("Connect share %(s)s successfully, path_info %(pi)s",
{'s': share, 'pi': path_info})
return {'path': share.export_location}
@ -322,8 +321,8 @@ class ManilaConnector(fuxi_connector.Connector):
self.manilaclient.shares.deny(share, share_access.id)
break
except manila_exception.ClientException as e:
LOG.error(_LE("Error happened when revoking access for share "
"%(s)s. Error: %(err)s"), {'s': share, 'err': e})
LOG.error("Error happened when revoking access for share "
"%(s)s. Error: %(err)s", {'s': share, 'err': e})
raise
@utils.wrap_check_authorized
@ -349,7 +348,7 @@ class ManilaConnector(fuxi_connector.Connector):
start_time = time.time()
while time.time() - start_time < consts.ACCSS_DENY_TIMEOUT:
if not _check_access_binded(share):
LOG.info(_LI("Disconnect share %s successfully"), share)
LOG.info("Disconnect share %s successfully", share)
return
time.sleep(consts.SCAN_INTERVAL)

View File

@ -21,7 +21,7 @@ from oslo_utils import importutils
from fuxi import app
from fuxi import exceptions
from fuxi.i18n import _, _LI, _LW
from fuxi.i18n import _
from fuxi import utils
CONF = cfg.CONF
@ -47,9 +47,9 @@ def init_app_conf():
if provider in volume_providers_conf:
app.volume_providers[provider] = importutils\
.import_class(volume_providers_conf[provider])()
LOG.info(_LI("Load volume provider: %s"), provider)
LOG.info("Load volume provider: %s", provider)
else:
LOG.warning(_LW("Could not find volume provider: %s"), provider)
LOG.warning("Could not find volume provider: %s", provider)
if not app.volume_providers:
raise Exception("Not provide at least one effective volume provider")
@ -74,14 +74,14 @@ def get_docker_volume(docker_volume_name):
@app.route('/Plugin.Activate', methods=['POST'])
def plugin_activate():
LOG.info(_LI("/Plugin.Activate"))
LOG.info("/Plugin.Activate")
return flask.jsonify(Implements=[u'VolumeDriver'])
@app.route('/VolumeDriver.Create', methods=['POST'])
def volumedriver_create():
json_data = flask.request.get_json(force=True)
LOG.info(_LI("Received JSON data %s for /VolumeDriver.Create"), json_data)
LOG.info("Received JSON data %s for /VolumeDriver.Create", json_data)
docker_volume_name = json_data.get('Name', None)
volume_opts = json_data.get('Opts', None) or {}
@ -125,7 +125,7 @@ def volumedriver_create():
@app.route('/VolumeDriver.Remove', methods=['POST'])
def volumedriver_remove():
json_data = flask.request.get_json(force=True)
LOG.info(_LI("Received JSON data %s for /VolumeDriver.Remove"), json_data)
LOG.info("Received JSON data %s for /VolumeDriver.Remove", json_data)
docker_volume_name = json_data.get('Name', None)
if not docker_volume_name:
@ -143,7 +143,7 @@ def volumedriver_remove():
@app.route('/VolumeDriver.Mount', methods=['POST'])
def volumedriver_mount():
json_data = flask.request.get_json(force=True)
LOG.info(_LI("Receive JSON data %s for /VolumeDriver.Mount"), json_data)
LOG.info("Receive JSON data %s for /VolumeDriver.Mount", json_data)
docker_volume_name = json_data.get('Name', None)
if not docker_volume_name:
@ -162,7 +162,7 @@ def volumedriver_mount():
@app.route('/VolumeDriver.Path', methods=['POST'])
def volumedriver_path():
json_data = flask.request.get_json(force=True)
LOG.info(_LI("Receive JSON data %s for /VolumeDriver.Path"), json_data)
LOG.info("Receive JSON data %s for /VolumeDriver.Path", json_data)
docker_volume_name = json_data.get('Name', None)
if not docker_volume_name:
@ -173,11 +173,11 @@ def volumedriver_path():
volume = get_docker_volume(docker_volume_name)
if volume is not None:
mountpoint = volume.get('Mountpoint', '')
LOG.info(_LI("Get mountpoint %(mp)s for docker volume %(name)s"),
LOG.info("Get mountpoint %(mp)s for docker volume %(name)s",
{'mp': mountpoint, 'name': docker_volume_name})
return flask.jsonify(Mountpoint=mountpoint, Err=u'')
LOG.warning(_LW("Can't find mountpoint for docker volume %(name)s"),
LOG.warning("Can't find mountpoint for docker volume %(name)s",
{'name': docker_volume_name})
return flask.jsonify(Err=u'Mountpoint Not Found')
@ -185,14 +185,14 @@ def volumedriver_path():
@app.route('/VolumeDriver.Unmount', methods=['POST'])
def volumedriver_unmount():
json_data = flask.request.get_json(force=True)
LOG.info(_LI('Receive JSON data %s for VolumeDriver.Unmount'), json_data)
LOG.info('Receive JSON data %s for VolumeDriver.Unmount', json_data)
return flask.jsonify(Err=u'')
@app.route('/VolumeDriver.Get', methods=['POST'])
def volumedriver_get():
json_data = flask.request.get_json(force=True)
LOG.info(_LI("Receive JSON data %s for /VolumeDriver.Get"), json_data)
LOG.info("Receive JSON data %s for /VolumeDriver.Get", json_data)
docker_volume_name = json_data.get('Name', None)
if not docker_volume_name:
@ -202,24 +202,24 @@ def volumedriver_get():
volume = get_docker_volume(docker_volume_name)
if volume is not None:
LOG.info(_LI("Get docker volume: %s"), volume)
LOG.info("Get docker volume: %s", volume)
return flask.jsonify(Volume=volume, Err=u'')
LOG.warning(_LW("Can't find volume %s from every provider"),
LOG.warning("Can't find volume %s from every provider",
docker_volume_name)
return flask.jsonify(Err=u'Volume Not Found')
@app.route('/VolumeDriver.List', methods=['POST'])
def volumedriver_list():
LOG.info(_LI("/VolumeDriver.List"))
LOG.info("/VolumeDriver.List")
docker_volumes = []
for provider in app.volume_providers.values():
vs = provider.list()
if vs:
docker_volumes.extend(vs)
LOG.info(_LI("Get volumes from volume providers. Volumes: %s"),
LOG.info("Get volumes from volume providers. Volumes: %s",
docker_volumes)
return flask.jsonify(Err=u'', Volumes=docker_volumes)

View File

@ -27,16 +27,6 @@ _C = _translators.contextual_form
# The plural translation function using the name "_P"
_P = _translators.plural_form
# Translators for log levels.
#
# The abbreviated names are meant to reflect the usual use of a short
# name like '_'. The "L" is for "log" and the other letter comes from
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical
def get_available_languages():
return oslo_i18n.get_available_languages(DOMAIN)

View File

@ -14,7 +14,6 @@ import docker
import os
from cinderclient.v2 import client
from fuxi.i18n import _LW
from keystoneauth1 import identity
from keystoneauth1 import session as ks
from manilaclient import client as manila_client
@ -123,11 +122,11 @@ class FuxiBaseTest(base.BaseTestCase):
self.manila_client = get_manila_client_from_env()
except Exception as e:
# We may missing or didn't source configured openrc file.
message = _LW('Missing environment variable %s in your local. '
'Please add it and also check other missing '
'environment variables. After that please source '
'the openrc file. '
'Trying credentials from DevStack cloud.yaml ...')
message = ('Missing environment variable %s in your local. '
'Please add it and also check other missing '
'environment variables. After that please source '
'the openrc file. '
'Trying credentials from DevStack cloud.yaml ...')
LOG.warning(message, e.args[0])
self.cinder_client = get_cinder_client_from_creds()
self.manila_client = get_manila_client_from_creds()

View File

@ -39,7 +39,6 @@ from werkzeug import exceptions as w_exceptions
from fuxi.common import config
from fuxi.common import constants
from fuxi import exceptions
from fuxi.i18n import _LW, _LE
cloud_init_conf = '/var/lib/cloud/instances'
@ -67,7 +66,7 @@ def get_instance_uuid():
if inst_uuid_count == 1:
return inst_uuid
except Exception:
LOG.warning(_LW("Get instance_uuid from cloud-init failed"))
LOG.warning("Get instance_uuid from cloud-init failed")
try:
resp = requests.get('http://169.254.169.254/openstack',
@ -75,7 +74,7 @@ def get_instance_uuid():
metadata_api_versions = resp.text.split()
metadata_api_versions.sort(reverse=True)
except Exception as e:
LOG.error(_LE("Get metadata apis failed. Error: %s"), e)
LOG.error("Get metadata apis failed. Error: %s", e)
raise exceptions.FuxiException("Metadata API Not Found")
for api_version in metadata_api_versions:
@ -89,8 +88,8 @@ def get_instance_uuid():
if metadata.get('uuid', None):
return metadata['uuid']
except Exception as e:
LOG.warning(_LW("Get instance_uuid from metadata server"
" %(md_url)s failed. Error: %(err)s"),
LOG.warning("Get instance_uuid from metadata server"
" %(md_url)s failed. Error: %(err)s",
{'md_url': metadata_url, 'err': e})
continue
@ -108,7 +107,7 @@ def make_json_app(import_name, **kwargs):
@app.errorhandler(processutils.ProcessExecutionError)
@app.errorhandler(brick_exception.BrickException)
def make_json_error(ex):
LOG.error(_LE("Unexpected error happened: %s"),
LOG.error("Unexpected error happened: %s",
traceback.format_exc())
response = flask.jsonify({"Err": str(ex)})
response.status_code = w_exceptions.InternalServerError.code

View File

@ -23,7 +23,7 @@ from fuxi.common import constants as consts
from fuxi.common import mount
from fuxi.common import state_monitor
from fuxi import exceptions
from fuxi.i18n import _, _LE, _LI, _LW
from fuxi.i18n import _
from fuxi import utils
from fuxi.volumeprovider import provider
@ -68,13 +68,13 @@ def get_cinder_volume_kwargs(docker_volume_name, docker_volume_opt):
try:
size = int(docker_volume_opt.pop('size'))
except ValueError:
msg = _LE("Volume size must be able to convert to int type")
msg = _("Volume size must be able to convert to int type")
LOG.error(msg)
raise exceptions.InvalidInput(msg)
else:
size = CONF.default_volume_size
LOG.info(_LI("Volume size doesn't provide from command, so use"
" default size %sG"), size)
LOG.info("Volume size doesn't provide from command, so use"
" default size %sG", size)
kwargs['size'] = size
for key, value in docker_volume_opt.items():
@ -119,7 +119,7 @@ class Cinder(provider.Provider):
def _get_connector(self):
connector = cinder_conf.volume_connector
if not connector or connector not in volume_connector_conf:
msg = _LE("Must provide an valid volume connector")
msg = _("Must provide an valid volume connector")
LOG.error(msg)
raise exceptions.FuxiException(msg)
return importutils.import_class(volume_connector_conf[connector])()
@ -130,8 +130,8 @@ class Cinder(provider.Provider):
'metadata': {consts.VOLUME_FROM: CONF.volume_from}}
vols = self.cinderclient.volumes.list(search_opts=search_opts)
except cinder_exception.ClientException as ex:
LOG.error(_LE("Error happened while getting volume list "
"information from Cinder. Error: %s"), ex)
LOG.error("Error happened while getting volume list "
"information from Cinder. Error: %s", ex)
raise
vol_num = len(vols)
@ -168,7 +168,7 @@ class Cinder(provider.Provider):
return False
def _create_volume(self, docker_volume_name, volume_opts):
LOG.info(_LI("Start to create docker volume %s from Cinder"),
LOG.info("Start to create docker volume %s from Cinder",
docker_volume_name)
cinder_volume_kwargs = get_cinder_volume_kwargs(docker_volume_name,
@ -177,12 +177,12 @@ class Cinder(provider.Provider):
try:
volume = self.cinderclient.volumes.create(**cinder_volume_kwargs)
except cinder_exception.ClientException as e:
LOG.error(_LE("Error happened when create an volume %(vol)s from"
" Cinder. Error: %(err)s"),
LOG.error("Error happened when create an volume %(vol)s from"
" Cinder. Error: %(err)s",
{'vol': docker_volume_name, 'err': e})
raise
LOG.info(_LI("Waiting volume %s to be available"), volume)
LOG.info("Waiting volume %s to be available", volume)
volume_monitor = state_monitor.StateMonitor(
self.cinderclient,
volume,
@ -191,8 +191,8 @@ class Cinder(provider.Provider):
time_delay=consts.VOLUME_SCAN_TIME_DELAY)
volume = volume_monitor.monitor_cinder_volume()
LOG.info(_LI("Create docker volume %(d_v)s %(vol)s from Cinder "
"successfully"),
LOG.info("Create docker volume %(d_v)s %(vol)s from Cinder "
"successfully",
{'d_v': docker_volume_name, 'vol': volume})
return volume
@ -202,28 +202,28 @@ class Cinder(provider.Provider):
try:
cinder_volume = self.cinderclient.volumes.get(cinder_volume_id)
except cinder_exception.ClientException as e:
msg = _LE("Failed to get volume %(vol_id)s from Cinder. "
"Error: %(err)s")
msg = ("Failed to get volume %(vol_id)s from Cinder. "
"Error: %(err)s")
LOG.error(msg, {'vol_id': cinder_volume_id, 'err': e})
raise
status = cinder_volume.status
if status not in ('available', 'in-use'):
LOG.error(_LE("Current volume %(vol)s status %(status)s not in "
"desired states"),
LOG.error("Current volume %(vol)s status %(status)s not in "
"desired states",
{'vol': cinder_volume, 'status': status})
raise exceptions.NotMatchedState('Cinder volume is unavailable')
elif status == 'in-use' and not cinder_volume.multiattach:
if not self._check_attached_to_this(cinder_volume):
msg = _LE("Current volume %(vol)s status %(status)s not "
"in desired states")
msg = ("Current volume %(vol)s status %(status)s not "
"in desired states")
LOG.error(msg, {'vol': cinder_volume, 'status': status})
raise exceptions.NotMatchedState(
'Cinder volume is unavailable')
if cinder_volume.name != docker_volume_name:
LOG.error(_LE("Provided volume name %(d_name)s does not match "
"with existing Cinder volume name %(c_name)s"),
LOG.error("Provided volume name %(d_name)s does not match "
"with existing Cinder volume name %(c_name)s",
{'d_name': docker_volume_name,
'c_name': cinder_volume.name})
raise exceptions.InvalidInput('Volume name does not match')
@ -232,9 +232,9 @@ class Cinder(provider.Provider):
vol_fstype = cinder_volume.metadata.get('fstype',
cinder_conf.fstype)
if fstype != vol_fstype:
LOG.error(_LE("Volume already exists with fstype %(c_fstype)s, "
"but currently provided fstype is %(fstype)s, not "
"match"), {'c_fstype': vol_fstype, 'fstype': fstype})
LOG.error("Volume already exists with fstype %(c_fstype)s, "
"but currently provided fstype is %(fstype)s, not "
"match", {'c_fstype': vol_fstype, 'fstype': fstype})
raise exceptions.InvalidInput('FSType does not match')
try:
@ -242,8 +242,8 @@ class Cinder(provider.Provider):
'fstype': fstype}
self.cinderclient.volumes.set_metadata(cinder_volume, metadata)
except cinder_exception.ClientException as e:
LOG.error(_LE("Failed to update volume %(vol)s information. "
"Error: %(err)s"),
LOG.error("Failed to update volume %(vol)s information. "
"Error: %(err)s",
{'vol': cinder_volume_id, 'err': e})
raise
return cinder_volume
@ -254,19 +254,19 @@ class Cinder(provider.Provider):
connector = self._get_connector()
cinder_volume, state = self._get_docker_volume(docker_volume_name)
LOG.info(_LI("Get docker volume %(d_v)s %(vol)s with state %(st)s"),
LOG.info("Get docker volume %(d_v)s %(vol)s with state %(st)s",
{'d_v': docker_volume_name, 'vol': cinder_volume,
'st': state})
device_info = {}
if state == ATTACH_TO_THIS:
LOG.warning(_LW("The volume %(d_v)s %(vol)s already exists "
"and attached to this server"),
LOG.warning("The volume %(d_v)s %(vol)s already exists "
"and attached to this server",
{'d_v': docker_volume_name, 'vol': cinder_volume})
device_info = {'path': connector.get_device_path(cinder_volume)}
elif state == NOT_ATTACH:
LOG.warning(_LW("The volume %(d_v)s %(vol)s is already exists "
"but not attached"),
LOG.warning("The volume %(d_v)s %(vol)s is already exists "
"but not attached",
{'d_v': docker_volume_name, 'vol': cinder_volume})
device_info = connector.connect_volume(cinder_volume)
elif state == ATTACH_TO_OTHER:
@ -276,15 +276,15 @@ class Cinder(provider.Provider):
cinder_conf.fstype)
if fstype != vol_fstype:
LOG.error(
_LE("Volume already exists with fstype: %{v_fs}s, but "
"currently provided fstype is %{fs}s, not "
"match"),
("Volume already exists with fstype: %{v_fs}s, but "
"currently provided fstype is %{fs}s, not "
"match"),
{'v_fs': vol_fstype, 'fs': fstype})
raise exceptions.FuxiException('FSType Not Match')
device_info = connector.connect_volume(cinder_volume)
else:
msg = _LE("The volume {0} {1} is already attached to another "
"server").format(docker_volume_name, cinder_volume)
msg = _("The volume {0} {1} is already attached to another "
"server").format(docker_volume_name, cinder_volume)
LOG.error(msg)
raise exceptions.FuxiException(msg)
elif state == UNKNOWN:
@ -311,8 +311,8 @@ class Cinder(provider.Provider):
except cinder_exception.NotFound:
return
except cinder_exception.ClientException as e:
LOG.error(_LE("Error happened when delete volume from Cinder."
" Error: %s"), e)
LOG.error("Error happened when delete volume from Cinder."
" Error: %s", e)
raise
start_time = time.time()
@ -325,24 +325,24 @@ class Cinder(provider.Provider):
time.sleep(consts.VOLUME_SCAN_TIME_DELAY)
# If the volume is not deleted, raise an exception
msg_ft = _LE("Timed out while waiting for volume. "
"Expected Volume: {0}, "
"Expected State: {1}, "
"Elapsed Time: {2}").format(volume,
None,
time.time() - start_time)
msg_ft = _("Timed out while waiting for volume. "
"Expected Volume: {0}, "
"Expected State: {1}, "
"Elapsed Time: {2}").format(volume,
None,
time.time() - start_time)
raise exceptions.TimeoutException(msg_ft)
def delete(self, docker_volume_name):
cinder_volume, state = self._get_docker_volume(docker_volume_name)
LOG.info(_LI("Get docker volume %(d_v)s %(vol)s with state %(st)s"),
LOG.info("Get docker volume %(d_v)s %(vol)s with state %(st)s",
{'d_v': docker_volume_name, 'vol': cinder_volume,
'st': state})
if state == ATTACH_TO_THIS:
link_path = self._get_connector().get_device_path(cinder_volume)
if not link_path or not os.path.exists(link_path):
msg = _LE(
msg = _(
"Could not find device link path for volume {0} {1} "
"in host").format(docker_volume_name, cinder_volume)
LOG.error(msg)
@ -350,8 +350,8 @@ class Cinder(provider.Provider):
devpath = os.path.realpath(link_path)
if not os.path.exists(devpath):
msg = _LE("Could not find device path for volume {0} {1} in "
"host").format(docker_volume_name, cinder_volume)
msg = ("Could not find device path for volume {0} {1} in "
"host").format(docker_volume_name, cinder_volume)
LOG.error(msg)
raise exceptions.FuxiException(msg)
@ -380,8 +380,8 @@ class Cinder(provider.Provider):
# than delete it from Cinder.
if not available_volume.attachments:
LOG.warning(
_LW("No other servers still use this volume %(d_v)s"
" %(vol)s any more, so delete it from Cinder"),
("No other servers still use this volume %(d_v)s"
" %(vol)s any more, so delete it from Cinder"),
{'d_v': docker_volume_name, 'vol': cinder_volume})
self._delete_volume(available_volume)
return True
@ -389,21 +389,21 @@ class Cinder(provider.Provider):
self._delete_volume(cinder_volume)
return True
elif state == ATTACH_TO_OTHER:
msg = _LW("Volume %s is still in use, could not delete it")
msg = "Volume %s is still in use, could not delete it"
LOG.warning(msg, cinder_volume)
return True
elif state == UNKNOWN:
return False
else:
msg = _LE("Volume %(vol_name)s %(c_vol)s "
"state %(state)s is invalid")
msg = ("Volume %(vol_name)s %(c_vol)s "
"state %(state)s is invalid")
LOG.error(msg, {'vol_name': docker_volume_name,
'c_vol': cinder_volume,
'state': state})
raise exceptions.NotMatchedState()
def list(self):
LOG.info(_LI("Start to retrieve all docker volumes from Cinder"))
LOG.info("Start to retrieve all docker volumes from Cinder")
docker_volumes = []
try:
@ -422,16 +422,16 @@ class Cinder(provider.Provider):
'Mountpoint': mountpoint}
docker_volumes.append(docker_vol)
except cinder_exception.ClientException as e:
LOG.error(_LE("Retrieve volume list failed. Error: %s"), e)
LOG.error("Retrieve volume list failed. Error: %s", e)
raise
LOG.info(_LI("Retrieve docker volumes %s from Cinder "
"successfully"), docker_volumes)
LOG.info("Retrieve docker volumes %s from Cinder "
"successfully", docker_volumes)
return docker_volumes
def show(self, docker_volume_name):
cinder_volume, state = self._get_docker_volume(docker_volume_name)
LOG.info(_LI("Get docker volume %(d_v)s %(vol)s with state %(st)s"),
LOG.info("Get docker volume %(d_v)s %(vol)s with state %(st)s",
{'d_v': docker_volume_name, 'vol': cinder_volume,
'st': state})
@ -440,8 +440,8 @@ class Cinder(provider.Provider):
self._get_connector().get_device_path(cinder_volume))
mp = self._get_mountpoint(docker_volume_name)
LOG.info(
_LI("Expected devpath: %(dp)s and mountpoint: %(mp)s for"
" volume: %(d_v)s %(vol)s"),
("Expected devpath: %(dp)s and mountpoint: %(mp)s for"
" volume: %(d_v)s %(vol)s"),
{'dp': devpath, 'mp': mp,
'd_v': docker_volume_name, 'vol': cinder_volume})
mounter = mount.Mounter()
@ -451,19 +451,19 @@ class Cinder(provider.Provider):
elif state in (NOT_ATTACH, ATTACH_TO_OTHER):
return {'Name': docker_volume_name, 'Mountpoint': ''}
elif state == UNKNOWN:
msg = _LW("Can't find this volume '{0}' in "
"Cinder").format(docker_volume_name)
msg = _("Can't find this volume '{0}' in "
"Cinder").format(docker_volume_name)
LOG.warning(msg)
raise exceptions.NotFound(msg)
else:
msg = _LE("Volume '{0}' exists, but not attached to this volume,"
"and current state is {1}").format(docker_volume_name,
state)
msg = _("Volume '{0}' exists, but not attached to this volume,"
"and current state is {1}").format(docker_volume_name,
state)
raise exceptions.NotMatchedState(msg)
def mount(self, docker_volume_name):
cinder_volume, state = self._get_docker_volume(docker_volume_name)
LOG.info(_LI("Get docker volume %(d_v)s %(vol)s with state %(st)s"),
LOG.info("Get docker volume %(d_v)s %(vol)s with state %(st)s",
{'d_v': docker_volume_name, 'vol': cinder_volume,
'st': state})
@ -487,8 +487,8 @@ class Cinder(provider.Provider):
link_path = connector.get_device_path(cinder_volume)
if not os.path.exists(link_path):
LOG.warning(_LW("Could not find device link file, "
"so rebuild it"))
LOG.warning("Could not find device link file, "
"so rebuild it")
connector.disconnect_volume(cinder_volume)
connector.connect_volume(cinder_volume)
@ -512,7 +512,7 @@ class Cinder(provider.Provider):
def check_exist(self, docker_volume_name):
_, state = self._get_docker_volume(docker_volume_name)
LOG.info(_LI("Get docker volume %(d_v)s with state %(st)s"),
LOG.info("Get docker volume %(d_v)s with state %(st)s",
{'d_v': docker_volume_name, 'st': state})
if state == UNKNOWN:

View File

@ -30,7 +30,7 @@ from manilaclient.common.apiclient import exceptions as manila_exception
from fuxi.common import constants as consts
from fuxi.common import state_monitor
from fuxi import exceptions
from fuxi.i18n import _LI, _LW, _LE
from fuxi.i18n import _
from fuxi import utils
from fuxi.volumeprovider import provider
@ -67,13 +67,13 @@ def extract_share_kwargs(docker_volume_name, docker_volume_opts):
try:
size = int(docker_volume_opts.pop('size'))
except ValueError:
msg = _LE("Volume size must able to convert to int type")
msg = _("Volume size must able to convert to int type")
LOG.error(msg)
raise exceptions.InvalidInput(msg)
else:
size = CONF.default_volume_size
LOG.info(_LI("Volume size doesn't provide from command, so use "
"default size %sG"), size)
LOG.info("Volume size doesn't provide from command, so use "
"default size %sG", size)
kwargs['size'] = size
share_proto = docker_volume_opts.pop('share_proto', None) \
@ -99,7 +99,7 @@ class Manila(provider.Provider):
conn_conf = manila_conf.volume_connector
if not conn_conf or conn_conf not in volume_connector_conf:
msg = _LE("Must provide a valid volume connector")
msg = _("Must provide a valid volume connector")
LOG.error(msg)
raise exceptions.InvalidInput(msg)
self.connector = importutils.import_object(
@ -116,8 +116,7 @@ class Manila(provider.Provider):
docker_shares = self.manilaclient.shares.list(
search_opts=search_opts)
except manila_exception.ClientException as e:
LOG.error(_LE("Could not retrieve Manila share list. Error: %s"),
e)
LOG.error("Could not retrieve Manila share list. Error: %s", e)
raise
if not docker_shares:
@ -143,16 +142,16 @@ class Manila(provider.Provider):
LOG.debug("Start to create share from Manila")
share = self.manilaclient.shares.create(**share_kwargs)
except manila_exception.ClientException as e:
LOG.error(_LE("Create Manila share failed. Error: {0}"), e)
LOG.error("Create Manila share failed. Error: {0}", e)
raise
LOG.info(_LI("Waiting for share %s status to be available"), share)
LOG.info("Waiting for share %s status to be available", share)
share_monitor = state_monitor.StateMonitor(self.manilaclient,
share,
'available',
('creating',))
share = share_monitor.monitor_manila_share()
LOG.info(_LI("Creating share %s successfully"), share)
LOG.info("Creating share %s successfully", share)
return share
def _create_from_existing_share(self, docker_volume_name,
@ -160,7 +159,7 @@ class Manila(provider.Provider):
try:
share = self.manilaclient.shares.get(share_id)
except manila_exception.NotFound:
LOG.error(_LE("Could not find share %s"), share_id)
LOG.error("Could not find share %s", share_id)
raise
if share.status != 'available':
@ -168,8 +167,8 @@ class Manila(provider.Provider):
"Manila share is unavailable")
if share.name != docker_volume_name:
LOG.error(_LE("Provided volume name %(d_name)s does not match "
"with existing share name %(s_name)s"),
LOG.error("Provided volume name %(d_name)s does not match "
"with existing share name %(s_name)s",
{'d_name': docker_volume_name,
's_name': share.name})
raise exceptions.InvalidInput('Volume name does not match')
@ -184,8 +183,8 @@ class Manila(provider.Provider):
try:
share, state = self._get_docker_volume(docker_volume_name)
if share:
LOG.warning(_LW("Volume %(vol)s already exists in Manila, and "
"the related Manila share is %(share)s"),
LOG.warning("Volume %(vol)s already exists in Manila, and "
"the related Manila share is %(share)s",
{'vol': docker_volume_name, 'share': share})
if state == NOT_ATTACH:
@ -209,14 +208,14 @@ class Manila(provider.Provider):
try:
share_access_list = self.manilaclient.shares.access_list(share)
if len(share_access_list) > 0:
LOG.warning(_LE("Share %s is still used by other server, so "
"should not delete it."), share)
LOG.warning("Share %s is still used by other server, so "
"should not delete it.", share)
return
self.manilaclient.shares.delete(share)
except manila_exception.ClientException as e:
LOG.error(_LE("Error happened when delete Volume %(vol)s (Manila "
"share: %(share)s). Error: %(err)s"),
LOG.error("Error happened when delete Volume %(vol)s (Manila "
"share: %(share)s). Error: %(err)s",
{'vol': share.name, 'share': share, 'err': e})
raise
@ -255,8 +254,8 @@ class Manila(provider.Provider):
def mount(self, docker_volume_name):
share, state = self._get_docker_volume(docker_volume_name)
if state == NOT_ATTACH:
LOG.warning(_LW("Find share %s, but not attach to this server, "
"so connect it"), share)
LOG.warning("Find share %s, but not attach to this server, "
"so connect it", share)
self.connector.connect_volume(share)
mountpoint = self.connector.get_mountpoint(share)
@ -278,7 +277,7 @@ class Manila(provider.Provider):
docker_shares = self.manilaclient.shares.list(
search_opts=search_opts)
except manila_exception.ClientException as e:
LOG.error(_LE('Could not retrieve Manila shares. Error: %s'), e)
LOG.error('Could not retrieve Manila shares. Error: %s', e)
raise
docker_volumes = []
@ -287,8 +286,8 @@ class Manila(provider.Provider):
docker_volumes.append(
{'Name': share.name,
'Mountpoint': self.connector.get_mountpoint(share)})
LOG.info(_LI("Retrieve docker volumes %s from Manila "
"successfully"), docker_volumes)
LOG.info("Retrieve docker volumes %s from Manila "
"successfully", docker_volumes)
return docker_volumes
@utils.wrap_check_authorized

View File

@ -15,7 +15,6 @@ import os
import six
from fuxi import exceptions
from fuxi.i18n import _LI, _LE
from fuxi import utils
from oslo_concurrency import processutils
@ -75,7 +74,7 @@ class Provider(object):
:rtype: str
"""
if not docker_volume_name:
LOG.error(_LE("Volume name could not be None"))
LOG.error("Volume name could not be None")
raise exceptions.FuxiException("Volume name could not be None")
if self.volume_provider_type:
return os.path.join(CONF.volume_dir,
@ -94,10 +93,10 @@ class Provider(object):
if not os.path.exists(mountpoint) or not os.path.isdir(mountpoint):
utils.execute('mkdir', '-p', '-m=755', mountpoint,
run_as_root=True)
LOG.info(_LI("Create mountpoint %s successfully"), mountpoint)
LOG.info("Create mountpoint %s successfully", mountpoint)
except processutils.ProcessExecutionError as e:
LOG.error(_LE("Error happened when create volume "
"directory. Error: %s"), e)
LOG.error("Error happened when create volume "
"directory. Error: %s", e)
raise
def _clear_mountpoint(self, mountpoint):
@ -108,8 +107,8 @@ class Provider(object):
if os.path.exists(mountpoint) and os.path.isdir(mountpoint):
try:
utils.execute('rm', '-r', mountpoint, run_as_root=True)
LOG.info(_LI("Clear mountpoint %s successfully"), mountpoint)
LOG.info("Clear mountpoint %s successfully", mountpoint)
except processutils.ProcessExecutionError as e:
LOG.error(_LE("Error happened when clear mountpoint. "
"Error: %s"), e)
LOG.error("Error happened when clear mountpoint. "
"Error: %s", e)
raise