|
1 | 1 | import pytest
|
2 | 2 | from kubernetes.stream import stream
|
3 |
| -from suite.utils.resources_utils import get_first_pod_name, wait_before_test |
| 3 | +from suite.utils.resources_utils import get_file_contents, get_first_pod_name, wait_before_test |
4 | 4 |
|
5 | 5 |
|
6 | 6 | @pytest.mark.agentv3
|
@@ -45,3 +45,49 @@ def test_agent(self, kube_apis, ingress_controller_prerequisites, ingress_contro
|
45 | 45 |
|
46 | 46 | assert f"Failed to get nginx-agent version: fork/exec /usr/bin/nginx-agent" not in log
|
47 | 47 | assert "nginx-agent version v3" in result_conf
|
| 48 | + |
| 49 | + # Test for agent.config file - verify the agent config exists inside the NIC pod |
| 50 | + # The expected config that will be asserted against later |
| 51 | + expected_config = """# |
| 52 | +# /etc/nginx-agent/nginx-agent.conf |
| 53 | +# |
| 54 | +# Configuration file for NGINX Agent. |
| 55 | +# |
| 56 | +
|
| 57 | +log: |
| 58 | + # set log level (error, warn, info, debug; default "info") |
| 59 | + level: info |
| 60 | + # set log path. if empty, don't log to file. |
| 61 | + path: /var/log/nginx-agent/ |
| 62 | +
|
| 63 | +allowed_directories: |
| 64 | + - /etc/nginx |
| 65 | + - /usr/local/etc/nginx |
| 66 | + - /usr/share/nginx/modules |
| 67 | + - /var/run/nginx |
| 68 | + - /var/log/nginx |
| 69 | +# |
| 70 | +# Command server settings to connect to a management plane server |
| 71 | +# |
| 72 | +#command: |
| 73 | +# server: |
| 74 | +# host: "agent.connect.nginx.com" |
| 75 | +# port: 443 |
| 76 | +# auth: |
| 77 | +# token: "" |
| 78 | +# tls: |
| 79 | +# skip_verify: false""" |
| 80 | + expected_config = expected_config.strip() |
| 81 | + |
| 82 | + # Get the actual config file content from the pod |
| 83 | + config_contents = get_file_contents( |
| 84 | + kube_apis.v1, "/etc/nginx-agent/nginx-agent.conf", pod_name, ingress_controller_prerequisites.namespace |
| 85 | + ) |
| 86 | + |
| 87 | + # Normalize whitespace for comparison - remove trailing spaces from each line |
| 88 | + def normalize_config(config_text): |
| 89 | + return "\n".join(line.rstrip() for line in config_text.strip().split("\n")) |
| 90 | + |
| 91 | + config_contents_normalized = normalize_config(config_contents) |
| 92 | + expected_config_normalized = normalize_config(expected_config) |
| 93 | + assert config_contents_normalized == expected_config_normalized |
0 commit comments