Merge branch '2019.2' into backport_49670

This commit is contained in:
Daniel Wozniak 2019-02-01 14:10:22 -07:00 committed by GitHub
commit 204432d924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 98 additions and 39 deletions

View File

@ -23,7 +23,6 @@ pyvmomi
setproctitle setproctitle
cherrypy>=3.2.2,<18.0.0; python_version < '3.5' and sys.platform != 'win32' and sys.platform != 'darwin' cherrypy>=3.2.2,<18.0.0; python_version < '3.5' and sys.platform != 'win32' and sys.platform != 'darwin'
cherrypy>=3.2.2; python_version >= '3.5' and sys.platform != 'win32' and sys.platform != 'darwin' cherrypy>=3.2.2; python_version >= '3.5' and sys.platform != 'win32' and sys.platform != 'darwin'
ldap; sys.platform != 'win32' and sys.platform != 'darwin'
pyinotify; sys.platform != 'win32' and sys.platform != 'darwin' pyinotify; sys.platform != 'win32' and sys.platform != 'darwin'
PyMySQL; sys.platform != 'win32' and sys.platform != 'darwin' PyMySQL; sys.platform != 'win32' and sys.platform != 'darwin'
jsonschema jsonschema

View File

@ -3035,12 +3035,16 @@ def run_chroot(root,
''' '''
__salt__['mount.mount']( __salt__['mount.mount'](
os.path.join(root, 'dev'), os.path.join(root, 'dev'),
'udev', 'devtmpfs',
fstype='devtmpfs') fstype='devtmpfs')
__salt__['mount.mount']( __salt__['mount.mount'](
os.path.join(root, 'proc'), os.path.join(root, 'proc'),
'proc', 'proc',
fstype='proc') fstype='proc')
__salt__['mount.mount'](
os.path.join(root, 'sys'),
'sysfs',
fstype='sysfs')
# Execute chroot routine # Execute chroot routine
sh_ = '/bin/sh' sh_ = '/bin/sh'
@ -3092,6 +3096,7 @@ def run_chroot(root,
log.error('Processes running in chroot could not be killed, ' log.error('Processes running in chroot could not be killed, '
'filesystem will remain mounted') 'filesystem will remain mounted')
__salt__['mount.umount'](os.path.join(root, 'sys'))
__salt__['mount.umount'](os.path.join(root, 'proc')) __salt__['mount.umount'](os.path.join(root, 'proc'))
__salt__['mount.umount'](os.path.join(root, 'dev')) __salt__['mount.umount'](os.path.join(root, 'dev'))
if hide_output: if hide_output:

View File

@ -577,7 +577,7 @@ def lsattr(path):
for line in result.splitlines(): for line in result.splitlines():
if not line.startswith('lsattr: '): if not line.startswith('lsattr: '):
vals = line.split(None, 1) vals = line.split(None, 1)
results[vals[1]] = re.findall(r"[acdijstuADST]", vals[0]) results[vals[1]] = re.findall(r"[aAcCdDeijPsStTu]", vals[0])
return results return results
@ -594,8 +594,8 @@ def chattr(*files, **kwargs):
should be added or removed from files should be added or removed from files
attributes attributes
One or more of the following characters: ``acdijstuADST``, representing One or more of the following characters: ``aAcCdDeijPsStTu``,
attributes to add to/remove from files representing attributes to add to/remove from files
version version
a version number to assign to the file(s) a version number to assign to the file(s)
@ -620,7 +620,7 @@ def chattr(*files, **kwargs):
raise SaltInvocationError( raise SaltInvocationError(
"Need an operator: 'add' or 'remove' to modify attributes.") "Need an operator: 'add' or 'remove' to modify attributes.")
if attributes is None: if attributes is None:
raise SaltInvocationError("Need attributes: [AacDdijsTtSu]") raise SaltInvocationError("Need attributes: [aAcCdDeijPsStTu]")
cmd = ['chattr'] cmd = ['chattr']

View File

@ -63,7 +63,9 @@ def _active_mountinfo(ret):
msg = 'File not readable {0}' msg = 'File not readable {0}'
raise CommandExecutionError(msg.format(filename)) raise CommandExecutionError(msg.format(filename))
blkid_info = __salt__['disk.blkid']() if 'disk.blkid' not in __context__:
__context__['disk.blkid'] = __salt__['disk.blkid']()
blkid_info = __context__['disk.blkid']
with salt.utils.files.fopen(filename) as ifile: with salt.utils.files.fopen(filename) as ifile:
for line in ifile: for line in ifile:

View File

@ -156,7 +156,7 @@ def list_(device, unit=None):
for line in out: for line in out:
if line in ('BYT;', 'CHS;', 'CYL;'): if line in ('BYT;', 'CHS;', 'CYL;'):
continue continue
cols = line.replace(';', '').split(':') cols = line.rstrip(';').split(':')
if mode == 'info': if mode == 'info':
if 7 <= len(cols) <= 8: if 7 <= len(cols) <= 8:
ret['info'] = { ret['info'] = {
@ -178,15 +178,26 @@ def list_(device, unit=None):
raise CommandExecutionError( raise CommandExecutionError(
'Problem encountered while parsing output from parted') 'Problem encountered while parsing output from parted')
else: else:
if len(cols) == 7: # Parted (v3.1) have a variable field list in machine
ret['partitions'][cols[0]] = { # readable output:
'number': cols[0], #
'start': cols[1], # number:start:end:[size:]([file system:name:flags;]|[free;])
'end': cols[2], #
'size': cols[3], # * If units are in CHS 'size' is not printed.
'type': cols[4], # * If is a logical partition with PED_PARTITION_FREESPACE
'file system': cols[5], # set, the last three fields are replaced with the
'flags': cols[6]} # 'free' text.
#
fields = ['number', 'start', 'end']
if unit != 'chs':
fields.append('size')
if cols[-1] == 'free':
# Drop the last element from the list
cols.pop()
else:
fields.extend(['file system', 'name', 'flags'])
if len(fields) == len(cols):
ret['partitions'][cols[0]] = dict(six.moves.zip(fields, cols))
else: else:
raise CommandExecutionError( raise CommandExecutionError(
'Problem encountered while parsing output from parted') 'Problem encountered while parsing output from parted')

View File

@ -425,13 +425,13 @@ def owner(*paths):
@salt.utils.decorators.path.which('rpm2cpio') @salt.utils.decorators.path.which('rpm2cpio')
@salt.utils.decorators.path.which('cpio') @salt.utils.decorators.path.which('cpio')
@salt.utils.decorators.path.which('diff') @salt.utils.decorators.path.which('diff')
def diff(package, path): def diff(package_path, path):
''' '''
Return a formatted diff between current file and original in a package. Return a formatted diff between current file and original in a package.
NOTE: this function includes all files (configuration and not), but does NOTE: this function includes all files (configuration and not), but does
not work on binary content. not work on binary content.
:param package: The name of the package :param package: Full pack of the RPM file
:param path: Full path to the installed file :param path: Full path to the installed file
:return: Difference or empty string. For binary files only a notification. :return: Difference or empty string. For binary files only a notification.
@ -439,13 +439,13 @@ def diff(package, path):
.. code-block:: bash .. code-block:: bash
salt '*' lowpkg.diff apache2 /etc/apache2/httpd.conf salt '*' lowpkg.diff /path/to/apache2.rpm /etc/apache2/httpd.conf
''' '''
cmd = "rpm2cpio {0} " \ cmd = "rpm2cpio {0} " \
"| cpio -i --quiet --to-stdout .{1} " \ "| cpio -i --quiet --to-stdout .{1} " \
"| diff -u --label 'A {1}' --from-file=- --label 'B {1}' {1}" "| diff -u --label 'A {1}' --from-file=- --label 'B {1}' {1}"
res = __salt__['cmd.shell'](cmd.format(package, path), res = __salt__['cmd.shell'](cmd.format(package_path, path),
output_loglevel='trace') output_loglevel='trace')
if res and res.startswith('Binary file'): if res and res.startswith('Binary file'):
return 'File \'{0}\' is binary and its content has been ' \ return 'File \'{0}\' is binary and its content has been ' \

View File

@ -41,6 +41,7 @@ def __virtual__():
'elementary OS', 'elementary OS',
'McAfee OS Server', 'McAfee OS Server',
'Raspbian', 'Raspbian',
'SUSE',
)) ))
if __grains__.get('os') in disable: if __grains__.get('os') in disable:
return (False, 'Your OS is on the disabled list') return (False, 'Your OS is on the disabled list')

