From 0baf2e4f19b445a08c4aac16a694a7e5671c8fbc Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 9 Aug 2024 14:37:43 -0400 Subject: [PATCH] qa/tasks: add a new cephadm_from_container feature to cephadm task The cephadm_from_container allows one to do a single container build and then point teuthology at that image as the "single source of truth". I find this extremely convenient when running teuthology locally and I keep carrying this patch around - I figure having it upstream will simplify my workflow. Maybe someday it'll benefit others too. To use it I set up a yaml overrides file with the following content: ```yaml overrides: cephadm: image: "quay.io/phlogistonjohn/ceph:dev" cephadm_from_container: true verify_ceph_hash: false verify_ceph_hash: false ``` This let's me test my custom builds fairly easily! Signed-off-by: John Mulligan --- qa/tasks/cephadm.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index 166ea9537ee72..41c095fc5d083 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -209,7 +209,9 @@ def normalize_hostnames(ctx): def download_cephadm(ctx, config, ref): cluster_name = config['cluster'] - if 'cephadm_binary_url' in config: + if 'cephadm_from_container' in config: + _fetch_cephadm_from_container(ctx, config) + elif 'cephadm_binary_url' in config: url = config['cephadm_binary_url'] _download_cephadm(ctx, url) elif config.get('cephadm_mode') != 'cephadm-package': @@ -232,6 +234,36 @@ def download_cephadm(ctx, config, ref): _rm_cephadm(ctx) +def _fetch_cephadm_from_container(ctx, config): + image = config['image'] + cengine = 'podman' + try: + log.info("Testing if podman is available") + ctx.cluster.run(args=['sudo', cengine, '--help']) + except CommandFailedError: + log.info("Failed to find podman. Using docker") + cengine = 'docker' + + ctx.cluster.run(args=['sudo', cengine, 'pull', image]) + ctx.cluster.run(args=[ + 'sudo', cengine, 'run', '--rm', '--entrypoint=cat', image, '/usr/sbin/cephadm', + run.Raw('>'), + ctx.cephadm, + ]) + + # sanity-check the resulting file and set executable bit + cephadm_file_size = '$(stat -c%s {})'.format(ctx.cephadm) + ctx.cluster.run( + args=[ + 'test', '-s', ctx.cephadm, + run.Raw('&&'), + 'test', run.Raw(cephadm_file_size), "-gt", run.Raw('1000'), + run.Raw('&&'), + 'chmod', '+x', ctx.cephadm, + ], + ) + + def _fetch_cephadm_from_rpm(ctx): log.info("Copying cephadm installed from an RPM package") # cephadm already installed from redhat.install task -- 2.39.5