Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests improvements #2161

Merged
merged 7 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/smoke-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ runs:
--service=nodeport --node-ip=${{ steps.k8s.outputs.cluster_ip }} \
--html=tests-${{ steps.k8s.outputs.cluster }}.html \
--self-contained-html \
--show-ic-logs=yes --profile \
--show-ic-logs=yes --profile -vv -l \
-m ${{ inputs.marker != '' && inputs.marker || '""' }}
working-directory: ./tests
shell: bash
4 changes: 2 additions & 2 deletions examples/appprotect/syslog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: syslog
image: balabit/syslog-ng:3.28.1
image: balabit/syslog-ng:3.31.2-buster
ports:
- containerPort: 514
- containerPort: 601
Expand All @@ -29,4 +29,4 @@ spec:
targetPort: 514
protocol: TCP
selector:
app: syslog
app: syslog
6 changes: 3 additions & 3 deletions examples/custom-resources/basic-tcp-udp/dns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
spec:
containers:
- name: coredns
image: coredns/coredns:1.6.7
image: coredns/coredns:1.8.6
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
Expand All @@ -51,10 +51,10 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: coredns
name: coredns
spec:
selector:
app: coredns
app: coredns
ports:
- name: dns
port: 5353
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-resources/oidc/keycloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
spec:
containers:
- name: keycloak
image: quay.io/keycloak/keycloak:12.0.1
image: quay.io/keycloak/keycloak:15.0.2
env:
- name: KEYCLOAK_USER
value: "admin"
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-resources/waf/syslog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: syslog
image: balabit/syslog-ng:3.28.1
image: balabit/syslog-ng:3.31.2-buster
ports:
- containerPort: 514
- containerPort: 601
Expand All @@ -29,4 +29,4 @@ spec:
targetPort: 514
protocol: TCP
selector:
app: syslog
app: syslog
8 changes: 4 additions & 4 deletions examples/tcp-udp/dns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
spec:
containers:
- name: coredns
image: coredns/coredns:1.2.0
image: coredns/coredns:1.8.6
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
Expand Down Expand Up @@ -57,10 +57,10 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: coredns
name: coredns
spec:
selector:
app: coredns
app: coredns
ports:
- name: dns
port: 53
Expand All @@ -76,7 +76,7 @@ metadata:
spec:
clusterIP: None
selector:
app: coredns
app: coredns
ports:
- name: dns
port: 53
Expand Down
2 changes: 1 addition & 1 deletion perf-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The table below shows various configuration options for the performance tests. U
| `--image` | The Ingress Controller image. | `nginx/nginx-ingress:edge` |
| `--image-pull-policy` | The pull policy of the Ingress Controller image. | `IfNotPresent` |
| `--deployment-type` | The type of the IC deployment: deployment or daemon-set. | `deployment` |
| `--ic-type` | The type of the Ingress Controller: nginx-ingress or nginx-ingress-plus. | `nginx-ingress` |
| `--ic-type` | The type of the Ingress Controller: nginx-ingress or nginx-plus-ingress. | `nginx-ingress` |
| `--service` | The type of the Ingress Controller service: nodeport or loadbalancer. | `nodeport` |
| `--node-ip` | The public IP of a cluster node. Not required if you use the loadbalancer service (see --service argument). | `""` |
| `--kubeconfig` | An absolute path to a kubeconfig file. | `~/.kube/config` or the value of the `KUBECONFIG` env variable |
Expand Down
31 changes: 18 additions & 13 deletions perf-tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Describe overall framework configuration."""

import os
import pytest
import sys

sys.path.insert(0, "../tests")
from kubernetes.config.kube_config import KUBE_CONFIG_DEFAULT_LOCATION
from suite.resources_utils import get_first_pod_name
from settings import (
DEFAULT_IMAGE,
DEFAULT_PULL_POLICY,
DEFAULT_IC_TYPE,
DEFAULT_SERVICE,
DEFAULT_DEPLOYMENT_TYPE,
)
from suite.resources_utils import get_first_pod_name
from kubernetes.config.kube_config import KUBE_CONFIG_DEFAULT_LOCATION
import os
import pytest
import sys

sys.path.insert(0, "../tests")


def pytest_addoption(parser) -> None:
Expand Down Expand Up @@ -44,7 +44,7 @@ def pytest_addoption(parser) -> None:
"--ic-type",
action="store",
default=DEFAULT_IC_TYPE,
help="The type of the Ingress Controller: nginx-ingress or nginx-ingress-plus.",
help="The type of the Ingress Controller: nginx-ingress or nginx-plus-ingress.",
)
parser.addoption(
"--service",
Expand Down Expand Up @@ -97,17 +97,20 @@ def pytest_collection_modifyitems(config, items) -> None:
:return:
"""
if config.getoption("--ic-type") == "nginx-ingress":
skip_for_nginx_oss = pytest.mark.skip(reason="Skip a test for Nginx OSS")
skip_for_nginx_oss = pytest.mark.skip(
reason="Skip a test for Nginx OSS")
for item in items:
if "skip_for_nginx_oss" in item.keywords:
item.add_marker(skip_for_nginx_oss)
if config.getoption("--ic-type") == "nginx-plus-ingress":
skip_for_nginx_plus = pytest.mark.skip(reason="Skip a test for Nginx Plus")
skip_for_nginx_plus = pytest.mark.skip(
reason="Skip a test for Nginx Plus")
for item in items:
if "skip_for_nginx_plus" in item.keywords:
item.add_marker(skip_for_nginx_plus)
if "-ap" not in config.getoption("--image"):
appprotect = pytest.mark.skip(reason="Skip AppProtect test in non-AP image")
appprotect = pytest.mark.skip(
reason="Skip AppProtect test in non-AP image")
for item in items:
if "appprotect" in item.keywords:
item.add_marker(appprotect)
Expand All @@ -131,7 +134,9 @@ def pytest_runtest_makereport(item) -> None:
# we only look at actual failing test calls, not setup/teardown
if rep.when == "call" and rep.failed and item.config.getoption("--show-ic-logs") == "yes":
pod_namespace = item.funcargs["ingress_controller_prerequisites"].namespace
pod_name = get_first_pod_name(item.funcargs["kube_apis"].v1, pod_namespace)
pod_name = get_first_pod_name(
item.funcargs["kube_apis"].v1, pod_namespace)
print("\n===================== IC Logs Start =====================")
print(item.funcargs["kube_apis"].v1.read_namespaced_pod_log(pod_name, pod_namespace))
print(item.funcargs["kube_apis"].v1.read_namespaced_pod_log(
pod_name, pod_namespace))
print("\n===================== IC Logs End =====================")
2 changes: 1 addition & 1 deletion tests/.flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
format = pylint
max-complexity = 10
max-line-length = 100
max-line-length = 120
exclude = .git,__pycache__,data,.idea.pytest_cache
10 changes: 5 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Below you will find the instructions on how to run the tests against a Minikube