View File

@ -2116,7 +2116,7 @@ def managed(name,
attrs attrs
The attributes to have on this file, e.g. ``a``, ``i``. The attributes The attributes to have on this file, e.g. ``a``, ``i``. The attributes
can be any or a combination of the following characters: can be any or a combination of the following characters:
``acdijstuADST``. ``aAcCdDeijPsStTu``.
.. note:: .. note::
This option is **not** supported on Windows. This option is **not** supported on Windows.

View File

@ -303,7 +303,7 @@ def saved(name,
attrs attrs
The attributes to have on this file, e.g. ``a``, ``i``. The attributes The attributes to have on this file, e.g. ``a``, ``i``. The attributes
can be any or a combination of the following characters: can be any or a combination of the following characters:
``acdijstuADST``. ``aAcCdDeijPsStTu``.
.. note:: .. note::
This option is **not** supported on Windows. This option is **not** supported on Windows.

View File

@ -116,6 +116,12 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
'''1:17.4kB:150MB:150MB:ext3::boot;\n''' '''1:17.4kB:150MB:150MB:ext3::boot;\n'''
'''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n''' '''2:3921GB:4000GB:79.3GB:linux-swap(v1)::;\n'''
), ),
"valid chs": (
'''CHS;\n'''
'''/dev/sda:3133,0,2:scsi:512:512:gpt:AMCC 9650SE-24M DISK:;\n'''
'''1:0,0,34:2431,134,43:ext3::boot;\n'''
'''2:2431,134,44:2492,80,42:linux-swap(v1)::;\n'''
),
"valid_legacy": ( "valid_legacy": (
'''BYT;\n''' '''BYT;\n'''
'''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK;\n''' '''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK;\n'''
@ -207,17 +213,17 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
'end': '150MB', 'end': '150MB',
'number': '1', 'number': '1',
'start': '17.4kB', 'start': '17.4kB',
'file system': '', 'file system': 'ext3',
'flags': 'boot', 'flags': 'boot',
'type': 'ext3', 'name': '',
'size': '150MB'}, 'size': '150MB'},
'2': { '2': {
'end': '4000GB', 'end': '4000GB',
'number': '2', 'number': '2',
'start': '3921GB', 'start': '3921GB',
'file system': '', 'file system': 'linux-swap(v1)',
'flags': '', 'flags': '',
'type': 'linux-swap(v1)', 'name': '',
'size': '79.3GB' 'size': '79.3GB'
} }
} }
@ -245,23 +251,58 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
'end': '150MB', 'end': '150MB',
'number': '1', 'number': '1',
'start': '17.4kB', 'start': '17.4kB',
'file system': '', 'file system': 'ext3',
'flags': 'boot', 'flags': 'boot',
'type': 'ext3', 'name': '',
'size': '150MB'}, 'size': '150MB'},
'2': { '2': {
'end': '4000GB', 'end': '4000GB',
'number': '2', 'number': '2',
'start': '3921GB', 'start': '3921GB',
'file system': '', 'file system': 'linux-swap(v1)',
'flags': '', 'flags': '',
'type': 'linux-swap(v1)', 'name': '',
'size': '79.3GB' 'size': '79.3GB'
} }
} }
} }
self.assertEqual(output, expected) self.assertEqual(output, expected)
def test_list__valid_unit_chs_valid_cmd_output(self):
with patch('salt.modules.parted._validate_device', MagicMock()):
self.cmdrun_stdout.return_value = self.parted_print_output('valid chs')
output = parted.list_('/dev/sda', unit='chs')
self.cmdrun_stdout.assert_called_once_with('parted -m -s /dev/sda unit chs print')
expected = {
'info': {
'logical sector': '512',
'physical sector': '512',
'interface': 'scsi',
'model': 'AMCC 9650SE-24M DISK',
'disk': '/dev/sda',
'disk flags': '',
'partition table': 'gpt',
'size': '3133,0,2'
},
'partitions': {
'1': {
'end': '2431,134,43',
'number': '1',
'start': '0,0,34',
'file system': 'ext3',
'flags': 'boot',
'name': ''},
'2': {
'end': '2492,80,42',
'number': '2',
'start': '2431,134,44',
'file system': 'linux-swap(v1)',
'flags': '',
'name': ''}
}
}
self.assertEqual(output, expected)
def test_list__valid_legacy_cmd_output(self): def test_list__valid_legacy_cmd_output(self):
with patch('salt.modules.parted._validate_device', MagicMock()): with patch('salt.modules.parted._validate_device', MagicMock()):
self.cmdrun_stdout.return_value = self.parted_print_output('valid_legacy') self.cmdrun_stdout.return_value = self.parted_print_output('valid_legacy')
@ -282,17 +323,17 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
'end': '150MB', 'end': '150MB',
'number': '1', 'number': '1',
'start': '17.4kB', 'start': '17.4kB',
'file system': '', 'file system': 'ext3',
'flags': 'boot', 'flags': 'boot',
'type': 'ext3', 'name': '',
'size': '150MB'}, 'size': '150MB'},
'2': { '2': {
'end': '4000GB', 'end': '4000GB',
'number': '2', 'number': '2',
'start': '3921GB', 'start': '3921GB',
'file system': '', 'file system': 'linux-swap(v1)',
'flags': '', 'flags': '',
'type': 'linux-swap(v1)', 'name': '',
'size': '79.3GB' 'size': '79.3GB'
} }
} }
@ -319,17 +360,17 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
'end': '150MB', 'end': '150MB',
'number': '1', 'number': '1',
'start': '17.4kB', 'start': '17.4kB',
'file system': '', 'file system': 'ext3',
'flags': 'boot', 'flags': 'boot',
'type': 'ext3', 'name': '',
'size': '150MB'}, 'size': '150MB'},
'2': { '2': {
'end': '4000GB', 'end': '4000GB',
'number': '2', 'number': '2',
'start': '3921GB', 'start': '3921GB',
'file system': '', 'file system': 'linux-swap(v1)',
'flags': '', 'flags': '',
'type': 'linux-swap(v1)', 'name': '',
'size': '79.3GB' 'size': '79.3GB'
} }
} }