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
This commit is contained in:
parent
ba825a4d5c
commit
7177014fcc
@ -54,7 +54,7 @@ Set host command
|
||||
|
||||
.. describe:: <host>
|
||||
|
||||
The host (name or ID)
|
||||
Host to modify (name only)
|
||||
|
||||
host show
|
||||
---------
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user