These tests now not only test the new functionality added for matching
on source URI and source_hash_name, but also test non-specific hash_type
lookups, specific hash_type lookups, and failed specific hash_type
lookups (i.e. requesting a hash type not present in the file).
This rewrite makes it possible for file.extract_hash to match on more
than just the filename being managed, also matching on the source URL as
well as a new user-specified name.
It also makes this function more efficient, as only a single pass is
performed when the hash_type is unspecified. Before, it would read the
entire file for each hash type.
Finally, it adds the ``source_hash_name`` argument to
``file.get_managed``, so that it can be passed to this function by
``file.managed`` states.
Fixes#31135
If a file exists but is empty, we are stack tracing on a call to
the body.split(os.linesep) function. This fix sets the body variable
to an empty string instead of stack tracing when the file is empty.
This allows the function to return ``False``, since no match can be
found in an empty file.
I also adjusted one of the ``line`` variables in the ``replace`` block
because it was shadowing the outer line function scope.
Here is the stack trace that happens when running file.line with
mode=replace on a file that exists, but is empty, as described in
the bug report:
unit.modules.file_test.FileModuleTestCase.test_replace_line_in_empty_file .................................................
Traceback (most recent call last):
File "/root/SaltStack/salt/tests/unit/modules/file_test.py", line 593, in test_replace_line_in_empty_file
mode='replace'))
File "/root/SaltStack/salt/salt/modules/file.py", line 1523, in line
for line in body.split(os.linesep)])
TypeError: expected a character buffer object
Current behavior always error logs, even if the module is not going to
be used. The loader will raise a proper error if it's attempted
accessed without having loaded properly anyway, and if that happens I'm
assuming you'll turn on debug logging and look for the cause. The
loader also logs which modules are not loaded and their reason, thus
there's no point in repeating the module name in the error message.
1. Re-raise StreamClosedError in the SaltEvent if the event was created
with `raise_errors=True`.
2. Handle StreamClosedError in the client if the client was created with
`auto_reconnect=True`.