FIX #38671 - zpool.get should support older zfs version

This commit is contained in:
Jorge Schrauwen 2018-04-21 18:35:06 +02:00 committed by rallytime
parent 23705b12cb
commit 1d191445a7
No known key found for this signature in database
GPG Key ID: E8F1A4B90D0DEA19
2 changed files with 7 additions and 5 deletions

View File

@ -470,14 +470,13 @@ def get(zpool, prop=None, show_source=False, parsable=True):
'''
ret = OrderedDict()
value_properties = ['property', 'value', 'source']
value_properties = ['name', 'property', 'value', 'source']
## collect get output
res = __salt__['cmd.run_all'](
__utils__['zfs.zpool_command'](
command='get',
flags=['-H'],
opts={'-o': ','.join(value_properties)},
property_name=prop if prop else 'all',
target=zpool,
),
@ -503,6 +502,9 @@ def get(zpool, prop=None, show_source=False, parsable=True):
[x for x in line.strip().split('\t') if x not in ['']],
)))
# NOTE: older zfs does not have -o, fall back to manually stipping the name field
del prop_data['name']
# NOTE: normalize values
if parsable:
# NOTE: raw numbers and pythonic types

View File

@ -223,7 +223,7 @@ class ZpoolTestCase(TestCase, LoaderModuleMockMixin):
Tests successful return of get function
'''
ret = {}
ret['stdout'] = "size\t1.81T\t-\n"
ret['stdout'] = "mypool\tsize\t1.81T\t-\n"
ret['stderr'] = ""
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
@ -238,7 +238,7 @@ class ZpoolTestCase(TestCase, LoaderModuleMockMixin):
Tests successful return of get function with parsable output
'''
ret = {}
ret['stdout'] = "size\t1.81T\t-\n"
ret['stdout'] = "mypool\tsize\t1.81T\t-\n"
ret['stderr'] = ""
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
@ -253,7 +253,7 @@ class ZpoolTestCase(TestCase, LoaderModuleMockMixin):
Tests successful return of get function with a string with whitespaces
'''
ret = {}
ret['stdout'] = "comment\tmy testing pool\t-\n"
ret['stdout'] = "mypool\tcomment\tmy testing pool\t-\n"
ret['stderr'] = ""
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)