|
Clement Verna |
37420e |
#! /usr/bin/python3
|
|
Clement Verna |
37420e |
import argparse
|
|
Clement Verna |
37420e |
import os
|
|
Clement Verna |
37420e |
import subprocess as sp
|
|
Clement Verna |
37420e |
from string import Template
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
TEMPLATE = "dev/docker/test_env_template"
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
1ee861 |
PKG_LIST = "python3-alembic python3-arrow python3-binaryornot \
|
|
Clement Verna |
1ee861 |
python3-bleach python3-blinker python3-chardet python3-cryptography \
|
|
Clement Verna |
1ee861 |
python3-docutils python3-flask python3-fedora-flask \
|
|
Clement Verna |
1ee861 |
python3-flask-wtf python3-bcrypt python3-jinja2 \
|
|
Clement Verna |
1ee861 |
python3-markdown python3-munch python3-openid-cla \
|
|
Clement Verna |
1ee861 |
python3-openid-teams python3-psutil python3-pygit2 python3-pillow \
|
|
Clement Verna |
1ee861 |
python3-sqlalchemy python3-straight-plugin python3-wtforms \
|
|
Clement Verna |
1ee861 |
python3-nose python3-coverage python3-mock python3-mock \
|
|
Clement Verna |
1ee861 |
python3-eventlet python3-flask-oidc python3-flake8 python3-celery \
|
|
Clement Verna |
1ee861 |
python3-redis python3-trololio python3-beautifulsoup4 python3-black redis vim git"
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
def setup_parser():
|
|
Clement Verna |
37420e |
""" Setup the cli arguments """
|
|
Clement Verna |
37420e |
parser = argparse.ArgumentParser(prog="pagure-test")
|
|
Clement Verna |
37420e |
parser.add_argument(
|
|
Clement Verna |
37420e |
"test_case", nargs="?", default="", help="Run the given test case"
|
|
Clement Verna |
37420e |
)
|
|
Clement Verna |
37420e |
parser.add_argument(
|
|
Clement Verna |
37420e |
"--fedora",
|
|
Clement Verna |
37420e |
action="store_true",
|
|
Clement Verna |
37420e |
help="Run the tests in fedora environment (DEFAULT)",
|
|
Clement Verna |
37420e |
)
|
|
Clement Verna |
37420e |
parser.add_argument(
|
|
Clement Verna |
37420e |
"--centos",
|
|
Clement Verna |
37420e |
action="store_true",
|
|
Clement Verna |
37420e |
help="Run the tests in centos environment",
|
|
Clement Verna |
37420e |
)
|
|
Clement Verna |
37420e |
parser.add_argument(
|
|
Clement Verna |
37420e |
"--skip-build",
|
|
Clement Verna |
37420e |
dest="skip_build",
|
|
Clement Verna |
37420e |
action="store_false",
|
|
Clement Verna |
37420e |
help="Skip building the container image",
|
|
Clement Verna |
37420e |
)
|
|
Pierre-Yves Chibon |
e944ac |
parser.add_argument(
|
|
Pierre-Yves Chibon |
e944ac |
"--shell",
|
|
Pierre-Yves Chibon |
e944ac |
dest="shell",
|
|
Pierre-Yves Chibon |
e944ac |
action="store_true",
|
|
Pierre-Yves Chibon |
e944ac |
help="Gives you a shell into the container instead "
|
|
Pierre-Yves Chibon |
e944ac |
"of running the tests",
|
|
Pierre-Yves Chibon |
e944ac |
)
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
return parser
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
if __name__ == "__main__":
|
|
Clement Verna |
37420e |
parser = setup_parser()
|
|
Clement Verna |
37420e |
args = parser.parse_args()
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
if args.centos is True:
|
|
Clement Verna |
37420e |
base_image = "centos:7"
|
|
Clement Verna |
37420e |
pkg_mgr = "yum"
|
|
Clement Verna |
37420e |
epel_pkg = "RUN yum -y install epel-release"
|
|
Clement Verna |
37420e |
infra_repo = (
|
|
Clement Verna |
37420e |
"ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo"
|
|
Clement Verna |
37420e |
)
|
|
Clement Verna |
37420e |
container_name = "pagure-test-centos"
|
|
Clement Verna |
37420e |
PKG_LIST += "python34 python34-coverage"
|
|
Clement Verna |
37420e |
else:
|
|
Clement Verna |
4e0b37 |
base_image = "registry.fedoraproject.org/fedora:latest"
|
|
Clement Verna |
37420e |
pkg_mgr = "dnf"
|
|
Clement Verna |
37420e |
container_name = "pagure-test-fedora"
|
|
Clement Verna |
37420e |
epel_pkg = ""
|
|
Clement Verna |
37420e |
infra_repo = ""
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
with open(TEMPLATE, "r") as fp:
|
|
Clement Verna |
37420e |
t = Template(fp.read())
|
|
Clement Verna |
37420e |
with open("dev/docker/test_env", "w") as fp:
|
|
Clement Verna |
37420e |
fp.write(
|
|
Clement Verna |
37420e |
t.substitute(
|
|
Clement Verna |
37420e |
base_image=base_image,
|
|
Clement Verna |
37420e |
pkg_list=PKG_LIST,
|
|
Clement Verna |
37420e |
pkg_mgr=pkg_mgr,
|
|
Clement Verna |
37420e |
epel_pkg=epel_pkg,
|
|
Clement Verna |
37420e |
infra_repo=infra_repo,
|
|
Clement Verna |
37420e |
)
|
|
Clement Verna |
37420e |
)
|
|
Clement Verna |
37420e |
|
|
Clement Verna |
37420e |
if args.skip_build is not False:
|
|
Clement Verna |
37420e |
print("------ Building Docker Image -----")
|
|
Clement Verna |
37420e |
sp.run(
|
|
Clement Verna |
37420e |
[
|
|
Clement Verna |
37420e |
"podman",
|
|
Clement Verna |
37420e |
"build",
|
|
Clement Verna |
37420e |
"--rm",
|
|
Clement Verna |
37420e |
"-t",
|
|
Clement Verna |
37420e |
container_name,
|
|
Clement Verna |
37420e |
"-f",
|
|
Clement Verna |
37420e |
"dev/docker/test_env",
|
|
Clement Verna |
37420e |
"dev/docker",
|
|
Clement Verna |
37420e |
]
|
|
Clement Verna |
37420e |
)
|
|
Pierre-Yves Chibon |
e944ac |
if args.shell:
|
|
Pierre-Yves Chibon |
e944ac |
print("--------- Shelling in the container --------------")
|
|
Pierre-Yves Chibon |
e944ac |
command = [
|
|
Clement Verna |
37420e |
"podman",
|
|
Clement Verna |
37420e |
"run",
|
|
Clement Verna |
37420e |
"-it",
|
|
Clement Verna |
37420e |
"--rm",
|
|
Clement Verna |
37420e |
"--name",
|
|
Clement Verna |
37420e |
container_name,
|
|
Clement Verna |
37420e |
"-v",
|
|
Clement Verna |
37420e |
"{}:/pagure".format(os.getcwd()),
|
|
Pierre-Yves Chibon |
e944ac |
"--entrypoint=/bin/bash",
|
|
Clement Verna |
37420e |
container_name,
|
|
Clement Verna |
37420e |
]
|
|
Pierre-Yves Chibon |
e944ac |
sp.run(command)
|
|
Pierre-Yves Chibon |
e944ac |
|
|
Pierre-Yves Chibon |
e944ac |
else:
|
|
Pierre-Yves Chibon |
e944ac |
|
|
Pierre-Yves Chibon |
e944ac |
print("--------- Running Test --------------")
|
|
Pierre-Yves Chibon |
e944ac |
sp.run(
|
|
Pierre-Yves Chibon |
e944ac |
[
|
|
Pierre-Yves Chibon |
e944ac |
"podman",
|
|
Pierre-Yves Chibon |
e944ac |
"run",
|
|
Pierre-Yves Chibon |
e944ac |
"-it",
|
|
Pierre-Yves Chibon |
e944ac |
"--rm",
|
|
Pierre-Yves Chibon |
e944ac |
"--name",
|
|
Pierre-Yves Chibon |
e944ac |
container_name,
|
|
Pierre-Yves Chibon |
e944ac |
"-v",
|
|
Pierre-Yves Chibon |
e944ac |
"{}:/pagure".format(os.getcwd()),
|
|
Pierre-Yves Chibon |
e944ac |
container_name,
|
|
Pierre-Yves Chibon |
e944ac |
args.test_case,
|
|
Pierre-Yves Chibon |
e944ac |
]
|
|
Pierre-Yves Chibon |
e944ac |
)
|