summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/v2/host.py22
-rw-r--r--openstackclient/tests/compute/v2/fakes.py1
-rw-r--r--openstackclient/tests/compute/v2/test_host.py14
3 files changed, 19 insertions, 18 deletions
diff --git a/openstackclient/compute/v2/host.py b/openstackclient/compute/v2/host.py
index 764b22af..78567589 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="<host>",
- 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 60abb8ef..97d0c96f 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 de537577..63ae1f6d 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)