Skip to content

Commit

Permalink
[cherry-pick] add agent test (#6115)
Browse files Browse the repository at this point in the history
  • Loading branch information
vepatel authored Aug 1, 2024
1 parent 1f40bb8 commit 7a062cc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/data/matrix-smoke.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@
"nap_modules": "dos",
"marker": "dos_learning",
"platforms": "linux/amd64"
},
{
"label": "AGENT 1/1",
"image": "debian-plus-nap",
"type": "plus",
"nap_modules": "waf",
"marker": "agent",
"platforms": "linux/amd64"
}
],
"k8s": []
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pythonpath = [
addopts = "--tb=native -ra --disable-warnings -x -l --profile -v"
log_cli = true
markers =[
"agent",
"appprotect",
"appprotect_integration",
"appprotect_waf_policies",
Expand Down
50 changes: 50 additions & 0 deletions tests/suite/test_agent_app_protect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
from kubernetes.stream import stream
from suite.utils.resources_utils import get_first_pod_name, wait_before_test


@pytest.mark.skip_for_nginx_oss
@pytest.mark.agent
@pytest.mark.parametrize(
"crd_ingress_controller_with_ap",
[
{
"extra_args": [
"-enable-app-protect",
"-agent=true",
"-agent-instance-group=test-ic",
]
}
],
indirect=["crd_ingress_controller_with_ap"],
)
class TestAppProtectAgent:
def test_ap_agent(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller_with_ap):
pod_name = get_first_pod_name(kube_apis.v1, "nginx-ingress")
log = kube_apis.v1.read_namespaced_pod_log(pod_name, ingress_controller_prerequisites.namespace)

command = ["/usr/bin/nginx-agent", "-v"]
retries = 0
while retries <= 3:
wait_before_test()
try:
resp = stream(
kube_apis.v1.connect_get_namespaced_pod_exec,
pod_name,
ingress_controller_prerequisites.namespace,
command=command,
stderr=True,
stdin=False,
stdout=True,
tty=False,
)
break
except Exception as e:
print(f"Error: {e}")
retries += 1
if retries == 3:
raise e
result_conf = str(resp)

assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log
assert "nginx-agent version " in result_conf

0 comments on commit 7a062cc

Please sign in to comment.