From 893852b75a53d1dfb8f4a69031c989205f441cc4 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 1 Apr 2013 00:53:25 +0100 Subject: [PATCH] Remove gettext.install() from nova/__init__.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gettext.install() function installs a builtin _() function which translates a string in the translation domain supplied to the install() function. If gettext.install() is called multiple times, it's the last call to the function which wins and the last supplied translation domain which is used e.g. >>> import os >>> os.environ['LANG'] = 'ja.UTF-8' >>> import gettext >>> gettext.install('keystone', unicode=1, localedir='/opt/stack/keystone/keystone/locale') >>> print _('Invalid syslog facility') 無効な syslog ファシリティ >>> gettext.install('nova', unicode=1, localedir='/opt/stack/nova/nova/locale') >>> print _('Invalid syslog facility') Invalid syslog facility Usually this function is called early on in a toplevel script and we assume that no other code will call it and override the installed _(). However, in Nova, we have taken a shortcut to avoid having to call it explicitly from each script and instead call it from nova/__init__.py. This shortcut would be perfectly fine if we were absolutely sure that nova modules would never be imported from another program. It's probably quite incorrect for a program to use nova code (indeed, if we wanted to support this, Nova code shouldn't use the default _() function) but nevertheless there are some corner cases where it happens. For example, the keystoneclient auth_token middleware tries to import cfg from nova.openstack.common and this in turn causes gettext.install('nova') in other projects like glance or quantum. To avoid any doubt here, let's just rip out the shortcut and always call gettext.install() from the top-level script. Change-Id: If4125d6bcbde63df95de129ac5c83b4a6d6f130a --- bin/nova-all | 2 ++ bin/nova-api | 2 ++ bin/nova-api-ec2 | 2 ++ bin/nova-api-metadata | 2 ++ bin/nova-api-os-compute | 2 ++ bin/nova-baremetal-deploy-helper | 3 +++ bin/nova-cells | 3 +++ bin/nova-cert | 2 ++ bin/nova-compute | 2 ++ bin/nova-conductor | 2 ++ bin/nova-console | 2 ++ bin/nova-consoleauth | 2 ++ bin/nova-network | 2 ++ bin/nova-novncproxy | 3 +++ bin/nova-objectstore | 2 ++ bin/nova-spicehtml5proxy | 3 +++ bin/nova-xvpvncproxy | 2 ++ 17 files changed, 38 insertions(+) diff --git a/bin/nova-all b/bin/nova-all index d96b7160..af947d36 100755 --- a/bin/nova-all +++ b/bin/nova-all @@ -30,6 +30,7 @@ continue attempting to launch the rest of the services. import eventlet eventlet.monkey_patch(os=False) +import gettext import os import sys @@ -40,6 +41,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.objectstore import s3server diff --git a/bin/nova-api b/bin/nova-api index d21d955c..171a23ea 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -26,6 +26,7 @@ Starts both the EC2 and OpenStack APIs in separate greenthreads. import eventlet eventlet.monkey_patch(os=False) +import gettext import os import sys @@ -36,6 +37,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-api-ec2 b/bin/nova-api-ec2 index d1b3d45e..a3e1be01 100755 --- a/bin/nova-api-ec2 +++ b/bin/nova-api-ec2 @@ -22,6 +22,7 @@ import eventlet eventlet.monkey_patch(os=False) +import gettext import os import sys @@ -31,6 +32,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-api-metadata b/bin/nova-api-metadata index e7cac260..2005d671 100755 --- a/bin/nova-api-metadata +++ b/bin/nova-api-metadata @@ -22,6 +22,7 @@ import eventlet eventlet.monkey_patch(os=False) +import gettext import os import sys @@ -31,6 +32,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-api-os-compute b/bin/nova-api-os-compute index 02f16a04..c2aa9e57 100755 --- a/bin/nova-api-os-compute +++ b/bin/nova-api-os-compute @@ -22,6 +22,7 @@ import eventlet eventlet.monkey_patch(os=False) +import gettext import os import sys @@ -31,6 +32,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-baremetal-deploy-helper b/bin/nova-baremetal-deploy-helper index 75630577..975fc761 100755 --- a/bin/nova-baremetal-deploy-helper +++ b/bin/nova-baremetal-deploy-helper @@ -23,6 +23,7 @@ import eventlet if __name__ == '__main__': eventlet.monkey_patch() +import gettext import os import sys import threading @@ -36,6 +37,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) + import cgi import Queue import re diff --git a/bin/nova-cells b/bin/nova-cells index bb955e9e..380e7126 100755 --- a/bin/nova-cells +++ b/bin/nova-cells @@ -21,6 +21,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -34,6 +35,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) + from nova import config from nova.openstack.common import log as logging from nova import service diff --git a/bin/nova-cert b/bin/nova-cert index c6d9ddba..861f3ba8 100755 --- a/bin/nova-cert +++ b/bin/nova-cert @@ -20,6 +20,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -33,6 +34,7 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-compute b/bin/nova-compute index 26d81d8c..a7ca4de5 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -29,6 +29,7 @@ if os.name == 'nt': else: eventlet.monkey_patch() +import gettext import os import sys import traceback @@ -43,6 +44,7 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) +gettext.install('nova', unicode=1) from nova import config import nova.db.api diff --git a/bin/nova-conductor b/bin/nova-conductor index 30d426f4..72e89804 100755 --- a/bin/nova-conductor +++ b/bin/nova-conductor @@ -20,6 +20,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -33,6 +34,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-console b/bin/nova-console index 6d656910..af037bb3 100755 --- a/bin/nova-console +++ b/bin/nova-console @@ -21,6 +21,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -34,6 +35,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-consoleauth b/bin/nova-consoleauth index 0cbec669..f867c8c7 100755 --- a/bin/nova-consoleauth +++ b/bin/nova-consoleauth @@ -21,6 +21,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -32,6 +33,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.consoleauth import manager diff --git a/bin/nova-network b/bin/nova-network index d0ee61ed..b7978521 100755 --- a/bin/nova-network +++ b/bin/nova-network @@ -22,6 +22,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -35,6 +36,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging diff --git a/bin/nova-novncproxy b/bin/nova-novncproxy index 29981f53..c40fdbfd 100755 --- a/bin/nova-novncproxy +++ b/bin/nova-novncproxy @@ -21,11 +21,14 @@ Websocket proxy that is compatible with OpenStack Nova noVNC consoles. Leverages websockify.py by Joel Martin """ +import gettext import os import sys from oslo.config import cfg +gettext.install('nova', unicode=1) + from nova import config from nova.console import websocketproxy diff --git a/bin/nova-objectstore b/bin/nova-objectstore index 8ec9fbf3..f6086894 100755 --- a/bin/nova-objectstore +++ b/bin/nova-objectstore @@ -22,6 +22,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -33,6 +34,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.objectstore import s3server diff --git a/bin/nova-spicehtml5proxy b/bin/nova-spicehtml5proxy index 012a202e..1d8fe81d 100755 --- a/bin/nova-spicehtml5proxy +++ b/bin/nova-spicehtml5proxy @@ -21,11 +21,14 @@ Websocket proxy that is compatible with OpenStack Nova SPICE HTML5 consoles. Leverages websockify.py by Joel Martin """ +import gettext import os import sys from oslo.config import cfg +gettext.install('nova', unicode=1) + from nova import config from nova.console import websocketproxy diff --git a/bin/nova-xvpvncproxy b/bin/nova-xvpvncproxy index 6ad61d0b..905c3de4 100755 --- a/bin/nova-xvpvncproxy +++ b/bin/nova-xvpvncproxy @@ -21,6 +21,7 @@ import eventlet eventlet.monkey_patch() +import gettext import os import sys @@ -30,6 +31,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +gettext.install('nova', unicode=1) from nova import config from nova.openstack.common import log as logging