Merge "Print security groups as a human readable list"
This commit is contained in:
commit
9088e29d06
novaclient
@ -320,6 +320,16 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
"Server Label": "DB 1"
|
||||
},
|
||||
"OS-EXT-SRV-ATTR:host": "computenode2",
|
||||
"security_groups": [{
|
||||
'id': 1, 'name': 'securitygroup1',
|
||||
'description': 'FAKE_SECURITY_GROUP',
|
||||
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7'
|
||||
},
|
||||
{
|
||||
'id': 2, 'name': 'securitygroup2',
|
||||
'description': 'ANOTHER_FAKE_SECURITY_GROUP',
|
||||
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7'
|
||||
}],
|
||||
},
|
||||
{
|
||||
"id": 9012,
|
||||
|
@ -20,7 +20,6 @@ import base64
|
||||
import datetime
|
||||
import os
|
||||
import mock
|
||||
import sys
|
||||
|
||||
import fixtures
|
||||
import six
|
||||
@ -71,13 +70,13 @@ class ShellTest(utils.TestCase):
|
||||
lambda *_: fakes.FakeClient))
|
||||
self.addCleanup(timeutils.clear_time_override)
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
def run_command(self, cmd):
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
def run_command(self, cmd, mock_stdout):
|
||||
if isinstance(cmd, list):
|
||||
self.shell.main(cmd)
|
||||
else:
|
||||
self.shell.main(cmd.split())
|
||||
return sys.stdout.getvalue()
|
||||
return mock_stdout.getvalue()
|
||||
|
||||
def assert_called(self, method, url, body=None, **kwargs):
|
||||
return self.shell.cs.assert_called(method, url, body, **kwargs)
|
||||
@ -830,6 +829,14 @@ class ShellTest(utils.TestCase):
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.run_command, 'show xxx')
|
||||
|
||||
@mock.patch('novaclient.v1_1.shell.utils.print_dict')
|
||||
def test_print_server(self, mock_print_dict):
|
||||
self.run_command('show 5678')
|
||||
args, kwargs = mock_print_dict.call_args
|
||||
parsed_server = args[0]
|
||||
self.assertEqual('securitygroup1, securitygroup2',
|
||||
parsed_server['security_groups'])
|
||||
|
||||
def test_delete(self):
|
||||
self.run_command('delete 1234')
|
||||
self.assert_called('DELETE', '/servers/1234')
|
||||
|
@ -1465,6 +1465,10 @@ def _print_server(cs, args):
|
||||
info['flavor'] = '%s (%s)' % (_find_flavor(cs, flavor_id).name,
|
||||
flavor_id)
|
||||
|
||||
if 'security_groups' in info:
|
||||
info['security_groups'] = \
|
||||
', '.join(group['name'] for group in info['security_groups'])
|
||||
|
||||
image = info.get('image', {})
|
||||
if image:
|
||||
image_id = image.get('id', '')
|
||||
|
Loading…
x
Reference in New Issue
Block a user