From 4d987d22e9a68c6ddda0182ff4da4d58f5905db3 Mon Sep 17 00:00:00 2001 From: Vasu Kulkarni Date: Fri, 8 Jun 2018 16:08:48 -0700 Subject: [PATCH] subscribe rhel octo nodes using stage cdn from configuration Signed-off-by: Vasu Kulkarni --- teuthology/run.py | 5 ++++ teuthology/task/internal/__init__.py | 2 +- teuthology/task/internal/redhat.py | 42 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/teuthology/run.py b/teuthology/run.py index 3d329b3a46..236cc0eb3a 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -230,6 +230,11 @@ def get_initial_tasks(lock, config, machine_type): {'selinux': None}, {'clock': None} ]) + + if 'redhat' in config: + init_tasks.extend([ + {'internal.setup_stage_cdn': None} + ]) # dont run cm-ansible by default unless requested in config # nodes are reimaged by FOG and the images provided # by FOG have already gone through cm-ansible run diff --git a/teuthology/task/internal/__init__.py b/teuthology/task/internal/__init__.py index 7d775d4b66..fd5e7f3f85 100644 --- a/teuthology/task/internal/__init__.py +++ b/teuthology/task/internal/__init__.py @@ -19,7 +19,7 @@ from teuthology.config import config as teuth_config from teuthology.exceptions import VersionNotFoundError from teuthology.job_status import get_status, set_status from teuthology.orchestra import cluster, remote, run -from .redhat import setup_cdn_repo, setup_base_repo, setup_additional_repo # noqa +from .redhat import setup_cdn_repo, setup_base_repo, setup_additional_repo, setup_stage_cdn # noqa log = logging.getLogger(__name__) diff --git a/teuthology/task/internal/redhat.py b/teuthology/task/internal/redhat.py index 7fedff0065..1dae10dd07 100644 --- a/teuthology/task/internal/redhat.py +++ b/teuthology/task/internal/redhat.py @@ -5,6 +5,7 @@ import contextlib import logging import requests from tempfile import NamedTemporaryFile +from teuthology.config import config as teuthconfig from teuthology.parallel import parallel from teuthology.orchestra import run from teuthology.task.install.redhat import set_deb_repo @@ -12,6 +13,47 @@ from teuthology.task.install.redhat import set_deb_repo log = logging.getLogger(__name__) +@contextlib.contextmanager +def setup_stage_cdn(ctx, config): + """ + Configure internal stage cdn + """ + with parallel() as p: + for remote in ctx.cluster.remotes.iterkeys(): + if remote.os.name == 'rhel': + log.info("subscribing stage cdn on : %s", remote.shortname) + p.spawn(_subscribe_stage_cdn, remote, teuthconfig) + + try: + yield + finally: + with parallel() as p: + for remote in ctx.cluster.remotes.iterkeys(): + p.spawn(_unsubscribe_stage_cdn, remote) + + +def _subscribe_stage_cdn(remote, teuthconfig): + cdn_config = teuthconfig.get('cdn-config', dict()) + server_url = cdn_config.get('server-url', 'subscription.rhsm.stage.redhat.com:443/subscription') + base_url = cdn_config.get('base-url', 'https://cdn.stage.redhat.com') + username = cdn_config.get('username', 'qa@redhat.com') + password = cdn_config.get('password') + remote.run( + args=[ + 'sudo', 'subscription-manager', '--force', 'register', + run.Raw('--serverurl=' + server_url), + run.Raw('--baseurl=' + base_url), + run.Raw('--username=' + username), + run.Raw('--password=' + password), + '--auto-attach' + ], + timeout=720) + + +def _unsubscribe_stage_cdn(remote): + remote.run(args=['sudo', 'subcription-manger', 'unregister']) + + @contextlib.contextmanager def setup_cdn_repo(ctx, config): """ -- 2.39.5