Skip to content

Commit

Permalink
Fix test cases with PermissionError on /var/cache
Browse files Browse the repository at this point in the history
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 saltstack#61148
Signed-off-by: Benjamin Drung <[email protected]>
  • Loading branch information
bdrung authored and Megan Wilhite committed Jul 13, 2022
1 parent 4449286 commit 3f4dbb1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/pytests/unit/state/test_state_format_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@


@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)


Expand Down

0 comments on commit 3f4dbb1

Please sign in to comment.