From 95ead7401fea97b0bb3033c6ad88ee0f2e31f3e2 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Wed, 26 Jan 2022 15:46:41 -0700 Subject: [PATCH] qa/tasks/cephadm: conditionally pull cephadm binary from chacra When a specific (older) version of cephadm is needed for a test, pull it from chacra. If we need to bootstrap an older version of ceph, we pull an older "single-script" binary using the older method. Co-authored-by: Michael Fritch Co-authored-by: John Mulligan Signed-off-by: Michael Fritch Signed-off-by: John Mulligan --- qa/tasks/cephadm.py | 168 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 137 insertions(+), 31 deletions(-) diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index 22c8da740b3..676453964ea 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -7,6 +7,7 @@ import contextlib import logging import os import json +import re import uuid import yaml @@ -16,11 +17,13 @@ from tarfile import ReadError from tasks.ceph_manager import CephManager from teuthology import misc as teuthology from teuthology import contextutil +from teuthology import packaging from teuthology.orchestra import run from teuthology.orchestra.daemon import DaemonGroup from teuthology.config import config as teuth_config from textwrap import dedent from tasks.cephfs.filesystem import MDSCluster, Filesystem +from tasks.util import chacra # these items we use from ceph.py should probably eventually move elsewhere from tasks.ceph import get_mons, healthy @@ -122,51 +125,154 @@ def download_cephadm(ctx, config, ref): cluster_name = config['cluster'] if config.get('cephadm_mode') != 'cephadm-package': - # cephadm already installed from install task + if ctx.config.get('redhat'): + _fetch_cephadm_from_rpm(ctx) + # TODO: come up with a sensible way to detect if we need an "old, uncompiled" + # cephadm + elif 'cephadm_git_url' in config and 'cephadm_branch' in config: + _fetch_cephadm_from_github(ctx, config, ref) + else: + _fetch_cephadm_from_chachra(ctx, config, cluster_name) + + try: + yield + finally: + _rm_cluster(ctx, cluster_name) + if config.get('cephadm_mode') == 'root': + _rm_cephadm(ctx) + + +def _fetch_cephadm_from_rpm(ctx): + log.info("Copying cephadm installed from an RPM package") + # cephadm already installed from redhat.install task + ctx.cluster.run( + args=[ + 'cp', + run.Raw('$(which cephadm)'), + ctx.cephadm, + run.Raw('&&'), + 'ls', '-l', + ctx.cephadm, + ] + ) + + +def _fetch_cephadm_from_github(ctx, config, ref): + ref = config.get('cephadm_branch', ref) + git_url = config.get('cephadm_git_url', teuth_config.get_ceph_git_url()) + log.info('Downloading cephadm (repo %s ref %s)...' % (git_url, ref)) + if git_url.startswith('https://github.com/'): + # git archive doesn't like https:// URLs, which we use with github. + rest = git_url.split('https://github.com/', 1)[1] + rest = re.sub(r'\.git/?$', '', rest).strip() # no .git suffix ctx.cluster.run( args=[ - 'cp', - run.Raw('$(which cephadm)'), + 'curl', '--silent', + 'https://raw.githubusercontent.com/' + rest + '/' + ref + '/src/cephadm/cephadm', + run.Raw('>'), ctx.cephadm, run.Raw('&&'), 'ls', '-l', ctx.cephadm, - ] + ], ) - - # sanity-check the resulting file and set executable bit - cephadm_file_size = '$(stat -c%s {})'.format(ctx.cephadm) + else: 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, + 'git', 'archive', + '--remote=' + git_url, + ref, + 'src/cephadm/cephadm', + run.Raw('|'), + 'tar', '-xO', 'src/cephadm/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, + ], + ) - try: - yield - finally: - log.info('Removing cluster...') - ctx.cluster.run(args=[ - 'sudo', + +def _fetch_cephadm_from_chachra(ctx, config, cluster_name): + log.info('Downloading "compiled" cephadm from cachra') + bootstrap_remote = ctx.ceph[cluster_name].bootstrap_remote + bp = packaging.get_builder_project()( + config.get('project', 'ceph'), + config, + ctx=ctx, + remote=bootstrap_remote, + ) + log.info('builder_project result: %s' % (bp._result.json())) + + flavor = config.get('flavor', 'default') + branch = config.get('branch') + sha1 = config.get('sha1') + + # pull the cephadm binary from chacra + url = chacra.get_binary_url( + 'cephadm', + project=bp.project, + distro=bp.distro.split('/')[0], + release=bp.distro.split('/')[1], + arch=bp.arch, + flavor=flavor, + branch=branch, + sha1=sha1, + ) + log.info("Discovered cachra url: %s", url) + ctx.cluster.run( + args=[ + 'curl', '--silent', '-L', url, + run.Raw('>'), ctx.cephadm, - 'rm-cluster', - '--fsid', ctx.ceph[cluster_name].fsid, - '--force', - ]) + run.Raw('&&'), + 'ls', '-l', + ctx.cephadm, + ], + ) - if config.get('cephadm_mode') == 'root': - log.info('Removing cephadm ...') - ctx.cluster.run( - args=[ - 'rm', - '-rf', - 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 _rm_cluster(ctx, cluster_name): + log.info('Removing cluster...') + ctx.cluster.run(args=[ + 'sudo', + ctx.cephadm, + 'rm-cluster', + '--fsid', ctx.ceph[cluster_name].fsid, + '--force', + ]) + + +def _rm_cephadm(ctx): + log.info('Removing cephadm ...') + ctx.cluster.run( + args=[ + 'rm', + '-rf', + ctx.cephadm, + ], + ) @contextlib.contextmanager -- 2.39.5