Blame SOURCES/01-smoke-test-fix.patch

9183b6
From 2f1b9d7f225530dfc88af57d364547d9ad425172 Mon Sep 17 00:00:00 2001
9183b6
From: Ondrej Mular <omular@redhat.com>
9183b6
Date: Thu, 24 Nov 2022 15:10:20 +0100
9183b6
Subject: [PATCH] smoke test improvements
9183b6
9183b6
---
9183b6
 .gitignore                         |  1 +
9183b6
 .gitlab-ci.yml                     |  1 +
9183b6
 configure.ac                       |  2 +-
9183b6
 pcs/Makefile.am                    |  1 -
9183b6
 pcs/api_v2_client.in               | 22 --------------------
9183b6
 pcs_test/Makefile.am               |  1 +
9183b6
 pcs_test/api_v2_client.in          | 20 +++++++++++++++++++
9183b6
 {pcs => pcs_test}/api_v2_client.py |  0
9183b6
 pcs_test/smoke.sh.in               | 32 +++++++++++++++++++-----------
9183b6
 9 files changed, 44 insertions(+), 36 deletions(-)
9183b6
 delete mode 100644 pcs/api_v2_client.in
9183b6
 create mode 100644 pcs_test/api_v2_client.in
9183b6
 rename {pcs => pcs_test}/api_v2_client.py (100%)
9183b6
9183b6
diff --git a/.gitignore b/.gitignore
9183b6
index b368a048..8dd3d5be 100644
9183b6
--- a/.gitignore
9183b6
+++ b/.gitignore
9183b6
@@ -21,6 +21,7 @@ requirements.txt
9183b6
 setup.py
9183b6
 setup.cfg
9183b6
 pcs/api_v2_client
9183b6
+pcs_test/api_v2_client
9183b6
 pcs/pcs
9183b6
 pcs/pcs_internal
9183b6
 pcs/settings.py
9183b6
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
9183b6
index d4e0074d..3d797729 100644
9183b6
--- a/.gitlab-ci.yml
9183b6
+++ b/.gitlab-ci.yml
9183b6
@@ -126,6 +126,7 @@ python_smoke_tests:
9183b6
     - ./autogen.sh
9183b6
     - ./configure --enable-local-build
9183b6
     - make
9183b6
+    - rm -rf pcs
9183b6
     - pcs_test/smoke.sh
9183b6
   artifacts:
9183b6
     paths:
9183b6
diff --git a/configure.ac b/configure.ac
9183b6
index bc8abb39..b61c1b25 100644
9183b6
--- a/configure.ac
9183b6
+++ b/configure.ac
9183b6
@@ -578,10 +578,10 @@ AC_CONFIG_FILES([Makefile
9183b6
 		 pcsd/settings.rb
9183b6
 		 pcsd/logrotate/pcsd])
9183b6
 
9183b6
-AC_CONFIG_FILES([pcs/api_v2_client], [chmod +x pcs/api_v2_client])
9183b6
 AC_CONFIG_FILES([pcs/pcs], [chmod +x pcs/pcs])
9183b6
 AC_CONFIG_FILES([pcs/pcs_internal], [chmod +x pcs/pcs_internal])
9183b6
 AC_CONFIG_FILES([pcs/snmp/pcs_snmp_agent], [chmod +x pcs/snmp/pcs_snmp_agent])
9183b6
+AC_CONFIG_FILES([pcs_test/api_v2_client], [chmod +x pcs_test/api_v2_client])
9183b6
 AC_CONFIG_FILES([pcs_test/smoke.sh], [chmod +x pcs_test/smoke.sh])
9183b6
 AC_CONFIG_FILES([pcs_test/pcs_for_tests], [chmod +x pcs_test/pcs_for_tests])
9183b6
 AC_CONFIG_FILES([pcs_test/suite], [chmod +x pcs_test/suite])
9183b6
diff --git a/pcs/Makefile.am b/pcs/Makefile.am
9183b6
index 5c5104b4..f562b32c 100644
9183b6
--- a/pcs/Makefile.am
9183b6
+++ b/pcs/Makefile.am
9183b6
@@ -20,7 +20,6 @@ EXTRA_DIST		= \
9183b6
 			  acl.py \
9183b6
 			  alert.py \
9183b6
 			  app.py \
9183b6
-			  api_v2_client.py \
9183b6
 			  cli/booth/command.py \
9183b6
 			  cli/booth/env.py \
9183b6
 			  cli/booth/__init__.py \
