diff --git a/.vscode/settings.json b/.vscode/settings.json index b312127..82230b2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,6 @@ "--disable=W0718" ], "python.testing.pytestArgs": [ - "--no-cov", "--capture=no", "--log-level=DEBUG", "tests" diff --git a/ebcl/tools/initrd/initrd.py b/ebcl/tools/initrd/initrd.py index f3a424e..ea85899 100644 --- a/ebcl/tools/initrd/initrd.py +++ b/ebcl/tools/initrd/initrd.py @@ -39,8 +39,7 @@ def __init__(self, config_file: str, output_path: str): self.config.busybox = parse_package( 'busybox-static', self.config.arch) - if self.config.kernel: - self.config.packages.append(self.config.kernel) + self.proxy = self.config.proxy def install_busybox(self) -> bool: """Get busybox and add it to the initrd. """ @@ -209,6 +208,18 @@ def add_devices(self): self.config.fake.run_sudo( f'chown {uid}:{gid} {dev_folder}/{device["name"]}') + def download_deb_packages(self): + """ Download all needed deb packages. """ + (_debs, _contents, missing) = self.proxy.download_deb_packages( + packages=self.config.packages, + contents=self.target_dir, + download_depends=True + ) + + if missing: + logging.critical('Not found packages: %s', missing) + raise InvalidConfiguration(f'Not found packages: {missing}') + @log_exception() def create_initrd(self) -> Optional[str]: """ Create the initrd image. """ @@ -220,6 +231,8 @@ def create_initrd(self) -> Optional[str]: if not success: return None + self.download_deb_packages() + # Create necessary directories for dir_name in ['proc', 'sys', 'dev', 'sysroot', 'var', 'bin', 'tmp', 'run', 'root', 'usr', 'sbin', 'lib', 'etc']: @@ -237,11 +250,11 @@ def create_initrd(self) -> Optional[str]: if self.config.modules_folder: mods_dir = self.config.modules_folder logging.info('Using modules from folder %s...', mods_dir) - elif self.config.packages: + elif self.config.kernel: mods_dir = tempfile.mkdtemp() - logging.info('Using modules from deb packages...') + logging.info('Using modules from kernel deb packages...') (_debs, _contents, missing) = self.config.proxy.download_deb_packages( - packages=self.config.packages, + packages=[self.config.kernel], contents=mods_dir ) if missing: @@ -253,7 +266,7 @@ def create_initrd(self) -> Optional[str]: else: logging.info('No module sources defined.') - if self.config.modules: + if self.config.modules and mods_dir: logging.info('Adding modules %s...', self.config.modules) self.copy_modules(mods_dir) else: diff --git a/tests/data/initrd.yaml b/tests/data/initrd.yaml index 05b01a3..9a6a40a 100644 --- a/tests/data/initrd.yaml +++ b/tests/data/initrd.yaml @@ -10,8 +10,7 @@ apt_repos: - nxp_public modules: - kernel/pfeng/pfeng.ko -packages: - - linux-modules-5.15.0-1023-s32-eb +kernel: linux-modules-5.15.0-1023-s32-eb arch: 'arm64' root_device: /dev/mmcblk0p2 devices: diff --git a/tests/test_config.py b/tests/test_config.py index 46f0a96..4d33abb 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -65,8 +65,8 @@ def test_initrd_yaml(self): assert len(config.modules) == 1 assert config.modules[0] == 'kernel/pfeng/pfeng.ko' - assert len(config.packages) == 1 - assert config.packages[0].name == 'linux-modules-5.15.0-1023-s32-eb' + assert len(config.packages) == 0 + assert config.kernel is not None and config.kernel.name == 'linux-modules-5.15.0-1023-s32-eb' assert config.arch == CpuArch.ARM64 diff --git a/tests/test_initrd.py b/tests/test_initrd.py index 09a8614..7689d00 100644 --- a/tests/test_initrd.py +++ b/tests/test_initrd.py @@ -52,6 +52,23 @@ def test_install_busybox(self): assert os.path.islink(os.path.join( self.generator.target_dir, 'bin', 'sh')) + @pytest.mark.requires_download + def test_add_cryptsetup(self): + """ Test yaml config loading. """ + vd = VersionDepends( + name='cryptsetup-bin', + package_relation=None, + version_relation=None, + version=None, + arch=self.generator.config.arch + ) + self.generator.config.packages.append(vd) + + self.generator.download_deb_packages() + + assert os.path.isfile(os.path.join( + self.generator.target_dir, 'sbin', 'cryptsetup')) + @pytest.mark.requires_download def test_download_deb_package(self): """ Test modules package download. """