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

Fix test findings #22

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ebcl/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.2"
__version__ = "1.3.3"
10 changes: 7 additions & 3 deletions ebcl/common/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ def __init__(self, folder: Optional[str] = None):
self.index_file = os.path.join(self.folder, 'index.json')

if os.path.isfile(self.index_file):
with open(self.index_file, encoding='utf8') as f:
data = f.read()
self.index: list[Package] = jsonpickle.decode(data)
try:
with open(self.index_file, encoding='utf8') as f:
data = f.read()
self.index: list[Package] = jsonpickle.decode(data)
except Exception as e:
logging.error('Loading cache state failed! %s', e)
self.index = []
else:
self.index = []

Expand Down
2 changes: 1 addition & 1 deletion ebcl/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, config_file: str, output_path: str):
# Primary repo for debootstrap
self.primary_distro: Optional[str] = None
# Additional debootstrap parameters
self.debootstrap_flags: Optional[str] = None
self.debootstrap_flags: Optional[str] = '--include=ca-certificates'
# Password for the root user
self.root_password: Optional[str] = 'linux'
# Hostname for the root filesystem
Expand Down
14 changes: 12 additions & 2 deletions ebcl/tools/boot/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import logging
import os
import shutil
import tempfile

from typing import Optional
Expand Down Expand Up @@ -40,10 +41,11 @@ def __init__(self, config_file: str, output_path: str):

def download_deb_packages(self, package_dir: str):
""" Download all needed deb packages. """
(_debs, _contents, missing) = self.proxy.download_deb_packages(
(debs, _contents, missing) = self.proxy.download_deb_packages(
packages=self.config.packages,
contents=package_dir
)
shutil.rmtree(debs)

if missing:
logging.critical('Not found packages: %s', missing)
Expand Down Expand Up @@ -113,7 +115,7 @@ def create_boot(self) -> Optional[str]:

# Remove package temporary folder
logging.info('Remove temporary package contents...')
self.fake.run_cmd(f'rm -rf {package_dir}', check=False)
self.fake.run_sudo(f'rm -rf {package_dir}', check=False)

if self.config.tar:
# create tar archive
Expand All @@ -135,6 +137,13 @@ def create_boot(self) -> Optional[str]:
fix_ownership=True)
return output_path

@log_exception()
def finalize(self):
""" Finalize output and cleanup. """

# delete temporary folder
self.config.fake.run_sudo(f'rm -rf {self.config.target_dir}')


@log_exception(call_exit=True)
def main() -> None:
Expand Down Expand Up @@ -163,6 +172,7 @@ def main() -> None:

# Create the boot.tar
image = generator.create_boot()
generator.finalize()

if image:
print(f'Results were written to {image}.')
Expand Down
9 changes: 7 additions & 2 deletions ebcl/tools/initrd/initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import queue
import shutil
import tempfile

from pathlib import Path
Expand Down Expand Up @@ -210,12 +211,14 @@ def add_devices(self):

def download_deb_packages(self, allow_missing=False):
""" Download all needed deb packages. """
(_debs, _contents, missing) = self.proxy.download_deb_packages(
(debs, _contents, missing) = self.proxy.download_deb_packages(
packages=self.config.packages,
contents=self.target_dir,
download_depends=True
)

shutil.rmtree(debs)

if not allow_missing and missing:
logging.critical('Not found packages: %s', missing)
raise InvalidConfiguration(f'Not found packages: {missing}')
Expand Down Expand Up @@ -253,10 +256,12 @@ def create_initrd(self) -> Optional[str]:
elif self.config.kernel:
mods_dir = tempfile.mkdtemp()
logging.info('Using modules from kernel deb packages...')
(_debs, _contents, missing) = self.config.proxy.download_deb_packages(
(debs, _contents, missing) = self.config.proxy.download_deb_packages(
packages=[self.config.kernel],
contents=mods_dir
)
shutil.rmtree(debs)

if missing:
logging.error('Not found packages: %s', missing)
elif self.config.modules:
Expand Down
13 changes: 10 additions & 3 deletions ebcl/tools/root/debootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def _get_apt_hash(self, debootstrap_hash: str) -> str:
def _get_debootstrap_hash(self) -> str:
""" Generate hash for the debootstrap configuration. """
params = f'{self.config.arch} {self.debootstrap_variant} ' \
f'{self.config.primary_distro} {self._find_deboostrap_repo()}'
f'{self.config.primary_distro} {self._find_deboostrap_repo()} ' \
f'{self.config.debootstrap_flags}'

return hashlib.md5(params.encode('utf-8')).digest().hex()

Expand Down Expand Up @@ -77,7 +78,10 @@ def _generate_apt_config(self):
components = ' '.join(apt.components)
f.write(f'deb {apt.url} {apt.distro} {components}\n\n')

(_key_pub_file, key_gpg_file) = apt.get_key_files()
(key_pub_file, key_gpg_file) = apt.get_key_files()
if key_pub_file:
os.remove(key_pub_file)

fake.run_sudo(
f'cp {key_gpg_file} {apt_key_dir}',
cwd=self.config.target_dir,
Expand Down Expand Up @@ -160,7 +164,10 @@ def _run_debootstrap(self) -> bool:
return False

keyring = ''
(_pub, gpg) = repo.get_key_files()
(pub, gpg) = repo.get_key_files()
if pub:
os.remove(pub)

if gpg is not None:
keyring = f' --keyring={gpg} '

Expand Down
5 changes: 4 additions & 1 deletion ebcl/tools/root/kiwi.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def _generate_berrymill_config(
cnt = 1
for apt in config.apt_repos:
apt_repo_key = None
(_pub, apt_repo_key) = apt.get_key_files(result_dir)
(pub, apt_repo_key) = apt.get_key_files(result_dir)
if pub:
os.remove(pub)

if not apt_repo_key:
logging.error('No key found for %s, skipping repo!', apt)
continue
Expand Down
2 changes: 1 addition & 1 deletion ebcl/tools/root/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def finalize(self):
@log_exception(call_exit=True)
def main() -> None:
""" Main entrypoint of EBcL root generator. """
init_logging('DEBUG')
init_logging()

logging.info('\n=========================\n'
'EBcL Root Generator %s\n'
Expand Down