Merge branch '2017.7' into jinja_test_fix

This commit is contained in:
Shane Lee 2018-04-16 10:15:27 -06:00 committed by GitHub
commit 673cd31c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 19 deletions

View File

@ -46,6 +46,7 @@ provisioner:
- .bundle
- .kitchen
- .kitchen.yml
- artifacts
- Gemfile
- Gemfile.lock
- README.rst

View File

@ -127,24 +127,24 @@ the following userdata example:
$SourceStoreScope = 'LocalMachine'
$SourceStorename = 'Remote Desktop'
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
$SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
$_.subject -like '*'
}
$DestStoreScope = 'LocalMachine'
$DestStoreName = 'My'
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$DestStore.Add($cert)
$SourceStore.Close()
$DestStore.Close()
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{Hostname=`"($certId)`"`;CertificateThumbprint=`"($cert.Thumbprint)`"`}
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{CertificateThumbprint=`"($cert.Thumbprint)`"`}
Restart-Service winrm
</powershell>

View File

@ -473,6 +473,7 @@ class LocalClient(object):
sub=3,
cli=False,
progress=False,
full_return=False,
**kwargs):
'''
Execute a command on a random subset of the targeted systems
@ -521,6 +522,7 @@ class LocalClient(object):
ret=ret,
kwarg=kwarg,
progress=progress,
full_return=full_return,
**kwargs)
def cmd_batch(

View File

@ -4571,7 +4571,7 @@ def _list_nodes(full=False):
pass
vms[name]['id'] = vm.find('ID').text
if vm.find('TEMPLATE').find('TEMPLATE_ID'):
if 'TEMPLATE_ID' in vm.find('TEMPLATE'):
vms[name]['image'] = vm.find('TEMPLATE').find('TEMPLATE_ID').text
vms[name]['name'] = name
vms[name]['size'] = {'cpu': cpu_size, 'memory': memory_size}

View File

@ -10,24 +10,24 @@ winrm set winrm/config/service/auth '@{Basic="true"}'
$SourceStoreScope = 'LocalMachine'
$SourceStorename = 'Remote Desktop'
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
$SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
$_.subject -like '*'
}
$DestStoreScope = 'LocalMachine'
$DestStoreName = 'My'
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$DestStore.Add($cert)
$SourceStore.Close()
$DestStore.Close()
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{Hostname=`"($certId)`"`;CertificateThumbprint=`"($cert.Thumbprint)`"`}
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{CertificateThumbprint=`"($cert.Thumbprint)`"`}
Restart-Service winrm
</powershell>

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.paths import TMP
from tests.support.paths import TMP, FILES
from tests.support.mixins import SaltReturnAssertsMixin
# Import salt libs
@ -23,6 +23,37 @@ from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
import salt.ext.six as six
DEFAULT_ENDING = salt.utils.to_bytes(os.linesep)
def trim_line_end(line):
'''
Remove CRLF or LF from the end of line.
'''
if line[-2:] == salt.utils.to_bytes('\r\n'):
return line[:-2]
elif line[-1:] == salt.utils.to_bytes('\n'):
return line[:-1]
raise Exception("Invalid line ending")
def reline(source, dest, force=False, ending=DEFAULT_ENDING):
'''
Normalize the line endings of a file.
'''
fp, tmp = tempfile.mkstemp()
os.close(fp)
with salt.utils.fopen(tmp, 'wb') as tmp_fd:
with salt.utils.fopen(source, 'rb') as fd:
lines = fd.readlines()
for line in lines:
line_noend = trim_line_end(line)
tmp_fd.write(line_noend + ending)
if os.path.exists(dest) and force:
os.remove(dest)
os.rename(tmp, dest)
class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
'''
Validate the state module
@ -30,6 +61,13 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
maxDiff = None
def setUp(self):
super(StateModuleTest, self).setUp()
destpath = os.path.join(FILES, 'file', 'base', 'testappend', 'firstif')
reline(destpath, destpath, force=True)
destpath = os.path.join(FILES, 'file', 'base', 'testappend', 'secondif')
reline(destpath, destpath, force=True)
def test_show_highstate(self):
'''
state.show_highstate

View File

@ -122,7 +122,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
self.assertIn('minion', data)
'''
arg_str = '-c {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr)
return self.run_script('salt', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr, timeout=timeout)
def run_ssh(self, arg_str, with_retcode=False, timeout=25,
catch_stderr=False, wipe=False, raw=False):

