Skip to content

Commit

Permalink
Porting PR saltstack#52749 to 2019.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgreenaway committed Sep 19, 2019
1 parent 8d4d5ea commit 7e08c5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 4 additions & 3 deletions salt/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,11 @@ def versions_report(include_salt_cloud=False):
Yield each version properly formatted for console output.
'''
ver_info = versions_information(include_salt_cloud)

not_installed = 'Not Installed'
ns_pad = len(not_installed)
lib_pad = max(len(name) for name in ver_info['Dependency Versions'])
sys_pad = max(len(name) for name in ver_info['System Versions'])
padding = max(lib_pad, sys_pad) + 1
padding = max(lib_pad, sys_pad, ns_pad) + 1

fmt = '{0:>{pad}}: {1}'
info = []
Expand All @@ -737,7 +738,7 @@ def versions_report(include_salt_cloud=False):
# List dependencies in alphabetical, case insensitive order
for name in sorted(ver_info[ver_type], key=lambda x: x.lower()):
ver = fmt.format(name,
ver_info[ver_type][name] or 'Not Installed',
ver_info[ver_type][name] or not_installed,
pad=padding)
info.append(ver)
info.append(' ')
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from tests.support.unit import TestCase

# Import Salt libs
from salt.version import SaltStackVersion
from salt.version import SaltStackVersion, versions_report


class VersionTestCase(TestCase):
Expand Down Expand Up @@ -71,3 +71,15 @@ def test_unparsable_version(self):

with self.assertRaises(ValueError):
SaltStackVersion.parse('Drunk')

def test_version_report_lines(self):
'''
Validate padding in versions report is correct
'''
# Get a set of all version report name lenghts including padding
line_lengths = set([
len(line.split(':')[0]) for line in list(versions_report())[4:]
if line != ' ' and line != 'System Versions:'
])
# Check that they are all the same size (only one element in the set)
assert len(line_lengths) == 1

0 comments on commit 7e08c5c

Please sign in to comment.