Merge branch '2018.3' into add_whitelist

This commit is contained in:
Daniel Wozniak 2018-09-16 10:49:21 -06:00 committed by GitHub
commit 2e1bf1335a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 79 additions and 34 deletions

View file

@ -1 +0,0 @@
144bf0d6aa27b4af01df0b7b734c39962649e1711554247d42e05e14d8945742b18745aefdba162e2dfc762b941fd7d3b2d5dc6a781ae4ba10a6f5a3cadb0687 ./openssl-1.0.2n.tar.gz

View file

@ -13,8 +13,8 @@ To enable these grains set `iscsi_grains: True`.
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import errno
import logging
import os
# Import Salt libs
import salt.modules.cmdmod
@ -64,7 +64,7 @@ def _linux_iqn():
if line.startswith('InitiatorName='):
ret.append(line.split('=', 1)[1])
except IOError as ex:
if ex.errno != os.errno.ENOENT:
if ex.errno != errno.ENOENT:
log.debug("Error while accessing '%s': %s", initiator, ex)
return ret

View file

@ -25,6 +25,9 @@ from salt.utils.odict import OrderedDict
# Import 3rd-party libs
from salt.ext import six
import logging
log = logging.getLogger(__name__)
__virtualname__ = 'ini'
@ -432,11 +435,14 @@ class _Ini(_Section):
# the ini file).
super(_Ini, self).refresh(inicontents.pop())
for section_name, sect_ini in self._gen_tuples(inicontents):
sect_obj = _Section(
section_name, sect_ini, separator=self.sep
)
sect_obj.refresh()
self.update({sect_obj.name: sect_obj})
try:
sect_obj = _Section(
section_name, sect_ini, separator=self.sep
)
sect_obj.refresh()
self.update({sect_obj.name: sect_obj})
except StopIteration:
pass
def flush(self):
try:
@ -463,6 +469,6 @@ class _Ini(_Section):
key = list_object.pop()
value = list_object.pop()
except IndexError:
raise StopIteration
return
else:
yield key, value

View file

@ -1140,7 +1140,7 @@ def convert_cidr(cidr):
ret = {'network': None,
'netmask': None}
cidr = calc_net(cidr)
network_info = salt.ext.ipaddress.ip_network(cidr)
network_info = ipaddress.ip_network(cidr)
ret['network'] = six.text_type(network_info.network_address)
ret['netmask'] = six.text_type(network_info.netmask)
return ret

View file

