Merge branch '2017.7' into '2018.3'

Conflicts:
  - salt/modules/file.py
  - salt/modules/reg.py
  - salt/states/reg.py
  - tests/integration/states/test_file.py
This commit is contained in:
rallytime 2018-08-14 09:48:13 -04:00
commit 49c2a784bb
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19
5 changed files with 91 additions and 25 deletions

View file

@ -2290,7 +2290,7 @@ def replace(path,
if prepend_if_not_found or append_if_not_found:
# Search for content, to avoid pre/appending the
# content if it was pre/appended in a previous run.
if re.search(salt.utils.stringutils.to_bytes('^{0}$'.format(re.escape(content))),
if re.search(salt.utils.stringutils.to_bytes('^{0}($|(?=\r\n))'.format(re.escape(content))),
r_data,
flags=flags_num):
# Content was found, so set found.
@ -4072,7 +4072,10 @@ def get_managed(
# If we have a source defined, let's figure out what the hash is
if source:
urlparsed_source = _urlparse(source)
parsed_scheme = urlparsed_source.scheme
if urlparsed_source.scheme in salt.utils.files.VALID_PROTOS:
parsed_scheme = urlparsed_source.scheme
else:
parsed_scheme = ''
parsed_path = os.path.join(
urlparsed_source.netloc, urlparsed_source.path).rstrip(os.sep)
unix_local_source = parsed_scheme in ('file', '')

View file

@ -16,6 +16,18 @@ Keys
Keys are the folders in the registry. Keys can have many nested subkeys. Keys
can have a value assigned to them under the (Default)
When passing a key on the CLI it must be quoted correctly depending on the
backslashes being used (``\`` vs ``\\``). The following are valid methods of
passing the the key on the CLI:
Using single backslashes:
``"SOFTWARE\Python"``
``'SOFTWARE\Python'`` (will not work on a Windows Master)
Using double backslashes:
``SOFTWARE\\Python``
-----------------
Values or Entries
-----------------
@ -169,7 +181,7 @@ def list_keys(hive, key=None, use_32bit_registry=False):
def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
'''
r'''
Enumerates the values in a registry key or hive.
Args:
@ -397,7 +409,7 @@ def set_value(hive,
def delete_key_recursive(hive, key, use_32bit_registry=False):
'''
r'''
.. versionadded:: 2015.5.4
Delete a registry key to include all subkeys and value/data pairs.
@ -439,7 +451,7 @@ def delete_key_recursive(hive, key, use_32bit_registry=False):
def delete_value(hive, key, vname=None, use_32bit_registry=False):
'''
r'''
Delete a registry value entry or the default value for a key.
Args:
@ -464,7 +476,7 @@ def delete_value(hive, key, vname=None, use_32bit_registry=False):
Deletes the 32bit portion of the registry on 64bit installations. On
32bit machines this is ignored.
Return:
Returns:
bool: True if successful, otherwise False
CLI Example:

View file

@ -193,17 +193,29 @@ def uptime(human_readable=False):
'''
.. versionadded:: 2015.8.0
Return the system uptime for this machine in seconds
Return the system uptime for the machine
human_readable : False
If ``True``, then return uptime in years, days, and seconds.
Args:
human_readable (bool):
Return uptime in human readable format if ``True``, otherwise
return seconds. Default is ``False``
.. note::
Human readable format is ``days, hours:min:sec``. Days will only
be displayed if more than 0
Returns:
str:
The uptime in seconds or human readable format depending on the
value of ``human_readable``
CLI Example:
.. code-block:: bash
salt '*' status.uptime
salt '*' status.uptime human_readable=True
salt '*' status.uptime
salt '*' status.uptime human_readable=True
'''
# Get startup time
startup_time = datetime.datetime.fromtimestamp(psutil.boot_time())

View file

@ -24,6 +24,18 @@ Keys
Hives contain keys. These are basically the folders beneath the hives. They can
contain any number of subkeys.
When passing the hive\key values they must be quoted correctly depending on the
backslashes being used (``\`` vs ``\\``). The way backslashes are handled in
the state file is different from the way they are handled when working on the
CLI. The following are valid methods of passing the hive\key:
Using single backslashes:
HKLM\SOFTWARE\Python
'HKLM\SOFTWARE\Python'
Using double backslashes:
"HKLM\\SOFTWARE\\Python"
Values or Entries
-----------------
@ -294,7 +306,7 @@ def present(name,
def absent(name, vname=None, use_32bit_registry=False):
'''
r'''
Ensure a registry value is removed. To remove a key use key_absent.
Args:

View file

@ -363,7 +363,11 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
with salt.utils.files.fopen(grain_path, 'r') as fp_:
file_contents = fp_.readlines()
self.assertTrue(re.match('^minion$', file_contents[0]))
if salt.utils.is_windows():
match = '^minion\r\n'
else:
match = '^minion\n'
self.assertTrue(re.match(match, file_contents[0]))
def test_managed_file_with_pillar_sls(self):
'''
@ -588,6 +592,9 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
name = os.path.join(TMP, 'local_source_with_source_hash')
local_path = os.path.join(BASE_FILES, 'grail', 'scene33')
actual_hash = '567fd840bf1548edc35c48eb66cdd78bfdfcccff'
if salt.utils.is_windows():
# CRLF vs LF causes a differnt hash on windows
actual_hash = 'f658a0ec121d9c17088795afcc6ff3c43cb9842a'
# Reverse the actual hash
bad_hash = actual_hash[::-1]
@ -670,6 +677,9 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
'-{0}_|-managed'.format(name)
local_path = os.path.join(BASE_FILES, 'hello_world.txt')
actual_hash = 'c98c24b677eff44860afea6f493bbaec5bb1c4cbb209c6fc2bbb47f66ff2ad31'
if salt.utils.is_windows():
# CRLF vs LF causes a differnt hash on windows
actual_hash = '92b772380a3f8e27a93e57e6deeca6c01da07f5aadce78bb2fbb20de10a66925'
uppercase_hash = actual_hash.upper()
try:
@ -851,10 +861,14 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
self.assertFalse(os.path.exists(straydir))
self.assertTrue(os.path.isdir(name))
@skipIf(salt.utils.platform.is_windows(), 'Skip on windows')
@with_tempdir()
def test_directory_clean_exclude(self, base_dir):
'''
file.directory with clean=True and exclude_pat set
Skipped on windows because clean and exclude_pat not supported by
salt.sates.file._check_directory_win
'''
name = os.path.join(base_dir, 'directory_clean_dir')
if not os.path.isdir(name):
@ -1216,6 +1230,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
self.assertTrue(os.path.isfile(os.path.join(name, '32', 'scene')))
self.assertTrue(os.path.isfile(os.path.join(name, 'scene34')))
@skipIf(salt.utils.platform.is_windows(), 'Skip on windows')
@with_tempdir()
def test_recurse_issue_34945(self, base_dir):
'''
@ -1231,6 +1246,8 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
repaired.
This was fixed in https://github.com/saltstack/salt/pull/35309
Skipped on windows because dir_mode is not supported.
'''
dir_mode = '2775'
issue_dir = 'issue-34945'
@ -1472,7 +1489,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
ret = []
for x in range(0, 3):
ret.append(self.run_state('file.replace',
name=path_test, pattern='^#foo=bar$', repl='foo=salt', append_if_not_found=True))
name=path_test, pattern='^#foo=bar($|(?=\r\n))', repl='foo=salt', append_if_not_found=True))
# ensure, the resulting file contains the expected lines
self.assertTrue(filecmp.cmp(path_test, path_out))
@ -1559,16 +1576,18 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
with salt.utils.files.fopen(path_test, 'r') as fp_:
serialized_file = fp_.read()
expected_file = '''{
"a_list": [
"first_element",
"second_element"
],
"description": "A basic test",
"finally": "the last item",
"name": "naive"
}
'''
expected_file = os.linesep.join([
'{',
' "a_list": [',
' "first_element",',
' "second_element"',
' ],',
' "description": "A basic test",',
' "finally": "the last item",',
' "name": "naive"',
'}',
'',
])
self.assertEqual(serialized_file, expected_file)
@with_tempdir()
@ -2005,6 +2024,10 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
def test_issue_8343_accumulated_require_in(self, base_dir):
template_path = os.path.join(TMP_STATE_TREE, 'issue-8343.sls')
testcase_filedest = os.path.join(base_dir, 'issue-8343.txt')
if os.path.exists(template_path):
os.remove(template_path)
if os.path.exists(testcase_filedest):
os.remove(testcase_filedest)
sls_template = [
'{0}:',
' file.managed:',
@ -3680,7 +3703,11 @@ class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
cls.webserver = Webserver()
cls.webserver.start()
cls.source = cls.webserver.url('grail/scene33')
cls.source_hash = 'd2feb3beb323c79fc7a0f44f1408b4a3'
if salt.utils.is_windows():
# CRLF vs LF causes a differnt hash on windows
cls.source_hash = '21438b3d5fd2c0028bcab92f7824dc69'
else:
cls.source_hash = 'd2feb3beb323c79fc7a0f44f1408b4a3'
@classmethod
def tearDownClass(cls):