Skip to content

Commit 9f2ed6b

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Improve output for "os security group show""
2 parents f560436 + 0e38ef8 commit 9f2ed6b

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

openstackclient/common/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ def format_dict(data):
154154
return output[:-2]
155155

156156

157-
def format_list(data):
157+
def format_list(data, separator=', '):
158158
"""Return a formatted strings
159159
160160
:param data: a list of strings
161-
:rtype: a string formatted to a,b,c
161+
:param separator: the separator to use between strings (default: ', ')
162+
:rtype: a string formatted based on separator
162163
"""
163164

164-
return ', '.join(sorted(data))
165+
return separator.join(sorted(data))
165166

166167

167168
def get_field(item, field):

openstackclient/compute/v2/security_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def take_action(self, parsed_args):
390390

391391
# Format rules into a list of strings
392392
info.update(
393-
{'rules': rules}
393+
{'rules': utils.format_list(rules, separator='\n')}
394394
)
395395
# Map 'tenant_id' column to 'project_id'
396396
info.update(

openstackclient/tests/common/test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,10 @@ def test_format_list(self):
347347
expected = 'a, b, c'
348348
self.assertEqual(expected, utils.format_list(['a', 'b', 'c']))
349349
self.assertEqual(expected, utils.format_list(['c', 'b', 'a']))
350+
351+
def test_format_list_separator(self):
352+
expected = 'a\nb\nc'
353+
actual_pre_sorted = utils.format_list(['a', 'b', 'c'], separator='\n')
354+
actual_unsorted = utils.format_list(['c', 'b', 'a'], separator='\n')
355+
self.assertEqual(expected, actual_pre_sorted)
356+
self.assertEqual(expected, actual_unsorted)

0 commit comments

Comments
 (0)