mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge branch '2019.2' into backport_49670
This commit is contained in:
commit
204432d924
@ -23,7 +23,6 @@ pyvmomi
|
||||
setproctitle
|
||||
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'
|
||||
ldap; sys.platform != 'win32' and sys.platform != 'darwin'
|
||||
pyinotify; sys.platform != 'win32' and sys.platform != 'darwin'
|
||||
PyMySQL; sys.platform != 'win32' and sys.platform != 'darwin'
|
||||
jsonschema
|
||||
|
@ -3035,12 +3035,16 @@ def run_chroot(root,
|
||||
'''
|
||||
__salt__['mount.mount'](
|
||||
os.path.join(root, 'dev'),
|
||||
'udev',
|
||||
'devtmpfs',
|
||||
fstype='devtmpfs')
|
||||
__salt__['mount.mount'](
|
||||
os.path.join(root, 'proc'),
|
||||
'proc',
|
||||
fstype='proc')
|
||||
__salt__['mount.mount'](
|
||||
os.path.join(root, 'sys'),
|
||||
'sysfs',
|
||||
fstype='sysfs')
|
||||
|
||||
# Execute chroot routine
|
||||
sh_ = '/bin/sh'
|
||||
@ -3092,6 +3096,7 @@ def run_chroot(root,
|
||||
log.error('Processes running in chroot could not be killed, '
|
||||
'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, 'dev'))
|
||||
if hide_output:
|
||||
|
@ -577,7 +577,7 @@ def lsattr(path):
|
||||
for line in result.splitlines():
|
||||
if not line.startswith('lsattr: '):
|
||||
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
|
||||
|
||||
@ -594,8 +594,8 @@ def chattr(*files, **kwargs):
|
||||
should be added or removed from files
|
||||
|
||||
attributes
|
||||
One or more of the following characters: ``acdijstuADST``, representing
|
||||
attributes to add to/remove from files
|
||||
One or more of the following characters: ``aAcCdDeijPsStTu``,
|
||||
representing attributes to add to/remove from files
|
||||
|
||||
version
|
||||
a version number to assign to the file(s)
|
||||
@ -620,7 +620,7 @@ def chattr(*files, **kwargs):
|
||||
raise SaltInvocationError(
|
||||
"Need an operator: 'add' or 'remove' to modify attributes.")
|
||||
if attributes is None:
|
||||
raise SaltInvocationError("Need attributes: [AacDdijsTtSu]")
|
||||
raise SaltInvocationError("Need attributes: [aAcCdDeijPsStTu]")
|
||||
|
||||
cmd = ['chattr']
|
||||
|
||||
|
@ -63,7 +63,9 @@ def _active_mountinfo(ret):
|
||||
msg = 'File not readable {0}'
|
||||
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:
|
||||
for line in ifile:
|
||||
|
@ -156,7 +156,7 @@ def list_(device, unit=None):
|
||||
for line in out:
|
||||
if line in ('BYT;', 'CHS;', 'CYL;'):
|
||||
continue
|
||||
cols = line.replace(';', '').split(':')
|
||||
cols = line.rstrip(';').split(':')
|
||||
if mode == 'info':
|
||||
if 7 <= len(cols) <= 8:
|
||||
ret['info'] = {
|
||||
@ -178,15 +178,26 @@ def list_(device, unit=None):
|
||||
raise CommandExecutionError(
|
||||
'Problem encountered while parsing output from parted')
|
||||
else:
|
||||
if len(cols) == 7:
|
||||
ret['partitions'][cols[0]] = {
|
||||
'number': cols[0],
|
||||
'start': cols[1],
|
||||
'end': cols[2],
|
||||
'size': cols[3],
|
||||
'type': cols[4],
|
||||
'file system': cols[5],
|
||||
'flags': cols[6]}
|
||||
# Parted (v3.1) have a variable field list in machine
|
||||
# readable output:
|
||||
#
|
||||
# number:start:end:[size:]([file system:name:flags;]|[free;])
|
||||
#
|
||||
# * If units are in CHS 'size' is not printed.
|
||||
# * If is a logical partition with PED_PARTITION_FREESPACE
|
||||
# set, the last three fields are replaced with the
|
||||
# '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:
|
||||
raise CommandExecutionError(
|
||||
'Problem encountered while parsing output from parted')
|
||||
|
@ -425,13 +425,13 @@ def owner(*paths):
|
||||
@salt.utils.decorators.path.which('rpm2cpio')
|
||||
@salt.utils.decorators.path.which('cpio')
|
||||
@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.
|
||||
NOTE: this function includes all files (configuration and not), but does
|
||||
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
|
||||
:return: Difference or empty string. For binary files only a notification.
|
||||
|
||||
@ -439,13 +439,13 @@ def diff(package, path):
|
||||
|
||||
.. 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} " \
|
||||
"| cpio -i --quiet --to-stdout .{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')
|
||||
if res and res.startswith('Binary file'):
|
||||
return 'File \'{0}\' is binary and its content has been ' \
|
||||
|
@ -41,6 +41,7 @@ def __virtual__():
|
||||
'elementary OS',
|
||||
'McAfee OS Server',
|
||||
'Raspbian',
|
||||
'SUSE',
|
||||
))
|
||||
if __grains__.get('os') in disable:
|
||||
return (False, 'Your OS is on the disabled list')
|
||||
|
@ -2116,7 +2116,7 @@ def managed(name,
|
||||
attrs
|
||||
The attributes to have on this file, e.g. ``a``, ``i``. The attributes
|
||||
can be any or a combination of the following characters:
|
||||
``acdijstuADST``.
|
||||
``aAcCdDeijPsStTu``.
|
||||
|
||||
.. note::
|
||||
This option is **not** supported on Windows.
|
||||
|
@ -303,7 +303,7 @@ def saved(name,
|
||||
attrs
|
||||
The attributes to have on this file, e.g. ``a``, ``i``. The attributes
|
||||
can be any or a combination of the following characters:
|
||||
``acdijstuADST``.
|
||||
``aAcCdDeijPsStTu``.
|
||||
|
||||
.. note::
|
||||
This option is **not** supported on Windows.
|
||||
|
@ -116,6 +116,12 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''1:17.4kB:150MB:150MB:ext3::boot;\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": (
|
||||
'''BYT;\n'''
|
||||
'''/dev/sda:4000GB:scsi:512:512:gpt:AMCC 9650SE-24M DISK;\n'''
|
||||
@ -207,17 +213,17 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'end': '150MB',
|
||||
'number': '1',
|
||||
'start': '17.4kB',
|
||||
'file system': '',
|
||||
'file system': 'ext3',
|
||||
'flags': 'boot',
|
||||
'type': 'ext3',
|
||||
'name': '',
|
||||
'size': '150MB'},
|
||||
'2': {
|
||||
'end': '4000GB',
|
||||
'number': '2',
|
||||
'start': '3921GB',
|
||||
'file system': '',
|
||||
'file system': 'linux-swap(v1)',
|
||||
'flags': '',
|
||||
'type': 'linux-swap(v1)',
|
||||
'name': '',
|
||||
'size': '79.3GB'
|
||||
}
|
||||
}
|
||||
@ -245,23 +251,58 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'end': '150MB',
|
||||
'number': '1',
|
||||
'start': '17.4kB',
|
||||
'file system': '',
|
||||
'file system': 'ext3',
|
||||
'flags': 'boot',
|
||||
'type': 'ext3',
|
||||
'name': '',
|
||||
'size': '150MB'},
|
||||
'2': {
|
||||
'end': '4000GB',
|
||||
'number': '2',
|
||||
'start': '3921GB',
|
||||
'file system': '',
|
||||
'file system': 'linux-swap(v1)',
|
||||
'flags': '',
|
||||
'type': 'linux-swap(v1)',
|
||||
'name': '',
|
||||
'size': '79.3GB'
|
||||
}
|
||||
}
|
||||
}
|
||||
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):
|
||||
with patch('salt.modules.parted._validate_device', MagicMock()):
|
||||
self.cmdrun_stdout.return_value = self.parted_print_output('valid_legacy')
|
||||
@ -282,17 +323,17 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'end': '150MB',
|
||||
'number': '1',
|
||||
'start': '17.4kB',
|
||||
'file system': '',
|
||||
'file system': 'ext3',
|
||||
'flags': 'boot',
|
||||
'type': 'ext3',
|
||||
'name': '',
|
||||
'size': '150MB'},
|
||||
'2': {
|
||||
'end': '4000GB',
|
||||
'number': '2',
|
||||
'start': '3921GB',
|
||||
'file system': '',
|
||||
'file system': 'linux-swap(v1)',
|
||||
'flags': '',
|
||||
'type': 'linux-swap(v1)',
|
||||
'name': '',
|
||||
'size': '79.3GB'
|
||||
}
|
||||
}
|
||||
@ -319,17 +360,17 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'end': '150MB',
|
||||
'number': '1',
|
||||
'start': '17.4kB',
|
||||
'file system': '',
|
||||
'file system': 'ext3',
|
||||
'flags': 'boot',
|
||||
'type': 'ext3',
|
||||
'name': '',
|
||||
'size': '150MB'},
|
||||
'2': {
|
||||
'end': '4000GB',
|
||||
'number': '2',
|
||||
'start': '3921GB',
|
||||
'file system': '',
|
||||
'file system': 'linux-swap(v1)',
|
||||
'flags': '',
|
||||
'type': 'linux-swap(v1)',
|
||||
'name': '',
|
||||
'size': '79.3GB'
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user