9183b6
diff --git a/pcs/api_v2_client.in b/pcs/api_v2_client.in
9183b6
deleted file mode 100644
9183b6
index 93336c31..00000000
9183b6
--- a/pcs/api_v2_client.in
9183b6
+++ /dev/null
9183b6
@@ -1,22 +0,0 @@
9183b6
-#!@PYTHON@
9183b6
-
9183b6
-import os.path
9183b6
-import sys
9183b6
-
9183b6
-CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
9183b6
-
9183b6
-# We prevent to import some module from this dir instead of e.g. standard module.
9183b6
-# There is no reason to import anything from this module.
9183b6
-sys.path.remove(CURRENT_DIR)
9183b6
-
9183b6
-# Add pcs package.
9183b6
-PACKAGE_DIR = os.path.dirname(CURRENT_DIR)
9183b6
-BUNDLED_PACKAGES_DIR = os.path.join(
9183b6
-    PACKAGE_DIR, "@PCS_BUNDLED_DIR_LOCAL@", "packages"
9183b6
-)
9183b6
-sys.path.insert(0, BUNDLED_PACKAGES_DIR)
9183b6
-sys.path.insert(0, PACKAGE_DIR)
9183b6
-
9183b6
-from pcs import api_v2_client
9183b6
-
9183b6
-api_v2_client.main()
9183b6
diff --git a/pcs_test/Makefile.am b/pcs_test/Makefile.am
9183b6
index 89a23e05..6f497a0e 100644
9183b6
--- a/pcs_test/Makefile.am
9183b6
+++ b/pcs_test/Makefile.am
9183b6
@@ -57,6 +57,7 @@ EXTRA_DIST		= \
9183b6
 			  resources/transitions01.xml \
9183b6
 			  resources/transitions02.xml \
9183b6
 			  suite.py \
9183b6
+			  api_v2_client.py \
9183b6
 			  tier0/cli/booth/__init__.py \
9183b6
 			  tier0/cli/booth/test_env.py \
9183b6
 			  tier0/cli/cluster/__init__.py \
9183b6
diff --git a/pcs_test/api_v2_client.in b/pcs_test/api_v2_client.in
9183b6
new file mode 100644
9183b6
index 00000000..73a22324
9183b6
--- /dev/null
9183b6
+++ b/pcs_test/api_v2_client.in
9183b6
@@ -0,0 +1,20 @@
9183b6
+#!@PYTHON@
9183b6
+import os.path
9183b6
+import sys
9183b6
+
9183b6
+CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
9183b6
+
9183b6
+TEST_INSTALLED = os.environ.get("PCS_TEST.TEST_INSTALLED", "0") == "1"
9183b6
+
9183b6
+if TEST_INSTALLED:
9183b6
+    BUNDLED_PACKAGES_DIR = os.path.join("@PCS_BUNDLED_DIR@", "packages")
9183b6
+else:
9183b6
+    PACKAGE_DIR = os.path.dirname(CURRENT_DIR)
9183b6
+    sys.path.insert(0, PACKAGE_DIR)
9183b6
+    BUNDLED_PACKAGES_DIR = os.path.join(PACKAGE_DIR, "@PCS_BUNDLED_DIR_LOCAL@", "packages")
9183b6
+
9183b6
+sys.path.insert(0, BUNDLED_PACKAGES_DIR)
9183b6
+
9183b6
+from api_v2_client import main
9183b6
+
9183b6
+main()
9183b6
diff --git a/pcs/api_v2_client.py b/pcs_test/api_v2_client.py
9183b6
similarity index 100%
9183b6
rename from pcs/api_v2_client.py
9183b6
rename to pcs_test/api_v2_client.py
9183b6
diff --git a/pcs_test/smoke.sh.in b/pcs_test/smoke.sh.in
9183b6
index 42321777..b845b6d6 100755
9183b6
--- a/pcs_test/smoke.sh.in
9183b6
+++ b/pcs_test/smoke.sh.in
9183b6
@@ -1,6 +1,8 @@
9183b6
 #!@BASH@
9183b6
 set -ex
9183b6
 
9183b6
+SCRIPT_DIR="$(dirname -- "$(realpath -- "$0")")"
9183b6
+
9183b6
 cluster_user=hacluster
9183b6
 cluster_user_password=qa57Jk27eP
9183b6
 pcsd_socket_path="@LOCALSTATEDIR@/run/pcsd.socket"
9183b6
@@ -15,13 +17,15 @@ if pidof systemd | grep "\b1\b"; then
9183b6
     pcs cluster setup cluster-name localhost --debug