### Prerequisites:

* Minikube.
* Minikube.
* Python3 or Docker.

#### Step 1 - Create a Minikube Cluster
Expand All @@ -18,7 +18,7 @@ $ minikube start
```

#### Step 2 - Run the Tests

**Note**: if you have the Ingress Controller deployed in the cluster, please uninstall it first, making sure to remove its namespace and RBAC resources.

Run the tests:
Expand Down Expand Up @@ -46,7 +46,7 @@ The tests will use the Ingress Controller for NGINX with the default *nginx/ngin
#### Step 1 - Create a Kind Cluster

```bash
$ make create-kind-cluster
$ make create-kind-cluster
```

#### Step 2 - Run the Tests
Expand All @@ -72,7 +72,7 @@ The table below shows various configuration options for the tests. If you use Py
| `--image` | `BUILD_IMAGE` | The Ingress Controller image. | `nginx/nginx-ingress:edge` |
| `--image-pull-policy` | `PULL_POLICY` | The pull policy of the Ingress Controller image. | `IfNotPresent` |
| `--deployment-type` | `DEPLOYMENT_TYPE` | The type of the IC deployment: deployment or daemon-set. | `deployment` |
| `--ic-type` | `IC_TYPE` | The type of the Ingress Controller: nginx-ingress or nginx-ingress-plus. | `nginx-ingress` |
| `--ic-type` | `IC_TYPE` | The type of the Ingress Controller: nginx-ingress or nginx-plus-ingress. | `nginx-ingress` |
| `--service` | `SERVICE`, not supported by `run-tests-in-kind` target. | The type of the Ingress Controller service: nodeport or loadbalancer. | `nodeport` |
| `--node-ip` | `NODE_IP`, not supported by `run-tests-in-kind` target. | The public IP of a cluster node. Not required if you use the loadbalancer service (see --service argument). | `""` |
| `--kubeconfig` | `N/A` | An absolute path to a kubeconfig file. | `~/.kube/config` or the value of the `KUBECONFIG` env variable |
Expand All @@ -85,4 +85,4 @@ If you would like to use an IDE (such as PyCharm) to run the tests, use the [pyt
Tests are marked with custom markers. The markers allow to logically split all the tests into smaller groups. The full list can be found in the [pytest.ini](pytest.ini) file or via command line:
```bash
$ python3 -m pytest --markers
```
```
19 changes: 6 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
"""Describe overall framework configuration."""

