summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/service.py5
-rw-r--r--nova/tests/test_localization.py100
-rw-r--r--nova/utils.py4
-rw-r--r--nova/virt/xenapi/vm_utils.py2
4 files changed, 106 insertions, 5 deletions
diff --git a/nova/service.py b/nova/service.py
index 2c30997f2..59648adf2 100644
--- a/nova/service.py
+++ b/nova/service.py
@@ -157,8 +157,9 @@ class Service(object):
report_interval = FLAGS.report_interval
if not periodic_interval:
periodic_interval = FLAGS.periodic_interval
- logging.audit(_("Starting %s node (version %s)"), topic,
- version.version_string_with_vcs())
+ vcs_string = version.version_string_with_vcs()
+ logging.audit(_("Starting %(topic)s node (version %(vcs_string)s)")
+ % locals())
service_obj = cls(host, binary, topic, manager,
report_interval, periodic_interval)
diff --git a/nova/tests/test_localization.py b/nova/tests/test_localization.py
new file mode 100644
index 000000000..6992773f5
--- /dev/null
+++ b/nova/tests/test_localization.py
@@ -0,0 +1,100 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2011 OpenStack LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import glob
+import logging
+import os
+import re
+import sys
+import unittest
+
+import nova
+
+
+class LocalizationTestCase(unittest.TestCase):
+ def test_multiple_positional_format_placeholders(self):
+ pat = re.compile("\W_\(")
+ single_pat = re.compile("\W%\W")
+ root_path = os.path.dirname(nova.__file__)
+ problems = {}
+ for root, dirs, files in os.walk(root_path):
+ for fname in files:
+ if not fname.endswith(".py"):
+ continue
+ pth = os.path.join(root, fname)
+ txt = fulltext = file(pth).read()
+ txt_lines = fulltext.splitlines()
+ if not pat.search(txt):
+ continue
+ problems[pth] = []
+ pos = txt.find("_(")
+ while pos > -1:
+ # Make sure that this isn't part of a dunder;
+ # e.g., __init__(...
+ # or something like 'self.assert_(...'
+ test_txt = txt[pos - 1: pos + 10]
+ if not (pat.search(test_txt)):
+ txt = txt[pos + 2:]
+ pos = txt.find("_(")
+ continue
+ pos += 2
+ txt = txt[pos:]
+ innerChars = []
+ # Count pairs of open/close parens until _() closing
+ # paren is found.
+ parenCount = 1
+ pos = 0
+ while parenCount > 0:
+ char = txt[pos]
+ if char == "(":
+ parenCount += 1
+ elif char == ")":
+ parenCount -= 1
+ innerChars.append(char)
+ pos += 1
+ inner_all = "".join(innerChars)
+ # Filter out '%%' and '%('
+ inner = inner_all.replace("%%", "").replace("%(", "")
+ # Filter out the single '%' operators
+ inner = single_pat.sub("", inner)
+ # Within the remaining content, count %
+ fmtCount = inner.count("%")
+ if fmtCount > 1:
+ inner_first = inner_all.splitlines()[0]
+ lns = ["%s" % (p + 1)
+ for p, t in enumerate(txt_lines)
+ if inner_first in t]
+ lnums = ", ".join(lns)
+ # Using ugly string concatenation to avoid having
+ # this test fail itself.
+ inner_all = "_" + "(" + "%s" % inner_all
+ problems[pth].append("Line: %s Text: %s" %
+ (lnums, inner_all))
+ # Look for more
+ pos = txt.find("_(")
+ if not problems[pth]:
+ del problems[pth]
+ if problems:
+ out = ["Problem(s) found in localized string formatting",
+ "(see http://www.gnu.org/software/hello/manual/"
+ "gettext/Python.html for more information)",
+ "",
+ " ------------ Files to fix ------------"]
+ for pth in problems:
+ out.append(" %s:" % pth)
+ for val in set(problems[pth]):
+ out.append(" %s" % val)
+ raise AssertionError("\n".join(out))
diff --git a/nova/utils.py b/nova/utils.py
index f71a4d880..5f5225289 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -215,8 +215,8 @@ def get_my_linklocal(interface):
raise exception.Error(_("Link Local address is not found.:%s")
% if_str)
except Exception as ex:
- raise exception.Error(_("Couldn't get Link Local IP of %s :%s")
- % (interface, ex))
+ raise exception.Error(_("Couldn't get Link Local IP of %(interface)s"
+ " :%(ex)s") % locals())
def to_global_ipv6(prefix, mac):
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index 4afd28dd8..4bbd522c1 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -640,7 +640,7 @@ def with_vdi_attached_here(session, vdi, read_only, f):
session.get_xenapi().VBD.plug(vbd)
LOG.debug(_('Plugging VBD %s done.'), vbd)
orig_dev = session.get_xenapi().VBD.get_device(vbd)
- LOG.debug(_('VBD %s plugged as %s'), vbd, orig_dev)
+ LOG.debug(_('VBD %(vbd)s plugged as %(orig_dev)s') % locals())
dev = remap_vbd_dev(orig_dev)
if dev != orig_dev:
LOG.debug(_('VBD %(vbd)s plugged into wrong dev, '