Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit 4964737

Browse files
authored
Diagnostic TS removal (#591)
Non of the existing TCs in the diagnostic test suite is actually a TC, since they cannot fail. They're just retrieving information from the cluster, so the only way for them to fail comes from network or cluster permissions related errors. On those cases, the output of any other TS/TC would also be unreliable/unstrustable. This PR makes the diagnostic retrieval to be done right before any other TS, so the claim.json will always have that information, no matter which TS was launched. The flag.Parse() function was not needed, since ginkgo calls it internally before calling TestTest() function. This second flag.Parse() call was reparsing everything and creating duplicates in the ginkgo config slices like FocusStrings/SkipStrings. + Some refactors, plus discarding -s and -l flags when -f is not set.
1 parent 14cbd5a commit 4964737

File tree

15 files changed

+557
-518
lines changed

15 files changed

+557
-518
lines changed

.github/workflows/pre-main.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ jobs:
157157
# Perform smoke tests.
158158

159159
- name: 'Test: Run test suites'
160-
run: ./run-cnf-suites.sh --focus access-control diagnostic lifecycle platform observability networking affiliated-certification operator
160+
run: ./run-cnf-suites.sh --focus access-control lifecycle platform observability networking affiliated-certification operator
161161

162162
- name: Upload smoke test results as an artifact
163163
uses: actions/upload-artifact@v2
@@ -188,8 +188,8 @@ jobs:
188188
cp test-network-function/*.yml $TNF_CONFIG_DIR
189189
shell: bash
190190

191-
- name: 'Test: Run diagnostic test suite in a TNF container'
192-
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -f diagnostic
191+
- name: 'Test: Run without any TS, just get diagnostic information'
192+
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }}
193193

194194
- name: Delete the deployment and deploy Statefulset pods
195195
uses: ./cnf-certification-test-partner/.github/actions/deploy-statefulset-pods

.github/workflows/tnf-image.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ jobs:
141141
cp test-network-function/*.yml $TNF_CONFIG_DIR
142142
shell: bash
143143

144-
- name: 'Test: Run diagnostic test suite in a TNF container'
145-
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -f diagnostic
144+
- name: 'Test: Run without any TS, just get diagnostic information'
145+
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }}
146146

147147
# Push the new TNF image to Quay.io.
148148

CATALOG.md

-63
Original file line numberDiff line numberDiff line change
@@ -111,69 +111,6 @@ Result Type|normative
111111
Suggested Remediation|Ensure that your Operator has passed Red Hat's Operator Certification Program (OCP).
112112
Best Practice Reference|[CNF Best Practice V1.2](https://connect.redhat.com/sites/default/files/2021-03/Cloud%20Native%20Network%20Function%20Requirements.pdf) Section 6.2.12 and Section 6.3.3
113113

114-
### diagnostic
115-
116-
#### cluster-csi-info
117-
118-
Property|Description
119-
---|---
120-
Test Case Name|cluster-csi-info
121-
Test Case Label|diagnostic-cluster-csi-info
122-
Unique ID|http://test-network-function.com/testcases/diagnostic/cluster-csi-info
123-
Version|v1.0.0
124-
Description|http://test-network-function.com/testcases/diagnostic/cluster-csi-info extracts CSI driver information in the cluster.
125-
Result Type|informative
126-
Suggested Remediation|
127-
Best Practice Reference|[CNF Best Practice V1.2](https://connect.redhat.com/sites/default/files/2021-03/Cloud%20Native%20Network%20Function%20Requirements.pdf) Section 6.3.6
128-
#### clusterversion
129-
130-
Property|Description
131-
---|---
132-
Test Case Name|clusterversion
133-
Test Case Label|diagnostic-clusterversion
134-
Unique ID|http://test-network-function.com/testcases/diagnostic/clusterversion
135-
Version|v1.0.0
136-
Description|http://test-network-function.com/testcases/diagnostic/clusterversion Extracts OCP versions from the cluster.
137-
Result Type|informative
138-
Suggested Remediation|
139-
Best Practice Reference|[CNF Best Practice V1.2](https://connect.redhat.com/sites/default/files/2021-03/Cloud%20Native%20Network%20Function%20Requirements.pdf) Section 6.3.6
140-
#### extract-node-information
141-
142-
Property|Description
143-
---|---
144-
Test Case Name|extract-node-information
145-
Test Case Label|diagnostic-extract-node-information
146-
Unique ID|http://test-network-function.com/testcases/diagnostic/extract-node-information
147-
Version|v1.0.0
148-
Description|http://test-network-function.com/testcases/diagnostic/extract-node-information extracts informational information about the cluster.
149-
Result Type|informative
150-
Suggested Remediation|
151-
Best Practice Reference|[CNF Best Practice V1.2](https://connect.redhat.com/sites/default/files/2021-03/Cloud%20Native%20Network%20Function%20Requirements.pdf) Section 6.3.6
152-
#### list-cni-plugins
153-
154-
Property|Description
155-
---|---
156-
Test Case Name|list-cni-plugins
157-
Test Case Label|diagnostic-list-cni-plugins
158-
Unique ID|http://test-network-function.com/testcases/diagnostic/list-cni-plugins
159-
Version|v1.0.0
160-
Description|http://test-network-function.com/testcases/diagnostic/list-cni-plugins lists CNI plugins
161-
Result Type|normative
162-
Suggested Remediation|
163-
Best Practice Reference|[CNF Best Practice V1.2](https://connect.redhat.com/sites/default/files/2021-03/Cloud%20Native%20Network%20Function%20Requirements.pdf) Section 6.2.4 and 6.3.7
164-
#### nodes-hw-info
165-
166-
Property|Description
167-
---|---
168-
Test Case Name|nodes-hw-info
169-
Test Case Label|diagnostic-nodes-hw-info
170-
Unique ID|http://test-network-function.com/testcases/diagnostic/nodes-hw-info
171-
Version|v1.0.0
172-
Description|http://test-network-function.com/testcases/diagnostic/nodes-hw-info list nodes HW info
173-
Result Type|normative
174-
Suggested Remediation|
175-
Best Practice Reference|[CNF Best Practice V1.2](https://connect.redhat.com/sites/default/files/2021-03/Cloud%20Native%20Network%20Function%20Requirements.pdf) Section 6.2
176-
177114
### lifecycle
178115

179116
#### container-shutdown

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,21 @@ There are several required arguments:
161161

162162
* `-t` gives the local directory that contains tnf config files set up for the test.
163163
* `-o` gives the local directory that the test results will be available in once the container exits. This directory must exist in order for the claim file to be written.
164-
* `-f` gives the list of suites to be run, space separated.
165164

166165
Optional arguments are:
167-
166+
* `-f` gives the list of suites to be run, space separated.
167+
* `-s` gives the name of tests that should be skipped. This flag is discarded if no `-f` was set.
168168
* `-i` gives a name to a custom TNF container image. Supports local images, as well as images from external registries.
169169
* `-k` gives a path to one or more kubeconfig files to be used by the container to authenticate with the cluster. Paths must be separated by a colon.
170170
* `-n` gives the network mode of the container. Defaults set to `host`, which requires selinux to be disabled. Alternatively, `bridge` mode can be used with selinux if TNF_CONTAINER_CLIENT is set to `docker` or running the test as root. See the [docker run --network parameter reference](https://docs.docker.com/engine/reference/run/#network-settings) for more information on how to configure network settings.
171-
* `-s` gives the name of tests that should be skipped
172171

172+
If `-f` is not specified, the tnf will run in 'diagnostic' mode. In this mode, no test case will run: it will only get information from the cluster (PUTs, CRDs, nodes info, etc...) to save it in the claim file. This can be used to make sure the configuration was properly set and the autodiscovery found the right pods/crds...
173173

174174
If `-k` is not specified, autodiscovery is performed.
175175
The autodiscovery first looks for paths in the `$KUBECONFIG` environment variable on the host system, and if the variable is not set or is empty, the default configuration stored in `$HOME/.kube/config` is checked.
176176

177177
```shell script
178-
./run-tnf-container.sh -k ~/.kube/config -t ~/tnf/config -o ~/tnf/output -f diagnostic access-control -s access-control-host-resource-PRIVILEGED_POD
178+
./run-tnf-container.sh -k ~/.kube/config -t ~/tnf/config -o ~/tnf/output -f networking access-control -s access-control-host-resource-PRIVILEGED_POD
179179
```
180180

181181
See [General tests](#general-tests) for a list of available keywords.
@@ -210,7 +210,7 @@ docker build -t test-network-function:v1.0.5 \
210210
To make `run-tnf-container.sh` use the newly built image, specify the custom TNF image using the `-i` parameter.
211211

212212
```shell script
213-
./run-tnf-container.sh -i test-network-function:v1.0.5 -t ~/tnf/config -o ~/tnf/output -f diagnostic access-control
213+
./run-tnf-container.sh -i test-network-function:v1.0.5 -t ~/tnf/config -o ~/tnf/output -f networking access-control
214214
```
215215
Note: see [General tests](#general-tests) for a list of available keywords.
216216

@@ -276,13 +276,15 @@ script.
276276
Run any combination of the suites keywords listed at in the [General tests](#general-tests) section, e.g.
277277

278278
```shell script
279-
./run-cnf-suites.sh -f diagnostic
280-
./run-cnf-suites.sh -f diagnostic lifecycle
281-
./run-cnf-suites.sh -f diagnostic networking operator
282-
./run-cnf-suites.sh -f diagnostic platform-alteration
283-
./run-cnf-suites.sh -f diagnostic lifecycle affiliated-certification operator
279+
./run-cnf-suites.sh -f lifecycle
280+
./run-cnf-suites.sh -f networking lifecycle
281+
./run-cnf-suites.sh -f operator networking
282+
./run-cnf-suites.sh -f networking platform-alteration
283+
./run-cnf-suites.sh -f networking lifecycle affiliated-certification operator
284284
```
285285

286+
As with "run-tnf-container.sh", if `-f` is not specified here, the tnf will run in 'diagnostic' mode. See [Run the tests](#run-the-tests) section for more info.
287+
286288
By default the claim file will be output into the same location as the test executable. The `-o` argument for
287289
`run-cnf-suites.sh` can be used to provide a new location that the output files will be saved to. For more detailed
288290
control over the outputs, see the output of `test-network-function.test --help`.
@@ -337,7 +339,6 @@ Suite|Test Spec Description|Minimum OpenShift Version
337339
---|---|---
338340
`access-control`|The access-control test suite is used to test service account, namespace and cluster/pod role binding for the pods under test. It also tests the pods/containers configuration.|4.6.0
339341
`affiliated-certification`|The affiliated-certification test suite verifies that the containers and operators listed in the configuration file or used by the CNF are certified by Redhat|4.6.0
340-
`diagnostic`|The diagnostic test suite is used to gather node information from an OpenShift cluster. The diagnostic test suite should be run whenever generating a claim.json file.|4.6.0
341342
`lifecycle`| The lifecycle test suite verifies the pods deployment, creation, shutdown and survivability. |4.6.0
342343
`networking`|The networking test suite contains tests that check connectivity and networking config related best practices.|4.6.0
343344
`operator`|The operator test suite is designed to test basic Kubernetes Operator functionality.|4.6.0
@@ -541,7 +542,7 @@ output.
541542
For example:
542543

543544
```shell script
544-
TNF_DEFAULT_BUFFER_SIZE=32768 ./run-cnf-suites.sh -f diagnostic
545+
TNF_DEFAULT_BUFFER_SIZE=32768 ./run-cnf-suites.sh -f networking
545546
```
546547

547548
# Testing certified operator

pkg/config/autodiscover/autodiscover_debug.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func FindDebugPods(tp *configsections.TestPartner) {
5959

6060
// AddDebugLabel add debug label to node
6161
func AddDebugLabel(nodeName string) {
62-
log.Info("add label", nodeLabelName, "=", nodeLabelValue, " to node ", nodeName)
62+
log.Info("add label ", nodeLabelName, "=", nodeLabelValue, " to node ", nodeName)
6363
ocCommand := fmt.Sprintf(addlabelCommand, nodeName, nodeLabelName, nodeLabelValue)
6464
_ = utils.ExecuteCommandAndValidate(ocCommand, ocCommandTimeOut, interactive.GetContext(expectersVerboseModeEnabled), func() {
6565
log.Error("error in adding label to node ", nodeName)
@@ -68,7 +68,7 @@ func AddDebugLabel(nodeName string) {
6868

6969
// AddDebugLabel remove debug label from node
7070
func DeleteDebugLabel(nodeName string) {
71-
log.Info("delete label", nodeLabelName, "=", nodeLabelValue, "to node ", nodeName)
71+
log.Info("delete label ", nodeLabelName, "=", nodeLabelValue, "to node ", nodeName)
7272
ocCommand := fmt.Sprintf(deletelabelCommand, nodeName, nodeLabelName)
7373
_ = utils.ExecuteCommandAndValidate(ocCommand, ocCommandTimeOut, interactive.GetContext(expectersVerboseModeEnabled), func() {
7474
log.Error("error in removing label from node ", nodeName)

pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ func (env *TestEnvironment) createContainerMapWithOcSession(containers []configs
356356
containerMap := make(map[configsections.ContainerIdentifier]*configsections.Container)
357357
for i := range containers {
358358
c := &containers[i]
359+
log.Debugf("Creating shell session for pod %s - container %s (ns %s)", c.PodName, c.ContainerName, c.Namespace)
359360
c.Oc = configsections.GetOcSession(c.PodName, c.ContainerName, c.Namespace, DefaultTimeout, interactive.Verbose(expectersVerboseModeEnabled), interactive.SendTimeout(DefaultTimeout))
360361
containerMap[c.ContainerIdentifier] = c
361362
}

run-cnf-suites.sh

+12-10
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ function html_output() {
6565
}
6666
trap html_output EXIT
6767

68-
69-
# If no focus is set then display usage and quit with a non-zero exit code.
70-
[ -z "$FOCUS" ] && echo "no focus found" && usage_error
71-
7268
FOCUS=${FOCUS%?} # strip the trailing "|" from the concatenation
7369
SKIP=${SKIP%?} # strip the trailing "|" from the concatenation
7470
LABEL=${LABEL%?} # strip the trailing "|" from the concatenation
@@ -98,13 +94,19 @@ echo "Running with skip '$SKIP'"
9894
echo "Running with label filter '$LABEL'"
9995
echo "Report will be output to '$OUTPUT_LOC'"
10096
echo "ginkgo arguments '${GINKGO_ARGS}'"
97+
FOCUS_STRING=""
10198
SKIP_STRING=""
10299
LABEL_STRING=""
103-
if [ -n "$SKIP" ]; then
104-
SKIP_STRING=-ginkgo.skip="$SKIP"
105-
fi
106-
if [ -n "$LABEL" ]; then
107-
LABEL_STRING=-ginkgo.label-filter="$LABEL"
100+
if [ -n "$FOCUS" ]; then
101+
FOCUS_STRING=-ginkgo.focus="$FOCUS"
102+
if [ -n "$SKIP" ]; then
103+
SKIP_STRING=-ginkgo.skip="$SKIP"
104+
fi
105+
if [ -n "$LABEL" ]; then
106+
LABEL_STRING=-ginkgo.label-filter="$LABEL"
107+
fi
108+
else
109+
echo "No test suite (-f) was set, so only diagnostic functions will run. Skip patterns (-s) and labels (-l) will be ignored".
108110
fi
109111

110-
cd ./test-network-function && ./test-network-function.test -ginkgo.focus="$FOCUS" $SKIP_STRING $LABEL_STRING ${GINKGO_ARGS}
112+
cd ./test-network-function && ./test-network-function.test $FOCUS_STRING $SKIP_STRING $LABEL_STRING ${GINKGO_ARGS}

run-tnf-container.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ usage() {
5959
(currently: $HOME/.kube/config).
6060
6161
Examples
62-
$0 -t ~/tnf/config -o ~/tnf/output -f diagnostic networking -s diagnostic-nodes-hw-info
62+
$0 -t ~/tnf/config -o ~/tnf/output -f networking access-control -s access-control-host-resource-PRIVILEGED_POD
6363
6464
Because -k is omitted, $(basename $0) will first try to autodiscover local kubeconfig files.
65-
If it succeeds, the diagnostic and networking tests will be run using the autodiscovered configuration.
65+
If it succeeds, the networking and access-control tests will be run using the autodiscovered configuration.
6666
The test results will be saved to the '~/tnf/output' directory on the host.
6767
68-
$0 -k ~/.kube/ABC:~/.kube/DEF -t ~/tnf/config -o ~/tnf/output -f diagnostic networking
68+
$0 -k ~/.kube/ABC:~/.kube/DEF -t ~/tnf/config -o ~/tnf/output -f access-control networking
6969
7070
The command will bind two kubeconfig files (~/.kube/ABC and ~/.kube/DEF) to the TNF container,
71-
run the diagnostic and networking tests, and save the test results into the '~/tnf/output' directory
71+
run the access-control and networking tests, and save the test results into the '~/tnf/output' directory
7272
on the host.
7373
74-
$0 -i custom-tnf-image:v1.2-dev -t ~/tnf/config -o ~/tnf/output -f diagnostic networking
74+
$0 -i custom-tnf-image:v1.2-dev -t ~/tnf/config -o ~/tnf/output -f access-control networking
7575
76-
The command will run the diagnostic and networking tests as implemented in the custom-tnf-image:v1.2-dev
76+
The command will run the access-control and networking tests as implemented in the custom-tnf-image:v1.2-dev
7777
local image set by the -i parameter. The test results will be saved to the '~/tnf/output' directory.
7878
7979
Test suites

test-network-function/common/suite.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ import (
2525

2626
var env *configpkg.TestEnvironment
2727

28-
var _ = ginkgo.BeforeSuite(func() {
28+
func RemoveLabelsFromAllNodes() {
2929
for name := range autodiscover.GetNodesList() {
3030
autodiscover.DeleteDebugLabel(name)
3131
}
32+
}
33+
34+
var _ = ginkgo.BeforeSuite(func() {
3235
})
3336

3437
var _ = ginkgo.AfterSuite(func() {
3538
// clean up added label to nodes
36-
log.Info("clean up added labels to nodes")
39+
log.Info("Clean up added labels to nodes")
3740
env = configpkg.GetTestEnvironment()
3841
env.LoadAndRefresh()
3942
for name, node := range env.NodesUnderTest {

0 commit comments

Comments
 (0)