Skip to content

Commit 712b0ea

Browse files
authored
Merge pull request ceph#65176 from phlogistonjohn/jjm-cephadm-build-el10rpm
cephadm: fix building rpm-sourced cephadm zippapp on el10 Reviewed-by: Adam King <[email protected]>
2 parents dd14904 + e915b39 commit 712b0ea

File tree

2 files changed

+71
-36
lines changed

2 files changed

+71
-36
lines changed

src/cephadm/build.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,47 @@ def _install_rpm_deps(tempdir, config):
434434
return dinfo
435435

436436

437+
def _gather_rpm_package_dirs(paths):
438+
# = The easy way =
439+
# the top_level.txt file can be used to determine where the python packages
440+
# actually are. We need all of those and the meta-data dir (parent of
441+
# top_level.txt) to be included in our zipapp
442+
top_level = None
443+
for path in paths:
444+
if path.endswith('top_level.txt'):
445+
top_level = pathlib.Path(path)
446+
if top_level:
447+
meta_dir = top_level.parent
448+
pkg_dirs = [
449+
top_level.parent.parent / p
450+
for p in top_level.read_text().splitlines()
451+
]
452+
return meta_dir, pkg_dirs
453+
# = The hard way =
454+
# loop through the directories to find the .dist-info dir (containing the
455+
# mandatory METADATA file, according to the spec) and once we know the
456+
# location of dist info we find the sibling paths from the rpm listing
457+
dist_info = None
458+
ppaths = []
459+
for path in paths:
460+
ppath = pathlib.Path(path)
461+
ppaths.append(ppath)
462+
if ppath.name == 'METADATA' and ppath.parent.name.endswith('.dist-info'):
463+
dist_info = ppath.parent
464+
break
465+
if not dist_info:
466+
raise ValueError('no .dist-info METADATA found')
467+
if not dist_info.parent.name == 'site-packages':
468+
raise ValueError(
469+
'unexpected parent directory (not site-packages):'
470+
f' {dist_info.parent.name}'
471+
)
472+
siblings = [
473+
p for p in ppaths if p.parent == dist_info.parent and p != dist_info
474+
]
475+
return dist_info, siblings
476+
477+
437478
def _deps_from_rpm(tempdir, config, dinfo, pkg):
438479
# first, figure out what rpm provides a particular python lib
439480
dist = f'python3.{sys.version_info.minor}dist({pkg})'.lower()
@@ -469,20 +510,7 @@ def _deps_from_rpm(tempdir, config, dinfo, pkg):
469510
['rpm', '-ql', rpmname], check=True, stdout=subprocess.PIPE
470511
)
471512
paths = [l.decode('utf8') for l in res.stdout.splitlines()]
472-
# the top_level.txt file can be used to determine where the python packages
473-
# actually are. We need all of those and the meta-data dir (parent of
474-
# top_level.txt) to be included in our zipapp
475-
top_level = None
476-
for path in paths:
477-
if path.endswith('top_level.txt'):
478-
top_level = pathlib.Path(path)
479-
if not top_level:
480-
raise ValueError('top_level not found')
481-
meta_dir = top_level.parent
482-
pkg_dirs = [
483-
top_level.parent.parent / p
484-
for p in top_level.read_text().splitlines()
485-
]
513+
meta_dir, pkg_dirs = _gather_rpm_package_dirs(paths)
486514
meta_dest = tempdir / meta_dir.name
487515
log.info(f"Copying {meta_dir} to {meta_dest}")
488516
# copy the meta data directory

src/cephadm/tests/build/test_cephadm_build.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,39 @@
1212

1313