View File

@ -57,6 +57,14 @@ class RootsTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMix
cls.test_symlink_list_file_roots = {'base': [root_dir]}
else:
cls.test_symlink_list_file_roots = None
cls.tmp_dir = tempfile.mkdtemp(dir=TMP)
full_path_to_file = os.path.join(FILES, 'file', 'base', 'testfile')
with salt.utils.fopen(full_path_to_file, 'rb') as s_fp:
with salt.utils.fopen(os.path.join(cls.tmp_dir, 'testfile'), 'wb') as d_fp:
for line in s_fp:
d_fp.write(
line.rstrip(b'\n').rstrip(b'\r') + os.linesep.encode('utf-8')
)
@classmethod
def tearDownClass(cls):
@ -68,6 +76,7 @@ class RootsTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMix
salt.utils.rm_rf(cls.test_symlink_list_file_roots['base'][0])
except OSError:
pass
salt.utils.rm_rf(cls.tmp_dir)
def tearDown(self):
del self.opts
@ -86,10 +95,10 @@ class RootsTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMix
def test_serve_file(self):
with patch.dict(roots.__opts__, {'file_buffer_size': 262144}):
load = {'saltenv': 'base',
'path': os.path.join(FILES, 'file', 'base', 'testfile'),
'path': os.path.join(self.tmp_dir, 'testfile'),
'loc': 0
}
fnd = {'path': os.path.join(FILES, 'file', 'base', 'testfile'),
fnd = {'path': os.path.join(self.tmp_dir, 'testfile'),
'rel': 'testfile'}
ret = roots.serve_file(load, fnd)
@ -134,10 +143,10 @@ class RootsTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMix
def test_file_hash(self):
load = {
'saltenv': 'base',
'path': os.path.join(FILES, 'file', 'base', 'testfile'),
'path': os.path.join(self.tmp_dir, 'testfile'),
}
fnd = {
'path': os.path.join(FILES, 'file', 'base', 'testfile'),
'path': os.path.join(self.tmp_dir, 'testfile'),
'rel': 'testfile'
}
ret = roots.file_hash(load, fnd)

View File

@ -54,20 +54,30 @@ class LocalClientTestCase(TestCase,
self.client.cmd_subset('*', 'first.func', sub=1, cli=True)
try:
cmd_cli_mock.assert_called_with(['minion2'], 'first.func', (), progress=False,
kwarg=None, tgt_type='list',
kwarg=None, tgt_type='list', full_return=False,
ret='')
except AssertionError:
cmd_cli_mock.assert_called_with(['minion1'], 'first.func', (), progress=False,
kwarg=None, tgt_type='list',
kwarg=None, tgt_type='list', full_return=False,
ret='')
self.client.cmd_subset('*', 'first.func', sub=10, cli=True)
try:
cmd_cli_mock.assert_called_with(['minion2', 'minion1'], 'first.func', (), progress=False,
kwarg=None, tgt_type='list',
kwarg=None, tgt_type='list', full_return=False,
ret='')
except AssertionError:
cmd_cli_mock.assert_called_with(['minion1', 'minion2'], 'first.func', (), progress=False,
kwarg=None, tgt_type='list',
kwarg=None, tgt_type='list', full_return=False,
ret='')
ret = self.client.cmd_subset('*', 'first.func', sub=1, cli=True, full_return=True)
try:
cmd_cli_mock.assert_called_with(['minion2'], 'first.func', (), progress=False,
kwarg=None, tgt_type='list', full_return=True,
ret='')
except AssertionError:
cmd_cli_mock.assert_called_with(['minion1'], 'first.func', (), progress=False,
kwarg=None, tgt_type='list', full_return=True,
ret='')
@skipIf(salt.utils.is_windows(), 'Not supported on Windows')