diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index e0b2d30f4..6fb7f5443 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -699,11 +699,11 @@ class FakeHTTPClient(base_client.HTTPClient): def put_os_services_enable(self, body, **kw): return (200, {}, {'host': body['host'], 'binary': body['binary'], - 'status': 'disabled'}) + 'status': 'enabled'}) def put_os_services_disable(self, body, **kw): return (200, {}, {'host': body['host'], 'binary': body['binary'], - 'status': 'enabled'}) + 'status': 'disabled'}) def get_os_availability_zone(self, **kw): return (200, {}, { diff --git a/cinderclient/tests/v1/test_services.py b/cinderclient/tests/v1/test_services.py index 7a1ec854d..de8993505 100644 --- a/cinderclient/tests/v1/test_services.py +++ b/cinderclient/tests/v1/test_services.py @@ -52,11 +52,15 @@ class ServicesTest(utils.TestCase): [self.assertEqual(s.binary, 'cinder-volume') for s in svs] def test_services_enable(self): - cs.services.enable('host1', 'cinder-volume') + s = cs.services.enable('host1', 'cinder-volume') values = {"host": "host1", 'binary': 'cinder-volume'} cs.assert_called('PUT', '/os-services/enable', values) + self.assertTrue(isinstance(s, services.Service)) + self.assertEqual(s.status, 'enabled') def test_services_disable(self): - cs.services.disable('host1', 'cinder-volume') + s = cs.services.disable('host1', 'cinder-volume') values = {"host": "host1", 'binary': 'cinder-volume'} cs.assert_called('PUT', '/os-services/disable', values) + self.assertTrue(isinstance(s, services.Service)) + self.assertEqual(s.status, 'disabled') diff --git a/cinderclient/tests/v1/test_shell.py b/cinderclient/tests/v1/test_shell.py index 79623696b..50293cf91 100644 --- a/cinderclient/tests/v1/test_shell.py +++ b/cinderclient/tests/v1/test_shell.py @@ -341,3 +341,13 @@ class ShellTest(utils.TestCase): self.run_command('readonly-mode-update 1234 False') expected = {'os-update_readonly_flag': {'readonly': False}} self.assert_called('POST', '/volumes/1234/action', body=expected) + + def test_service_disable(self): + self.run_command('service-disable host cinder-volume') + self.assert_called('PUT', '/os-services/disable', + {"binary": "cinder-volume", "host": "host"}) + + def test_service_disable(self): + self.run_command('service-enable host cinder-volume') + self.assert_called('PUT', '/os-services/enable', + {"binary": "cinder-volume", "host": "host"}) diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index c90749a1d..70c5840d0 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -709,11 +709,11 @@ class FakeHTTPClient(base_client.HTTPClient): def put_os_services_enable(self, body, **kw): return (200, {}, {'host': body['host'], 'binary': body['binary'], - 'status': 'disabled'}) + 'status': 'enabled'}) def put_os_services_disable(self, body, **kw): return (200, {}, {'host': body['host'], 'binary': body['binary'], - 'status': 'enabled'}) + 'status': 'disabled'}) def get_os_availability_zone(self, **kw): return (200, {}, { diff --git a/cinderclient/tests/v2/test_services.py b/cinderclient/tests/v2/test_services.py index 5ee3ea107..07a238983 100644 --- a/cinderclient/tests/v2/test_services.py +++ b/cinderclient/tests/v2/test_services.py @@ -52,11 +52,15 @@ class ServicesTest(utils.TestCase): [self.assertEqual(s.binary, 'cinder-volume') for s in svs] def test_services_enable(self): - cs.services.enable('host1', 'cinder-volume') + s = cs.services.enable('host1', 'cinder-volume') values = {"host": "host1", 'binary': 'cinder-volume'} cs.assert_called('PUT', '/os-services/enable', values) + self.assertTrue(isinstance(s, services.Service)) + self.assertEqual(s.status, 'enabled') def test_services_disable(self): - cs.services.disable('host1', 'cinder-volume') + s = cs.services.disable('host1', 'cinder-volume') values = {"host": "host1", 'binary': 'cinder-volume'} cs.assert_called('PUT', '/os-services/disable', values) + self.assertTrue(isinstance(s, services.Service)) + self.assertEqual(s.status, 'disabled') diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py index 7c90328d9..d203c07f8 100644 --- a/cinderclient/tests/v2/test_shell.py +++ b/cinderclient/tests/v2/test_shell.py @@ -319,3 +319,13 @@ class ShellTest(utils.TestCase): self.run_command('readonly-mode-update 1234 False') expected = {'os-update_readonly_flag': {'readonly': False}} self.assert_called('POST', '/volumes/1234/action', body=expected) + + def test_service_disable(self): + self.run_command('service-disable host cinder-volume') + self.assert_called('PUT', '/os-services/disable', + {"binary": "cinder-volume", "host": "host"}) + + def test_service_disable(self): + self.run_command('service-enable host cinder-volume') + self.assert_called('PUT', '/os-services/enable', + {"binary": "cinder-volume", "host": "host"}) diff --git a/cinderclient/v1/services.py b/cinderclient/v1/services.py index 6afd5c584..2669a5edd 100644 --- a/cinderclient/v1/services.py +++ b/cinderclient/v1/services.py @@ -48,9 +48,11 @@ class ServiceManager(base.ManagerWithFind): def enable(self, host, binary): """Enable the service specified by hostname and binary.""" body = {"host": host, "binary": binary} - self._update("/os-services/enable", body) + result = self._update("/os-services/enable", body) + return self.resource_class(self, result) def disable(self, host, binary): """Enable the service specified by hostname and binary.""" body = {"host": host, "binary": binary} - self._update("/os-services/disable", body) + result = self._update("/os-services/disable", body) + return self.resource_class(self, result) diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 76480d25b..02ea76941 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -993,7 +993,9 @@ def do_service_list(cs, args): @utils.service_type('volume') def do_service_enable(cs, args): """Enable the service.""" - cs.services.enable(args.host, args.binary) + result = cs.services.enable(args.host, args.binary) + columns = ["Host", "Binary", "Status"] + utils.print_list([result], columns) @utils.arg('host', metavar='', help='Name of host.') @@ -1001,7 +1003,9 @@ def do_service_enable(cs, args): @utils.service_type('volume') def do_service_disable(cs, args): """Disable the service.""" - cs.services.disable(args.host, args.binary) + result = cs.services.disable(args.host, args.binary) + columns = ["Host", "Binary", "Status"] + utils.print_list([result], columns) def _treeizeAvailabilityZone(zone): diff --git a/cinderclient/v2/services.py b/cinderclient/v2/services.py index 6afd5c584..2669a5edd 100644 --- a/cinderclient/v2/services.py +++ b/cinderclient/v2/services.py @@ -48,9 +48,11 @@ class ServiceManager(base.ManagerWithFind): def enable(self, host, binary): """Enable the service specified by hostname and binary.""" body = {"host": host, "binary": binary} - self._update("/os-services/enable", body) + result = self._update("/os-services/enable", body) + return self.resource_class(self, result) def disable(self, host, binary): """Enable the service specified by hostname and binary.""" body = {"host": host, "binary": binary} - self._update("/os-services/disable", body) + result = self._update("/os-services/disable", body) + return self.resource_class(self, result) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index baffa37a3..55ceb5b56 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1087,7 +1087,9 @@ def do_service_list(cs, args): @utils.service_type('volumev2') def do_service_enable(cs, args): """Enable the service.""" - cs.services.enable(args.host, args.binary) + result = cs.services.enable(args.host, args.binary) + columns = ["Host", "Binary", "Status"] + utils.print_list([result], columns) @utils.arg('host', metavar='', help='Name of host.') @@ -1095,7 +1097,9 @@ def do_service_enable(cs, args): @utils.service_type('volumev2') def do_service_disable(cs, args): """Disable the service.""" - cs.services.disable(args.host, args.binary) + result = cs.services.disable(args.host, args.binary) + columns = ["Host", "Binary", "Status"] + utils.print_list([result], columns) def _treeizeAvailabilityZone(zone):