Fix can't process the resource with name 'help'

novaclient can't process the resource if the name is 'help',
like 'nova show help', 'nova flavor-show help', 'nova delete help',
etc. We should encourage user to use 'nova help xxxx' to show
subcommand usage, rather than 'nova xxxx help`.

Change-Id: I65204a908dc2378b6264297ddd87fcb8912a5770
Closes-Bug: #1641048
This commit is contained in:
int32bit 2016-11-26 21:49:50 +08:00
parent 57c397d822
commit 2446755606
3 changed files with 23 additions and 3 deletions

View File

@ -621,8 +621,7 @@ class OpenStackComputeShell(object):
self.setup_debugging(args.debug)
self.extensions = []
do_help = ('help' in argv) or (
'--help' in argv) or ('-h' in argv) or not argv
do_help = args.help or not args_list or args_list[0] == 'help'
# bash-completion should not require authentication
skip_auth = do_help or (

View File

@ -389,7 +389,8 @@ class FakeHTTPClient(base_client.HTTPClient):
def get_servers(self, **kw):
return (200, {}, {"servers": [
{'id': '1234', 'name': 'sample-server'},
{'id': '5678', 'name': 'sample-server2'}
{'id': '5678', 'name': 'sample-server2'},
{'id': '9014', 'name': 'help'}
]})
def get_servers_detail(self, **kw):
@ -520,6 +521,18 @@ class FakeHTTPClient(base_client.HTTPClient):
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
},
{
"id": '9014',
"name": "help",
"flavor": {
"id": '80645cf4-6ad3-410a-bbc8-6f3e1e291f51',
},
"image": {
"id": '3e861307-73a6-4d1f-8d68-f68b03223032',
},
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
},
]})
def post_servers(self, body, **kw):
@ -577,6 +590,10 @@ class FakeHTTPClient(base_client.HTTPClient):
r = {'server': self.get_servers_detail()[2]['servers'][3]}
return (200, {}, r)
def get_servers_9014(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][4]}
return (200, {}, r)
def delete_os_server_groups_12345(self, **kw):
return (202, {}, None)

View File

@ -1524,6 +1524,10 @@ class ShellTest(utils.TestCase):
self.assertIn('Image not found', output)
self.assertIn('Flavor not found', output)
def test_show_with_name_help(self):
output, _ = self.run_command('show help')
self.assert_called('GET', '/servers/9014', pos=-6)
@mock.patch('novaclient.v2.shell.utils.print_dict')
def test_print_server(self, mock_print_dict):
self.run_command('show 5678')