Merge "Improve output for "os security group show""

This commit is contained in:
Jenkins 2015-12-28 13:53:58 +00:00 committed by Gerrit Code Review
commit 9f2ed6b03a
3 changed files with 12 additions and 4 deletions

View File

@ -154,14 +154,15 @@ def format_dict(data):
return output[:-2]
def format_list(data):
def format_list(data, separator=', '):
"""Return a formatted strings
:param data: a list of strings
:rtype: a string formatted to a,b,c
:param separator: the separator to use between strings (default: ', ')
:rtype: a string formatted based on separator
"""
return ', '.join(sorted(data))
return separator.join(sorted(data))
def get_field(item, field):

View File

@ -390,7 +390,7 @@ class ShowSecurityGroup(show.ShowOne):
# Format rules into a list of strings
info.update(
{'rules': rules}
{'rules': utils.format_list(rules, separator='\n')}
)
# Map 'tenant_id' column to 'project_id'
info.update(

View File

@ -347,3 +347,10 @@ class TestFindResource(test_utils.TestCase):
expected = 'a, b, c'
self.assertEqual(expected, utils.format_list(['a', 'b', 'c']))
self.assertEqual(expected, utils.format_list(['c', 'b', 'a']))
def test_format_list_separator(self):
expected = 'a\nb\nc'
actual_pre_sorted = utils.format_list(['a', 'b', 'c'], separator='\n')
actual_unsorted = utils.format_list(['c', 'b', 'a'], separator='\n')
self.assertEqual(expected, actual_pre_sorted)
self.assertEqual(expected, actual_unsorted)