Skip to content

Commit 7177014

Browse files
author
Huanxuan Ao
committed
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
1 parent ba825a4 commit 7177014

4 files changed

Lines changed: 20 additions & 19 deletions

File tree

doc/source/command-objects/host.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Set host command
5454

5555
.. describe:: <host>
5656

57-
The host (name or ID)
57+
Host to modify (name only)
5858

5959
host show
6060
---------

openstackclient/compute/v2/host.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_parser(self, prog_name):
5454
parser.add_argument(
5555
"host",
5656
metavar="<host>",
57-
help=_("The host to modify (name or ID)")
57+
help=_("Host to modify (name only)")
5858
)
5959
status = parser.add_mutually_exclusive_group()
6060
status.add_argument(
@@ -84,22 +84,24 @@ def take_action(self, parsed_args):
8484
kwargs = {}
8585

8686
if parsed_args.enable:
87-
kwargs['status'] = True
87+
kwargs['status'] = 'enable'
8888
if parsed_args.disable:
89-
kwargs['status'] = False
89+
kwargs['status'] = 'disable'
9090
if parsed_args.enable_maintenance:
91-
kwargs['maintenance_mode'] = True
91+
kwargs['maintenance_mode'] = 'enable'
9292
if parsed_args.disable_maintenance:
93-
kwargs['maintenance_mode'] = False
93+
kwargs['maintenance_mode'] = 'disable'
9494

9595
compute_client = self.app.client_manager.compute
96-
foundhost = utils.find_resource(
97-
compute_client.hosts,
98-
parsed_args.host
99-
)
96+
97+
# More than one hosts will be returned by using find_resource()
98+
# so that the return value cannot be used in host update() method.
99+
# find_resource() is just used for checking existence of host and
100+
# keeping the exception message consistent with other commands.
101+
utils.find_resource(compute_client.hosts, parsed_args.host)
100102

101103
compute_client.hosts.update(
102-
foundhost.id,
104+
parsed_args.host,
103105
kwargs
104106
)
105107

openstackclient/tests/compute/v2/fakes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,6 @@ def create_one_host(attrs=None):
10221022

10231023
# Set default attributes.
10241024
host_info = {
1025-
"id": 1,
10261025
"service_id": 1,
10271026
"host": "host1",
10281027
"uuid": 'host-id-' + uuid.uuid4().hex,

openstackclient/tests/compute/v2/test_host.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def setUp(self):
4040

4141
def test_host_set_no_option(self):
4242
arglist = [
43-
str(self.host.id)
43+
self.host.host
4444
]
4545
verifylist = [
46-
('host', str(self.host.id))
46+
('host', self.host.host)
4747
]
4848

4949
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -52,24 +52,24 @@ def test_host_set_no_option(self):
5252
self.assertIsNone(result)
5353

5454
body = {}
55-
self.host_mock.update.assert_called_with(self.host.id, body)
55+
self.host_mock.update.assert_called_with(self.host.host, body)
5656

5757
def test_host_set(self):
5858
arglist = [
5959
'--enable',
6060
'--disable-maintenance',
61-
str(self.host.id)
61+
self.host.host
6262
]
6363
verifylist = [
6464
('enable', True),
6565
('enable_maintenance', False),
66-
('host', str(self.host.id))
66+
('host', self.host.host)
6767
]
6868

6969
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
7070

7171
result = self.cmd.take_action(parsed_args)
7272
self.assertIsNone(result)
7373

74-
body = {'status': True, 'maintenance_mode': False}
75-
self.host_mock.update.assert_called_with(self.host.id, body)
74+
body = {'status': 'enable', 'maintenance_mode': 'disable'}
75+
self.host_mock.update.assert_called_with(self.host.host, body)

0 commit comments

Comments
 (0)