1414
CONTAINERS = {
15-
'centos-8': {
16-
'name': 'cephadm-build-test:centos8-py36',
17-
'base_image': 'quay.io/centos/centos:stream8',
18-
'script': 'dnf install -y python36',
19-
},
2015
'centos-9': {
2116
'name': 'cephadm-build-test:centos9-py3',
2217
'base_image': 'quay.io/centos/centos:stream9',
2318
'script': 'dnf install -y python3',
2419
},
25-
'centos-8-plusdeps': {
26-
'name': 'cephadm-build-test:centos8-py36-deps',
27-
'base_image': 'quay.io/centos/centos:stream8',
28-
'script': 'dnf install -y python36 python3-jinja2 python3-pyyaml',
20+
'centos-10': {
21+
'name': 'cephadm-build-test:centos10-py3',
22+
'base_image': 'quay.io/centos/centos:stream10',
23+
'script': 'dnf install -y python3',
2924
},
3025
'centos-9-plusdeps': {
3126
'name': 'cephadm-build-test:centos9-py3-deps',
3227
'base_image': 'quay.io/centos/centos:stream9',
3328
'script': 'dnf install -y python3 python3-jinja2 python3-pyyaml',
3429
},
30+
'centos-10-plusdeps': {
31+
'name': 'cephadm-build-test:centos10-py3-deps',
32+
'base_image': 'quay.io/centos/centos:stream10',
33+
'script': 'dnf install -y python3 python3-jinja2 python3-pyyaml',
34+
},
3535
'ubuntu-20.04': {
3636
'name': 'cephadm-build-test:ubuntu-20-04-py3',
37-
'base_image': 'quay.io/library/ubuntu:20.04',
37+
'base_image': 'docker.io/library/ubuntu:20.04',
3838
'script': 'apt update && apt install -y python3-venv',
3939
},
4040
'ubuntu-22.04': {
4141
'name': 'cephadm-build-test:ubuntu-22-04-py3',
42-
'base_image': 'quay.io/library/ubuntu:22.04',
42+
'base_image': 'docker.io/library/ubuntu:22.04',
43+
'script': 'apt update && apt install -y python3-venv',
44+
},
45+
'ubuntu-24.04': {
46+
'name': 'cephadm-build-test:ubuntu-24-04-py3',
47+
'base_image': 'docker.io/library/ubuntu:24.04',
4348
'script': 'apt update && apt install -y python3-venv',
4449
},
4550
}
@@ -95,10 +100,11 @@ def source_dir():
95100
@pytest.mark.parametrize(
96101
'env',
97102
[
98-
'centos-8',
99103
'centos-9',
104+
'centos-10',
100105
'ubuntu-20.04',
101106
'ubuntu-22.04',
107+
'ubuntu-24.04',
102108
],
103109
)
104110
def test_cephadm_build(env, source_dir, tmp_path):
@@ -128,8 +134,8 @@ def test_cephadm_build(env, source_dir, tmp_path):
128134
assert all('requirements_entry' in v for v in data['bundled_packages'])
129135
assert 'zip_root_entries' in data
130136
zre = data['zip_root_entries']
131-
assert any(e.startswith('Jinja2') for e in zre)
132-
assert any(e.startswith('MarkupSafe') for e in zre)
137+
assert any(_dist_info(e, 'Jinja2') for e in zre)
138+
assert any(_dist_info(e, 'MarkupSafe') for e in zre)
133139
assert any(e.startswith('jinja2') for e in zre)
134140
assert any(e.startswith('markupsafe') for e in zre)
135141
assert any(e.startswith('cephadmlib') for e in zre)
@@ -139,8 +145,8 @@ def test_cephadm_build(env, source_dir, tmp_path):
139145
@pytest.mark.parametrize(
140146
'env',
141147
[
142-
'centos-8-plusdeps',
143148
'centos-9-plusdeps',
149+
'centos-10-plusdeps',
144150
'centos-9',
145151
],
146152
)
@@ -155,11 +161,6 @@ def test_cephadm_build_from_rpms(env, source_dir, tmp_path):
155161
assert res.returncode != 0
156162
return
157163
binary = tmp_path / 'cephadm'
158-
if 'centos-8' in env and sys.version_info[:2] >= (3, 10):
159-
# The version of markupsafe in centos 8 is incompatible with
160-
# python>=3.10 due to changes in the stdlib therefore we can't execute
161-
# the cephadm binary, so we quit the test early.
162-
return
163164
assert binary.is_file()
164165
res = subprocess.run(
165166
[sys.executable, str(binary), 'version'],
@@ -184,9 +185,15 @@ def test_cephadm_build_from_rpms(env, source_dir, tmp_path):
184185
assert all('requirements_entry' in v for v in data['bundled_packages'])
185186
assert 'zip_root_entries' in data
186187
zre = data['zip_root_entries']
187-
assert any(e.startswith('Jinja2') for e in zre)
188-
assert any(e.startswith('MarkupSafe') for e in zre)
188+
assert any(_dist_info(e, 'Jinja2') for e in zre)
189+
assert any(_dist_info(e, 'MarkupSafe') for e in zre)
189190
assert any(e.startswith('jinja2') for e in zre)
190191
assert any(e.startswith('markupsafe') for e in zre)
191192
assert any(e.startswith('cephadmlib') for e in zre)
192193
assert any(e.startswith('_cephadmmeta') for e in zre)
194+
195+
196+
def _dist_info(entry, name):
197+
return (
198+
entry.startswith(entry) or entry.startswith(entry.lower())
199+
) and (entry.endswith('.dist-info') or entry.endswith('.egg-info'))

0 commit comments

Comments
 (0)