Skip to content

Commit 377daeb

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix errors for "host set" command"
2 parents 29dd2b1 + 7177014 commit 377daeb

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
@@ -1062,7 +1062,6 @@ def create_one_host(attrs=None):
10621062

10631063
# Set default attributes.
10641064
host_info = {
1065-
"id": 1,
10661065
"service_id": 1,
10671066
"host": "host1",
10681067
"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)