From d60148673b781962e5b6aa0097f1970ef9dce0e6 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Jul 18 2019 08:24:20 +0000 Subject: Add helper developer scripts --- diff --git a/dev_scripts/README.md b/dev_scripts/README.md new file mode 100644 index 0000000..3b7065b --- /dev/null +++ b/dev_scripts/README.md @@ -0,0 +1,13 @@ +## Development scripts + +This directory contains useful scripts for Freshmaker development. + +It is hard to test Freshmaker end to end locally, because it depends +on lot of other services. To be able to test some parts locally, +we use few scripts stored in this directory. + +The scripts are just templates creating instances of particular Freshmaker +classes so they can later be used for testing. + +The intended use-case is that when developing some feature, you can test +the feature using these scripts. You should *not* commit the changed script. diff --git a/dev_scripts/errata.py b/dev_scripts/errata.py new file mode 100755 index 0000000..8ac1a9d --- /dev/null +++ b/dev_scripts/errata.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +from __future__ import print_function +import os +import sys +from pprint import pprint + +# Allow imports from parent directory. +sys.path.insert(1, os.path.join(sys.path[0], '..')) + +# Set the FRESHMAKER_DEVELOPER_ENV variable. +os.environ["FRESHMAKER_DEVELOPER_ENV"] = "1" + +from freshmaker.errata import Errata +from freshmaker import conf + + +if len(sys.argv) != 2: + print("Template for testing freshmaker.Errata class") + print("Usage: ./errata.py ERRATA_TOOL_SERVER_URL") + sys.exit(1) + + +conf.errata_tool_server_url = sys.argv[1] +errata = Errata() + +# Example usage: +data = errata.get_builds(42515) +pprint(data) diff --git a/dev_scripts/lightblue.py b/dev_scripts/lightblue.py new file mode 100755 index 0000000..4f4ceed --- /dev/null +++ b/dev_scripts/lightblue.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +from __future__ import print_function +import os +import sys +from pprint import pprint + +# Allow imports from parent directory. +sys.path.insert(1, os.path.join(sys.path[0], '..')) + +# Set the FRESHMAKER_DEVELOPER_ENV variable. +os.environ["FRESHMAKER_DEVELOPER_ENV"] = "1" + +from freshmaker.lightblue import LightBlue + + +if len(sys.argv) != 4: + print("Template for testing freshmaker.Lightblue class") + print("Usage: ./lightblue.py LB_SERVER_URL PATH_TO_LB_CLIENT_CERT " + "PATH_TO_LB_CLIENT_KEY") + sys.exit(1) + + +lb = LightBlue(sys.argv[1], sys.argv[2], sys.argv[3], False) + + +def example_image_request(lb): + query = { + "objectType": "containerImage", + "query": { + "$and": [ + { + "field": "repositories.*.tags.*.name", + "op": "=", + "rvalue": "latest" + }, + { + "field": "brew.build", + "op": "=", + "rvalue": "s2i-core-container-1-66" + }, + { + "field": "parsed_data.files.*.key", + "op": "=", + "rvalue": "buildfile" + } + ] + }, + "projection": lb._get_default_projection(include_rpms=False) + } + images = lb.find_container_images(query) + pprint(images) + + +def example_repository_request(lb): + # Get all the latest container images containing "httpd" + query = { + "objectType": "containerRepository", + "query": { + "$and": [ + { + "field": "images.*.brew.build", + "op": "=", + "rvalue": "s2i-core-container-1-66" + }, + + ] + }, + "projection": [ + {"field": "repository", "include": True}, + ] + } + repositories = lb.find_container_repositories(query) + pprint(repositories) + + +example_image_request(lb) +example_repository_request(lb) diff --git a/dev_scripts/pulp.py b/dev_scripts/pulp.py new file mode 100755 index 0000000..afdf49b --- /dev/null +++ b/dev_scripts/pulp.py @@ -0,0 +1,28 @@ +#!/usr/bin/python +from __future__ import print_function +import os +import sys +from pprint import pprint + +# Allow imports from parent directory. +sys.path.insert(1, os.path.join(sys.path[0], '..')) + +# Set the FRESHMAKER_DEVELOPER_ENV variable. +os.environ["FRESHMAKER_DEVELOPER_ENV"] = "1" + +from freshmaker.pulp import Pulp + + +if len(sys.argv) != 4: + print("Template for testing freshmaker.Pulp class") + print("Usage: ./pulp.py PULP_SERVER_URL PULP_USERNAME PULP_PASSWORD") + sys.exit(1) + + +pulp = Pulp(sys.argv[1], sys.argv[2], sys.argv[3]) + + +repo_ids = [ + "rhel-7-server-release-e2e-test-1-rpms__x86_64" +] +pprint(pulp.get_content_set_by_repo_ids(repo_ids)) diff --git a/tox.ini b/tox.ini index d6e5f69..3d71cab 100644 --- a/tox.ini +++ b/tox.ini @@ -37,7 +37,7 @@ ignore_outcome = True [flake8] ignore = E501,E731,W504 -exclude = freshmaker/migrations/*,.tox/*,build/*,__pycache__,scripts/print_handlers_md.py,.copr/*,.env +exclude = dev_scripts/*,freshmaker/migrations/*,.tox/*,build/*,__pycache__,scripts/print_handlers_md.py,.copr/*,.env [pytest] addopts = --cov=freshmaker