Merge "Fix errors for "host set" command"
This commit is contained in:
		@@ -54,7 +54,7 @@ Set host command
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
.. describe:: <host>
 | 
					.. describe:: <host>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    The host (name or ID)
 | 
					    Host to modify (name only)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
host show
 | 
					host show
 | 
				
			||||||
---------
 | 
					---------
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,7 +54,7 @@ class SetHost(command.Command):
 | 
				
			|||||||
        parser.add_argument(
 | 
					        parser.add_argument(
 | 
				
			||||||
            "host",
 | 
					            "host",
 | 
				
			||||||
            metavar="<host>",
 | 
					            metavar="<host>",
 | 
				
			||||||
            help=_("The host to modify (name or ID)")
 | 
					            help=_("Host to modify (name only)")
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        status = parser.add_mutually_exclusive_group()
 | 
					        status = parser.add_mutually_exclusive_group()
 | 
				
			||||||
        status.add_argument(
 | 
					        status.add_argument(
 | 
				
			||||||
@@ -84,22 +84,24 @@ class SetHost(command.Command):
 | 
				
			|||||||
        kwargs = {}
 | 
					        kwargs = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if parsed_args.enable:
 | 
					        if parsed_args.enable:
 | 
				
			||||||
            kwargs['status'] = True
 | 
					            kwargs['status'] = 'enable'
 | 
				
			||||||
        if parsed_args.disable:
 | 
					        if parsed_args.disable:
 | 
				
			||||||
            kwargs['status'] = False
 | 
					            kwargs['status'] = 'disable'
 | 
				
			||||||
        if parsed_args.enable_maintenance:
 | 
					        if parsed_args.enable_maintenance:
 | 
				
			||||||
            kwargs['maintenance_mode'] = True
 | 
					            kwargs['maintenance_mode'] = 'enable'
 | 
				
			||||||
        if parsed_args.disable_maintenance:
 | 
					        if parsed_args.disable_maintenance:
 | 
				
			||||||
            kwargs['maintenance_mode'] = False
 | 
					            kwargs['maintenance_mode'] = 'disable'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        compute_client = self.app.client_manager.compute
 | 
					        compute_client = self.app.client_manager.compute
 | 
				
			||||||
        foundhost = utils.find_resource(
 | 
					
 | 
				
			||||||
            compute_client.hosts,
 | 
					        # More than one hosts will be returned by using find_resource()
 | 
				
			||||||
            parsed_args.host
 | 
					        # 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(
 | 
					        compute_client.hosts.update(
 | 
				
			||||||
            foundhost.id,
 | 
					            parsed_args.host,
 | 
				
			||||||
            kwargs
 | 
					            kwargs
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1062,7 +1062,6 @@ class FakeHost(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # Set default attributes.
 | 
					        # Set default attributes.
 | 
				
			||||||
        host_info = {
 | 
					        host_info = {
 | 
				
			||||||
            "id": 1,
 | 
					 | 
				
			||||||
            "service_id": 1,
 | 
					            "service_id": 1,
 | 
				
			||||||
            "host": "host1",
 | 
					            "host": "host1",
 | 
				
			||||||
            "uuid": 'host-id-' + uuid.uuid4().hex,
 | 
					            "uuid": 'host-id-' + uuid.uuid4().hex,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,10 +40,10 @@ class TestHostSet(TestHost):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def test_host_set_no_option(self):
 | 
					    def test_host_set_no_option(self):
 | 
				
			||||||
        arglist = [
 | 
					        arglist = [
 | 
				
			||||||
            str(self.host.id)
 | 
					            self.host.host
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        verifylist = [
 | 
					        verifylist = [
 | 
				
			||||||
            ('host', str(self.host.id))
 | 
					            ('host', self.host.host)
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
					        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
				
			||||||
@@ -52,18 +52,18 @@ class TestHostSet(TestHost):
 | 
				
			|||||||
        self.assertIsNone(result)
 | 
					        self.assertIsNone(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        body = {}
 | 
					        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):
 | 
					    def test_host_set(self):
 | 
				
			||||||
        arglist = [
 | 
					        arglist = [
 | 
				
			||||||
            '--enable',
 | 
					            '--enable',
 | 
				
			||||||
            '--disable-maintenance',
 | 
					            '--disable-maintenance',
 | 
				
			||||||
            str(self.host.id)
 | 
					            self.host.host
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        verifylist = [
 | 
					        verifylist = [
 | 
				
			||||||
            ('enable', True),
 | 
					            ('enable', True),
 | 
				
			||||||
            ('enable_maintenance', False),
 | 
					            ('enable_maintenance', False),
 | 
				
			||||||
            ('host', str(self.host.id))
 | 
					            ('host', self.host.host)
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
					        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
				
			||||||
@@ -71,5 +71,5 @@ class TestHostSet(TestHost):
 | 
				
			|||||||
        result = self.cmd.take_action(parsed_args)
 | 
					        result = self.cmd.take_action(parsed_args)
 | 
				
			||||||
        self.assertIsNone(result)
 | 
					        self.assertIsNone(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        body = {'status': True, 'maintenance_mode': False}
 | 
					        body = {'status': 'enable', 'maintenance_mode': 'disable'}
 | 
				
			||||||
        self.host_mock.update.assert_called_with(self.host.id, body)
 | 
					        self.host_mock.update.assert_called_with(self.host.host, body)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user