From 4eb9cd5fb4129f573f120198432504773a3b15e3 Mon Sep 17 00:00:00 2001 From: Bracha Frenkel Date: Wed, 28 Feb 2024 20:04:51 +0200 Subject: [PATCH] Add kuttl test for neutron operator Implement a kuttl test to ensure that any modifications to the neutron service settings lead to the creation of a new pod with the updated settings. These tests should first confirm that the default logging setting excludes debug details. Then, after adjusting the neutron configuration to enable debug mode (debug = true), the tests should verify that the logs from the newly created pod now contain debug information. --- .../scripts/check_debug_in_neutron_pod_logs.sh | 7 +++++++ .../tests/change_neutron_config/01-assert.yaml | 1 + .../change_neutron_config/01-deploy-neutron.yaml | 6 ++++++ .../tests/change_neutron_config/02-assert.yaml | 6 ++++++ .../tests/change_neutron_config/03-assert.yaml | 7 +++++++ .../03-change_neutron_debug_config.yaml | 8 ++++++++ .../change_neutron_config/04-cleanup-neutron.yaml | 1 + .../tests/change_neutron_config/04-errors.yaml | 1 + .../change_neutron_config/deploy/kustomization.yaml | 13 +++++++++++++ 9 files changed, 50 insertions(+) create mode 100755 test/kuttl/common/scripts/check_debug_in_neutron_pod_logs.sh create mode 120000 test/kuttl/tests/change_neutron_config/01-assert.yaml create mode 100644 test/kuttl/tests/change_neutron_config/01-deploy-neutron.yaml create mode 100644 test/kuttl/tests/change_neutron_config/02-assert.yaml create mode 100644 test/kuttl/tests/change_neutron_config/03-assert.yaml create mode 100644 test/kuttl/tests/change_neutron_config/03-change_neutron_debug_config.yaml create mode 120000 test/kuttl/tests/change_neutron_config/04-cleanup-neutron.yaml create mode 120000 test/kuttl/tests/change_neutron_config/04-errors.yaml create mode 100644 test/kuttl/tests/change_neutron_config/deploy/kustomization.yaml diff --git a/test/kuttl/common/scripts/check_debug_in_neutron_pod_logs.sh b/test/kuttl/common/scripts/check_debug_in_neutron_pod_logs.sh new file mode 100755 index 00000000..6bc64f83 --- /dev/null +++ b/test/kuttl/common/scripts/check_debug_in_neutron_pod_logs.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +pod=$(oc get pods -n $NAMESPACE -l service=neutron -o name) + +# Check if the neutron pod logs contain DEBUG messages +oc logs -n $NAMESPACE "$pod" | grep -q "DEBUG" +exit $? diff --git a/test/kuttl/tests/change_neutron_config/01-assert.yaml b/test/kuttl/tests/change_neutron_config/01-assert.yaml new file mode 120000 index 00000000..461654ea --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/01-assert.yaml @@ -0,0 +1 @@ +../../common/assert_sample_deployment.yaml \ No newline at end of file diff --git a/test/kuttl/tests/change_neutron_config/01-deploy-neutron.yaml b/test/kuttl/tests/change_neutron_config/01-deploy-neutron.yaml new file mode 100644 index 00000000..af916ae6 --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/01-deploy-neutron.yaml @@ -0,0 +1,6 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + cp ../../../../config/samples/neutron_v1beta1_neutronapi.yaml deploy + oc kustomize deploy | oc apply -n $NAMESPACE -f - diff --git a/test/kuttl/tests/change_neutron_config/02-assert.yaml b/test/kuttl/tests/change_neutron_config/02-assert.yaml new file mode 100644 index 00000000..c676dda3 --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/02-assert.yaml @@ -0,0 +1,6 @@ +# check that by default, debug is set in neutron config +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + $NEUTRON_KUTTL_DIR/../common/scripts/check_debug_in_neutron_pod_logs.sh diff --git a/test/kuttl/tests/change_neutron_config/03-assert.yaml b/test/kuttl/tests/change_neutron_config/03-assert.yaml new file mode 100644 index 00000000..f6d17f93 --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/03-assert.yaml @@ -0,0 +1,7 @@ +# check that now, debug is not set in neutron config +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + $NEUTRON_KUTTL_DIR/../common/scripts/check_debug_in_neutron_pod_logs.sh + test $? -ne 0 diff --git a/test/kuttl/tests/change_neutron_config/03-change_neutron_debug_config.yaml b/test/kuttl/tests/change_neutron_config/03-change_neutron_debug_config.yaml new file mode 100644 index 00000000..9ecc8d6d --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/03-change_neutron_debug_config.yaml @@ -0,0 +1,8 @@ +apiVersion: neutron.openstack.org/v1beta1 +kind: NeutronAPI +metadata: + name: neutron +spec: + customServiceConfig: | + [DEFAULT] + debug = false diff --git a/test/kuttl/tests/change_neutron_config/04-cleanup-neutron.yaml b/test/kuttl/tests/change_neutron_config/04-cleanup-neutron.yaml new file mode 120000 index 00000000..553f02bd --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/04-cleanup-neutron.yaml @@ -0,0 +1 @@ +../../common/cleanup-neutron.yaml \ No newline at end of file diff --git a/test/kuttl/tests/change_neutron_config/04-errors.yaml b/test/kuttl/tests/change_neutron_config/04-errors.yaml new file mode 120000 index 00000000..ad072677 --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/04-errors.yaml @@ -0,0 +1 @@ +../../common/errors_cleanup_neutron.yaml \ No newline at end of file diff --git a/test/kuttl/tests/change_neutron_config/deploy/kustomization.yaml b/test/kuttl/tests/change_neutron_config/deploy/kustomization.yaml new file mode 100644 index 00000000..aa457581 --- /dev/null +++ b/test/kuttl/tests/change_neutron_config/deploy/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ./neutron_v1beta1_neutronapi.yaml +patches: +- patch: |- + - op: replace + path: /spec/secret + value: osp-secret + - op: remove + path: /metadata/namespace + target: + kind: NeutronAPI