From 7177014fcc143eb98ffc7fdeafc23eade49c1bb8 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Mon, 20 Jun 2016 19:40:26 +0800 Subject: [PATCH] Fix errors for "host set" command "Host set" command cannot work. Because: 1.Host has no 'ID' attribute, so 'ID' attribute cannot be found in "host set" command. 2.value "True" and "Flase" are invalid in updata() method of host. 3.Some update functionalities is not supported in host API now. This patch solves the problems 1 and 2 in OSC. But the problem 3 is a API problem and can't be solved in OSC, only XenServer driver support to set enable/disable and maintenance host, it is a normal problem. After this patch the output of "host set" command is: The requested functionality is not supported. (HTTP 501) (Request-ID: req-14031fce-8c90-48a0-8492-dc8e3dd349f3) Just the same as the "host-update" command in novaclient. Change-Id: Ibe94c4d3d492d3d63355de803810edb988e1b4e9 Closes-Bug: #1594689 --- doc/source/command-objects/host.rst | 2 +- openstackclient/compute/v2/host.py | 22 ++++++++++--------- openstackclient/tests/compute/v2/fakes.py | 1 - openstackclient/tests/compute/v2/test_host.py | 14 ++++++------ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/source/command-objects/host.rst b/doc/source/command-objects/host.rst index ede62c562e..8c34d3fb97 100644 --- a/doc/source/command-objects/host.rst +++ b/doc/source/command-objects/host.rst @@ -54,7 +54,7 @@ Set host command .. describe:: - The host (name or ID) + Host to modify (name only) host show --------- diff --git a/openstackclient/compute/v2/host.py b/openstackclient/compute/v2/host.py index 764b22af0b..7856758933 100644 --- a/openstackclient/compute/v2/host.py +++ b/openstackclient/compute/v2/host.py @@ -54,7 +54,7 @@ class SetHost(command.Command): parser.add_argument( "host", metavar="", - help=_("The host to modify (name or ID)") + help=_("Host to modify (name only)") ) status = parser.add_mutually_exclusive_group() status.add_argument( @@ -84,22 +84,24 @@ class SetHost(command.Command): kwargs = {} if parsed_args.enable: - kwargs['status'] = True + kwargs['status'] = 'enable' if parsed_args.disable: - kwargs['status'] = False + kwargs['status'] = 'disable' if parsed_args.enable_maintenance: - kwargs['maintenance_mode'] = True + kwargs['maintenance_mode'] = 'enable' if parsed_args.disable_maintenance: - kwargs['maintenance_mode'] = False + kwargs['maintenance_mode'] = 'disable' compute_client = self.app.client_manager.compute - foundhost = utils.find_resource( - compute_client.hosts, - parsed_args.host - ) + + # More than one hosts will be returned by using find_resource() + # so that the return value cannot be used in host update() method. + # find_resource() is just used for checking existence of host and + # keeping the exception message consistent with other commands. + utils.find_resource(compute_client.hosts, parsed_args.host) compute_client.hosts.update( - foundhost.id, + parsed_args.host, kwargs ) diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 60abb8ef1e..97d0c96f0c 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -1022,7 +1022,6 @@ class FakeHost(object): # Set default attributes. host_info = { - "id": 1, "service_id": 1, "host": "host1", "uuid": 'host-id-' + uuid.uuid4().hex, diff --git a/openstackclient/tests/compute/v2/test_host.py b/openstackclient/tests/compute/v2/test_host.py index de5375771f..63ae1f6dbb 100644 --- a/openstackclient/tests/compute/v2/test_host.py +++ b/openstackclient/tests/compute/v2/test_host.py @@ -40,10 +40,10 @@ class TestHostSet(TestHost): def test_host_set_no_option(self): arglist = [ - str(self.host.id) + self.host.host ] verifylist = [ - ('host', str(self.host.id)) + ('host', self.host.host) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -52,18 +52,18 @@ class TestHostSet(TestHost): self.assertIsNone(result) body = {} - self.host_mock.update.assert_called_with(self.host.id, body) + self.host_mock.update.assert_called_with(self.host.host, body) def test_host_set(self): arglist = [ '--enable', '--disable-maintenance', - str(self.host.id) + self.host.host ] verifylist = [ ('enable', True), ('enable_maintenance', False), - ('host', str(self.host.id)) + ('host', self.host.host) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -71,5 +71,5 @@ class TestHostSet(TestHost): result = self.cmd.take_action(parsed_args) self.assertIsNone(result) - body = {'status': True, 'maintenance_mode': False} - self.host_mock.update.assert_called_with(self.host.id, body) + body = {'status': 'enable', 'maintenance_mode': 'disable'} + self.host_mock.update.assert_called_with(self.host.host, body)