pcs/01-smoke-test-fix.patch
Michal Pospisil 9792d48c7b Resolves: rhbz#2148124 rhbz#2151164 rhbz#2151524
- Fixed stopping of pcsd service using `systemctl stop pcsd` command
- Fixed smoke test execution during gating
- Added warning when omitting validation of misconfigured resource
- Fixed displaying of bool and integer values in `pcs resource config` command
- Updated bundled rubygems: ethon, rack-protection, sinatra
2022-12-15 12:00:30 +01:00

216 lines
7.8 KiB
Diff

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