[BUG] test_pkgrepo not run on Debian
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
The tests in tests/pytests/functional/states/test_pkgrepo.py should be run on Debian based systems:
@pytest.mark.skipif(
not any([x for x in ["ubuntu", "debian"] if x in platform.platform()]),
reason="Test only for debian based platforms",
)
But on Ubuntu 21.10, platform.platform() does not return the distribution name:
$ python3 -c "import platform; print(platform.platform())"
Linux-5.13.0-28-generic-x86_64-with-glibc2.34
Note 1
Once https://github.com/saltstack/salt/pull/61626 is reviewed and merged, following code could be used to run the test cases on all Debian based systems (not only on Debian and Ubuntu):
from salt.grains.core import freedesktop_os_release, _family_id
def is_debian_based():
os_release = freedesktop_os_release()
return _family_id(os_release["ID"], os_release.get["ID_LIKE"]) == "debian"
@pytest.mark.skipif(
not is_debian_based(),
reason="Test only for debian based platforms",
)
Note 2
If I remove the skipif, these test cases fail to run during Debian package build, because they want to write to /etc/apt/sources.list:
____________________________ test_adding_repo_file _____________________________
states = <LazyLoader module='salt.loaded.states'>
tmp_path = PosixPath('/tmp/pytest-of-bdrung/pytest-0/test_adding_repo_file0')
def test_adding_repo_file(states, tmp_path):
"""
test adding a repo file using pkgrepo.managed
"""
repo_file = str(tmp_path / "stable-binary.list")
repo_content = "deb http://www.deb-multimedia.org stable main"
ret = states.pkgrepo.managed(name=repo_content, file=repo_file, clean_file=True)
with salt.utils.files.fopen(repo_file, "r") as fp:
file_content = fp.read()
> assert file_content.strip() == repo_content
E AssertionError: assert '' == 'deb http://w...g stable main'
E - deb http://www.deb-multimedia.org stable main
tests/pytests/functional/states/test_pkgrepo.py:16: AssertionError
------------------------------ Captured log setup ------------------------------
ERROR salt.utils.event:event.py:426 Unable to connect pusher: Stream is closed
Traceback (most recent call last):
File "/<<PKGBUILDDIR>>/salt/utils/event.py", line 423, in connect_pull
self.pusher.connect(timeout=timeout)
File "/<<PKGBUILDDIR>>/salt/utils/asynchronous.py", line 125, in wrap
raise exc_info[1].with_traceback(exc_info[2])
File "/<<PKGBUILDDIR>>/salt/utils/asynchronous.py", line 131, in _target
result = io_loop.run_sync(lambda: getattr(self.obj, key)(*args, **kwargs))
File "/<<PKGBUILDDIR>>/salt/ext/tornado/ioloop.py", line 459, in run_sync
return future_cell[0].result()
File "/<<PKGBUILDDIR>>/salt/ext/tornado/concurrent.py", line 249, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "/<<PKGBUILDDIR>>/salt/transport/ipc.py", line 342, in _connect
yield self.stream.connect(sock_addr)
File "/<<PKGBUILDDIR>>/salt/ext/tornado/gen.py", line 1056, in run
value = future.result()
File "/<<PKGBUILDDIR>>/salt/ext/tornado/concurrent.py", line 249, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
salt.ext.tornado.iostream.StreamClosedError: Stream is closed
------------------------------ Captured log call -------------------------------
ERROR salt.state:state.py:317 Failed to configure repo 'deb http://www.deb-multimedia.org stable main': [Errno 13] Permission denied: '/etc/apt/sources.list'
Versions Report
salt 3004, but the master branch is affected as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/pytests/functional/states/test_pkgrepo.py and inspect its platform-based skip condition. Review the referenced freedesktop_os_release and _family_id helpers, then run the test in the Debian-based environments described by the issue. Done means the tests are selected on Debian-based systems without requiring unauthorized writes to /etc/apt/sources.list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100