2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-05-14 17:18:36 +00:00
|
|
|
'''
|
|
|
|
Tests for the file state
|
|
|
|
'''
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
# Import Python libs
|
2017-12-15 18:14:18 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2016-08-10 20:04:56 +00:00
|
|
|
import errno
|
2015-04-07 02:31:13 +00:00
|
|
|
import os
|
|
|
|
import textwrap
|
2012-06-30 22:48:28 +00:00
|
|
|
import tempfile
|
2012-05-14 17:18:36 +00:00
|
|
|
|
2013-06-27 12:32:54 +00:00
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-03-07 12:49:17 +00:00
|
|
|
from tests.support.paths import TMP_STATE_TREE
|
2017-04-02 16:09:47 +00:00
|
|
|
from tests.support.mixins import SaltReturnAssertsMixin
|
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
# Import Salt libs
|
2017-07-18 16:31:01 +00:00
|
|
|
import salt.utils.files
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
import salt.utils.platform
|
2015-04-07 02:31:13 +00:00
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
IS_WINDOWS = salt.utils.platform.is_windows()
|
2013-06-24 19:06:49 +00:00
|
|
|
|
2012-05-29 16:40:20 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class CMDTest(ModuleCase, SaltReturnAssertsMixin):
|
2012-05-14 17:18:36 +00:00
|
|
|
'''
|
|
|
|
Validate the cmd state
|
|
|
|
'''
|
2015-04-07 02:31:13 +00:00
|
|
|
def test_run_simple(self):
|
2012-05-14 17:18:36 +00:00
|
|
|
'''
|
|
|
|
cmd.run
|
|
|
|
'''
|
2016-08-03 18:24:55 +00:00
|
|
|
cmd = 'dir' if IS_WINDOWS else 'ls'
|
|
|
|
ret = self.run_state('cmd.run', name=cmd, cwd=tempfile.gettempdir())
|
2012-11-21 12:43:53 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-05-14 17:18:36 +00:00
|
|
|
|
2015-04-07 02:31:13 +00:00
|
|
|
def test_test_run_simple(self):
|
2012-05-14 17:18:36 +00:00
|
|
|
'''
|
|
|
|
cmd.run test interface
|
|
|
|
'''
|
2012-06-30 22:48:28 +00:00
|
|
|
ret = self.run_state('cmd.run', name='ls',
|
|
|
|
cwd=tempfile.gettempdir(), test=True)
|
2012-11-21 12:43:53 +00:00
|
|
|
self.assertSaltNoneReturn(ret)
|
2012-07-20 06:21:01 +00:00
|
|
|
|
2017-12-05 22:07:30 +00:00
|
|
|
def test_run_hide_output(self):
|
|
|
|
'''
|
|
|
|
cmd.run with output hidden
|
|
|
|
'''
|
|
|
|
ret = self.run_state(
|
|
|
|
u'cmd.run',
|
|
|
|
name=u'ls',
|
|
|
|
hide_output=True)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
ret = ret[next(iter(ret))]
|
|
|
|
self.assertEqual(ret[u'changes'][u'stdout'], u'')
|
|
|
|
self.assertEqual(ret[u'changes'][u'stderr'], u'')
|
|
|
|
|
2016-05-09 17:06:44 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class CMDRunRedirectTest(ModuleCase, SaltReturnAssertsMixin):
|
2016-05-09 17:06:44 +00:00
|
|
|
'''
|
|
|
|
Validate the cmd state of run_redirect
|
|
|
|
'''
|
|
|
|
def setUp(self):
|
|
|
|
self.state_name = 'run_redirect'
|
|
|
|
state_filename = self.state_name + '.sls'
|
2017-03-07 12:49:17 +00:00
|
|
|
self.state_file = os.path.join(TMP_STATE_TREE, state_filename)
|
2016-05-09 17:06:44 +00:00
|
|
|
|
2016-08-10 22:09:38 +00:00
|
|
|
# Create the testfile and release the handle
|
2017-03-07 12:49:17 +00:00
|
|
|
fd, self.test_file = tempfile.mkstemp()
|
2016-08-10 20:04:56 +00:00
|
|
|
try:
|
2017-03-07 12:49:17 +00:00
|
|
|
os.close(fd)
|
|
|
|
except OSError as exc:
|
|
|
|
if exc.errno != errno.EBADF:
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
# Create the testfile and release the handle
|
|
|
|
fd, self.test_tmp_path = tempfile.mkstemp()
|
|
|
|
try:
|
|
|
|
os.close(fd)
|
2016-08-10 20:04:56 +00:00
|
|
|
except OSError as exc:
|
|
|
|
if exc.errno != errno.EBADF:
|
|
|
|
raise exc
|
2016-08-10 22:09:38 +00:00
|
|
|
|
2016-05-09 17:06:44 +00:00
|
|
|
super(CMDRunRedirectTest, self).setUp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
2017-03-07 12:49:17 +00:00
|
|
|
for path in (self.state_file, self.test_tmp_path, self.test_file):
|
|
|
|
try:
|
|
|
|
os.remove(path)
|
|
|
|
except OSError:
|
|
|
|
# Not all of the tests leave files around that we want to remove
|
|
|
|
# As some of the tests create the sls files in the test itself,
|
|
|
|
# And some are using files in the integration test file state tree.
|
|
|
|
pass
|
2016-05-09 17:06:44 +00:00
|
|
|
super(CMDRunRedirectTest, self).tearDown()
|
2015-04-07 02:31:13 +00:00
|
|
|
|
|
|
|
def test_run_unless(self):
|
|
|
|
'''
|
|
|
|
test cmd.run unless
|
|
|
|
'''
|
2017-03-07 12:49:17 +00:00
|
|
|
state_key = 'cmd_|-{0}_|-{0}_|-run'.format(self.test_tmp_path)
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(self.state_file, 'w') as fb_:
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
fb_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
|
2017-03-07 12:49:17 +00:00
|
|
|
{0}:
|
2016-08-10 22:09:38 +00:00
|
|
|
cmd.run:
|
2017-03-07 12:49:17 +00:00
|
|
|
- unless: echo cheese > {1}
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
'''.format(self.test_tmp_path, self.test_file))))
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', [self.state_name])
|
|
|
|
self.assertTrue(ret[state_key]['result'])
|
2015-04-07 02:31:13 +00:00
|
|
|
|
2016-08-18 17:01:32 +00:00
|
|
|
def test_run_unless_multiple_cmds(self):
|
|
|
|
'''
|
|
|
|
test cmd.run using multiple unless options where the first cmd in the
|
|
|
|
list will pass, but the second will fail. This tests the fix for issue
|
|
|
|
#35384. (The fix is in PR #35545.)
|
|
|
|
'''
|
|
|
|
sls = self.run_function('state.sls', mods='issue-35384')
|
|
|
|
self.assertSaltTrueReturn(sls)
|
|
|
|
# We must assert against the comment here to make sure the comment reads that the
|
|
|
|
# command "echo "hello"" was run. This ensures that we made it to the last unless
|
2017-10-25 14:55:24 +00:00
|
|
|
# command in the state. If the comment reads "unless condition is true", or similar,
|
2016-08-18 17:01:32 +00:00
|
|
|
# then the unless state run bailed out after the first unless command succeeded,
|
|
|
|
# which is the bug we're regression testing for.
|
|
|
|
self.assertEqual(sls['cmd_|-cmd_run_unless_multiple_|-echo "hello"_|-run']['comment'],
|
|
|
|
'Command "echo "hello"" run')
|
|
|
|
|
2015-04-07 02:31:13 +00:00
|
|
|
def test_run_creates_exists(self):
|
|
|
|
'''
|
|
|
|
test cmd.run creates already there
|
|
|
|
'''
|
2016-08-10 22:09:38 +00:00
|
|
|
state_key = 'cmd_|-echo >> {0}_|-echo >> {0}_|-run'.format(self.test_file)
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(self.state_file, 'w') as fb_:
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
fb_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
|
2016-08-10 22:09:38 +00:00
|
|
|
echo >> {0}:
|
|
|
|
cmd.run:
|
|
|
|
- creates: {0}
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
'''.format(self.test_file))))
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', [self.state_name])
|
|
|
|
self.assertTrue(ret[state_key]['result'])
|
|
|
|
self.assertEqual(len(ret[state_key]['changes']), 0)
|
2015-04-07 02:31:13 +00:00
|
|
|
|
|
|
|
def test_run_creates_new(self):
|
|
|
|
'''
|
|
|
|
test cmd.run creates not there
|
|
|
|
'''
|
2016-05-09 17:06:44 +00:00
|
|
|
os.remove(self.test_file)
|
2016-08-10 22:09:38 +00:00
|
|
|
state_key = 'cmd_|-echo >> {0}_|-echo >> {0}_|-run'.format(self.test_file)
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(self.state_file, 'w') as fb_:
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
fb_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
|
2016-08-10 22:09:38 +00:00
|
|
|
echo >> {0}:
|
|
|
|
cmd.run:
|
|
|
|
- creates: {0}
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
'''.format(self.test_file))))
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', [self.state_name])
|
|
|
|
self.assertTrue(ret[state_key]['result'])
|
|
|
|
self.assertEqual(len(ret[state_key]['changes']), 4)
|
|
|
|
|
|
|
|
def test_run_redirect(self):
|
|
|
|
'''
|
|
|
|
test cmd.run with shell redirect
|
|
|
|
'''
|
2016-08-10 22:09:38 +00:00
|
|
|
state_key = 'cmd_|-echo test > {0}_|-echo test > {0}_|-run'.format(self.test_file)
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(self.state_file, 'w') as fb_:
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
fb_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
|
2016-08-10 22:09:38 +00:00
|
|
|
echo test > {0}:
|
|
|
|
cmd.run
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
'''.format(self.test_file))))
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', [self.state_name])
|
|
|
|
self.assertTrue(ret[state_key]['result'])
|
|
|
|
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class CMDRunWatchTest(ModuleCase, SaltReturnAssertsMixin):
|
2016-05-09 17:06:44 +00:00
|
|
|
'''
|
|
|
|
Validate the cmd state of run_watch
|
|
|
|
'''
|
|
|
|
def setUp(self):
|
|
|
|
self.state_name = 'run_watch'
|
|
|
|
state_filename = self.state_name + '.sls'
|
2017-03-07 12:49:17 +00:00
|
|
|
self.state_file = os.path.join(TMP_STATE_TREE, state_filename)
|
2016-05-09 17:06:44 +00:00
|
|
|
super(CMDRunWatchTest, self).setUp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
os.remove(self.state_file)
|
|
|
|
super(CMDRunWatchTest, self).tearDown()
|
2015-04-07 02:31:13 +00:00
|
|
|
|
|
|
|
def test_run_watch(self):
|
|
|
|
'''
|
|
|
|
test cmd.run watch
|
|
|
|
'''
|
2016-08-10 22:09:38 +00:00
|
|
|
saltines_key = 'cmd_|-saltines_|-echo changed=true_|-run'
|
|
|
|
biscuits_key = 'cmd_|-biscuits_|-echo biscuits_|-wait'
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(self.state_file, 'w') as fb_:
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
fb_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
|
2016-08-10 22:09:38 +00:00
|
|
|
saltines:
|
|
|
|
cmd.run:
|
|
|
|
- name: echo changed=true
|
|
|
|
- cwd: /
|
|
|
|
- stateful: True
|
|
|
|
|
|
|
|
biscuits:
|
|
|
|
cmd.wait:
|
|
|
|
- name: echo biscuits
|
|
|
|
- cwd: /
|
|
|
|
- watch:
|
|
|
|
- cmd: saltines
|
Update file state/execution modules and associated files with unicode_literals
This updates the file state and execution modules to use
unicode_literals. Since the serializers and the cmd module are touched
by the file state/exec module, those are also updated here, as well as
the cmd state module, for good measure.
Additionally, I found that salt.utils.data.decode_dict (and decode_list)
are misnamed for what they actually do. Since they *encode* the
contents, the functions should be named encode_dict and encode_list,
respectively. And we also should have counterparts which actually
decode, so I've added them. The compatibility functions from salt.utils
still use the old "decode" names to preserve backward compatibility, but
they now invoke the renamed "encode" functions in salt.utils.data. Note
that this means that the compatibility functions
salt.utils.decode_dict/list, and their cognates in salt.utils.data now
do different things, but since the move to salt.utils.data is also
happening in the Oxygen release this is as good a time as any to correct
this oversight.
I've updated the jinja filter docs to include information on the renamed
jinja filters, and also added a section on jinja filter renaming to the
Oxygen release notes. There was another filter that I renamed during the
process of moving functions from salt.utils which I did not properly
document in the release notes, so this is now included along with the
others.
2017-12-12 16:30:33 +00:00
|
|
|
''')))
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
ret = self.run_function('state.sls', [self.state_name])
|
|
|
|
self.assertTrue(ret[saltines_key]['result'])
|
|
|
|
self.assertTrue(ret[biscuits_key]['result'])
|