Merge branch 'master' into fix_win_network_type

This commit is contained in:
Wayne Werner 2020-03-11 11:08:10 -06:00 committed by GitHub
commit 18a31a0b22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 842 additions and 436 deletions

View file

@ -96,10 +96,11 @@ include option.
slspath
=======
The `slspath` variable contains the path to the current sls file. The value
of `slspath` in files referenced in the current sls depends on the reference
method. For jinja includes `slspath` is the path to the current file. For
salt includes `slspath` is the path to the included file.
The `slspath` variable contains the path to the directory of the current sls
file. The value of `slspath` in files referenced in the current sls depends on
the reference method. For jinja includes `slspath` is the path to the current
directory of the file. For salt includes `slspath` is the path to the directory
of the included file.
.. code-block:: jinja

File diff suppressed because it is too large Load diff

View file

@ -239,28 +239,16 @@ def _parse_rules(sg, rules):
def get_all_security_groups(groupnames=None, group_ids=None, filters=None,
region=None, key=None, keyid=None, profile=None):
'''
Return a list of all Security Groups matching the given criteria and filters.
Return a list of all Security Groups matching the given criteria and
filters.
Note that the 'groupnames' argument only functions correctly for EC2 Classic
and default VPC Security Groups. To find groups by name in other VPCs you'll
want to use the 'group-name' filter instead.
Note that the ``groupnames`` argument only functions correctly for EC2
Classic and default VPC Security Groups. To find groups by name in other
VPCs you'll want to use the ``group-name`` filter instead.
Valid keys for the filters argument are:
description - The description of the security group.
egress.ip-permission.prefix-list-id - The ID (prefix) of the AWS service to which the security group allows access.
group-id - The ID of the security group.
group-name - The name of the security group.
ip-permission.cidr - A CIDR range that has been granted permission.
ip-permission.from-port - The start of port range for the TCP and UDP protocols, or an ICMP type number.
ip-permission.group-id - The ID of a security group that has been granted permission.
ip-permission.group-name - The name of a security group that has been granted permission.
ip-permission.protocol - The IP protocol for the permission (tcp | udp | icmp or a protocol number).
ip-permission.to-port - The end of port range for the TCP and UDP protocols, or an ICMP code.
ip-permission.user-id - The ID of an AWS account that has been granted permission.
owner-id - The AWS account ID of the owner of the security group.
tag-key - The key of a tag assigned to the security group.
tag-value - The value of a tag assigned to the security group.
vpc-id - The ID of the VPC specified when the security group was created.
The valid keys for the ``filters`` argument can be found in `AWS's API
documentation
<https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html>`_.
CLI example::
@ -590,7 +578,7 @@ def set_tags(tags,
keyid=None,
profile=None):
'''
sets tags on a security group
Sets tags on a security group.
.. versionadded:: 2016.3.0
@ -654,7 +642,7 @@ def delete_tags(tags,
keyid=None,
profile=None):
'''
deletes tags from a security group
Deletes tags from a security group.
.. versionadded:: 2016.3.0

View file

@ -487,7 +487,7 @@ def running(name,
time.sleep(init_delay)
# only force a change state if we have explicitly detected them
after_toggle_status = __salt__['service.status'](name, sig, **kwargs)
after_toggle_status = __salt__['service.status'](name, sig, **status_kwargs)
if 'service.enabled' in __salt__:
after_toggle_enable_status = __salt__['service.enabled'](name)
else:

View file

@ -122,6 +122,8 @@ def wrap_tmpl_func(render_str):
slspath = context['sls'].replace('.', '/')
if tmplpath is not None:
context['tplpath'] = tmplpath
if not tmplpath.lower().replace('\\', '/').endswith('/init.sls'):
slspath = os.path.dirname(slspath)
template = tmplpath.replace('\\', '/')
i = template.rfind(slspath.replace('.', '/'))
if i != -1:

View file

@ -7,14 +7,15 @@
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing Libs
from tests.support.helpers import destructiveTest
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase
from tests.support.mock import (
MagicMock,
patch,
)
from tests.support.unit import TestCase, skipIf
from tests.support.mock import MagicMock, patch
# Import Salt Libs
import salt.utils.platform
import salt.config
import salt.loader
import salt.states.service as service
@ -251,3 +252,71 @@ class ServiceTestCase(TestCase, LoaderModuleMockMixin):
ret[3])
self.assertDictEqual(service.mod_watch("salt", "stack"), ret[1])
@destructiveTest
@skipIf(salt.utils.platform.is_darwin(), "service.running is currently failing on OSX")
class ServiceTestCaseFunctional(TestCase, LoaderModuleMockMixin):
'''
Validate the service state
'''
def setup_loader_modules(self):
self.opts = salt.config.DEFAULT_MINION_OPTS.copy()
self.opts['grains'] = salt.loader.grains(self.opts)
self.utils = salt.loader.utils(self.opts)
self.modules = salt.loader.minion_mods(self.opts, utils=self.utils)
self.service_name = 'cron'
cmd_name = 'crontab'
os_family = self.opts['grains']['os_family']
os_release = self.opts['grains']['osrelease']
if os_family == 'RedHat':
self.service_name = 'crond'
elif os_family == 'Arch':
self.service_name = 'sshd'
cmd_name = 'systemctl'
elif os_family == 'MacOS':
self.service_name = 'org.ntp.ntpd'
if int(os_release.split('.')[1]) >= 13:
self.service_name = 'com.openssh.sshd'
elif os_family == 'Windows':
self.service_name = 'Spooler'
if os_family != 'Windows' and salt.utils.path.which(cmd_name) is None:
self.skipTest('{0} is not installed'.format(cmd_name))
return {
service: {
'__grains__': self.opts['grains'],
'__opts__': self.opts,
'__salt__': self.modules,
'__utils__': self.utils,
},
}
def setUp(self):
self.pre_srv_enabled = True if self.service_name in self.modules['service.get_enabled']() else False
self.post_srv_disable = False
if not self.pre_srv_enabled:
self.modules['service.enable'](self.service_name)
self.post_srv_disable = True
def tearDown(self):
if self.post_srv_disable:
self.modules['service.disable'](self.service_name)
def test_running_with_reload(self):
with patch.dict(service.__opts__, {'test': False}):
service.dead(self.service_name, enable=False)
result = service.running(name=self.service_name, enable=True, reload=False)
expected = {
'changes': {
self.service_name: True
},
'comment': 'Service {0} has been enabled, and is '
'running'.format(self.service_name),
'name': self.service_name,
'result': True
}
self.assertDictEqual(result, expected)

View file

@ -5,13 +5,16 @@ Unit tests for salt.utils.templates.py
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import os
import sys
import logging
# Import Salt libs
import salt.utils.templates
import salt.utils.files
# Import Salt Testing Libs
from tests.support.helpers import with_tempdir
from tests.support.unit import TestCase, skipIf
log = logging.getLogger(__name__)
@ -181,3 +184,46 @@ class RenderTestCase(TestCase):
ctx['var'] = 'OK'
res = salt.utils.templates.render_cheetah_tmpl(tmpl, ctx)
self.assertEqual(res.strip(), 'OK')
class MockRender(object):
def __call__(self, tplstr, context, tmplpath=None):
self.tplstr = tplstr
self.context = context
self.tmplpath = tmplpath
return tplstr
class WrapRenderTestCase(TestCase):
@with_tempdir()
def test_wrap_issue_56119_a(self, tempdir):
slsfile = os.path.join(tempdir, 'foo')
with salt.utils.files.fopen(slsfile, 'w') as fp:
fp.write('{{ slspath }}')
context = {'opts': {}, 'saltenv': 'base', 'sls': 'foo.bar'}
render = MockRender()
wrapped = salt.utils.templates.wrap_tmpl_func(render)
res = wrapped(
slsfile,
context=context,
tmplpath='/tmp/foo/bar/init.sls'
)
assert render.context['slspath'] == 'foo/bar', render.context['slspath']
assert render.context['tpldir'] == 'foo/bar', render.context['tpldir']
@with_tempdir()
def test_wrap_issue_56119_b(self, tempdir):
slsfile = os.path.join(tempdir, 'foo')
with salt.utils.files.fopen(slsfile, 'w') as fp:
fp.write('{{ slspath }}')
context = {'opts': {}, 'saltenv': 'base', 'sls': 'foo.bar.bang'}
render = MockRender()
wrapped = salt.utils.templates.wrap_tmpl_func(render)
res = wrapped(
slsfile,
context=context,
tmplpath='/tmp/foo/bar/bang.sls'
)
assert render.context['slspath'] == 'foo/bar', render.context['slspath']
assert render.context['tpldir'] == 'foo/bar', render.context['tpldir']