diff options
author | Markus Zoeller <mzoeller@de.ibm.com> | 2016-04-08 15:19:59 +0200 |
---|---|---|
committer | Markus Zoeller <mzoeller@de.ibm.com> | 2016-04-08 15:19:59 +0200 |
commit | e42ff5e5ca8c0d72802b5ad8ae7867c2f5ae2fac (patch) | |
tree | 43454c3d5ce1c3e8f8050abb57be3009680bec90 | |
parent | e6aab744a38395ccbf8faaee80085bd4765edabe (diff) | |
download | nova-e42ff5e5ca8c0d72802b5ad8ae7867c2f5ae2fac.tar.gz |
Add "__repr__" method to class "Service"
The class "Service" doesn't have a "__repr__" method which results
in log outputs like:
DEBUG [...] service = <nova.service.Service object at 0x56eb890>
This is not helpful when analyzing logs. Therefore this change adds a
"__repr__" method.
Change-Id: I49c8b7f0dde298de780808c988e4b50278eed665
-rw-r--r-- | nova/service.py | 9 | ||||
-rw-r--r-- | nova/tests/unit/test_service.py | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/nova/service.py b/nova/service.py index dc40de4a0c..9810ce275d 100644 --- a/nova/service.py +++ b/nova/service.py @@ -110,6 +110,15 @@ class Service(service.Service): self.conductor_api = conductor.API(use_local=db_allowed) self.conductor_api.wait_until_ready(context.get_admin_context()) + def __repr__(self): + return "<%(cls_name)s: host=%(host)s, binary=%(binary)s, " \ + "manager_class_name=%(manager)s>" % { + 'cls_name': self.__class__.__name__, + 'host': self.host, + 'binary': self.binary, + 'manager': self.manager_class_name + } + def start(self): verstr = version.version_string_with_package() LOG.info(_LI('Starting %(topic)s node (version %(version)s)'), diff --git a/nova/tests/unit/test_service.py b/nova/tests/unit/test_service.py index 07063c9c4d..22fe864f47 100644 --- a/nova/tests/unit/test_service.py +++ b/nova/tests/unit/test_service.py @@ -109,6 +109,17 @@ class ServiceTestCase(test.NoDBTestCase): self.assertTrue(app) + def test_repr(self): + # Test if a Service object is correctly represented, for example in + # log files. + serv = service.Service(self.host, + self.binary, + self.topic, + 'nova.tests.unit.test_service.FakeManager') + exp = "<Service: host=foo, binary=nova-fake, " \ + "manager_class_name=nova.tests.unit.test_service.FakeManager>" + self.assertEqual(exp, repr(serv)) + def _service_start_mocks(self): self.mox.StubOutWithMock(objects.Service, 'create') self.mox.StubOutWithMock(objects.Service, 'get_by_host_and_binary') |