mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #46232 from rallytime/merge-2018.3
[2018.3] Merge forward from 2017.7 to 2018.3
This commit is contained in:
commit
123625213e
14 changed files with 310 additions and 143 deletions
|
@ -250,7 +250,7 @@ on_saltstack = 'SALT_ON_SALTSTACK' in os.environ
|
|||
project = 'Salt'
|
||||
|
||||
version = salt.version.__version__
|
||||
latest_release = '2017.7.3' # latest release
|
||||
latest_release = '2017.7.4' # latest release
|
||||
previous_release = '2016.11.9' # latest release from previous branch
|
||||
previous_release_dir = '2016.11' # path on web server for previous branch
|
||||
next_release = '' # next release
|
||||
|
|
|
@ -1266,10 +1266,10 @@ A sample skeleton for the ``README.rst`` file:
|
|||
|
||||
Install and configure the FOO service.
|
||||
|
||||
.. note::
|
||||
**NOTE**
|
||||
|
||||
See the full `Salt Formulas installation and usage instructions
|
||||
<https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html>`_.
|
||||
See the full `Salt Formulas installation and usage instructions
|
||||
<https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html>`_.
|
||||
|
||||
Available states
|
||||
================
|
||||
|
|
|
@ -9,17 +9,45 @@ Changes for v2017.7.3..v2017.7.4
|
|||
|
||||
Extended changelog courtesy of Todd Stansell (https://github.com/tjstansell/salt-changelogs):
|
||||
|
||||
*Generated at: 2018-02-13T16:29:07Z*
|
||||
*Generated at: 2018-02-16T16:44:38Z*
|
||||
|
||||
Statistics:
|
||||
|
||||
- Total Merges: **4**
|
||||
- Total Issue references: **3**
|
||||
- Total PR references: **7**
|
||||
- Total Merges: **7**
|
||||
- Total Issue references: **4**
|
||||
- Total PR references: **11**
|
||||
|
||||
Changes:
|
||||
|
||||
|
||||
- **PR** `#46066`_: (*rallytime*) Pin tornado version in requirements file
|
||||
@ *2018-02-16T16:40:05Z*
|
||||
|
||||
- **ISSUE** `#45790`_: (*bdarnell*) Test with Tornado 5.0b1
|
||||
| refs: `#46066`_
|
||||
* 32f3d00e44 Merge pull request `#46066`_ from rallytime/pin-tornado
|
||||
* 6dc1a3b9dc Pin tornado version in requirements file
|
||||
|
||||
- **PR** `#46036`_: (*terminalmage*) git.latest: Fix regression with identity file usage
|
||||
@ *2018-02-16T13:57:23Z*
|
||||
|
||||
* 85761ee650 Merge pull request `#46036`_ from terminalmage/issue43769
|
||||
* e2140d9a84 Mock the ssh.key_is_encrypted utils func
|
||||
|
||||
* 169924b3fe Move ssh.key_is_encrypted to a utils module temporarily
|
||||
|
||||
* 54f4d78f7a Only keep ssh.py in the Windows installer
|
||||
|
||||
* 5f04531e1b Keep ssh state and execution modules in the installer
|
||||
|
||||
* f2b69f703d git.latest: Fix regression with identity file usage
|
||||
|
||||
- **PR** `#46009`_: (*Ch3LL*) Add 2017.7.4 Release Notes with PRs
|
||||
@ *2018-02-13T16:40:30Z*
|
||||
|
||||
* 6d534c6e7e Merge pull request `#46009`_ from Ch3LL/rn_7.4
|
||||
* ac0baf4b34 Add 2017.7.4 Release Notes with PRs
|
||||
|
||||
- **PR** `#45981`_: (*gtmanfred*) use local config for vault when masterless
|
||||
@ *2018-02-13T15:22:01Z*
|
||||
|
||||
|
@ -66,6 +94,7 @@ Changes:
|
|||
|
||||
|
||||
.. _`#45742`: https://github.com/saltstack/salt/pull/45742
|
||||
.. _`#45790`: https://github.com/saltstack/salt/issues/45790
|
||||
.. _`#45893`: https://github.com/saltstack/salt/issues/45893
|
||||
.. _`#45902`: https://github.com/saltstack/salt/pull/45902
|
||||
.. _`#45915`: https://github.com/saltstack/salt/issues/45915
|
||||
|
@ -75,6 +104,9 @@ Changes:
|
|||
.. _`#45953`: https://github.com/saltstack/salt/pull/45953
|
||||
.. _`#45976`: https://github.com/saltstack/salt/issues/45976
|
||||
.. _`#45981`: https://github.com/saltstack/salt/pull/45981
|
||||
.. _`#46009`: https://github.com/saltstack/salt/pull/46009
|
||||
.. _`#46036`: https://github.com/saltstack/salt/pull/46036
|
||||
.. _`#46066`: https://github.com/saltstack/salt/pull/46066
|
||||
.. _`bp-45742`: https://github.com/saltstack/salt/pull/45742
|
||||
.. _`bp-45902`: https://github.com/saltstack/salt/pull/45902
|
||||
.. _`bp-45928`: https://github.com/saltstack/salt/pull/45928
|
||||
|
|
5
doc/topics/releases/2017.7.5.rst
Normal file
5
doc/topics/releases/2017.7.5.rst
Normal file
|
@ -0,0 +1,5 @@
|
|||
===========================
|
||||
Salt 2017.7.5 Release Notes
|
||||
===========================
|
||||
|
||||
Version 2017.7.5 is a bugfix release for :ref:`2017.7.0 <release-2017-7-0>`.
|
|
@ -1331,19 +1331,22 @@ def _get_interfaces():
|
|||
return _INTERFACES
|
||||
|
||||
|
||||
def _parse_os_release():
|
||||
def _parse_os_release(os_release_files):
|
||||
'''
|
||||
Parse /etc/os-release and return a parameter dictionary
|
||||
Parse os-release and return a parameter dictionary
|
||||
|
||||
See http://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
for specification of the file format.
|
||||
'''
|
||||
|
||||
filename = '/etc/os-release'
|
||||
if not os.path.isfile(filename):
|
||||
filename = '/usr/lib/os-release'
|
||||
|
||||
data = dict()
|
||||
for filename in os_release_files:
|
||||
if os.path.isfile(filename):
|
||||
break
|
||||
else:
|
||||
# None of the specified os-release files exist
|
||||
return data
|
||||
|
||||
with salt.utils.files.fopen(filename) as ifile:
|
||||
regex = re.compile('^([\\w]+)=(?:\'|")?(.*?)(?:\'|")?$')
|
||||
for line in ifile:
|
||||
|
@ -1538,13 +1541,15 @@ def os_data():
|
|||
# to be incorrectly set to "Arch".
|
||||
grains['osfullname'] = 'Antergos Linux'
|
||||
elif 'lsb_distrib_id' not in grains:
|
||||
if os.path.isfile('/etc/os-release') or os.path.isfile('/usr/lib/os-release'):
|
||||
os_release = _parse_os_release()
|
||||
os_release = _parse_os_release(['/etc/os-release', '/usr/lib/os-release'])
|
||||
if os_release:
|
||||
if 'NAME' in os_release:
|
||||
grains['lsb_distrib_id'] = os_release['NAME'].strip()
|
||||
if 'VERSION_ID' in os_release:
|
||||
grains['lsb_distrib_release'] = os_release['VERSION_ID']
|
||||
if 'PRETTY_NAME' in os_release:
|
||||
if 'VERSION_CODENAME' in os_release:
|
||||
grains['lsb_distrib_codename'] = os_release['VERSION_CODENAME']
|
||||
elif 'PRETTY_NAME' in os_release:
|
||||
codename = os_release['PRETTY_NAME']
|
||||
# https://github.com/saltstack/salt/issues/44108
|
||||
if os_release['ID'] == 'debian':
|
||||
|
@ -1808,7 +1813,7 @@ def os_data():
|
|||
grains['osrelease_info']
|
||||
)
|
||||
os_name = grains['os' if grains.get('os') in (
|
||||
'FreeBSD', 'OpenBSD', 'NetBSD', 'Mac', 'Raspbian') else 'osfullname']
|
||||
'Debian', 'FreeBSD', 'OpenBSD', 'NetBSD', 'Mac', 'Raspbian') else 'osfullname']
|
||||
grains['osfinger'] = '{0}-{1}'.format(
|
||||
os_name, grains['osrelease'] if os_name in ('Ubuntu',) else grains['osrelease_info'][0])
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Retrieve EC2 instance data for minions for ec2_tags and ec2_tags_list
|
||||
|
||||
The minion id must be the AWS instance-id or value in 'tag_key'.
|
||||
For example set 'tag_key' to 'Name', to have the minion-id matched against the
|
||||
tag 'Name'. The tag contents must be unique. The value of tag_value can
|
||||
The minion id must be the AWS instance-id or value in 'tag_match_key'.
|
||||
For example set 'tag_match_key' to 'Name', to have the minion-id matched against the
|
||||
tag 'Name'. The tag contents must be unique. The value of tag_match_value can
|
||||
be 'uqdn' or 'asis'. if 'uqdn' strips any domain before comparison.
|
||||
|
||||
The option use_grain can be set to True. This allows the use of an
|
||||
|
@ -27,8 +27,8 @@ exist it is still included as an empty list.
|
|||
|
||||
ext_pillar:
|
||||
- ec2_pillar:
|
||||
tag_key: 'Name'
|
||||
tag_value: 'asis'
|
||||
tag_match_key: 'Name'
|
||||
tag_match_value: 'asis'
|
||||
tag_list_key:
|
||||
- Role
|
||||
tag_list_sep: ';'
|
||||
|
@ -100,14 +100,14 @@ def ext_pillar(minion_id,
|
|||
pillar, # pylint: disable=W0613
|
||||
use_grain=False,
|
||||
minion_ids=None,
|
||||
tag_key=None,
|
||||
tag_value='asis',
|
||||
tag_match_key=None,
|
||||
tag_match_value='asis',
|
||||
tag_list_key=None,
|
||||
tag_list_sep=';'):
|
||||
'''
|
||||
Execute a command and read the output as YAML
|
||||
'''
|
||||
valid_tag_value = ['uqdn', 'asis']
|
||||
valid_tag_match_value = ['uqdn', 'asis']
|
||||
|
||||
# meta-data:instance-id
|
||||
grain_instance_id = __grains__.get('meta-data', {}).get('instance-id', None)
|
||||
|
@ -121,22 +121,22 @@ def ext_pillar(minion_id,
|
|||
grain_instance_id = None # invalid instance id found, remove it from use.
|
||||
|
||||
# Check AWS Tag restrictions .i.e. letters, spaces, and numbers and + - = . _ : / @
|
||||
if tag_key and re.match(r'[\w=.:/@-]+$', tag_key) is None:
|
||||
log.error('External pillar %s, tag_key \'%s\' is not valid ',
|
||||
__name__, tag_key if isinstance(tag_key, six.text_type) else 'non-string')
|
||||
if tag_match_key and re.match(r'[\w=.:/@-]+$', tag_match_key) is None:
|
||||
log.error('External pillar %s, tag_match_key \'%s\' is not valid ',
|
||||
__name__, tag_match_key if isinstance(tag_match_key, six.text_type) else 'non-string')
|
||||
return {}
|
||||
|
||||
if tag_key and tag_value not in valid_tag_value:
|
||||
if tag_match_key and tag_match_value not in valid_tag_match_value:
|
||||
log.error('External pillar %s, tag_value \'%s\' is not valid must be one '
|
||||
'of %s', __name__, tag_value, ' '.join(valid_tag_value))
|
||||
'of %s', __name__, tag_match_value, ' '.join(valid_tag_match_value))
|
||||
return {}
|
||||
|
||||
if not tag_key:
|
||||
if not tag_match_key:
|
||||
base_msg = ('External pillar %s, querying EC2 tags for minion id \'%s\' '
|
||||
'against instance-id', __name__, minion_id)
|
||||
else:
|
||||
base_msg = ('External pillar %s, querying EC2 tags for minion id \'%s\' '
|
||||
'against instance-id or \'%s\' against \'%s\'', __name__, minion_id, tag_key, tag_value)
|
||||
'against instance-id or \'%s\' against \'%s\'', __name__, minion_id, tag_match_key, tag_match_value)
|
||||
|
||||
log.debug(base_msg)
|
||||
find_filter = None
|
||||
|
@ -145,11 +145,11 @@ def ext_pillar(minion_id,
|
|||
if re.search(r'^i-([0-9a-z]{17}|[0-9a-z]{8})$', minion_id) is not None:
|
||||
find_filter = None
|
||||
find_id = minion_id
|
||||
elif tag_key:
|
||||
if tag_value == 'uqdn':
|
||||
find_filter = {'tag:{0}'.format(tag_key): minion_id.split('.', 1)[0]}
|
||||
elif tag_match_key:
|
||||
if tag_match_value == 'uqdn':
|
||||
find_filter = {'tag:{0}'.format(tag_match_key): minion_id.split('.', 1)[0]}
|
||||
else:
|
||||
find_filter = {'tag:{0}'.format(tag_key): minion_id}
|
||||
find_filter = {'tag:{0}'.format(tag_match_key): minion_id}
|
||||
if grain_instance_id:
|
||||
# we have an untrusted grain_instance_id, use it to narrow the search
|
||||
# even more. Combination will be unique even if uqdn is set.
|
||||
|
@ -173,7 +173,7 @@ def ext_pillar(minion_id,
|
|||
if not (find_filter or find_id):
|
||||
log.debug('External pillar %s, querying EC2 tags for minion id \'%s\' against '
|
||||
'instance-id or \'%s\' against \'%s\' noughthing to match against',
|
||||
__name__, minion_id, tag_key, tag_value)
|
||||
__name__, minion_id, tag_match_key, tag_match_value)
|
||||
return {}
|
||||
|
||||
myself = boto.utils.get_instance_metadata(timeout=0.1, num_retries=1)
|
||||
|
|
|
@ -2157,6 +2157,9 @@ class GitBase(object):
|
|||
for saltenv, saltenv_conf in six.iteritems(repo_obj.saltenv):
|
||||
if 'ref' in saltenv_conf:
|
||||
ref = saltenv_conf['ref']
|
||||
repo_obj.saltenv_revmap.setdefault(
|
||||
ref, []).append(saltenv)
|
||||
|
||||
if saltenv == 'base':
|
||||
# Remove redundant 'ref' config for base saltenv
|
||||
repo_obj.saltenv[saltenv].pop('ref')
|
||||
|
@ -2171,9 +2174,6 @@ class GitBase(object):
|
|||
)
|
||||
# Rewrite 'base' config param
|
||||
repo_obj.base = ref
|
||||
else:
|
||||
repo_obj.saltenv_revmap.setdefault(
|
||||
ref, []).append(saltenv)
|
||||
|
||||
# Build list of all envs defined by ref mappings in the
|
||||
# per-remote 'saltenv' param. We won't add any matching envs
|
||||
|
|
|
@ -540,6 +540,7 @@ class CPModuleTest(ModuleCase):
|
|||
url = url_prefix + (code or 'actual_file')
|
||||
log.debug('attempting to cache %s', url)
|
||||
ret = self.run_function('cp.cache_file', [url])
|
||||
self.assertTrue(ret)
|
||||
with salt.utils.files.fopen(ret) as fp_:
|
||||
cached_contents = salt.utils.stringutils.to_unicode(fp_.read())
|
||||
self.assertEqual(cached_contents, file_contents)
|
||||
|
|
10
tests/unit/grains/os-releases/debian-7
Normal file
10
tests/unit/grains/os-releases/debian-7
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Taken from base-files 7.1wheezy11
|
||||
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="7"
|
||||
VERSION="7 (wheezy)"
|
||||
ID=debian
|
||||
ANSI_COLOR="1;31"
|
||||
HOME_URL="http://www.debian.org/"
|
||||
SUPPORT_URL="http://www.debian.org/support/"
|
||||
BUG_REPORT_URL="http://bugs.debian.org/"
|
9
tests/unit/grains/os-releases/debian-8
Normal file
9
tests/unit/grains/os-releases/debian-8
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Taken from base-files 8+deb8u10
|
||||
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="8"
|
||||
VERSION="8 (jessie)"
|
||||
ID=debian
|
||||
HOME_URL="http://www.debian.org/"
|
||||
SUPPORT_URL="http://www.debian.org/support"
|
||||
BUG_REPORT_URL="https://bugs.debian.org/"
|
9
tests/unit/grains/os-releases/debian-9
Normal file
9
tests/unit/grains/os-releases/debian-9
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Taken from base-files 9.9+deb9u3
|
||||
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="9"
|
||||
VERSION="9 (stretch)"
|
||||
ID=debian
|
||||
HOME_URL="https://www.debian.org/"
|
||||
SUPPORT_URL="https://www.debian.org/support"
|
||||
BUG_REPORT_URL="https://bugs.debian.org/"
|
12
tests/unit/grains/os-releases/ubuntu-16.04
Normal file
12
tests/unit/grains/os-releases/ubuntu-16.04
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Taken from base-files 9.4ubuntu4.5
|
||||
NAME="Ubuntu"
|
||||
VERSION="16.04.3 LTS (Xenial Xerus)"
|
||||
ID=ubuntu
|
||||
ID_LIKE=debian
|
||||
PRETTY_NAME="Ubuntu 16.04.3 LTS"
|
||||
VERSION_ID="16.04"
|
||||
HOME_URL="http://www.ubuntu.com/"
|
||||
SUPPORT_URL="http://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
|
||||
VERSION_CODENAME=xenial
|
||||
UBUNTU_CODENAME=xenial
|
13
tests/unit/grains/os-releases/ubuntu-17.10
Normal file
13
tests/unit/grains/os-releases/ubuntu-17.10
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Taken from base-files 9.6ubuntu102
|
||||
NAME="Ubuntu"
|
||||
VERSION="17.10 (Artful Aardvark)"
|
||||
ID=ubuntu
|
||||
ID_LIKE=debian
|
||||
PRETTY_NAME="Ubuntu 17.10"
|
||||
VERSION_ID="17.10"
|
||||
HOME_URL="https://www.ubuntu.com/"
|
||||
SUPPORT_URL="https://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
|
||||
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
|
||||
VERSION_CODENAME=artful
|
||||
UBUNTU_CODENAME=artful
|
|
@ -25,6 +25,7 @@ from tests.support.mock import (
|
|||
)
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils.files
|
||||
import salt.utils.platform
|
||||
import salt.grains.core as core
|
||||
|
||||
|
@ -46,6 +47,7 @@ IP4_ADD2 = '10.0.0.2'
|
|||
IP6_LOCAL = '::1'
|
||||
IP6_ADD1 = '2001:4860:4860::8844'
|
||||
IP6_ADD2 = '2001:4860:4860::8888'
|
||||
OS_RELEASE_DIR = os.path.join(os.path.dirname(__file__), "os-releases")
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
|
@ -57,6 +59,35 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
def setup_loader_modules(self):
|
||||
return {core: {}}
|
||||
|
||||
@patch("os.path.isfile")
|
||||
def test_parse_etc_os_release(self, path_isfile_mock):
|
||||
path_isfile_mock.side_effect = lambda x: x == "/usr/lib/os-release"
|
||||
with salt.utils.files.fopen(os.path.join(OS_RELEASE_DIR, "ubuntu-17.10")) as os_release_file:
|
||||
os_release_content = os_release_file.readlines()
|
||||
with patch("salt.utils.files.fopen", mock_open()) as os_release_file:
|
||||
os_release_file.return_value.__iter__.return_value = os_release_content
|
||||
os_release = core._parse_os_release(["/etc/os-release", "/usr/lib/os-release"])
|
||||
self.assertEqual(os_release, {
|
||||
"NAME": "Ubuntu",
|
||||
"VERSION": "17.10 (Artful Aardvark)",
|
||||
"ID": "ubuntu",
|
||||
"ID_LIKE": "debian",
|
||||
"PRETTY_NAME": "Ubuntu 17.10",
|
||||
"VERSION_ID": "17.10",
|
||||
"HOME_URL": "https://www.ubuntu.com/",
|
||||
"SUPPORT_URL": "https://help.ubuntu.com/",
|
||||
"BUG_REPORT_URL": "https://bugs.launchpad.net/ubuntu/",
|
||||
"PRIVACY_POLICY_URL": "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
|
||||
"VERSION_CODENAME": "artful",
|
||||
"UBUNTU_CODENAME": "artful",
|
||||
})
|
||||
|
||||
@patch("os.path.isfile")
|
||||
def test_missing_os_release(self, path_isfile_mock):
|
||||
path_isfile_mock.return_value = False
|
||||
os_release = core._parse_os_release(["/etc/os-release", "/usr/lib/os-release"])
|
||||
self.assertEqual(os_release, {})
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_gnu_slash_linux_in_os_name(self):
|
||||
'''
|
||||
|
@ -155,9 +186,6 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
_path_exists_map = {
|
||||
'/proc/1/cmdline': False
|
||||
}
|
||||
_path_isfile_map = {
|
||||
'/etc/os-release': True,
|
||||
}
|
||||
_os_release_map = {
|
||||
'NAME': 'SLES',
|
||||
'VERSION': '12-SP1',
|
||||
|
@ -169,9 +197,6 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
}
|
||||
|
||||
path_exists_mock = MagicMock(side_effect=lambda x: _path_exists_map[x])
|
||||
path_isfile_mock = MagicMock(
|
||||
side_effect=lambda x: _path_isfile_map.get(x, False)
|
||||
)
|
||||
empty_mock = MagicMock(return_value={})
|
||||
osarch_mock = MagicMock(return_value="amd64")
|
||||
os_release_mock = MagicMock(return_value=_os_release_map)
|
||||
|
@ -199,7 +224,7 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('{0}.__import__'.format(built_in),
|
||||
side_effect=_import_mock):
|
||||
# Skip all the /etc/*-release stuff (not pertinent)
|
||||
with patch.object(os.path, 'isfile', path_isfile_mock):
|
||||
with patch.object(os.path, 'isfile', MagicMock(return_value=False)):
|
||||
with patch.object(core, '_parse_os_release', os_release_mock):
|
||||
# Mock linux_distribution to give us the OS
|
||||
# name that we want.
|
||||
|
@ -218,11 +243,16 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
self.assertEqual(os_grains.get('os_family'), 'Suse')
|
||||
self.assertEqual(os_grains.get('os'), 'SUSE')
|
||||
|
||||
def _run_suse_os_grains_tests(self, os_release_map):
|
||||
path_isfile_mock = MagicMock(side_effect=lambda x: x in os_release_map['files'])
|
||||
def _run_os_grains_tests(self, os_release_filename, os_release_map, expectation):
|
||||
path_isfile_mock = MagicMock(side_effect=lambda x: x in os_release_map.get('files', []))
|
||||
empty_mock = MagicMock(return_value={})
|
||||
osarch_mock = MagicMock(return_value="amd64")
|
||||
os_release_mock = MagicMock(return_value=os_release_map.get('os_release_file'))
|
||||
if os_release_filename:
|
||||
os_release_data = core._parse_os_release(
|
||||
[os.path.join(OS_RELEASE_DIR, os_release_filename)])
|
||||
else:
|
||||
os_release_data = os_release_map.get('os_release_file', {})
|
||||
os_release_mock = MagicMock(return_value=os_release_data)
|
||||
|
||||
orig_import = __import__
|
||||
if six.PY2:
|
||||
|
@ -252,10 +282,11 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
# Mock linux_distribution to give us the OS
|
||||
# name that we want.
|
||||
distro_mock = MagicMock(
|
||||
return_value=('SUSE test', 'version', 'arch')
|
||||
return_value=os_release_map['linux_distribution']
|
||||
)
|
||||
with patch('salt.utils.files.fopen', mock_open()) as suse_release_file:
|
||||
suse_release_file.return_value.__iter__.return_value = os_release_map.get('suse_release_file', '').splitlines()
|
||||
suse_release_file.return_value.__iter__.return_value = \
|
||||
os_release_map.get('suse_release_file', '').splitlines()
|
||||
with patch.object(core, 'linux_distribution', distro_mock):
|
||||
with patch.object(core, '_linux_gpu_data', empty_mock):
|
||||
with patch.object(core, '_linux_cpudata', empty_mock):
|
||||
|
@ -264,13 +295,16 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(core.__salt__, {'cmd.run': osarch_mock}):
|
||||
os_grains = core.os_data()
|
||||
|
||||
self.assertEqual(os_grains.get('os'), 'SUSE')
|
||||
self.assertEqual(os_grains.get('os_family'), 'Suse')
|
||||
self.assertEqual(os_grains.get('osfullname'), os_release_map['osfullname'])
|
||||
self.assertEqual(os_grains.get('oscodename'), os_release_map['oscodename'])
|
||||
self.assertEqual(os_grains.get('osrelease'), os_release_map['osrelease'])
|
||||
self.assertListEqual(list(os_grains.get('osrelease_info')), os_release_map['osrelease_info'])
|
||||
self.assertEqual(os_grains.get('osmajorrelease'), os_release_map['osmajorrelease'])
|
||||
grains = {k: v for k, v in os_grains.items()
|
||||
if k in set(["os", "os_family", "osfullname", "oscodename", "osfinger",
|
||||
"osrelease", "osrelease_info", "osmajorrelease"])}
|
||||
self.assertEqual(grains, expectation)
|
||||
|
||||
def _run_suse_os_grains_tests(self, os_release_map, expectation):
|
||||
os_release_map['linux_distribution'] = ('SUSE test', 'version', 'arch')
|
||||
expectation['os'] = 'SUSE'
|
||||
expectation['os_family'] = 'Suse'
|
||||
self._run_os_grains_tests(None, os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_sles11sp3(self):
|
||||
|
@ -282,14 +316,17 @@ class CoreGrainsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
VERSION = 11
|
||||
PATCHLEVEL = 3
|
||||
''',
|
||||
'files': ["/etc/SuSE-release"],
|
||||
}
|
||||
expectation = {
|
||||
'oscodename': 'SUSE Linux Enterprise Server 11 SP3',
|
||||
'osfullname': "SLES",
|
||||
'osrelease': '11.3',
|
||||
'osrelease_info': [11, 3],
|
||||
'osrelease_info': (11, 3),
|
||||
'osmajorrelease': 11,
|
||||
'files': ["/etc/SuSE-release"],
|
||||
'osfinger': 'SLES-11',
|
||||
}
|
||||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
self._run_suse_os_grains_tests(_os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_sles11sp4(self):
|
||||
|
@ -306,14 +343,16 @@ PATCHLEVEL = 3
|
|||
'ANSI_COLOR': '0;32',
|
||||
'CPE_NAME': 'cpe:/o:suse:sles:11:4'
|
||||
},
|
||||
}
|
||||
expectation = {
|
||||
'oscodename': 'SUSE Linux Enterprise Server 11 SP4',
|
||||
'osfullname': "SLES",
|
||||
'osrelease': '11.4',
|
||||
'osrelease_info': [11, 4],
|
||||
'osrelease_info': (11, 4),
|
||||
'osmajorrelease': 11,
|
||||
'files': ["/etc/os-release"],
|
||||
'osfinger': 'SLES-11',
|
||||
}
|
||||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
self._run_suse_os_grains_tests(_os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_sles12(self):
|
||||
|
@ -330,14 +369,16 @@ PATCHLEVEL = 3
|
|||
'ANSI_COLOR': '0;32',
|
||||
'CPE_NAME': 'cpe:/o:suse:sles:12'
|
||||
},
|
||||
}
|
||||
expectation = {
|
||||
'oscodename': 'SUSE Linux Enterprise Server 12',
|
||||
'osfullname': "SLES",
|
||||
'osrelease': '12',
|
||||
'osrelease_info': [12],
|
||||
'osrelease_info': (12,),
|
||||
'osmajorrelease': 12,
|
||||
'files': ["/etc/os-release"],
|
||||
'osfinger': 'SLES-12',
|
||||
}
|
||||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
self._run_suse_os_grains_tests(_os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_sles12sp1(self):
|
||||
|
@ -354,14 +395,16 @@ PATCHLEVEL = 3
|
|||
'ANSI_COLOR': '0;32',
|
||||
'CPE_NAME': 'cpe:/o:suse:sles:12:sp1'
|
||||
},
|
||||
}
|
||||
expectation = {
|
||||
'oscodename': 'SUSE Linux Enterprise Server 12 SP1',
|
||||
'osfullname': "SLES",
|
||||
'osrelease': '12.1',
|
||||
'osrelease_info': [12, 1],
|
||||
'osrelease_info': (12, 1),
|
||||
'osmajorrelease': 12,
|
||||
'files': ["/etc/os-release"],
|
||||
'osfinger': 'SLES-12',
|
||||
}
|
||||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
self._run_suse_os_grains_tests(_os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_opensuse_leap_42_1(self):
|
||||
|
@ -378,14 +421,16 @@ PATCHLEVEL = 3
|
|||
'ANSI_COLOR': '0;32',
|
||||
'CPE_NAME': 'cpe:/o:opensuse:opensuse:42.1'
|
||||
},
|
||||
}
|
||||
expectation = {
|
||||
'oscodename': 'openSUSE Leap 42.1 (x86_64)',
|
||||
'osfullname': "Leap",
|
||||
'osrelease': '42.1',
|
||||
'osrelease_info': [42, 1],
|
||||
'osrelease_info': (42, 1),
|
||||
'osmajorrelease': 42,
|
||||
'files': ["/etc/os-release"],
|
||||
'osfinger': 'Leap-42',
|
||||
}
|
||||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
self._run_suse_os_grains_tests(_os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_suse_os_grains_tumbleweed(self):
|
||||
|
@ -402,90 +447,116 @@ PATCHLEVEL = 3
|
|||
'ANSI_COLOR': '0;32',
|
||||
'CPE_NAME': 'cpe:/o:opensuse:opensuse:20160504'
|
||||
},
|
||||
}
|
||||
expectation = {
|
||||
'oscodename': 'openSUSE Tumbleweed (20160504) (x86_64)',
|
||||
'osfullname': "Tumbleweed",
|
||||
'osrelease': '20160504',
|
||||
'osrelease_info': [20160504],
|
||||
'osrelease_info': (20160504,),
|
||||
'osmajorrelease': 20160504,
|
||||
'files': ["/etc/os-release"],
|
||||
'osfinger': 'Tumbleweed-20160504',
|
||||
}
|
||||
self._run_suse_os_grains_tests(_os_release_map)
|
||||
self._run_suse_os_grains_tests(_os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_ubuntu_os_grains(self):
|
||||
def test_debian_7_os_grains(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
|
||||
Test if OS grains are parsed correctly in Debian 7 "wheezy"
|
||||
'''
|
||||
_os_release_map = {
|
||||
'os_release_file': {
|
||||
'NAME': 'Ubuntu',
|
||||
'VERSION': '16.04.1 LTS (Xenial Xerus)',
|
||||
'VERSION_ID': '16.04',
|
||||
'PRETTY_NAME': '',
|
||||
'ID': 'ubuntu',
|
||||
},
|
||||
'linux_distribution': ('debian', '7.11', ''),
|
||||
}
|
||||
expectation = {
|
||||
'os': 'Debian',
|
||||
'os_family': 'Debian',
|
||||
'oscodename': 'wheezy',
|
||||
'osfullname': 'Debian GNU/Linux',
|
||||
'osrelease': '7',
|
||||
'osrelease_info': (7,),
|
||||
'osmajorrelease': 7,
|
||||
'osfinger': 'Debian-7',
|
||||
}
|
||||
self._run_os_grains_tests("debian-7", _os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_debian_8_os_grains(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Debian 8 "jessie"
|
||||
'''
|
||||
_os_release_map = {
|
||||
'linux_distribution': ('debian', '8.10', ''),
|
||||
}
|
||||
expectation = {
|
||||
'os': 'Debian',
|
||||
'os_family': 'Debian',
|
||||
'oscodename': 'jessie',
|
||||
'osfullname': 'Debian GNU/Linux',
|
||||
'osrelease': '8',
|
||||
'osrelease_info': (8,),
|
||||
'osmajorrelease': 8,
|
||||
'osfinger': 'Debian-8',
|
||||
}
|
||||
self._run_os_grains_tests("debian-8", _os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_debian_9_os_grains(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Debian 9 "stretch"
|
||||
'''
|
||||
_os_release_map = {
|
||||
'linux_distribution': ('debian', '9.3', ''),
|
||||
}
|
||||
expectation = {
|
||||
'os': 'Debian',
|
||||
'os_family': 'Debian',
|
||||
'oscodename': 'stretch',
|
||||
'osfullname': 'Debian GNU/Linux',
|
||||
'osrelease': '9',
|
||||
'osrelease_info': (9,),
|
||||
'osmajorrelease': 9,
|
||||
'osfinger': 'Debian-9',
|
||||
}
|
||||
self._run_os_grains_tests("debian-9", _os_release_map, expectation)
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_ubuntu_xenial_os_grains(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Ubuntu 16.04 "Xenial Xerus"
|
||||
'''
|
||||
_os_release_map = {
|
||||
'linux_distribution': ('Ubuntu', '16.04', 'xenial'),
|
||||
}
|
||||
expectation = {
|
||||
'os': 'Ubuntu',
|
||||
'os_family': 'Debian',
|
||||
'oscodename': 'xenial',
|
||||
'osfullname': 'Ubuntu',
|
||||
'osrelease': '16.04',
|
||||
'osrelease_info': [16, 4],
|
||||
'osrelease_info': (16, 4),
|
||||
'osmajorrelease': 16,
|
||||
'osfinger': 'Ubuntu-16.04',
|
||||
}
|
||||
self._run_ubuntu_os_grains_tests(_os_release_map)
|
||||
self._run_os_grains_tests("ubuntu-16.04", _os_release_map, expectation)
|
||||
|
||||
def _run_ubuntu_os_grains_tests(self, os_release_map):
|
||||
path_isfile_mock = MagicMock(side_effect=lambda x: x in ['/etc/os-release'])
|
||||
empty_mock = MagicMock(return_value={})
|
||||
osarch_mock = MagicMock(return_value="amd64")
|
||||
os_release_mock = MagicMock(return_value=os_release_map.get('os_release_file'))
|
||||
|
||||
if six.PY2:
|
||||
built_in = '__builtin__'
|
||||
else:
|
||||
built_in = 'builtins'
|
||||
|
||||
orig_import = __import__
|
||||
|
||||
def _import_mock(name, *args):
|
||||
if name == 'lsb_release':
|
||||
raise ImportError('No module named lsb_release')
|
||||
return orig_import(name, *args)
|
||||
|
||||
# Skip the first if statement
|
||||
with patch.object(salt.utils.platform, 'is_proxy',
|
||||
MagicMock(return_value=False)):
|
||||
# Skip the selinux/systemd stuff (not pertinent)
|
||||
with patch.object(core, '_linux_bin_exists',
|
||||
MagicMock(return_value=False)):
|
||||
# Skip the init grain compilation (not pertinent)
|
||||
with patch.object(os.path, 'exists', path_isfile_mock):
|
||||
# Ensure that lsb_release fails to import
|
||||
with patch('{0}.__import__'.format(built_in),
|
||||
side_effect=_import_mock):
|
||||
# Skip all the /etc/*-release stuff (not pertinent)
|
||||
with patch.object(os.path, 'isfile', path_isfile_mock):
|
||||
with patch.object(core, '_parse_os_release', os_release_mock):
|
||||
# Mock linux_distribution to give us the OS
|
||||
# name that we want.
|
||||
distro_mock = MagicMock(return_value=('Ubuntu', '16.04', 'xenial'))
|
||||
with patch('salt.utils.files.fopen', mock_open()) as suse_release_file:
|
||||
suse_release_file.return_value.__iter__.return_value = os_release_map.get(
|
||||
'suse_release_file', '').splitlines()
|
||||
with patch.object(core, 'linux_distribution', distro_mock):
|
||||
with patch.object(core, '_linux_gpu_data', empty_mock):
|
||||
with patch.object(core, '_linux_cpudata', empty_mock):
|
||||
with patch.object(core, '_virtual', empty_mock):
|
||||
# Mock the osarch
|
||||
with patch.dict(core.__salt__, {'cmd.run': osarch_mock}):
|
||||
os_grains = core.os_data()
|
||||
|
||||
self.assertEqual(os_grains.get('os'), 'Ubuntu')
|
||||
self.assertEqual(os_grains.get('os_family'), 'Debian')
|
||||
self.assertEqual(os_grains.get('osfullname'), os_release_map['osfullname'])
|
||||
self.assertEqual(os_grains.get('oscodename'), os_release_map['oscodename'])
|
||||
self.assertEqual(os_grains.get('osrelease'), os_release_map['osrelease'])
|
||||
self.assertListEqual(list(os_grains.get('osrelease_info')), os_release_map['osrelease_info'])
|
||||
self.assertEqual(os_grains.get('osmajorrelease'), os_release_map['osmajorrelease'])
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_ubuntu_artful_os_grains(self):
|
||||
'''
|
||||
Test if OS grains are parsed correctly in Ubuntu 17.10 "Artful Aardvark"
|
||||
'''
|
||||
_os_release_map = {
|
||||
'linux_distribution': ('Ubuntu', '17.10', 'artful'),
|
||||
}
|
||||
expectation = {
|
||||
'os': 'Ubuntu',
|
||||
'os_family': 'Debian',
|
||||
'oscodename': 'artful',
|
||||
'osfullname': 'Ubuntu',
|
||||
'osrelease': '17.10',
|
||||
'osrelease_info': (17, 10),
|
||||
'osmajorrelease': 17,
|
||||
'osfinger': 'Ubuntu-17.10',
|
||||
}
|
||||
self._run_os_grains_tests("ubuntu-17.10", _os_release_map, expectation)
|
||||
|
||||
def test_windows_iscsi_iqn_grains(self):
|
||||
cmd_run_mock = MagicMock(
|
||||
|
|
Loading…
Add table
Reference in a new issue