Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EBLINUX-26196: Add support for packages to initrd-generator #9

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"--disable=W0718"
],
"python.testing.pytestArgs": [
"--no-cov",
"--capture=no",
"--log-level=DEBUG",
"tests"
Expand Down
22 changes: 21 additions & 1 deletion ebcl/tools/initrd/initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def __init__(self, config_file: str, output_path: str):
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. """
package = None
Expand Down Expand Up @@ -209,6 +211,22 @@ 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. """
packages = self.config.packages.copy()
if self.config.kernel:
packages.remove(self.config.kernel)

(_debs, _contents, missing) = self.proxy.download_deb_packages(
packages=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. """
Expand All @@ -220,6 +238,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']:
Expand Down Expand Up @@ -253,7 +273,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:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down
Loading