summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem@us.ibm.com>2014-09-23 08:05:54 -0700
committerMatt Riedemann <mriedem@us.ibm.com>2014-09-25 07:40:27 -0700
commit59576bc73423f37466af4c7c511190a3d51d0449 (patch)
tree619623cef27da163b01dd2aa4127161db277efc9
parentf2d486db9913531cae9014ab7b4c7ee9ac5d5a95 (diff)
downloadnova-59576bc73423f37466af4c7c511190a3d51d0449.tar.gz
Remove usage of self.__dict__ for message var replacement
This is the same as using locals() for variable replacement in a log message which violates hacking rule H501. On Cinder this actually caused the cinder-api process to hang on python 2.6. Nova has the same code so this fixes the hacking violation. Note that the H501 rule was updated in commit 55e96ee but it's not in a released version of hacking yet (and won't be in time for Juno). Closes-Bug: #1365901 Change-Id: I1be0db327a2fa1e866328eecd2e7c3dd3ee3cc93
-rw-r--r--nova/api/openstack/compute/limits.py8
-rw-r--r--nova/tests/matchers.py35
-rw-r--r--nova/wsgi.py7
3 files changed, 35 insertions, 15 deletions
diff --git a/nova/api/openstack/compute/limits.py b/nova/api/openstack/compute/limits.py
index 0b52af405d..bafde8c4cd 100644
--- a/nova/api/openstack/compute/limits.py
+++ b/nova/api/openstack/compute/limits.py
@@ -159,9 +159,11 @@ class Limit(object):
self.water_level = 0
self.capacity = self.unit
self.request_value = float(self.capacity) / float(self.value)
- msg = _("Only %(value)s %(verb)s request(s) can be "
- "made to %(uri)s every %(unit_string)s.")
- self.error_message = msg % self.__dict__
+ msg = (_("Only %(value)s %(verb)s request(s) can be "
+ "made to %(uri)s every %(unit_string)s.") %
+ {'value': self.value, 'verb': self.verb, 'uri': self.uri,
+ 'unit_string': self.unit_string})
+ self.error_message = msg
def __call__(self, verb, url):
"""Represents a call to this limit from a relevant request.
diff --git a/nova/tests/matchers.py b/nova/tests/matchers.py
index fc3db616ec..b392e3e852 100644
--- a/nova/tests/matchers.py
+++ b/nova/tests/matchers.py
@@ -29,7 +29,8 @@ class DictKeysMismatch(object):
def describe(self):
return ('Keys in d1 and not d2: %(d1only)s.'
- ' Keys in d2 and not d1: %(d2only)s' % self.__dict__)
+ ' Keys in d2 and not d1: %(d2only)s' %
+ {'d1only': self.d1only, 'd2only': self.d2only})
def get_details(self):
return {}
@@ -43,7 +44,9 @@ class DictMismatch(object):
def describe(self):
return ("Dictionaries do not match at %(key)s."
- " d1: %(d1_value)s d2: %(d2_value)s" % self.__dict__)
+ " d1: %(d1_value)s d2: %(d2_value)s" %
+ {'key': self.key, 'd1_value': self.d1_value,
+ 'd2_value': self.d2_value})
def get_details(self):
return {}
@@ -113,7 +116,7 @@ class ListLengthMismatch(object):
def describe(self):
return ('Length mismatch: len(L1)=%(len1)d != '
- 'len(L2)=%(len2)d' % self.__dict__)
+ 'len(L2)=%(len2)d' % {'len1': self.len1, 'len2': self.len2})
def get_details(self):
return {}
@@ -221,7 +224,7 @@ class XMLMismatch(object):
self.actual = state.actual
def describe(self):
- return "%(path)s: XML does not match" % self.__dict__
+ return "%(path)s: XML does not match" % self.path
def get_details(self):
return {
@@ -242,7 +245,10 @@ class XMLTagMismatch(XMLMismatch):
def describe(self):
return ("%(path)s: XML tag mismatch at index %(idx)d: "
"expected tag <%(expected_tag)s>; "
- "actual tag <%(actual_tag)s>" % self.__dict__)
+ "actual tag <%(actual_tag)s>" %
+ {'path': self.path, 'idx': self.idx,
+ 'expected_tag': self.expected_tag,
+ 'actual_tag': self.actual_tag})
class XMLAttrKeysMismatch(XMLMismatch):
@@ -256,7 +262,9 @@ class XMLAttrKeysMismatch(XMLMismatch):
def describe(self):
return ("%(path)s: XML attributes mismatch: "
"keys only in expected: %(expected_only)s; "
- "keys only in actual: %(actual_only)s" % self.__dict__)
+ "keys only in actual: %(actual_only)s" %
+ {'path': self.path, 'expected_only': self.expected_only,
+ 'actual_only': self.actual_only})
class XMLAttrValueMismatch(XMLMismatch):
@@ -271,7 +279,10 @@ class XMLAttrValueMismatch(XMLMismatch):
def describe(self):
return ("%(path)s: XML attribute value mismatch: "
"expected value of attribute %(key)s: %(expected_value)r; "
- "actual value: %(actual_value)r" % self.__dict__)
+ "actual value: %(actual_value)r" %
+ {'path': self.path, 'key': self.key,
+ 'expected_value': self.expected_value,
+ 'actual_value': self.actual_value})
class XMLTextValueMismatch(XMLMismatch):
@@ -285,7 +296,9 @@ class XMLTextValueMismatch(XMLMismatch):
def describe(self):
return ("%(path)s: XML text value mismatch: "
"expected text value: %(expected_text)r; "
- "actual value: %(actual_text)r" % self.__dict__)
+ "actual value: %(actual_text)r" %
+ {'path': self.path, 'expected_text': self.expected_text,
+ 'actual_text': self.actual_text})
class XMLUnexpectedChild(XMLMismatch):
@@ -298,7 +311,8 @@ class XMLUnexpectedChild(XMLMismatch):
def describe(self):
return ("%(path)s: XML unexpected child element <%(tag)s> "
- "present at index %(idx)d" % self.__dict__)
+ "present at index %(idx)d" %
+ {'path': self.path, 'tag': self.tag, 'idx': self.idx})
class XMLExpectedChild(XMLMismatch):
@@ -311,7 +325,8 @@ class XMLExpectedChild(XMLMismatch):
def describe(self):
return ("%(path)s: XML expected child element <%(tag)s> "
- "not present at index %(idx)d" % self.__dict__)
+ "not present at index %(idx)d" %
+ {'path': self.path, 'tag': self.tag, 'idx': self.idx})
class XMLMatchState(object):
diff --git a/nova/wsgi.py b/nova/wsgi.py
index 4f9a95bd9c..8d41d66f90 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -135,7 +135,8 @@ class Server(object):
raise
(self.host, self.port) = self._socket.getsockname()[0:2]
- LOG.info(_("%(name)s listening on %(host)s:%(port)s") % self.__dict__)
+ LOG.info(_("%(name)s listening on %(host)s:%(port)s"),
+ {'name': self.name, 'host': self.host, 'port': self.port})
def start(self):
"""Start serving a WSGI application.
@@ -200,7 +201,9 @@ class Server(object):
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_("Failed to start %(name)s on %(host)s"
- ":%(port)s with SSL support") % self.__dict__)
+ ":%(port)s with SSL support"),
+ {'name': self.name, 'host': self.host,
+ 'port': self.port})
wsgi_kwargs = {
'func': eventlet.wsgi.server,