Package installer fails if `/etc/apt/sources.list` is absent
Metadata
Current evaluation
No evaluation has been recorded for this issue yet.
Issue body
### Bug Description
On a fresh Ubuntu Plucky install, `/etc/apt/sources.list` is not included, as Ubuntu has migrated to fully utilising deb822. However, craft-parts
### To Reproduce
Clone the repository on a fresh plucky machine and run the cmake integration tests. It does not matter whether cmake is installed - it just needs any plugin that has a build dependency.
### part yaml
```shell
n/a
```
### Relevant log output
```shell
(craft-parts) lengau@ratel:~/Work/Code/craft-parts$ pytest tests/integration/plugins/test_cmake.py::test_cmake_plugin[-bin]
========================================================================================= test session starts =========================================================================================
platform linux -- Python 3.11.10, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/lengau/Work/Code/craft-parts
configfile: pyproject.toml
plugins: subprocess-1.5.3, cov-5.0.0, requests-mock-1.12.1, check-2.4.1, hypothesis-6.123.7, mock-3.14.0
collected 1 item
tests/integration/plugins/test_cmake.py F [100%]
============================================================================================== FAILURES ===============================================================================================
_______________________________________________________________________________________ test_cmake_plugin[-bin] _______________________________________________________________________________________
new_dir = local('/tmp/pytest-of-lengau/pytest-15/test_cmake_plugin__bin_0'), partitions = None, prefix = '', install_path = 'bin'
@pytest.mark.parametrize(
("prefix", "install_path"),
[
(None, "usr/local/bin"),
("", "bin"),
("/usr/local", "usr/local/bin"),
("/something/else", "something/else/bin"),
],
)
def test_cmake_plugin(new_dir, partitions, prefix, install_path):
parts_yaml = textwrap.dedent(
"""\
parts:
foo:
plugin: cmake
source: .
"""
)
if prefix is not None:
parts_yaml += f" cmake-parameters: [-DCMAKE_INSTALL_PREFIX={prefix}]"
parts = yaml.safe_load(parts_yaml)
Path("cmake.build").write_text(
textwrap.dedent(
"""\
project('cmake-hello', 'c')
executable('hello', 'hello.c', install : true)
"""
)
)
Path("hello.c").write_text(
textwrap.dedent(
"""\
#include <stdio.h>
int main()
{
printf(\"hello world\\n\");
return 0;
}
"""
)
)
Path("CMakeLists.txt").write_text(
textwrap.dedent(
"""\
cmake_minimum_required(VERSION 2.6)
project(cmake-hello C)
add_executable(cmake-hello hello.c)
install(TARGETS cmake-hello RUNTIME DESTINATION bin)
"""
)
)
lf = LifecycleManager(
parts, application_name="test_cmake", cache_dir=new_dir, partitions=partitions
)
actions = lf.plan(Step.PRIME)
> with lf.action_executor() as ctx:
/home/lengau/Work/Code/craft-parts/tests/integration/plugins/test_cmake.py:88:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/lengau/Work/Code/craft-parts/craft_parts/executor/executor.py:304: in __enter__
self._executor.prologue()
/home/lengau/Work/Code/craft-parts/craft_parts/executor/executor.py:88: in prologue
self._install_build_packages()
/home/lengau/Work/Code/craft-parts/craft_parts/executor/executor.py:246: in _install_build_packages
packages.Repository.install_packages(sorted(build_packages))
/home/lengau/Work/Code/craft-parts/craft_parts/packages/deb.py:562: in install_packages
if not cls._check_if_all_packages_installed(package_names):
/home/lengau/Work/Code/craft-parts/craft_parts/packages/deb.py:293: in wrapped
return method(*args, **kwargs)
/home/lengau/Work/Code/craft-parts/craft_parts/packages/deb.py:466: in _check_if_all_packages_installed
with AptCache() as apt_cache: # pyright: ignore[reportPossiblyUnboundVariable]
/home/lengau/Work/Code/craft-parts/craft_parts/packages/apt_cache.py:103: in __enter__
self.cache = apt.cache.Cache(rootdir="/")
/home/lengau/Work/Code/craft-parts/.venv/lib/python3.11/site-packages/apt/cache.py:148: in __init__
self._check_and_create_required_dirs(rootdir)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <apt.cache.Cache object at 0x7a99f22c1fd0>, rootdir = '/'
def _check_and_create_required_dirs(self, rootdir: str) -> None:
"""
check if the required apt directories/files are there and if
not create them
"""
files = [
"/var/lib/dpkg/status",
"/etc/apt/sources.list",
]
dirs = [
"/var/lib/dpkg",
"/etc/apt/",
"/var/cache/apt/archives/partial",
"/var/lib/apt/lists/partial",
]
for d in dirs:
if not os.path.exists(rootdir + d):
# print "creating: ", rootdir + d
os.makedirs(rootdir + d)
for f in files:
if not os.path.exists(rootdir + f):
> open(rootdir + f, "w").close()
E PermissionError: [Errno 13] Permission denied: '//etc/apt/sources.list'
/home/lengau/Work/Code/craft-parts/.venv/lib/python3.11/site-packages/apt/cache.py:188: PermissionError
======================================================================================= short test summary info =======================================================================================
FAILED tests/integration/plugins/test_cmake.py::test_cmake_plugin[-bin] - PermissionError: [Errno 13] Permission denied: '//etc/apt/sources.list'
========================================================================================== 1 failed in 0.11s ==========================================================================================
```
Evaluation history
No evaluation history available.