diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /qa/tasks/rabbitmq.py | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/tasks/rabbitmq.py')
-rw-r--r-- | qa/tasks/rabbitmq.py | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/qa/tasks/rabbitmq.py b/qa/tasks/rabbitmq.py new file mode 100644 index 000000000..c78ac1e56 --- /dev/null +++ b/qa/tasks/rabbitmq.py @@ -0,0 +1,130 @@ +""" +Deploy and configure RabbitMQ for Teuthology +""" +import contextlib +import logging + +from teuthology import misc as teuthology +from teuthology import contextutil +from teuthology.orchestra import run + +log = logging.getLogger(__name__) + + +@contextlib.contextmanager +def install_rabbitmq(ctx, config): + """ + Downloading the RabbitMQ package. + """ + assert isinstance(config, dict) + log.info('Installing RabbitMQ...') + + for (client, _) in config.items(): + (remote,) = ctx.cluster.only(client).remotes.keys() + + ctx.cluster.only(client).run(args=[ + 'sudo', 'yum', '-y', 'install', 'epel-release' + ]) + + link1 = 'https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh' + + ctx.cluster.only(client).run(args=[ + 'curl', '-s', link1, run.Raw('|'), 'sudo', 'bash' + ]) + + ctx.cluster.only(client).run(args=[ + 'sudo', 'yum', '-y', 'install', 'erlang' + ]) + + link2 = 'https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh' + + ctx.cluster.only(client).run(args=[ + 'curl', '-s', link2, run.Raw('|'), 'sudo', 'bash' + ]) + + ctx.cluster.only(client).run(args=[ + 'sudo', 'yum', '-y', 'install', 'rabbitmq-server' + ]) + + try: + yield + finally: + log.info('Removing packaged dependencies of RabbitMQ...') + + for (client, _) in config.items(): + ctx.cluster.only(client).run(args=[ + 'sudo', 'yum', '-y', 'remove', 'rabbitmq-server.noarch' + ]) + + +@contextlib.contextmanager +def run_rabbitmq(ctx, config): + """ + This includes two parts: + 1. Starting Daemon + 2. Starting RabbitMQ service + """ + assert isinstance(config, dict) + log.info('Bringing up Daemon and RabbitMQ service...') + for (client,_) in config.items(): + (remote,) = ctx.cluster.only(client).remotes.keys() + + ctx.cluster.only(client).run(args=[ + 'sudo', 'chkconfig', 'rabbitmq-server', 'on' + ], + ) + + ctx.cluster.only(client).run(args=[ + 'sudo', '/sbin/service', 'rabbitmq-server', 'start' + ], + ) + + ''' + # To check whether rabbitmq-server is running or not + ctx.cluster.only(client).run(args=[ + 'sudo', '/sbin/service', 'rabbitmq-server', 'status' + ], + ) + ''' + + try: + yield + finally: + log.info('Stopping RabbitMQ Service...') + + for (client, _) in config.items(): + (remote,) = ctx.cluster.only(client).remotes.keys() + + ctx.cluster.only(client).run(args=[ + 'sudo', '/sbin/service', 'rabbitmq-server', 'stop' + ], + ) + + +@contextlib.contextmanager +def task(ctx,config): + """ + To run rabbitmq the prerequisite is to run the tox task. Following is the way how to run + tox and then rabbitmq:: + tasks: + - rabbitmq: + client.0: + """ + assert config is None or isinstance(config, list) \ + or isinstance(config, dict), \ + "task rabbitmq only supports a list or dictionary for configuration" + + all_clients = ['client.{id}'.format(id=id_) + for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')] + if config is None: + config = all_clients + if isinstance(config, list): + config = dict.fromkeys(config) + + log.debug('RabbitMQ config is %s', config) + + with contextutil.nested( + lambda: install_rabbitmq(ctx=ctx, config=config), + lambda: run_rabbitmq(ctx=ctx, config=config), + ): + yield |