@ -12,7 +12,7 @@ import time
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, flaky
log = logging.getLogger(__name__)
@ -182,6 +182,7 @@ class GrainsAppendTestCase(ModuleCase):
assert msg == ret
@flaky
def test_grains_append_val_is_list(self):
'''
Tests the return of a grains.append call when val is passed in as a list.

View file

@ -24,7 +24,7 @@ class ReactorTest(ModuleCase, SaltMinionEventAssertsMixin):
Test Salt's reactor system
'''
@flaky()
@flaky
def test_ping_reaction(self):
'''
Fire an event on the master and ensure

View file

@ -367,6 +367,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
if os.path.isdir(config_dir):
shutil.rmtree(config_dir)
@skipIf(True, 'This test is unreliable. Need to investigate why more deeply.')
@flaky
def test_issue_15074_output_file_append(self):
output_file_append = os.path.join(TMP, 'issue-15074')
@ -400,6 +401,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
if os.path.exists(output_file_append):
os.unlink(output_file_append)
@skipIf(True, 'This test is unreliable. Need to investigate why more deeply.')
@flaky
def test_issue_14979_output_file_permissions(self):
output_file = os.path.join(TMP, 'issue-14979')

View file

@ -11,6 +11,7 @@ from tests.support.case import ShellCase
from tests.support.helpers import flaky
from tests.support.mixins import ShellCaseCommonTestsMixin
from tests.support.paths import TMP
from tests.support.unit import skipIf
# Import salt libs
import salt.utils.files
@ -92,12 +93,14 @@ class MatchTest(ShellCase, ShellCaseCommonTestsMixin):
assert minion_in_returns('minion', data) is True
assert minion_in_returns('sub_minion', data) is True
@skipIf(True, 'This test is unreliable. Need to investigate why more deeply.')
@flaky
def test_compound_pillar(self):
data = self.run_salt("-C 'I%@companions%three%sarah*' test.ping")
assert minion_in_returns('minion', data) is True
assert minion_in_returns('sub_minion', data) is True
@skipIf(True, 'This test is unreliable. Need to investigate why more deeply.')
@flaky
def test_coumpound_pillar_pcre(self):
data = self.run_salt("-C 'J%@knights%^(Lancelot|Galahad)$' test.ping")

View file

@ -153,7 +153,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
try:
os.remove(path)
except OSError as exc:
if exc.errno != os.errno.ENOENT:
if exc.errno != errno.ENOENT:
log.error('Failed to remove %s: %s', path, exc)
def test_symlink(self):
@ -830,6 +830,13 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
initial_mode = '0111'
changed_mode = '0555'
initial_modes = {0: {sub: '0755',
subsub: '0111'},
1: {sub: '0111',
subsub: '0111'},
2: {sub: '0111',
subsub: '0111'}}
if not os.path.isdir(subsub):
os.makedirs(subsub, int(initial_mode, 8))
@ -845,8 +852,16 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
self.assertEqual(changed_mode,
_get_oct_mode(changed_dir))
for untouched_dir in dirs[depth+1:]:
self.assertEqual(initial_mode,
_get_oct_mode(untouched_dir))
# Beginning in Python 3.7, os.makedirs no longer sets
# the mode of intermediate directories to the mode that
# is passed.
if sys.version_info >= (3, 7):
_mode = initial_modes[depth][untouched_dir]
self.assertEqual(_mode,
_get_oct_mode(untouched_dir))
else:
self.assertEqual(initial_mode,
_get_oct_mode(untouched_dir))
finally:
shutil.rmtree(top)
@ -2269,7 +2284,9 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
if salt.utils.platform.is_windows():
import subprocess
import win32api
p = subprocess.Popen(salt.utils.stringutils.to_str('type {}'.format(win32api.GetShortPathName(test_file))),
p = subprocess.Popen(
salt.utils.stringutils.to_str(
'type {}'.format(win32api.GetShortPathName(test_file))),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.poll()
out = p.stdout.read()

View file

@ -338,6 +338,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
@destructiveTest
@skip_if_not_root
@skipIf(salt.utils.platform.is_darwin(), 'Test is flaky on macosx')
@skipIf(not CAN_RUNAS, 'Runas support required')
@with_system_user('issue-6912', on_existing='delete', delete=True,
password='PassWord1!')

View file

@ -28,6 +28,7 @@ from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
@skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
class VirtualenvTest(ModuleCase, SaltReturnAssertsMixin):
@skipIf(salt.utils.platform.is_darwin(), 'Test is flaky on macosx')
@destructiveTest
@skip_if_not_root
def test_issue_1959_virtualenv_runas(self):

View file

@ -5,7 +5,7 @@ unit tests for the localfs cache
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import os
import errno
import shutil
import tempfile
@ -53,7 +53,7 @@ class LocalFSTest(TestCase, LoaderModuleMockMixin):
Tests that a SaltCacheError is raised when the base directory doesn't exist and
cannot be created.
'''
with patch('os.makedirs', MagicMock(side_effect=OSError(os.errno.EEXIST, ''))):
with patch('os.makedirs', MagicMock(side_effect=OSError(errno.EEXIST, ''))):
with patch('tempfile.mkstemp', MagicMock(side_effect=Exception)):
self.assertRaises(Exception, localfs.store, bank='', key='', data='', cachedir='')
@ -73,7 +73,7 @@ class LocalFSTest(TestCase, LoaderModuleMockMixin):
This test mocks the call to mkstemp, but forces an OSError to be raised when the
close() function is called on a file descriptor that doesn't exist.
'''
with patch('os.makedirs', MagicMock(side_effect=OSError(os.errno.EEXIST, ''))):
with patch('os.makedirs', MagicMock(side_effect=OSError(errno.EEXIST, ''))):
with patch('tempfile.mkstemp', MagicMock(return_value=(12345, 'foo'))):
self.assertRaises(OSError, localfs.store, bank='', key='', data='', cachedir='')
@ -82,7 +82,7 @@ class LocalFSTest(TestCase, LoaderModuleMockMixin):
Tests that a SaltCacheError is raised when there is a problem writing to the
cache file.
'''
with patch('os.makedirs', MagicMock(side_effect=OSError(os.errno.EEXIST, ''))):
with patch('os.makedirs', MagicMock(side_effect=OSError(errno.EEXIST, ''))):
with patch('tempfile.mkstemp', MagicMock(return_value=('one', 'two'))):
with patch('os.close', MagicMock(return_value=None)):
with patch('salt.utils.files.fopen', MagicMock(side_effect=IOError)):

View file

@ -4,7 +4,7 @@
'''
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import os
import errno
import textwrap
# Import Salt Testing Libs
@ -68,7 +68,7 @@ class IscsiGrainsTestCase(TestCase):
assert len(iqn) == 1
assert iqn == ['iqn.1993-08.org.debian:01:d12f7aba36']
@patch('salt.utils.files.fopen', MagicMock(side_effect=IOError(os.errno.EPERM,
@patch('salt.utils.files.fopen', MagicMock(side_effect=IOError(errno.EPERM,
'The cables are not the same length.')))
@patch('salt.grains.iscsi.log', MagicMock())
def test_linux_iqn_non_root(self):
@ -81,10 +81,10 @@ class IscsiGrainsTestCase(TestCase):
iscsi.log.debug.assert_called()
assert 'Error while accessing' in iscsi.log.debug.call_args[0][0]
assert 'cables are not the same' in iscsi.log.debug.call_args[0][2].strerror
assert iscsi.log.debug.call_args[0][2].errno == os.errno.EPERM
assert iscsi.log.debug.call_args[0][2].errno == errno.EPERM
assert iscsi.log.debug.call_args[0][1] == '/etc/iscsi/initiatorname.iscsi'
@patch('salt.utils.files.fopen', MagicMock(side_effect=IOError(os.errno.ENOENT, '')))
@patch('salt.utils.files.fopen', MagicMock(side_effect=IOError(errno.ENOENT, '')))
@patch('salt.grains.iscsi.log', MagicMock())
def test_linux_iqn_no_iscsii_initiator(self):
'''

