From 7e3b764a84137a7ec4e89a40a6cc96bf9c025778 Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Thu, 22 Nov 2012 22:05:28 +0800 Subject: [PATCH] Correct i18n message Part of bp make-string-localizable Change-Id: I9020d7ef426602656fc198018c176eec813cd74b --- quantum/agent/l3_agent.py | 25 +++++++++++++------------ quantum/agent/linux/interface.py | 2 +- quantum/agent/linux/ovs_lib.py | 15 +++++++++------ quantum/agent/linux/utils.py | 7 ++++--- quantum/common/config.py | 4 ++-- quantum/manager.py | 18 +++++++++--------- quantum/service.py | 4 ++-- quantum/wsgi.py | 14 +++++++------- 8 files changed, 47 insertions(+), 42 deletions(-) diff --git a/quantum/agent/l3_agent.py b/quantum/agent/l3_agent.py index 766362285..154d7c4fc 100644 --- a/quantum/agent/l3_agent.py +++ b/quantum/agent/l3_agent.py @@ -111,8 +111,8 @@ class L3NATAgent(object): self.driver = importutils.import_object(conf.interface_driver, conf) except: - LOG.exception(_("Error importing interface driver '%s'" - % conf.interface_driver)) + LOG.exception(_("Error importing interface driver '%s'"), + conf.interface_driver) sys.exit(1) self.polling_interval = conf.polling_interval @@ -139,7 +139,7 @@ class L3NATAgent(object): try: self._destroy_router_namespace(ns) except: - LOG.exception("couldn't delete namespace '%s'" % ns) + LOG.exception(_("Couldn't delete namespace '%s'"), ns) def _destroy_router_namespace(self, namespace): ns_ip = ip_lib.IPWrapper(self.conf.root_helper, @@ -170,7 +170,7 @@ class L3NATAgent(object): try: self.do_single_loop() except: - LOG.exception("Error running l3_nat daemon_loop") + LOG.exception(_("Error running l3_nat daemon_loop")) time.sleep(self.polling_interval) @@ -182,8 +182,9 @@ class L3NATAgent(object): params = {'router:external': True} ex_nets = self.qclient.list_networks(**params)['networks'] if len(ex_nets) > 1: - raise Exception("must configure 'gateway_external_network_id' if " - "Quantum has more than one external network.") + raise Exception(_("Must configure 'gateway_external_network_id' " + "if Quantum has more than one external " + "network.")) if len(ex_nets) == 0: return None return ex_nets[0]['id'] @@ -192,8 +193,8 @@ class L3NATAgent(object): if (self.conf.external_network_bridge and not ip_lib.device_exists(self.conf.external_network_bridge)): - LOG.error("external network bridge '%s' does not exist" - % self.conf.external_network_bridge) + LOG.error(_("External network bridge '%s' does not exist"), + self.conf.external_network_bridge) return prev_router_ids = set(self.router_info) @@ -257,9 +258,9 @@ class L3NATAgent(object): def _set_subnet_info(self, port): ips = port['fixed_ips'] if not ips: - raise Exception("Router port %s has no IP address" % port['id']) + raise Exception(_("Router port %s has no IP address") % port['id']) if len(ips) > 1: - LOG.error("Ignoring multiple IPs on router port %s" % port['id']) + LOG.error(_("Ignoring multiple IPs on router port %s"), port['id']) port['subnet'] = self.qclient.show_subnet( ips[0]['subnet_id'])['subnet'] prefixlen = netaddr.IPNetwork(port['subnet']['cidr']).prefixlen @@ -356,8 +357,8 @@ class L3NATAgent(object): elif len(ports) == 1: return ports[0] else: - LOG.error("Ignoring multiple gateway ports for router %s" - % ri.router_id) + LOG.error(_("Ignoring multiple gateway ports for router %s"), + ri.router_id) def _send_gratuitous_arp_packet(self, ri, interface_name, ip_address): if self.conf.send_arp_for_ha > 0: diff --git a/quantum/agent/linux/interface.py b/quantum/agent/linux/interface.py index 1c496e242..1e9fadb9d 100644 --- a/quantum/agent/linux/interface.py +++ b/quantum/agent/linux/interface.py @@ -288,6 +288,6 @@ class MetaInterfaceDriver(LinuxInterfaceDriver): return driver.unplug(device_name, bridge, namespace, prefix) def _load_driver(self, driver_provider): - LOG.debug("Driver location:%s", driver_provider) + LOG.debug(_("Driver location: %s"), driver_provider) plugin_klass = importutils.import_class(driver_provider) return plugin_klass(self.conf) diff --git a/quantum/agent/linux/ovs_lib.py b/quantum/agent/linux/ovs_lib.py index 65d840e41..00f6586b0 100644 --- a/quantum/agent/linux/ovs_lib.py +++ b/quantum/agent/linux/ovs_lib.py @@ -62,7 +62,8 @@ class OVSBridge: try: return utils.execute(full_args, root_helper=self.root_helper) except Exception, e: - LOG.error("Unable to execute %s. Exception: %s", full_args, e) + LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"), + {'cmd': full_args, 'exception': e}) def reset_bridge(self): self.run_vsctl(["--", "--if-exists", "del-br", self.br_name]) @@ -90,7 +91,8 @@ class OVSBridge: try: return utils.execute(full_args, root_helper=self.root_helper) except Exception, e: - LOG.error("Unable to execute %s. Exception: %s", full_args, e) + LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"), + {'cmd': full_args, 'exception': e}) def count_flows(self): flow_list = self.run_ofctl("dump-flows", []).split("\n")[1:] @@ -116,7 +118,7 @@ class OVSBridge: kwargs.get('priority', '1'))) flow_expr_arr.append(prefix) elif 'priority' in kwargs: - raise Exception("Cannot match priority on flow deletion") + raise Exception(_("Cannot match priority on flow deletion")) in_port = ('in_port' in kwargs and ",in_port=%s" % kwargs['in_port'] or '') @@ -140,7 +142,7 @@ class OVSBridge: def add_flow(self, **kwargs): if "actions" not in kwargs: - raise Exception("must specify one or more actions") + raise Exception(_("Must specify one or more actions")) if "priority" not in kwargs: kwargs["priority"] = "0" @@ -211,7 +213,8 @@ class OVSBridge: try: return utils.execute(args, root_helper=self.root_helper).strip() except Exception, e: - LOG.error("Unable to execute %s. Exception: %s", args, e) + LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"), + {'cmd': args, 'exception': e}) # returns a VIF object for each VIF port def get_vif_ports(self): @@ -265,7 +268,7 @@ class OVSBridge: ofport = int(match.group('ofport')) return VifPort(port_name, ofport, vif_id, vif_mac, self) except Exception, e: - LOG.info("Unable to parse regex results. Exception: %s", e) + LOG.info(_("Unable to parse regex results. Exception: %s"), e) return diff --git a/quantum/agent/linux/utils.py b/quantum/agent/linux/utils.py index 8f6275303..5a55e0d4d 100644 --- a/quantum/agent/linux/utils.py +++ b/quantum/agent/linux/utils.py @@ -38,7 +38,7 @@ def execute(cmd, root_helper=None, process_input=None, addl_env=None, cmd = shlex.split(root_helper) + cmd cmd = map(str, cmd) - LOG.debug("Running command: " + " ".join(cmd)) + LOG.debug(_("Running command: %s"), cmd) env = os.environ.copy() if addl_env: env.update(addl_env) @@ -52,8 +52,9 @@ def execute(cmd, root_helper=None, process_input=None, addl_env=None, obj.communicate(process_input) or obj.communicate()) obj.stdin.close() - m = ("\nCommand: %s\nExit code: %s\nStdout: %r\nStderr: %r" % - (cmd, obj.returncode, _stdout, _stderr)) + m = _("\nCommand: %(cmd)s\nExit code: %(code)s\nStdout: %(stdout)r\n" + "Stderr: %(stderr)r") % {'cmd': cmd, 'code': obj.returncode, + 'stdout': _stdout, 'stderr': _stderr} LOG.debug(m) if obj.returncode and check_exit_code: raise RuntimeError(m) diff --git a/quantum/common/config.py b/quantum/common/config.py index 5f99fc404..78e9a0b14 100644 --- a/quantum/common/config.py +++ b/quantum/common/config.py @@ -83,7 +83,7 @@ def setup_logging(conf): logging.setup(product_name) log_root = logging.getLogger(product_name).logger log_root.propagate = 0 - LOG.info("Logging enabled!") + LOG.info(_("Logging enabled!")) def load_paste_app(app_name): @@ -97,7 +97,7 @@ def load_paste_app(app_name): config_path = os.path.abspath(cfg.CONF.find_file( cfg.CONF.api_paste_config)) - LOG.info("Config paste file: %s", config_path) + LOG.info(_("Config paste file: %s"), config_path) try: app = deploy.loadapp("config:%s" % config_path, name=app_name) diff --git a/quantum/manager.py b/quantum/manager.py index 5d494a9f7..e1cd16928 100644 --- a/quantum/manager.py +++ b/quantum/manager.py @@ -47,16 +47,16 @@ class QuantumManager(object): # intentianally to allow v2 plugins to be monitored # for performance metrics. plugin_provider = cfg.CONF.core_plugin - LOG.debug("Plugin location:%s", plugin_provider) + LOG.debug(_("Plugin location: %s"), plugin_provider) # If the plugin can't be found let them know gracefully try: - LOG.info("Loading Plugin: %s" % plugin_provider) + LOG.info(_("Loading Plugin: %s"), plugin_provider) plugin_klass = importutils.import_class(plugin_provider) except ClassNotFound: - LOG.exception("Error loading plugin") - raise Exception("Plugin not found. You can install a " + LOG.exception(_("Error loading plugin")) + raise Exception(_("Plugin not found. You can install a " "plugin with: pip install \n" - "Example: pip install quantum-sample-plugin") + "Example: pip install quantum-sample-plugin")) self.plugin = plugin_klass() # core plugin as a part of plugin collection simplifies @@ -68,12 +68,12 @@ class QuantumManager(object): def _load_service_plugins(self): plugin_providers = cfg.CONF.service_plugins - LOG.debug(_("Loading service plugins: %s" % plugin_providers)) + LOG.debug(_("Loading service plugins: %s"), plugin_providers) for provider in plugin_providers: if provider == '': continue try: - LOG.info(_("Loading Plugin: %s" % provider)) + LOG.info(_("Loading Plugin: %s"), provider) plugin_class = importutils.import_class(provider) except ClassNotFound: LOG.exception(_("Error loading plugin")) @@ -85,8 +85,8 @@ class QuantumManager(object): # for the same type is a fatal exception if plugin_inst.get_plugin_type() in self.service_plugins: raise Exception(_("Multiple plugins for service " - "%s were configured" % - plugin_inst.get_plugin_type())) + "%s were configured"), + plugin_inst.get_plugin_type()) self.service_plugins[plugin_inst.get_plugin_type()] = plugin_inst diff --git a/quantum/service.py b/quantum/service.py index dfe72cdbf..39c0850f8 100644 --- a/quantum/service.py +++ b/quantum/service.py @@ -70,7 +70,7 @@ def serve_wsgi(cls): try: service = cls.create() except Exception: - LOG.exception('in WsgiService.create()') + LOG.exception(_('In WsgiService.create()')) raise service.start() @@ -87,7 +87,7 @@ def _run_wsgi(app_name): server.start(app, cfg.CONF.bind_port, cfg.CONF.bind_host) # Dump all option values here after all options are parsed cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) - LOG.info("Quantum service started, listening on %(host)s:%(port)s" % + LOG.info(_("Quantum service started, listening on %(host)s:%(port)s"), {'host': cfg.CONF.bind_host, 'port': cfg.CONF.bind_port}) return server diff --git a/quantum/wsgi.py b/quantum/wsgi.py index af46267e9..afef2db41 100644 --- a/quantum/wsgi.py +++ b/quantum/wsgi.py @@ -754,19 +754,19 @@ class Resource(Application): def __call__(self, request): """WSGI method that controls (de)serialization and method dispatch.""" - LOG.info("%(method)s %(url)s" % {"method": request.method, - "url": request.url}) + LOG.info(_("%(method)s %(url)s"), {"method": request.method, + "url": request.url}) try: action, args, accept = self.deserializer.deserialize(request) except exception.InvalidContentType: msg = _("Unsupported Content-Type") - LOG.exception("InvalidContentType:%s", msg) + LOG.exception(_("InvalidContentType: %s"), msg) return Fault(webob.exc.HTTPBadRequest(explanation=msg), self._xmlns) except exception.MalformedRequestBody: msg = _("Malformed request body") - LOG.exception("MalformedRequestBody:%s", msg) + LOG.exception(_("MalformedRequestBody: %s"), msg) return Fault(webob.exc.HTTPBadRequest(explanation=msg), self._xmlns) @@ -778,7 +778,7 @@ class Resource(Application): self._xmlns, self._fault_body_function) except Exception: - LOG.exception("Internal error") + LOG.exception(_("Internal error")) # Do not include the traceback to avoid returning it to clients. action_result = Fault(webob.exc.HTTPServerError(), self._xmlns, @@ -795,8 +795,8 @@ class Resource(Application): msg_dict = dict(url=request.url, status=response.status_int) msg = _("%(url)s returned with HTTP %(status)d") % msg_dict except AttributeError, e: - msg_dict = dict(url=request.url, e=e) - msg = _("%(url)s returned a fault: %(e)s" % msg_dict) + msg_dict = dict(url=request.url, exception=e) + msg = _("%(url)s returned a fault: %(exception)s") % msg_dict LOG.info(msg) -- 2.45.2