Fix test cases with PermissionError on /var/cache

Some test cases fail when run without root permission, because they want
to read/write to `/var/cache`:

```
python3 -m pytest -ra tests/pytests/unit/state/test_state_format_slots.py
```

`test_format_slots_parallel` fails with:

```
Process ParallelState(always-changes-and-succeeds):
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "salt/utils/process.py", line 996, in wrapped_run_func
    return run_func()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "salt/state.py", line 2023, in _call_parallel_target
    with salt.utils.files.fopen(tfile, "wb+") as fp_:
  File "salt/utils/files.py", line 385, in fopen
    f_handle = open(*args, **kwargs)  # pylint: disable=resource-leakage
FileNotFoundError: [Errno 2] No such file or directory: '/var/cache/salt/minion/123/174993d470c5f21b548d929d1904021966cb279f'
```

fixes #61148
Signed-off-by: Benjamin Drung <bdrung@debian.org>
This commit is contained in:
Benjamin Drung 2022-04-16 04:16:42 +02:00 committed by Megan Wilhite
parent 4449286632
commit 3f4dbb1f5a

View file

@ -15,9 +15,10 @@ log = logging.getLogger(__name__)
@pytest.fixture
def state_obj():
def state_obj(tmp_path):
with patch("salt.state.State._gather_pillar"):
minion_opts = salt.config.DEFAULT_MINION_OPTS.copy()
minion_opts["cachedir"] = str(tmp_path)
yield salt.state.State(minion_opts)