Add missing returns and remove superfluous ones

Some methods which should have returned  objects dit not return and some
methods which don't  return anything used return ... Fixed  all that and
added tests to detect two returns which were missing.

Fixes bug 892058

Change-Id: If59468cfe1c7b1ab74ed0bfc6f81590dfd5dd668
This commit is contained in:
François Charlier 2011-12-30 17:40:02 +01:00
parent b8e6ec895e
commit d18954f4a8
12 changed files with 53 additions and 11 deletions

View File

@ -13,6 +13,7 @@ Dean Troyer <dtroyer@gmail.com>
Ed Leafe <ed@leafe.com>
Edouard Thuleau <edouard1.thuleau@orange.com>
Eldar Nugaev <eldr@ya.ru>
François Charlier <francois.charlier@enovance.com>
Gabriel Hurley <gabriel@strikeawe.com>
Gaurav Gupta <gaurav@denali-systems.com>
Ilya Alekseyev <ilyaalekseyev@acm.org>

View File

@ -80,5 +80,5 @@ class FloatingIPDNSManager(base.ManagerWithFind):
qparams = {'name': name}
params = "?%s" % urllib.urlencode(qparams) if qparams else ""
return self._delete("/os-floating-ip-dns/%s%s" %
self._delete("/os-floating-ip-dns/%s%s" %
(_quote_zone(zone), params))

View File

@ -45,7 +45,7 @@ class FloatingIPManager(base.ManagerWithFind):
:param key: The :class:`Keypair` (or its ID) to delete.
"""
return self._delete("/os-floating-ips/%s" % base.getid(floating_ip))
self._delete("/os-floating-ips/%s" % base.getid(floating_ip))
def get(self, floating_ip):
"""

View File

@ -17,7 +17,7 @@ class Image(base.Resource):
"""
Delete this image.
"""
return self.manager.delete(self)
self.manager.delete(self)
class ImageManager(base.ManagerWithFind):

View File

@ -54,7 +54,7 @@ class QuotaSetManager(base.ManagerWithFind):
if body['quota_set'][key] == None:
body['quota_set'].pop(key)
return self._update('/os-quota-sets/%s' % (tenant_id), body)
self._update('/os-quota-sets/%s' % (tenant_id), body)
def defaults(self, tenant_id):
return self._get('/os-quota-sets/%s/defaults' % tenant_id,

View File

@ -60,4 +60,4 @@ class SecurityGroupRuleManager(base.ManagerWithFind):
:param rule: The security group rule to delete (ID or Class)
"""
return self._delete('/os-security-group-rules/%s' % base.getid(rule))
self._delete('/os-security-group-rules/%s' % base.getid(rule))

View File

@ -52,7 +52,7 @@ class SecurityGroupManager(base.ManagerWithFind):
:param group: The security group to delete (group or ID)
:rtype: None
"""
return self._delete('/os-security-groups/%s' % base.getid(group))
self._delete('/os-security-groups/%s' % base.getid(group))
def get(self, id):
"""

View File

@ -117,11 +117,11 @@ class Server(base.Resource):
def diagnostics(self):
"""Diagnostics -- Retrieve server diagnostics."""
self.manager.diagnostics(self)
return self.manager.diagnostics(self)
def actions(self):
"""Actions -- Retrieve server actions."""
self.manager.actions(self)
return self.manager.actions(self)
def migrate(self):
"""

View File

@ -31,7 +31,7 @@ class Snapshot(base.Resource):
"""
Delete this snapshot.
"""
return self.manager.delete(self)
self.manager.delete(self)
class SnapshotManager(base.ManagerWithFind):

View File

@ -31,7 +31,7 @@ class Volume(base.Resource):
"""
Delete this volume.
"""
return self.manager.delete(self)
self.manager.delete(self)
class VolumeManager(base.ManagerWithFind):
@ -128,5 +128,5 @@ class VolumeManager(base.ManagerWithFind):
:param server_id: The ID of the server
:param attachment_id: The ID of the attachment
"""
return self._delete("/servers/%s/os-volume_attachments/%s" %
self._delete("/servers/%s/os-volume_attachments/%s" %
(server_id, attachment_id,))

View File

@ -240,6 +240,23 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_servers_1234_metadata(self, **kw):
return (204, {'metadata': {'test_key': 'test_value'}})
def get_servers_1234_diagnostics(self, **kw):
return (200, 'Fake diagnostics')
def get_servers_1234_actions(self, **kw):
return (200, {'actions': [
{
'action': 'rebuild',
'error': None,
'created_at': '2011-12-30 11:45:36'
},
{
'action': 'reboot',
'error': 'Failed!',
'created_at': '2011-12-30 11:40:29'
},
]})
#
# Server Addresses
#

View File

@ -223,3 +223,27 @@ class ServersTest(utils.TestCase):
cs.servers.get_console_output(s, length=50)
self.assertEqual(cs.servers.get_console_output(s, length=50), success)
cs.assert_called('POST', '/servers/1234/action')
def test_get_server_actions(self):
s = cs.servers.get(1234)
actions = s.actions()
self.assertTrue(actions is not None)
cs.assert_called('GET', '/servers/1234/actions')
actions_from_manager = cs.servers.actions(1234)
self.assertTrue(actions_from_manager is not None)
cs.assert_called('GET', '/servers/1234/actions')
self.assertEqual(actions, actions_from_manager)
def test_get_server_diagnostics(self):
s = cs.servers.get(1234)
diagnostics = s.diagnostics()
self.assertTrue(diagnostics is not None)
cs.assert_called('GET', '/servers/1234/diagnostics')
diagnostics_from_manager = cs.servers.diagnostics(1234)
self.assertTrue(diagnostics_from_manager is not None)
cs.assert_called('GET', '/servers/1234/diagnostics')
self.assertEqual(diagnostics, diagnostics_from_manager)