mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Parse chattr version and fix test case
- Parse the system's chattr version from the chattr man page - Fix integration.states.test_cron on centos 6
This commit is contained in:
parent
af4f2043bf
commit
0ea007de6f
3 changed files with 65 additions and 2 deletions
|
@ -23,6 +23,7 @@ import re
|
|||
import shutil
|
||||
import stat
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
@ -61,6 +62,7 @@ import salt.utils.templates
|
|||
import salt.utils.url
|
||||
import salt.utils.user
|
||||
import salt.utils.data
|
||||
import salt.utils.versions
|
||||
from salt.exceptions import CommandExecutionError, MinionError, SaltInvocationError, get_error_message as _get_error_message
|
||||
from salt.utils.files import HASHES, HASHES_REVMAP
|
||||
|
||||
|
@ -159,6 +161,32 @@ def _splitlines_preserving_trailing_newline(str):
|
|||
return lines
|
||||
|
||||
|
||||
def _get_chattr_man():
|
||||
'''
|
||||
Get the contents of the chattr man page
|
||||
'''
|
||||
return subprocess.check_output(['man', 'chattr'])
|
||||
|
||||
|
||||
def _parse_chattr_man(man):
|
||||
'''
|
||||
Parse the contents of a chattr man page to find the E2fsprogs version
|
||||
'''
|
||||
match = re.search('E2fsprogs version [0-9\.]+', man)
|
||||
if match:
|
||||
version = match.group().strip('E2fsprogs version ')
|
||||
else:
|
||||
version = None
|
||||
return version
|
||||
|
||||
|
||||
def _chattr_version():
|
||||
'''
|
||||
Return the version of chattr installed
|
||||
'''
|
||||
return _parse_chattr_man(_get_chattr_man())
|
||||
|
||||
|
||||
def gid_to_group(gid):
|
||||
'''
|
||||
Convert the group id to the group name on this system
|
||||
|
@ -577,7 +605,14 @@ def lsattr(path):
|
|||
for line in result.splitlines():
|
||||
if not line.startswith('lsattr: '):
|
||||
vals = line.split(None, 1)
|
||||
results[vals[1]] = re.findall(r"[aAcCdDeijPsStTu]", vals[0])
|
||||
needed_version = salt.utils.versions.LooseVersion('1.41.12')
|
||||
chattr_version = salt.utils.versions.LooseVersion(_chattr_version())
|
||||
# The version of chattr on Centos 6 does not support extended
|
||||
# attributes.
|
||||
if chattr_version > needed_version:
|
||||
results[vals[1]] = re.findall(r"[aAcCdDeijPsStTu]", vals[0])
|
||||
else:
|
||||
results[vals[1]] = re.findall(r"[acdijstuADST]", vals[0])
|
||||
|
||||
return results
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@ salt/modules/dockermod.py:
|
|||
- integration.states.test_docker_container
|
||||
- integration.states.test_docker_network
|
||||
|
||||
salt/modules/file.py:
|
||||
- integration.states.test_cron
|
||||
|
||||
salt/modules/influxdb08mod.py:
|
||||
- unit.states.test_influxdb08_database
|
||||
- unit.states.test_influxdb08_user
|
||||
|
|
|
@ -8,7 +8,7 @@ import tempfile
|
|||
import textwrap
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.helpers import with_tempfile
|
||||
from tests.support.helpers import with_tempfile, dedent
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.paths import TMP
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
|
@ -2045,3 +2045,28 @@ class FileBasicsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
ret = filemod.source_list(
|
||||
[{'file://' + self.myfile: ''}], 'filehash', 'base')
|
||||
self.assertEqual(list(ret), ['file://' + self.myfile, 'filehash'])
|
||||
|
||||
|
||||
class ChattrVersionTests(TestCase):
|
||||
CHATTR_MAN = (
|
||||
'AVAILABILITY\n'
|
||||
'chattr is part of the e2fsprogs package and is available '
|
||||
'from http://e2fsprogs.sourceforge.net.\n'
|
||||
'SEE ALSO\n'
|
||||
' lsattr(1), btrfs(5), ext4(5), xfs(5).\n\n'
|
||||
'E2fsprogs version 1.43.4 '
|
||||
' '
|
||||
'January 2017 '
|
||||
' '
|
||||
' CHATTR(1)'
|
||||
)
|
||||
|
||||
def test_chattr_version(self):
|
||||
man_out = dedent(self.CHATTR_MAN)
|
||||
parsed_version = filemod._parse_chattr_man(man_out)
|
||||
assert parsed_version == '1.43.4', parsed_version
|
||||
|
||||
def test_chattr_version(self):
|
||||
with patch('subprocess.check_output', return_value=self.CHATTR_MAN):
|
||||
parsed_version = filemod._chattr_version()
|
||||
assert parsed_version == '1.43.4', parsed_version
|
||||
|
|
Loading…
Add table
Reference in a new issue