#505 Add the script to test new freshmaker deployment
Merged 4 years ago by mulaieva. Opened 4 years ago by mulaieva.
mulaieva/freshmaker errata_id_script  into  master

file modified
+16
@@ -8,3 +8,19 @@ 

  

  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.

@@ -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)

Find out the lstest successful event and get it the errata_id.
At the moment, when we release a new freshmaker version, we start a
dry-run build to manually check that the deployment was successful
curl --negotiate -u : -k -X POST -d '{"errata_id": 46932, "dry_run": true}'
https://freshmaker.dev.engineering.redhat.com/api/1/builds/ -l -v
But if the errata_id is old, it can happen that the build won't be
successful. This script is for this reason, it extract the errata_id
and then run that curl command. This way, we don't need to update the
documentation every time this happens.
JIRA: https://projects.engineering.redhat.com/browse/FACTORY-5408

Could you add the reference to the jira card in the commit message?

It would be nice to have prod by default, and maybe add a parameter to this script (maybe with argparse) that will allow to specify if you want to run this in dev.
For example I could run:
python3 dev_scripts/last_errata_id.py --dev true

Using argparse we also automatically have a nice --help parameter.

Instead of last_errata_id.py, since this is a script for submitting a dry run build on the latest errata, I'd maybe call it build_last_errata_on_dry_run_mode.py
or something more explicit... I'm bad bad bad at names.

rebased onto c6c1837f232c8e9f3c6251e05cec2c642daf1221

4 years ago

Can you add some comment to explain why this was created? Like:
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 build, the errata_id and it submits a build in dry_run mode.

The name of the script was updated.

rebased onto ca2121a

4 years ago

Awesome! Looks good, thank you, Mariana +1
Feel free to remove the WIP and merge it.

Commit d12fa7e fixes this pull-request

Pull-Request has been merged by mulaieva

4 years ago

Pull-Request has been merged by mulaieva

4 years ago