View file

@ -6,6 +6,8 @@
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import sys
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
@ -32,12 +34,17 @@ class GenesisTestCase(TestCase, LoaderModuleMockMixin):
'''
Test for Create an image for a specific platform.
'''
# Changed in 3.7.0 pformat no longer includes the comma
if sys.version_info >= (3, 7):
exception_string = 'Exception({0})'.format(repr('foo'))
else:
exception_string = 'Exception({0},)'.format(repr('foo'))
mock = MagicMock(return_value=False)
with patch.dict(genesis.__salt__, {'file.directory_exists': mock}):
mock = MagicMock(side_effect=Exception('foo'))
with patch.dict(genesis.__salt__, {'file.mkdir': mock}):
self.assertEqual(genesis.bootstrap('platform', 'root'),
{'Error': 'Exception({0},)'.format(repr('foo'))})
{'Error': exception_string})
with patch.object(genesis, '_bootstrap_yum', return_value='A'):
with patch.dict(genesis.__salt__, {'mount.umount': MagicMock(),

View file

@ -5,6 +5,7 @@
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import errno
import os
# Import Salt Testing Libs
@ -140,7 +141,7 @@ class PuppetTestCase(TestCase, LoaderModuleMockMixin):
mock_open(read_data="resources: 1")):
self.assertDictEqual(puppet.summary(), {'resources': 1})
permission_error = IOError(os.errno.EACCES, 'Permission denied:', '/file')
permission_error = IOError(errno.EACCES, 'Permission denied:', '/file')
with patch('salt.utils.files.fopen',
mock_open(read_data=permission_error)) as m_open:
self.assertRaises(CommandExecutionError, puppet.summary)

View file

@ -102,7 +102,7 @@ class TestSerializers(TestCase):
@skipIf(not yaml.available, SKIP_MESSAGE % 'yaml')
@skipIf(not yamlex.available, SKIP_MESSAGE % 'sls')
@flaky
@skipIf(six.PY3, 'Flaky on Python 3.')
def test_compare_sls_vs_yaml_with_jinja(self):
tpl = '{{ data }}'
env = jinja2.Environment()

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import re
import sys
import textwrap
# Import Salt libs
@ -105,12 +105,6 @@ class TestBuildWhitespaceRegex(TestCase):
regex = salt.utils.stringutils.build_whitespace_split_regex(SINGLE_DOUBLE_SAME_LINE_TXT)
self.assertTrue(re.search(regex, MATCH))
def test_build_whitespace_split_regex(self):
expected_regex = '(?m)^(?:[\\s]+)?Lorem(?:[\\s]+)?ipsum(?:[\\s]+)?dolor(?:[\\s]+)?sit(?:[\\s]+)?amet\\,' \
'(?:[\\s]+)?$'
ret = salt.utils.stringutils.build_whitespace_split_regex(' '.join(LOREM_IPSUM.split()[:5]))
self.assertEqual(ret, expected_regex)
class StringutilsTestCase(TestCase):
def test_contains_whitespace(self):
@ -254,6 +248,19 @@ class StringutilsTestCase(TestCase):
result = salt.utils.stringutils.to_unicode(LATIN1_BYTES, encoding=('utf-8', 'latin1'))
assert result == LATIN1_UNICODE
def test_build_whitespace_split_regex(self):
# With 3.7+, re.escape only escapes special characters, no longer
# escaping all characters other than ASCII letters, numbers and
# underscores. This includes commas.
if sys.version_info >= (3, 7):
expected_regex = '(?m)^(?:[\\s]+)?Lorem(?:[\\s]+)?ipsum(?:[\\s]+)?dolor(?:[\\s]+)?sit(?:[\\s]+)?amet,' \
'(?:[\\s]+)?$'
else:
expected_regex = '(?m)^(?:[\\s]+)?Lorem(?:[\\s]+)?ipsum(?:[\\s]+)?dolor(?:[\\s]+)?sit(?:[\\s]+)?amet\\,' \
'(?:[\\s]+)?$'
ret = salt.utils.stringutils.build_whitespace_split_regex(' '.join(LOREM_IPSUM.split()[:5]))
self.assertEqual(ret, expected_regex)
def test_get_context(self):
expected_context = textwrap.dedent('''\
---