From 36fb7b670e9fb641033f786d724c829bf8f6cbb9 Mon Sep 17 00:00:00 2001 From: mohamad aldawamneh Date: Thu, 31 Jul 2025 15:37:02 +0100 Subject: [PATCH 1/3] Add integration test for agent --- tests/suite/test_agent.py | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/suite/test_agent.py b/tests/suite/test_agent.py index 30e2658a5f..faa3591e2b 100644 --- a/tests/suite/test_agent.py +++ b/tests/suite/test_agent.py @@ -1,6 +1,6 @@ import pytest from kubernetes.stream import stream -from suite.utils.resources_utils import get_first_pod_name, wait_before_test +from suite.utils.resources_utils import get_first_pod_name, wait_before_test, get_file_contents @pytest.mark.agentv3 @@ -45,3 +45,47 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log assert "nginx-agent version v3" in result_conf + + # Test for agent.config file - verify the agent config exists inside the NIC pod + # The expected config that will be asserted against later + expected_config = """# +# /etc/nginx-agent/nginx-agent.conf +# +# Configuration file for NGINX Agent. +# + +log: + # set log level (error, warn, info, debug; default "info") + level: info + # set log path. if empty, don't log to file. + path: /var/log/nginx-agent/ + +allowed_directories: + - /etc/nginx + - /usr/local/etc/nginx + - /usr/share/nginx/modules + - /var/run/nginx + - /var/log/nginx +# +# Command server settings to connect to a management plane server +# +#command: +# server: +# host: "agent.connect.nginx.com" +# port: 443 +# auth: +# token: "" +# tls: +# skip_verify: false""" + expected_config = expected_config.strip() + + # Get the actual config file content from the pod + config_contents = get_file_contents( + kube_apis.v1, + "/etc/nginx-agent/nginx-agent.conf", + pod_name, + ingress_controller_prerequisites.namespace + ) + + config_contents = config_contents.strip() + assert config_contents == expected_config \ No newline at end of file From 2636ae3ff0aefbc7323cbe615f71ce064a2bac55 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 31 Jul 2025 14:51:23 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/suite/test_agent.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/suite/test_agent.py b/tests/suite/test_agent.py index faa3591e2b..5c4ac408af 100644 --- a/tests/suite/test_agent.py +++ b/tests/suite/test_agent.py @@ -1,6 +1,6 @@ import pytest from kubernetes.stream import stream -from suite.utils.resources_utils import get_first_pod_name, wait_before_test, get_file_contents +from suite.utils.resources_utils import get_file_contents, get_first_pod_name, wait_before_test @pytest.mark.agentv3 @@ -47,7 +47,7 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro assert "nginx-agent version v3" in result_conf # Test for agent.config file - verify the agent config exists inside the NIC pod - # The expected config that will be asserted against later + # The expected config that will be asserted against later expected_config = """# # /etc/nginx-agent/nginx-agent.conf # @@ -60,7 +60,7 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro # set log path. if empty, don't log to file. path: /var/log/nginx-agent/ -allowed_directories: +allowed_directories: - /etc/nginx - /usr/local/etc/nginx - /usr/share/nginx/modules @@ -79,13 +79,10 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro # skip_verify: false""" expected_config = expected_config.strip() - # Get the actual config file content from the pod + # Get the actual config file content from the pod config_contents = get_file_contents( - kube_apis.v1, - "/etc/nginx-agent/nginx-agent.conf", - pod_name, - ingress_controller_prerequisites.namespace + kube_apis.v1, "/etc/nginx-agent/nginx-agent.conf", pod_name, ingress_controller_prerequisites.namespace ) config_contents = config_contents.strip() - assert config_contents == expected_config \ No newline at end of file + assert config_contents == expected_config From ee7883faef66166af7f3467612dee564000b6acd Mon Sep 17 00:00:00 2001 From: mohamad aldawamneh Date: Thu, 31 Jul 2025 16:29:28 +0100 Subject: [PATCH 3/3] Improve config comparison with normalized whitespace handling --- tests/suite/test_agent.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/suite/test_agent.py b/tests/suite/test_agent.py index 5c4ac408af..5f627fed9c 100644 --- a/tests/suite/test_agent.py +++ b/tests/suite/test_agent.py @@ -84,5 +84,10 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro kube_apis.v1, "/etc/nginx-agent/nginx-agent.conf", pod_name, ingress_controller_prerequisites.namespace ) - config_contents = config_contents.strip() - assert config_contents == expected_config + # Normalize whitespace for comparison - remove trailing spaces from each line + def normalize_config(config_text): + return "\n".join(line.rstrip() for line in config_text.strip().split("\n")) + + config_contents_normalized = normalize_config(config_contents) + expected_config_normalized = normalize_config(expected_config) + assert config_contents_normalized == expected_config_normalized