Skip to content

Commit

Permalink
Changed systemfiles provider
Browse files Browse the repository at this point in the history
Instead of providing a static list of filenames, provide a list
of package names. It is expected that the pilot of flake-pilot
resolves this list against the local package database to build
up the filelist for provisioning
  • Loading branch information
schaefi committed Dec 16, 2024
1 parent 5ebf22e commit 9c7fbe0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 195 deletions.
3 changes: 0 additions & 3 deletions kiwi/system/root_import/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def overlay_finalize(self, xml_state: XMLState) -> None:
with open(systemfiles, 'a') as systemfiles_fd:
# copy on write makes this file to become part of the delta
systemfiles_fd.write(os.linesep)
with open(f'{systemfiles}.libs', 'a') as systemlibs_fd:
# copy on write makes this file to become part of the delta
systemlibs_fd.write(os.linesep)

# Umount and rename upper to be the new root
self.overlay.umount()
Expand Down
79 changes: 8 additions & 71 deletions kiwi/system/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,84 +1349,21 @@ def _text(self, section_content):
return section_content[0]

def _export_rpm_flake_pilot_system_file_list(self, filename):
log.info('Export rpm packages system file list for flake-pilot')
log.info('Export rpm system files script for flake-pilot')
dbpath_option = [
'--dbpath', self._get_rpm_database_location()
]
skip_list = self.xml_state.get_system_files_ignore_packages()
query_call = Command.run(
['rpm', '--root', self.root_dir, '-qa'] + dbpath_option
[
'rpm', '--root', self.root_dir, '-qa', '--qf', '%{NAME}\n'
] + dbpath_option
)
libcheck = [
'/lib', '/usr/lib', '/lib64', '/usr/lib64'
]
packmeta = {}
for package in query_call.output.splitlines():
skip = False
for skip_package in skip_list:
if package.startswith(skip_package):
skip = True
break
if not skip and package:
package = package.strip()
packmeta[package] = {}
query_call = Command.run(
[
'rpm', '--root', self.root_dir, '-ql',
'--noghost', '--dump', package
] + dbpath_option
)
for raw in query_call.output.splitlines():
meta = raw.lstrip().split(' ')
if len(meta) == 11:
islib = False
for libpath in libcheck:
if meta[0].startswith(libpath):
islib = True
break
packmeta[package][meta[0]] = {
'islib': islib,
'isdoc': True if meta[8] == '1' else False,
'islink': True if meta[10] != 'X' else False,
'linkname': meta[10]
}

with open(filename, 'w', encoding='utf-8') as systemfiles:
for package in packmeta.keys():
for file in packmeta[package].keys():
meta = packmeta[package][file]
if not meta['isdoc'] and not meta['islib']:
systemfiles.write(f'{file}{os.linesep}')

with open(f'{filename}.libs', 'w', encoding='utf-8') as systemlibs:
for package in packmeta.keys():
for file in packmeta[package].keys():
meta = packmeta[package][file]
if meta['islib']:
if meta['islink']:
systemlibs.write(f'{file}{os.linesep}')
elif not self._has_link_target(packmeta, file):
systemlibs.write(f'{file}{os.linesep}')

def _has_link_target(
self, packages: Dict[str, Dict[str, Dict[str, str]]], filename: str
) -> bool:
if 'ld-linux' in filename:
# exceptional case. /lib.../ld-linux-* could be a
# symlink to /usr/bin/ld.so but only providing
# /usr/bin/ld.so is not enough to call programs.
# Thus in this case we indicate the file has no link
# target such that the later pilot sync takes it
# into account.
return False
for package in packages.keys():
for file in packages[package].keys():
meta = packages[package][file]
base_filename = os.path.basename(filename)
base_linkname = os.path.basename(meta['linkname'])
if meta['islink'] and base_filename == base_linkname:
return True
return False
systemfiles.write('set -e\n')
for package in query_call.output.splitlines():
if package not in skip_list:
systemfiles.write(f'rpm --noghost -ql {package}\n')

def _export_rpm_package_list(self, filename):
log.info('Export rpm packages metadata')
Expand Down
48 changes: 0 additions & 48 deletions test/data/rpm_ql_dump_glibc

This file was deleted.

