The location of the rpm database is no longer a standard path one can trust. Some distributions put it to /var/lib others to /usr/lib. This introduces the problem of dealing with different locations between the bootstrapping (host rpm) phase and the image installation (image rpm) phase. This commit implements a solution based on an intermediate rpm database configuration. KIWI creates the macros.kiwi file inside of the image root which is read by any call of rpm in the inner and outer system. During bootstrap phase the rpm dbpath from the host system is used and later in the install phase the dbpath from the rpm package as it was installed by the target image distribution is used. In case of a dbpath difference the database is automatically moved to the new location by setting the _dbpath_rebuild macro to the correct location. At the end the custom KIWI macro is deleted. As this process allows custom macro defintions during the KIWI run it also serves as the base for a solution to Issue #771 which will be done in a follow up request to this commit. Also the workaround for bsc#1112357 which uses a static dbpath to store an optionally given signing key will be addressed with this commit. The macro setup happens before the import_trusted_keys method which makes any specification for a strict dbpath obsolete. Last the implementation deletes the obsolete dump_reload_package_database code. rpm is able to automatically do the conversion of different db versions such that the code in kiwi is obsolete. In addition that code only worked for rather old db versions. The public API has not changed though, but the method is marked obsolete and does nothing anymore. In addition to the deletion of obsolete code a new API method post_process_install_requests_bootstrap has been introduced to handle actions required after bootstrap and before installing of packages from inside the new image
91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
import io
|
|
import os
|
|
from .test_helper import patch_open
|
|
from mock import (
|
|
patch, Mock, MagicMock, call
|
|
)
|
|
|
|
from kiwi.utils.rpm import Rpm
|
|
from kiwi.defaults import Defaults
|
|
|
|
|
|
class TestRpm(object):
|
|
def setup(self):
|
|
self.rpm_host = Rpm()
|
|
self.rpm_image = Rpm('root_dir')
|
|
self.macro_file = os.sep.join(
|
|
[
|
|
Defaults.get_custom_rpm_macros_path(),
|
|
Defaults.get_custom_rpm_bootstrap_macro_name()
|
|
]
|
|
)
|
|
|
|
@patch('kiwi.utils.rpm.Command.run')
|
|
def test_expand_query(self, mock_Command_run):
|
|
self.rpm_host.expand_query('foo')
|
|
mock_Command_run.assert_called_once_with(
|
|
['rpm', '-E', 'foo']
|
|
)
|
|
mock_Command_run.reset_mock()
|
|
self.rpm_image.expand_query('foo')
|
|
mock_Command_run.assert_called_once_with(
|
|
['chroot', 'root_dir', 'rpm', '-E', 'foo']
|
|
)
|
|
|
|
@patch('kiwi.utils.rpm.Command.run')
|
|
def test_get_query(self, mock_Command_run):
|
|
rpmdb_call = Mock()
|
|
rpmdb_call.output = '%_dbpath %{_usr}/lib/sysimage/rpm'
|
|
mock_Command_run.return_value = rpmdb_call
|
|
assert self.rpm_host.get_query('_dbpath') == \
|
|
'%{_usr}/lib/sysimage/rpm'
|
|
mock_Command_run.assert_called_once_with(
|
|
['rpmdb', '--showrc']
|
|
)
|
|
mock_Command_run.reset_mock()
|
|
assert self.rpm_image.get_query('_dbpath') == \
|
|
'%{_usr}/lib/sysimage/rpm'
|
|
mock_Command_run.assert_called_once_with(
|
|
['chroot', 'root_dir', 'rpmdb', '--showrc']
|
|
)
|
|
|
|
def test_set_config_value(self):
|
|
self.rpm_host.set_config_value('key', 'value')
|
|
assert self.rpm_host.custom_config[0] == '%key\tvalue'
|
|
|
|
@patch('kiwi.utils.rpm.Path.wipe')
|
|
def test_wipe_config(self, mock_Path_wipe):
|
|
self.rpm_host.wipe_config()
|
|
mock_Path_wipe.assert_called_once_with(
|
|
os.sep + self.macro_file
|
|
)
|
|
mock_Path_wipe.reset_mock()
|
|
self.rpm_image.wipe_config()
|
|
mock_Path_wipe.assert_called_once_with(
|
|
os.sep.join(['root_dir', self.macro_file])
|
|
)
|
|
|
|
@patch_open
|
|
@patch('kiwi.utils.rpm.Path.create')
|
|
def test_write_config(self, mock_Path_create, mock_open):
|
|
mock_open.return_value = MagicMock(spec=io.IOBase)
|
|
file_handle = mock_open.return_value.__enter__.return_value
|
|
self.rpm_host.set_config_value('key', 'value')
|
|
self.rpm_host.write_config()
|
|
mock_open.assert_called_once_with(
|
|
os.sep + self.macro_file, 'w'
|
|
)
|
|
assert file_handle.write.call_args_list == [
|
|
call('%key\tvalue\n')
|
|
]
|
|
mock_open.reset_mock()
|
|
file_handle.write.reset_mock()
|
|
self.rpm_image.set_config_value('foo', 'bar')
|
|
self.rpm_image.write_config()
|
|
mock_open.assert_called_once_with(
|
|
os.sep.join(['root_dir', self.macro_file]), 'w'
|
|
)
|
|
assert file_handle.write.call_args_list == [
|
|
call('%foo\tbar\n')
|
|
]
|