]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks: add a new cephadm_from_container feature to cephadm task 59421/head
authorJohn Mulligan <phlogistonjohn@asynchrono.us>
Fri, 9 Aug 2024 18:37:43 +0000 (14:37 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 23 Aug 2024 18:35:55 +0000 (14:35 -0400)
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 <phlogistonjohn@asynchrono.us>
qa/tasks/cephadm.py

index 166ea9537ee72e8f4232545ade34a6aa3c90727b..41c095fc5d083c5147862735727c713093f87acd 100644 (file)
@@ -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