Skip to content

Commit

Permalink
Support older apt versions for bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
schaefi committed Sep 30, 2024
1 parent e466bfa commit a682603
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 10 additions & 1 deletion kiwi/package_manager/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import glob
import logging
import pathlib
from typing import (
List, Dict
)
Expand Down Expand Up @@ -221,6 +222,13 @@ def _process_install_requests_bootstrap(self) -> CommandCallT:
# the essential debs and tell us their full in the apt cache without
# actually installing them.
try:
# TODO: Drop once apt 2.5.4 is widely available.
pathlib.Path(f'{self.root_dir}/var/lib/dpkg').mkdir(
parents=True, exist_ok=True
)
pathlib.Path(f'{self.root_dir}/var/lib/dpkg/status.kiwi').touch()
pathlib.Path(f'{self.root_dir}/var/lib/dpkg/available').touch()

if 'apt' not in self.package_requests:
self.package_requests.append('apt')
update_cache = [
Expand Down Expand Up @@ -255,14 +263,15 @@ def _process_install_requests_bootstrap(self) -> CommandCallT:
# Extract bootstrap packages
with open(package_names.name) as packages:
solved_debootstrap_packages = [p.rstrip() for p in packages]
self.command_env['PATH'] = '$PATH:/usr/bin:/bin:/usr/sbin:/sbin'
for package in solved_debootstrap_packages:
Command.run(
[
'bash', '-c',
'dpkg-deb --fsys-tarfile {0} | tar -C {1} -x'.format(
package, self.root_dir
)
]
], self.command_env
)
# 1. Pass: Run package scripts, manual order
self._run_bootstrap_scripts(
Expand Down
15 changes: 10 additions & 5 deletions test/unit/package_manager/apt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ def test_request_package_exclusion(self):
def test_setup_repository_modules(self):
self.manager.setup_repository_modules({})

@patch('pathlib.Path')
@patch('kiwi.command.Command.run')
@patch.object(PackageManagerApt, 'process_install_requests')
@patch('os.path.isfile')
def test_process_install_requests_bootstrap_prebuild_root(
self, mock_os_path_isfile, mock_process_install_requests,
mock_Command_run
mock_Command_run, mock_pathlib_Path
):
mock_os_path_isfile.return_value = True
self.manager.process_install_requests_bootstrap(
Expand Down Expand Up @@ -102,25 +103,28 @@ def test_process_install_requests_bootstrap_prebuild_root(
bootstrap_package='bootstrap-package'
)

@patch('pathlib.Path')
@patch('kiwi.command.Command.call')
@patch('kiwi.command.Command.run')
def test_process_install_requests_bootstrap_failed(
self, mock_Command_run, mock_Command_call
self, mock_Command_run, mock_Command_call, mock_pathlib_Path
):
self.manager.request_package('apt')
mock_Command_call.side_effect = Exception
with patch('builtins.open', create=True):
with raises(KiwiDebianBootstrapError):
self.manager.process_install_requests_bootstrap()

@patch('pathlib.Path')
@patch('kiwi.command.Command.run')
@patch('kiwi.command.Command.call')
@patch('kiwi.package_manager.apt.Temporary.new_file')
@patch('kiwi.package_manager.apt.Temporary.new_dir')
@patch('os.path.exists')
def test_process_install_requests_bootstrap(
self, mock_os_path_exists, mock_Temporary_new_dir,
mock_Temporary_new_file, mock_Command_call, mock_Command_run
mock_Temporary_new_file, mock_Command_call, mock_Command_run,
mock_pathlib_Path
):
mock_os_path_exists.return_value = True
mock_Temporary_new_dir.return_value.name = 'tempdir'
Expand All @@ -135,6 +139,7 @@ def test_process_install_requests_bootstrap(
file_handle.__iter__.return_value = ['base-passwd\n', 'vim\n']
self.manager.process_install_requests_bootstrap()
new_env = self.env | {
'PATH': '$PATH:/usr/bin:/bin:/usr/sbin:/sbin',
'DPKG_MAINTSCRIPT_NAME': 'true',
'DPKG_MAINTSCRIPT_PACKAGE': 'libc6'
}
Expand All @@ -158,13 +163,13 @@ def test_process_install_requests_bootstrap(
[
'bash', '-c',
'dpkg-deb --fsys-tarfile base-passwd | tar -C root-dir -x'
]
], self.env
),
call(
[
'bash', '-c',
'dpkg-deb --fsys-tarfile vim | tar -C root-dir -x'
]
], self.env
),
call(
[
Expand Down

0 comments on commit a682603

Please sign in to comment.