From 29917b494de3d163307cf0c91e3fa3a07a8845f9 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Jul 17 2020 20:22:46 +0000
Subject: [PATCH 1/12] Run tests in virtualenvs using tox


Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/.gitignore b/.gitignore
index 19649a3..05b13b6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,4 @@ docs/build/
 .vagrant
 .gitreview
 devtools/*.conf
+.tox
diff --git a/Makefile b/Makefile
index 24b830d..992446a 100644
--- a/Makefile
+++ b/Makefile
@@ -79,20 +79,11 @@ test: test2 test3
 	@echo "All tests are finished for python 2&3"
 
 test2:
-	coverage2 erase
-	PYTHONPATH=.:plugins/builder/.:plugins/cli/.:cli/.:www/lib coverage2 run \
-	    --source . -m nose tests/test_builder tests/test_cli tests/test_lib \
-	    tests/test_plugins/test*builder.py tests/test_plugins/test*cli.py
-	coverage2 report
-	coverage2 html
+	tox -e py2
 	@echo Full coverage report at file://${CURDIR}/htmlcov/py2/index.html
 
 test3:
-	coverage3 erase --rcfile .coveragerc3
-	PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib coverage3 run \
-	    --rcfile .coveragerc3 --source . -m nose
-	coverage3 report --rcfile .coveragerc3
-	coverage3 html --rcfile .coveragerc3
+	tox -e py3
 	@echo Full coverage report at file://${CURDIR}/htmlcov/py3/index.html
 
 test-tarball:
@@ -136,7 +127,7 @@ pypi-upload:
 	twine upload dist/*
 
 flake8:
-	flake8
+	tox -e flake8
 
 tag::
 	git tag -a $(TAG)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..83107c7
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,7 @@
+-e .
+Cheetah;python_version < '3.0'
+Cheetah3;python_version >= '3.0'
+psycopg2-binary;python_version >= '3.0'
+python-multilib
+python-qpid-proton
+rpm-py-installer
diff --git a/test-requirements.txt b/test-requirements.txt
index 7cba63d..f73ab63 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,6 +1,8 @@
+-e .
 flake8
 flake8-import-order
 mock<=2.0.0
 requests-mock
 coverage
 nose
+unittest2;python_version < '3.0'
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..1e07fd3
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,55 @@
+[tox]
+envlist = flake8,py2,py3
+
+[testenv:flake8]
+deps =
+    flake8
+# On EL6, pip would get us a flake8 that doesn't work with python2.6. The next
+# two lines let us use an RPM-based version from EPEL if it is installed
+sitepackages = true
+whitelist_externals = flake8
+# These two lines just speed things up by avoiding unnecessary setup
+skip_install=true
+usedevelop=true
+commands =
+    flake8 --exclude=.tox
+
+[testenv]
+deps =
+    -r{toxinidir}/requirements.txt
+    -r{toxinidir}/test-requirements.txt
+# We need to access python-rpm, at least, and potentially more on EL6
+sitepackages = true
+# If rpm's python bindings are missing, don't continue
+# Also, because coverage might be installed system-wide and it serves as our
+# entry point, let's make sure it's installed in the virtualenv.
+commands_pre =
+    {envbindir}/python -c "import rpm"
+    pip install -I coverage
+
+[testenv:py3]
+setenv = 
+    PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib
+commands_pre =
+    {[testenv]commands_pre}
+    {envbindir}/coverage3 erase --rcfile .coveragerc3
+commands = 
+    {envbindir}/coverage3 run --rcfile .coveragerc3 --source . -m nose
+    {envbindir}/coverage3 report --rcfile .coveragerc3
+    {envbindir}/coverage3 html -d {toxinidir}/htmlcov/py3 --rcfile .coveragerc3
+
+[testenv:py2]
+setenv = 
+    PYTHONPATH=.:plugins/builder/.:plugins/cli/.:cli/.:www/lib
+commands_pre =
+    {[testenv]commands_pre}
+    {envbindir}/coverage2 erase
+commands =
+    {envbindir}/coverage2 run --source . -m nose \
+        tests/test_builder tests/test_cli \
+        tests/test_plugins/test_runroot_builder.py \
+        tests/test_plugins/test_save_failed_tree_builder.py \
+        tests/test_plugins/test_runroot_cli.py \
+        tests/test_plugins/test_save_failed_tree_cli.py
+    {envbindir}/coverage2 report
+    {envbindir}/coverage2 html -d {toxinidir}/htmlcov/py3

From fa17bcd571178e723aaca3c939d3f210de3e8c9e Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Jul 17 2020 20:22:46 +0000
Subject: [PATCH 2/12] Add Dockerfiles to aid in testing


Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/devtools/containers/README.md b/devtools/containers/README.md
new file mode 100644
index 0000000..92d1676
--- /dev/null
+++ b/devtools/containers/README.md
@@ -0,0 +1,13 @@
+Dockerfiles for development
+===========================
+
+To facilitate in development - specifically, running tests, two Dockerfiles are
+provided:
+
+* [`./centos/Dockerfile`](./centos/Dockerfile) CentOS 6, for testing with python2.6
+* [`./fedora/Dockerfile`](./fedora/Dockerfile) Fedora 32, for testing with python3.8
+
+To use them, taking fedora as an example:
+
+    docker build -t koji_test_fedora:latest --no-cache ./devtools/containers/fedora
+    docker run --rm -v $PWD:/koji --name koji_test koji_test_fedora:latest bash -c "cd /koji && tox -e flake8,py3"
diff --git a/devtools/containers/centos/Dockerfile b/devtools/containers/centos/Dockerfile
new file mode 100644
index 0000000..6adf59e
--- /dev/null
+++ b/devtools/containers/centos/Dockerfile
@@ -0,0 +1,24 @@
+FROM centos:6
+RUN \
+  yum install -y \
+    gcc \
+    git \
+    make \
+    krb5-devel \
+    libffi-devel \
+    openssl-devel \
+    pyOpenSSL \
+    python-devel \
+    redhat-rpm-config \
+    rpm-build \
+    rpm-python \
+    yum-utils && \
+  yum install -y epel-release && \
+  yum install -y \
+    python-flake8 \
+    python-pip \
+    python-psycopg2 \
+    python-qpid-proton \
+    python-requests-kerberos && \
+  pip install -U 'pip==9.0.1' && \
+  pip install -U tox
diff --git a/devtools/containers/fedora/Dockerfile b/devtools/containers/fedora/Dockerfile
new file mode 100644
index 0000000..417113e
--- /dev/null
+++ b/devtools/containers/fedora/Dockerfile
@@ -0,0 +1,20 @@
+FROM fedora:32
+RUN \
+  dnf install -y \
+  gcc \
+  git \
+  glib2-devel \
+  glibc-langpack-en \
+  krb5-devel \
+  libffi-devel \
+  libxml2-devel \
+  make \
+  openssl-devel \
+  python3-devel \
+  python3-pip \
+  python3-rpm \
+  python3-tox \
+  redhat-rpm-config \
+  rpm-build \
+  sqlite-devel \
+  yum-utils

From 08777e30502878cb7d26596df9eb3b2d7069dbd7 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 03 2020 20:06:08 +0000
Subject: [PATCH 3/12] rpm-py-installer: Download binaries


Instead of building from source.

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/devtools/containers/centos/Dockerfile b/devtools/containers/centos/Dockerfile
index 6adf59e..8446ffe 100644
--- a/devtools/containers/centos/Dockerfile
+++ b/devtools/containers/centos/Dockerfile
@@ -19,6 +19,7 @@ RUN \
     python-pip \
     python-psycopg2 \
     python-qpid-proton \
-    python-requests-kerberos && \
+    python-requests-kerberos \
+    yumdownloader && \
   pip install -U 'pip==9.0.1' && \
   pip install -U tox
diff --git a/devtools/containers/fedora/Dockerfile b/devtools/containers/fedora/Dockerfile
index 417113e..5bb554e 100644
--- a/devtools/containers/fedora/Dockerfile
+++ b/devtools/containers/fedora/Dockerfile
@@ -1,6 +1,7 @@
 FROM fedora:32
 RUN \
   dnf install -y \
+  'dnf-command(download)' \
   gcc \
   git \
   glib2-devel \
diff --git a/tox.ini b/tox.ini
index 1e07fd3..5198f2e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -20,6 +20,10 @@ deps =
     -r{toxinidir}/test-requirements.txt
 # We need to access python-rpm, at least, and potentially more on EL6
 sitepackages = true
+# Tell the rpm-py-installer package to download binaries instead of building
+# from source
+setenv =
+    RPM_PY_INSTALL_BIN=true
 # If rpm's python bindings are missing, don't continue
 # Also, because coverage might be installed system-wide and it serves as our
 # entry point, let's make sure it's installed in the virtualenv.
@@ -29,6 +33,7 @@ commands_pre =
 
 [testenv:py3]
 setenv = 
+    {[testenv]setenv}
     PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib
 commands_pre =
     {[testenv]commands_pre}
@@ -40,6 +45,7 @@ commands =
 
 [testenv:py2]
 setenv = 
+    {[testenv]setenv}
     PYTHONPATH=.:plugins/builder/.:plugins/cli/.:cli/.:www/lib
 commands_pre =
     {[testenv]commands_pre}

From 9b88f21a2f7284f7d66257baa23ce6f8fbae8a79 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 03 2020 20:06:08 +0000
Subject: [PATCH 4/12] test-requirements: Refine requests-mock versions


python2.6 and 2.7 need specific versions due to compatibility breakage

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/test-requirements.txt b/test-requirements.txt
index f73ab63..1a8a17c 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -2,7 +2,8 @@
 flake8
 flake8-import-order
 mock<=2.0.0
-requests-mock
+requests-mock;python_version >= '2.7'
+requests-mock<1.5.0;python_version < '2.7'
 coverage
 nose
 unittest2;python_version < '3.0'

From 8110e2614c17f5a52096aedc6304b08807059bce Mon Sep 17 00:00:00 2001
From: Ken Dreyer <kdreyer@redhat.com>
Date: Aug 03 2020 20:06:08 +0000
Subject: [PATCH 5/12] devtools: add instructions for CentOS, podman, and SELinux


Document how to run the CentOS container, and mention the
"--security-opt label=disable" setting when running podman with SELinux
in enforcing mode.

---

diff --git a/devtools/containers/README.md b/devtools/containers/README.md
index 92d1676..65cb771 100644
--- a/devtools/containers/README.md
+++ b/devtools/containers/README.md
@@ -11,3 +11,13 @@ To use them, taking fedora as an example:
 
     docker build -t koji_test_fedora:latest --no-cache ./devtools/containers/fedora
     docker run --rm -v $PWD:/koji --name koji_test koji_test_fedora:latest bash -c "cd /koji && tox -e flake8,py3"
+
+Or CentOS as an example:
+
+    docker build -t koji_test_centos:latest --no-cache ./devtools/containers/centos
+    docker run --rm -v $PWD:/koji --name koji_test koji_test_centos:latest bash -c "cd /koji && tox -e py2"
+
+When running with Podman and SELinux enabled, use the "--security-opt
+label=disable" option:
+
+    podman run --rm -v $PWD:/koji --security-opt label=disable --name koji_test koji_test_fedora:latest bash -c "cd /koji && ls -l /koji && tox -e flake8,py3"

From c92ce76bed19d024806f6e7be53b96e02576eaa5 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 03 2020 20:06:08 +0000
Subject: [PATCH 6/12] Add koji's python reqs to centos6 docker image


This will allow, but not require, running tests using only RPM-packaged
requirements.

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/devtools/containers/centos/Dockerfile b/devtools/containers/centos/Dockerfile
index 8446ffe..55c2e01 100644
--- a/devtools/containers/centos/Dockerfile
+++ b/devtools/containers/centos/Dockerfile
@@ -8,7 +8,9 @@ RUN \
     libffi-devel \
     openssl-devel \
     pyOpenSSL \
+    python-cheetah \
     python-devel \
+    python-requests \
     redhat-rpm-config \
     rpm-build \
     rpm-python \
@@ -16,6 +18,7 @@ RUN \
   yum install -y epel-release && \
   yum install -y \
     python-flake8 \
+    python-multilib \
     python-pip \
     python-psycopg2 \
     python-qpid-proton \

From 4aa802b65768aed8a5edc210a7da68ce88bb4d92 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 03 2020 20:06:08 +0000
Subject: [PATCH 7/12] tox: Add py2-rpmdeps testenv


This avoids grabbing requirements from PyPI. Use this testenv if you
want to only test with globally-available (read: RPM) requirements.

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/tox.ini b/tox.ini
index 5198f2e..6cf91ff 100644
--- a/tox.ini
+++ b/tox.ini
@@ -59,3 +59,16 @@ commands =
         tests/test_plugins/test_save_failed_tree_cli.py
     {envbindir}/coverage2 report
     {envbindir}/coverage2 html -d {toxinidir}/htmlcov/py3
+
+# This is identical to the py2 testenv, but without attempting to install
+# dependencies from requirements.txt. In practice this will mean RPM-based
+# dependencies must be installed.
+[testenv:py2-rpmdeps]
+deps =
+    -r{toxinidir}/test-requirements.txt
+setenv =
+    {[testenv:py2]setenv}
+commands_pre =
+    {[testenv:py2]commands_pre}
+commands =
+    {[testenv:py2]commands}

From 1f3df8fb4e57681c557a6d0a0f8a72ebb9149a96 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 03 2020 20:06:08 +0000
Subject: [PATCH 8/12] tox: Set PYTHONHASHSEED=0 for py2


This fixes a breakage in test_import_comps_sample_yumcomps

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/tox.ini b/tox.ini
index 6cf91ff..f39ecf5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -47,6 +47,7 @@ commands =
 setenv = 
     {[testenv]setenv}
     PYTHONPATH=.:plugins/builder/.:plugins/cli/.:cli/.:www/lib
+    PYTHONHASHSEED=0
 commands_pre =
     {[testenv]commands_pre}
     {envbindir}/coverage2 erase

From 3f4dd05b0b6946aeb6961e5a758785e5c115b5e0 Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 13 2020 18:21:11 +0000
Subject: [PATCH 9/12] tox: Fix typo in py2 env


Coverage reports were going in the wrong place.

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/tox.ini b/tox.ini
index f39ecf5..7ae2a3c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -59,7 +59,7 @@ commands =
         tests/test_plugins/test_runroot_cli.py \
         tests/test_plugins/test_save_failed_tree_cli.py
     {envbindir}/coverage2 report
-    {envbindir}/coverage2 html -d {toxinidir}/htmlcov/py3
+    {envbindir}/coverage2 html -d {toxinidir}/htmlcov/py2
 
 # This is identical to the py2 testenv, but without attempting to install
 # dependencies from requirements.txt. In practice this will mean RPM-based

From 0d6a8fa1e1bbc60f8ed401d8a584f3d5e46e710d Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 13 2020 18:21:49 +0000
Subject: [PATCH 10/12] Add rpm-devel to fedora container


This allows us to build python2 rpm bindings if necessary.

Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/devtools/containers/fedora/Dockerfile b/devtools/containers/fedora/Dockerfile
index 5bb554e..6c7fccc 100644
--- a/devtools/containers/fedora/Dockerfile
+++ b/devtools/containers/fedora/Dockerfile
@@ -17,5 +17,6 @@ RUN \
   python3-tox \
   redhat-rpm-config \
   rpm-build \
+  rpm-devel \
   sqlite-devel \
   yum-utils

From 0f2ba067461d7f9b0541cb9164864d3368acf85e Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 31 2020 20:40:18 +0000
Subject: [PATCH 11/12] tox: Fix flake8 invocation


Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/tox.ini b/tox.ini
index 7ae2a3c..c188442 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,7 +12,7 @@ whitelist_externals = flake8
 skip_install=true
 usedevelop=true
 commands =
-    flake8 --exclude=.tox
+    flake8
 
 [testenv]
 deps =

From 45badd56820db581c5dc9eaa1e3993e3a569e5eb Mon Sep 17 00:00:00 2001
From: Zack Cerza <zack@redhat.com>
Date: Aug 31 2020 20:40:29 +0000
Subject: [PATCH 12/12] flake8: Ignore .tox


Signed-off-by: Zack Cerza <zack@redhat.com>

---

diff --git a/.flake8 b/.flake8
index 2051214..b555855 100644
--- a/.flake8
+++ b/.flake8
@@ -15,7 +15,8 @@ exclude =
     __pycache__,
     tests,
     docs,
-    ./koji-*/*
+    ./koji-*/*,
+    .tox
 
 filename =
     *.py,