9183b6
 fi
9183b6
 
9183b6
+output_file=$(mktemp)
9183b6
+token_file=$(mktemp)
9183b6
+
9183b6
 # Sanity check of API V0
9183b6
 token=$(python3 -c "import json; print(json.load(open('@LOCALSTATEDIR@/lib/pcsd/known-hosts'))['known_hosts']['localhost']['token']);")
9183b6
-curl -kb "token=${token}" https://localhost:2224/remote/cluster_status_plaintext -d 'data_json={}' > output.json
9183b6
-cat output.json; echo ""
9183b6
-python3 -c "import json; import sys; json.load(open('output.json'))['status'] == 'exception' and (sys.exit(1))";
9183b6
+curl -kb "token=${token}" https://localhost:2224/remote/cluster_status_plaintext -d 'data_json={}' > "${output_file}"
9183b6
+cat "${output_file}"; echo ""
9183b6
+python3 -c "import json; import sys; json.load(open('${output_file}'))['status'] == 'exception' and (sys.exit(1))";
9183b6
 
9183b6
-token_file=$(mktemp)
9183b6
 dd if=/dev/urandom bs=32 count=1 status=none | base64 > "${token_file}"
9183b6
 custom_localhost_node_name="custom-node-name"
9183b6
 
9183b6
@@ -30,24 +34,28 @@ pcs pcsd accept_token "${token_file}"
9183b6
 pcs pcsd status "${custom_localhost_node_name}" | grep "${custom_localhost_node_name}: Online"
9183b6
 
9183b6
 # Sanity check of API V1
9183b6
-curl -kb "token=${token}" https://localhost:2224/api/v1/resource-agent-get-agents-list/v1 --data '{}' > output.json
9183b6
-cat output.json; echo ""
9183b6
-python3 -c "import json; import sys; json.load(open('output.json'))['status'] != 'success' and (sys.exit(1))";
9183b6
+curl -kb "token=${token}" https://localhost:2224/api/v1/resource-agent-get-agents-list/v1 --data '{}' > "${output_file}"
9183b6
+cat "${output_file}"; echo ""
9183b6
+python3 -c "import json; import sys; json.load(open('${output_file}'))['status'] != 'success' and (sys.exit(1))";
9183b6
 
9183b6
 # Sanity check of API V2
9183b6
 # async
9183b6
-pcs/api_v2_client resource_agent.get_agent_metadata '{"agent_name":{"standard":"ocf","provider":"pacemaker","type":"Dummy"}}'
9183b6
+env "PCS_TEST.TEST_INSTALLED=1" ${SCRIPT_DIR}/api_v2_client resource_agent.get_agent_metadata '{"agent_name":{"standard":"ocf","provider":"pacemaker","type":"Dummy"}}'
9183b6
 
9183b6
 # sync
9183b6
-pcs/api_v2_client --sync resource_agent.get_agent_metadata '{"agent_name":{"standard":"ocf","provider":"pacemaker","type":"Stateful"}}'
9183b6
+env "PCS_TEST.TEST_INSTALLED=1" ${SCRIPT_DIR}/api_v2_client --sync resource_agent.get_agent_metadata '{"agent_name":{"standard":"ocf","provider":"pacemaker","type":"Stateful"}}'
9183b6
 
9183b6
 # unix socket test
9183b6
-curl --unix-socket "${pcsd_socket_path}" http:/something/api/v1/resource-agent-get-agents-list/v1 --data '{}' > output.json
9183b6
-cat output.json; echo ""
9183b6
-python3 -c "import json; import sys; json.load(open('output.json'))['status'] != 'success' and (sys.exit(1))";
9183b6
+curl --unix-socket "${pcsd_socket_path}" http:/something/api/v1/resource-agent-get-agents-list/v1 --data '{}' > "${output_file}"
9183b6
+cat "${output_file}"; echo ""
9183b6
+python3 -c "import json; import sys; json.load(open('${output_file}'))['status'] != 'success' and (sys.exit(1))";
9183b6
 
9183b6
 # make sure socket is not accessible by all users
9183b6
 useradd testuser
9183b6
 su testuser
9183b6
 ! curl --unix-socket "${pcsd_socket_path}" http:/something/api/v1/resource-agent-get-agents-list/v1 --data '{}'
9183b6
+
9183b6
+# cleanup
9183b6
+rm "${token_file}"
9183b6
+rm "${output_file}"
9183b6
 exit 0
9183b6
-- 
9183b6
2.38.1
9183b6