From d12fa7ea017144838a74e24491e5d64e2dd43be2 Mon Sep 17 00:00:00 2001 From: Mariana Ulaieva Date: Mar 23 2020 11:28:34 +0000 Subject: Merge #505 `Add the script to test new freshmaker deployment` --- diff --git a/dev_scripts/README.md b/dev_scripts/README.md index 14e2e98..aa753b7 100644 --- a/dev_scripts/README.md +++ b/dev_scripts/README.md @@ -8,3 +8,19 @@ we use few scripts stored in this directory. The scripts with "template_" prefix are just templates creating instances of particular Freshmaker classes so they can later be used for testing. + +## Running the scripts + + +### dry_mode_build_errata_id + +This script can be useful to try a build in dry_run mode after a complete deployment, to manually +test if the deployment was successful. It automatically selects, from the latest successful event, +the errata_id and it submits a build in dry_run mode. + +``REQUESTS_CA_BUNDLE`` should be passed in `python3` to avoid SSL errors. Example usage: + + REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt python3 dev_scripts/dry_mode_build_errata_id.py + +By default, the script is executed on prod. To execute the script on dev the parameter `--dev` +should be added. diff --git a/dev_scripts/dry_mode_build_errata_id.py b/dev_scripts/dry_mode_build_errata_id.py new file mode 100644 index 0000000..9d3e5ae --- /dev/null +++ b/dev_scripts/dry_mode_build_errata_id.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 +import subprocess +import shlex + +import requests +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument('--dev', default=False, action='store_true', help="Run the script on the dev") +args = parser.parse_args() +if args.dev: + url = "https://freshmaker.dev.engineering.redhat.com/api/1/" +else: + url = "https://freshmaker.engineering.redhat.com/api/1/" + +r = requests.get(url + "events/?state=2") +r.raise_for_status() +data = r.json() + +# Get errata_id from last successful event +errata_id = data['items'][0]['search_key'] + +# Check that the deployment was successful: + +url_build = url + "builds/" +command = ( + "curl --negotiate -u : -k -X POST -d '{\"errata_id\": %s, \"dry_run\": true}' %s -l -v" + % (errata_id, url_build)) +subprocess_cmd = shlex.split(command) +stdout = subprocess.run(subprocess_cmd, stdout=subprocess.PIPE).stdout.decode('utf-8') + +print(stdout)