Skip to content

Commit dc79e1e

Browse files
authored
Add test to check for agent (#6111)
1 parent 594da3d commit dc79e1e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

.github/data/matrix-smoke-nap.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
"nap_modules": "dos",
5656
"marker": "dos_learning",
5757
"platforms": "linux/amd64"
58+
},
59+
{
60+
"label": "AGENT 1/1",
61+
"image": "debian-plus-nap",
62+
"type": "plus",
63+
"nap_modules": "waf",
64+
"marker": "agent",
65+
"platforms": "linux/amd64"
5866
}
5967
],
6068
"k8s": []

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pythonpath = [
2323
addopts = "--tb=native -ra --disable-warnings -x -l --profile -v --strict-markers"
2424
log_cli = true
2525
markers =[
26+
"agent",
2627
"annotations",
2728
"appprotect",
2829
"appprotect_integration",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
from kubernetes.stream import stream
3+
from suite.utils.resources_utils import get_first_pod_name, wait_before_test
4+
5+
6+
@pytest.mark.skip_for_nginx_oss
7+
@pytest.mark.agent
8+
@pytest.mark.parametrize(
9+
"crd_ingress_controller_with_ap",
10+
[
11+
{
12+
"extra_args": [
13+
"-enable-app-protect",
14+
"-agent=true",
15+
"-agent-instance-group=test-ic",
16+
]
17+
}
18+
],
19+
indirect=["crd_ingress_controller_with_ap"],
20+
)
21+
class TestAppProtectAgent:
22+
def test_ap_agent(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller_with_ap):
23+
pod_name = get_first_pod_name(kube_apis.v1, "nginx-ingress")
24+
log = kube_apis.v1.read_namespaced_pod_log(pod_name, ingress_controller_prerequisites.namespace)
25+
26+
command = ["/usr/bin/nginx-agent", "-v"]
27+
retries = 0
28+
while retries <= 3:
29+
wait_before_test()
30+
try:
31+
resp = stream(
32+
kube_apis.v1.connect_get_namespaced_pod_exec,
33+
pod_name,
34+
ingress_controller_prerequisites.namespace,
35+
command=command,
36+
stderr=True,
37+
stdin=False,
38+
stdout=True,
39+
tty=False,
40+
)
41+
break
42+
except Exception as e:
43+
print(f"Error: {e}")
44+
retries += 1
45+
if retries == 3:
46+
raise e
47+
result_conf = str(resp)
48+
49+
assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log
50+
assert "nginx-agent version " in result_conf

0 commit comments

Comments
 (0)