import os
import pytest

import pytest
from kubernetes.config.kube_config import KUBE_CONFIG_DEFAULT_LOCATION
from settings import (
DEFAULT_IMAGE,
DEFAULT_PULL_POLICY,
DEFAULT_IC_TYPE,
DEFAULT_SERVICE,
DEFAULT_DEPLOYMENT_TYPE,
NUM_REPLICAS,
BATCH_START,
BATCH_RESOURCES,
)
from settings import (BATCH_RESOURCES, BATCH_START, DEFAULT_DEPLOYMENT_TYPE,
DEFAULT_IC_TYPE, DEFAULT_IMAGE, DEFAULT_PULL_POLICY,
DEFAULT_SERVICE, NUM_REPLICAS)
from suite.resources_utils import get_first_pod_name


Expand Down Expand Up @@ -51,7 +44,7 @@ def pytest_addoption(parser) -> None:
"--ic-type",
action="store",
default=DEFAULT_IC_TYPE,
help="The type of the Ingress Controller: nginx-ingress or nginx-ingress-plus.",
help="The type of the Ingress Controller: nginx-ingress or nginx-plus-ingress.",
)
parser.addoption(
"--service",
Expand Down Expand Up @@ -124,7 +117,7 @@ def pytest_collection_modifyitems(config, items) -> None:
for item in items:
if "appprotect" in item.keywords:
item.add_marker(appprotect)
if str(config.getoption("--batch-start")) != "True":
if str(config.getoption("--batch-start")) != "True":
batch_start = pytest.mark.skip(reason="Skipping pod restart test with multiple resources")
for item in items:
if "batch_start" in item.keywords:
Expand Down
42 changes: 40 additions & 2 deletions tests/data/ap-waf/syslog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ spec:
spec:
containers:
- name: syslog
image: balabit/syslog-ng:3.28.1
image: balabit/syslog-ng:3.31.2-buster
ports:
- containerPort: 514
- containerPort: 601
volumeMounts:
- name: config-volume
mountPath: /etc/syslog-ng/syslog-ng.conf
subPath: syslog-ng.conf
volumes:
- name: config-volume
configMap:
name: syslog-config
---
apiVersion: v1
kind: Service
Expand All @@ -29,4 +37,34 @@ spec:
targetPort: 514
protocol: TCP
selector:
app: syslog
app: syslog
---
apiVersion: v1
kind: ConfigMap
metadata:
name: syslog-config
data:
syslog-ng.conf: |-
@version: 3.29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what are the reasons for adding the config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logs were saying that the connection was refused because the max number of connections was reached. So that is basically the default config from the container and I added max_connections

@include "scl.conf"

source s_local {
internal();
};

source s_network {
default-network-drivers(
max_connections(300)
);
};

destination d_local {
file("/var/log/messages");
file("/var/log/messages-kv.log" template("$ISODATE $HOST $(format-welf --scope all-nv-pairs)\n") frac-digits(3));
};

log {
source(s_local);
source(s_network);
destination(d_local);
};