From a387f775ea855cad7b04dcc97dcd10b24500919c Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Wed, 18 Dec 2019 16:33:32 +0100
Subject: [PATCH] Use CLUSTER_DIR instead of INVENTORY in CI

---
 .gitlab-ci.yml                   | 10 +++++-----
 test/README.md                   | 10 +++++-----
 test/pytest/test_helmreleases.py |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 48bcec935..b9961957f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -18,7 +18,7 @@ variables:
   FQDN: "${CI_COMMIT_REF_SLUG}.ci.openappstack.net"
   ANSIBLE_HOST_KEY_CHECKING: "False"
   KANIKO_BUILD_IMAGENAME: "openappstack-ci"
-  INVENTORY: "/builds/openappstack/openappstack/clusters/${CI_COMMIT_REF_SLUG}/inventory.yml"
+  CLUSTER_DIR: "/builds/openappstack/openappstack/clusters/${CI_COMMIT_REF_SLUG}"
 
 default:
   image: "${CI_REGISTRY_IMAGE}/${KANIKO_BUILD_IMAGENAME}:${CI_COMMIT_REF_SLUG}"
@@ -100,7 +100,7 @@ test_helmreleases:
   script:
     - cd ansible/
     - export KUBECONFIG="${PWD}/../clusters/${HOSTNAME}/secrets/kube_config_cluster.yml"
-    - pytest -v -s -m 'helmreleases' --connection=ansible --ansible-inventory=${INVENTORY} --hosts='ansible://*' --reruns 120 --reruns-delay 10
+    - pytest -v -s -m 'helmreleases' --connection=ansible --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*' --reruns 120 --reruns-delay 10
   only:
     changes:
       - .gitlab-ci.yml
@@ -114,7 +114,7 @@ testinfra:
   stage: health-test
   script:
     - cd ansible/
-    - pytest -v -m 'testinfra' --connection=ansible --ansible-inventory=${INVENTORY} --hosts='ansible://*'
+    - pytest -v -m 'testinfra' --connection=ansible --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*'
   only:
     changes:
       - .gitlab-ci.yml
@@ -129,7 +129,7 @@ certs:
   allow_failure: true
   script:
     - cd ansible/
-    - pytest -s -m 'certs' --connection=ansible --ansible-inventory=${INVENTORY} --hosts='ansible://*'
+    - pytest -s -m 'certs' --connection=ansible --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*'
   only:
     changes:
       - .gitlab-ci.yml
@@ -144,7 +144,7 @@ prometheus-alerts:
   allow_failure: true
   script:
     - cd test/
-    - pytest -s -m 'prometheus' --connection=ansible --ansible-inventory=${INVENTORY} --hosts='ansible://*'
+    - pytest -s -m 'prometheus' --connection=ansible --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*'
   only:
     changes:
       - .gitlab-ci.yml
diff --git a/test/README.md b/test/README.md
index 7da4ce188..b91e561c2 100644
--- a/test/README.md
+++ b/test/README.md
@@ -13,13 +13,13 @@ There are two types of tests: "testinfra" tests, and "behave" tests.
 
 ## Run *testinfra* tests
 
-Export `INVENTORY` env var to the location of your clusters inventory file:
+Export `CLUSTER_DIR` env var with the location of your cluster config directory:
 
-    export INVENTORY=../clusters/CLUSTERNAME/inventory.yml
+    export CLUSTER_DIR="../clusters/CLUSTERNAME"
 
 Run all tests:
 
-    py.test -sv --ansible-inventory=${INVENTORY} --hosts='ansible://*'
+    py.test -sv --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*'
 
 Specify host manually:
 
@@ -27,13 +27,13 @@ Specify host manually:
 
 Run only tests tagged with `prometheus`:
 
-    py.test -sv --ansible-inventory=${INVENTORY} --hosts='ansible://*' -m prometheus
+    py.test -sv --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*' -m prometheus
 
 ### Cert tests
 
 Run cert test manually using the ansible inventory file:
 
-    py.test -sv --ansible-inventory=${INVENTORY} --hosts='ansible://*' -m certs
+    py.test -sv --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*' -m certs
 
 Run cert test manually against a different cluster, not configured in any
 ansible inventory file, either by using pytest:
diff --git a/test/pytest/test_helmreleases.py b/test/pytest/test_helmreleases.py
index 476dcebd4..624cf04da 100644
--- a/test/pytest/test_helmreleases.py
+++ b/test/pytest/test_helmreleases.py
@@ -36,7 +36,7 @@ def test_helmreleases(host):
         'oas-apps': ['nextcloud']
     }
 
-    cluster_dir = os.path.dirname(os.environ.get("INVENTORY"))
+    cluster_dir = os.environ.get("CLUSTER_DIR")
     kubeconfig = os.path.join(cluster_dir, 'secrets',
                               'kube_config_cluster.yml')
     config.load_kube_config(config_file=kubeconfig)
-- 
GitLab