Fix Service.__repr__ to remove the undefined attribute

The self.name is undefined in the Service class.
And also there is no need any unique information to
identify this object, so we just remove it directly.

Change-Id: I3ce8663f830357855f2155e080393ea97f8f80ba
Partial-Bug: #1585024
This commit is contained in:
xiexs 2016-06-25 11:43:32 -04:00
parent 6cadb738b8
commit f0f8e6b5ab
2 changed files with 17 additions and 1 deletions

View File

@ -20,6 +20,11 @@ from cinderclient.v1 import services
cs = fakes.FakeClient()
FAKE_SERVICE = {"host": "host1",
'binary': 'cinder-volume',
"status": "enable",
"availability_zone": "nova"}
class ServicesTest(utils.TestCase):
@ -73,3 +78,14 @@ class ServicesTest(utils.TestCase):
cs.assert_called('PUT', '/os-services/disable-log-reason', values)
self.assertIsInstance(s, services.Service)
self.assertEqual('disabled', s.status)
def test___repr__(self):
"""
Unit test for Service.__repr__
Verify that one Service object can be printed.
"""
svs = services.Service(None, FAKE_SERVICE)
self.assertEqual(
"<Service: binary=%s host=%s>" % (FAKE_SERVICE['binary'],
FAKE_SERVICE['host']), repr(svs))

View File

@ -22,7 +22,7 @@ from cinderclient import base
class Service(base.Resource):
def __repr__(self):
return "<Service: %s>" % self.service
return "<Service: binary=%s host=%s>" % (self.binary, self.host)
class ServiceManager(base.ManagerWithFind):