Merge "Fix errors for "host set" command"
This commit is contained in:
		@@ -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
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1062,7 +1062,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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user