1 change: 0 additions & 1 deletion test/unit/system/root_import/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def test_overlay_finalize(
]
# create removed files metadata for later host provisioning
assert file_handle.write.call_args_list == [
call('\n'),
call('\n'),
call('/file_a'), call(os.linesep),
call('/file_b'), call(os.linesep)
Expand Down
84 changes: 12 additions & 72 deletions test/unit/system/setup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,90 +1316,30 @@ def test_export_flake_pilot_system_file_list(
rpmdb.rpmdb_host.expand_query.return_value = 'host_dbpath'
rpmdb.has_rpm.return_value = True
mock_RpmDataBase.return_value = rpmdb
with open('../data/rpm_ql_dump_glibc', 'r') as glibc:
rpm_ql_dump_glibc = glibc.read()
self.xml_state.get_system_files_ignore_packages = Mock(
return_value=['rpm', 'yast', 'zypp']
return_value=['rpm', 'zypper']
)

def command_call(args):
if args[3] == '-qa':
return Mock(output='glibc\nzypper\n')
else:
return Mock(output=rpm_ql_dump_glibc)

mock_command_run.side_effect = command_call
mock_command_run.return_value = Mock(output='glibc\nzypper\n')

with patch('builtins.open') as mock_open:
mock_open.return_value = MagicMock(spec=io.IOBase)
file_handle = mock_open.return_value.__enter__.return_value
result = self.setup.export_flake_pilot_system_file_list(
'target_dir', 'system_files'
)
assert mock_open.call_args_list == [
call('target_dir/system_files', 'w', encoding='utf-8'),
call('target_dir/system_files.libs', 'w', encoding='utf-8')
]
mock_open.assert_called_once_with(
'target_dir/system_files', 'w', encoding='utf-8'
)
assert file_handle.write.call_args_list == [
call('/etc/bindresvport.blacklist\n'),
call('/etc/gai.conf\n'),
call('/etc/ld.so.cache\n'),
call('/etc/ld.so.conf\n'),
call('/etc/nsswitch.conf\n'),
call('/etc/rpc\n'),
call('/sbin/ldconfig\n'),
call('/usr/bin/gencat\n'),
call('/usr/bin/getconf\n'),
call('/usr/bin/getent\n'),
call('/usr/bin/iconv\n'),
call('/usr/bin/ld.so\n'),
call('/usr/bin/ldd\n'),
call('/usr/bin/locale\n'),
call('/usr/bin/localedef\n'),
call('/usr/sbin/iconvconfig\n'),
call('/usr/share/doc/packages/glibc\n'),
call('/usr/share/licenses/glibc\n'),
call('/usr/share/licenses/glibc/LICENSES\n'),
call('/var/cache/ldconfig\n'),
call('/lib64/ld-linux-x86-64.so.2\n'),
call('/lib64/ld-lsb-x86-64.so.3\n'),
call('/lib64/libBrokenLocale.so.1\n'),
call('/lib64/libanl.so.1\n'),
call('/lib64/libc.so.6\n'),
call('/lib64/libc_malloc_debug.so.0\n'),
call('/lib64/libdl.so.2\n'),
call('/lib64/libm.so.6\n'),
call('/lib64/libmvec.so.1\n'),
call('/lib64/libnss_compat.so.2\n'),
call('/lib64/libnss_db.so.2\n'),
call('/lib64/libnss_dns.so.2\n'),
call('/lib64/libnss_files.so.2\n'),
call('/lib64/libnss_hesiod.so.2\n'),
call('/lib64/libpthread.so.0\n'),
call('/lib64/libresolv.so.2\n'),
call('/lib64/librt.so.1\n'),
call('/lib64/libthread_db.so.1\n'),
call('/lib64/libutil.so.1\n'),
call('/usr/lib/getconf/POSIX_V6_LP64_OFF64\n'),
call('/usr/lib/getconf/POSIX_V7_LP64_OFF64\n'),
call('/usr/lib/getconf/XBS5_LP64_OFF64\n')
call('set -e\n'), call('rpm --noghost -ql glibc\n')
]
assert result == 'target_dir/system_files'
assert mock_command_run.call_args_list == [
call(
[
'rpm', '--root', 'root_dir',
'-qa', '--dbpath', 'image_dbpath'
]
),
call(
[
'rpm', '--root', 'root_dir',
'-ql', '--noghost', '--dump', 'glibc',
'--dbpath', 'image_dbpath'
]
)
]
mock_command_run.assert_called_once_with(
[
'rpm', '--root', 'root_dir',
'-qa', '--qf', '%{NAME}\n', '--dbpath', 'image_dbpath'
]
)

@patch('kiwi.system.setup.Command.run')
@patch('kiwi.system.setup.RpmDataBase')
Expand Down

0 comments on commit 9c7fbe0

Please sign in to comment.