8000 add initial functional test · nginx/kubernetes-ingress@8f2738d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f2738d

Browse files
committed
add initial functional test
1 parent 45606fa commit 8f2738d

File tree

8 files changed

+196
-0
lines changed

8 files changed

+196
-0
lines changed

tests/data/common/service/loadbalancer-with-additional-ports.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ spec:
2323
targetPort: 8443
2424
protocol: TCP
2525
name: custom-tls-port
26+
- port: 8085
27+
targetPort: 8085
28+
protocol: TCP
29+
name: custom-http
30+
- port: 8445
31+
targetPort: 8445
32+
protocol: TCP
33+
name: custom-https
2634
- port: 9113
2735
targetPort: 9113
2836
protocol: TCP

tests/data/common/service/nodeport-with-additional-ports.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,13 @@ spec:
3838
targetPort: 8443
3939
protocol: TCP
4040
name: custom-ssl-port
41+
- port: 8085
42+
targetPort: 8085
43+
protocol: TCP
44+
name: custom-http
45+
- port: 8445
46+
targetPort: 8445
47+
protocol: TCP
48+
name: custom-https
4149
selector:
4250
app: nginx-ingress
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: k8s.nginx.org/v1alpha1
2+
kind: GlobalConfiguration
3+
metadata:
4+
name: nginx-configuration
5+
namespace: nginx-ingress
6+
spec:
7+
listeners:
8+
- name: dns-udp
9+
port: 5353
10+
protocol: UDP
11+
- name: dns-tcp
12+
port: 5353
13+
protocol: TCP
14+
- name: http-8085
15+
port: 8085
16+
protocol: HTTP
17+
- name: https-8445
18+
port: 8445
19+
protocol: HTTP
20+
ssl: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: k8s.nginx.org/v1
2+
kind: VirtualServer
3+
metadata:
4+
name: virtual-server-status
5+
spec:
6+
host: virtual-server-status.example.com
7+
tls:
8+
secret: virtual-server-tls-secret
9+
upstreams:
10+
- name: backend2
11+
service: backend2-svc
12+
port: 80
13+
- name: backend1
14+
service: backend1-svc
15+
port: 80
16+
routes:
17+
- path: /backend1
18+
action:
19+
pass: backend1
20+
- path: /backend2
21+
action:
22+
pass: backend2
Lines changed: 25 additions & 0 deletions
67DE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: k8s.nginx.org/v1
2+
kind: VirtualServer
3+
metadata:
4+
name: virtual-server-status
5+
spec:
6+
listener:
7+
http: http-8085
8+
https: https-8445
9+
host: virtual-server-status.example.com
10+
tls:
11+
secret: virtual-server-tls-secret
12+
upstreams:
13+
- name: backend2
14+
service: backend2-svc
15+
port: 80
16+
- name: backend1
17+
service: backend1-svc
18+
port: 80
19+
routes:
20+
- path: /backend1
21+
action:
22+
pass: backend1
23+
- path: /backend2
24+
action:
25+
pass: backend2

tests/suite/fixtures/custom_resource_fixtures.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def __init__(self, public_endpoint: PublicEndpoint, namespace, vs_host, vs_name,
5454
self.backend_2_url = f"http://{public_endpoint.public_ip}:{public_endpoint.port}{vs_paths[1]}"
5555
self.backend_1_url_ssl = f"https://{public_endpoint.public_ip}:{public_endpoint.port_ssl}{vs_paths[0]}"
5656
self.backend_2_url_ssl = f"https://{public_endpoint.public_ip}:{public_endpoint.port_ssl}{vs_paths[1]}"
57+
self.backend_1_url_custom = f"http://{public_endpoint.public_ip}:{public_endpoint.custom_http}{vs_paths[0]}"
58+
self.backend_2_url_custom = f"http://{public_endpoint.public_ip}:{public_endpoint.custom_http}{vs_paths[1]}"
59+
self.backend_1_url_custom_ssl = (
60+
f"https://{public_endpoint.public_ip}:{public_endpoint.custom_https}{vs_paths[0]}"
61+
)
62+
self.backend_2_url_custom_ssl = (
63+
f"https://{public_endpoint.public_ip}:{public_endpoint.custom_https}{vs_paths[1]}"
64+
)
5765
self.metrics_url = f"http://{public_endpoint.public_ip}:{public_endpoint.metrics_port}/metrics"
5866

5967

tests/suite/fixtures/fixtures.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def __init__(
8787
udp_server_port=3334,
8888
service_insight_port=9114,
8989
custom_ssl_port=8443,
90+
custom_http=8085,
91+
custom_https=8445,
9092
):
9193
self.public_ip = public_ip
9294
self.port = port
@@ -97,6 +99,8 @@ def __init__(
9799
self.udp_server_port = udp_server_port
98100
self.service_insight_port = service_insight_port
99101
self.custom_ssl_port = custom_ssl_port
102+
self.custom_http = custom_http
103+
self.custom_https = custom_https
100104

101105

102106
class IngressControllerPrerequisites:
@@ -185,6 +189,8 @@ def ingress_controller_endpoint(cli_arguments, kube_apis, ingress_controller_pre
185189
udp_server_port,
186190
service_insight_port,
187191
custom_ssl_port,
192+
custom_http,
193+
custom_https,
188194
) = get_service_node_ports(kube_apis.v1, service_name, namespace)
189195
return PublicEndpoint(
190196
public_ip,
@@ -196,6 +202,8 @@ def ingress_controller_endpoint(cli_arguments, kube_apis, ingress_controller_pre
196202
udp_server_port,
197203
service_insight_port,
198204
custom_ssl_port,
205+
custom_http,
206+
custom_https,
199207
)
200208
else:
201209
create_service_from_yaml(
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import pytest
2+
import requests
3+
from settings import TEST_DATA
4+
from suite.utils.custom_resources_utils import create_gc_from_yaml, delete_gc
5+
from suite.utils.resources_utils import create_secret_from_yaml, delete_secret, wait_before_test
6+
from suite.utils.vs_vsr_resources_utils import patch_virtual_server_from_yaml
7+
8+
9+
@pytest.mark.test
10+
@pytest.mark.parametrize(
11+
"crd_ingress_controller, virtual_server_setup",
12+
[
13+
(
14+
{
15+
"type": "complete",
16+
"extra_args": [
17+
f"-global-configurat 67DE ion=nginx-ingress/nginx-configuration",
18+
f"-enable-leader-election=false",
19+
],
20+
},
21+
{
22+
"example": "virtual-server-custom-listeners",
23+
"app_type": "simple",
24+
},
25+
)
26+
],
27+
indirect=True,
28+
)
29+
class TestVirtualServerCustomListeners:
30+
def restore_default_vs(self, kube_apis, virtual_server_setup) -> None:
31+
"""
32+
Function to revert vs deployment to valid state
33+
"""
34+
patch_src = f"{TEST_DATA}/virtual-server-status/standard/virtual-server.yaml"
35+
patch_virtual_server_from_yaml(
36+
kube_apis.custom_objects,
37+
virtual_server_setup.vs_name,
38+
patch_src,
39+
virtual_server_setup.namespace,
40+
)
41+
wait_before_test()
42+
43+
def test_custom_listeners(self, kube_apis, crd_ingress_controller, virtual_server_setup) -> None:
44+
print("\nStep 1: Create GC resource")
45+
secret_name = create_secret_from_yaml(
46+
kube_apis.v1, virtual_server_setup.namespace, f"{TEST_DATA}/virtual-server-tls/tls-secret.yaml"
47+
)
48+
global_config_file = f"{TEST_DATA}/virtual-server-custom-listeners/global-configuration.yaml"
49+
gc_resource = create_gc_from_yaml(kube_apis.custom_objects, global_config_file, "nginx-ingress")
50+
patch_src = f"{TEST_DATA}/virtual-server-custom-listeners/virtual-server.yaml"
51+
patch_virtual_server_from_yaml(
52+
kube_apis.custom_objects,
53+
virtual_server_setup. 38BA vs_name,
54+
patch_src,
55+
virtual_server_setup.namespace,
56+
)
57+
wait_before_test()
58+
print(virtual_server_setup.backend_1_url_custom_ssl)
59+
resp1 = requests.get(
60+
virtual_server_setup.backend_1_url_custom_ssl,
61+
headers={"host": virtual_server_setup.vs_host},
62+
allow_redirects=False,
63+
verify=False,
64+
)
65+
print(virtual_server_setup.backend_1_url_custom)
66+
resp2 = requests.get(
67+
virtual_server_setup.backend_1_url_custom,
68+
headers={"host": virtual_server_setup.vs_host},
69+
)
70+
print(resp1.status_code)
71+
print(resp1.text)
72+
print(resp2.status_code)
73+
print(resp2.text)
74+
75+
print(virtual_server_setup.backend_1_url_ssl)
76+
resp3 = requests.get(
77+
virtual_server_setup.backend_1_url_ssl,
78+
headers={"host": virtual_server_setup.vs_host},
79+
allow_redirects=False,
80+
verify=False,
81+
)
82+
print(virtual_server_setup.backend_1_url)
83+
resp4 = requests.get(
84+
virtual_server_setup.backend_1_url,
85+
headers={"host": virtual_server_setup.vs_host},
86+
)
87+
print(resp3.status_code)
88+
print(resp3.text)
89+
print(resp4.status_code)
90+
print(resp4.text)
91+
92+
delete_secret(kube_apis.v1, secret_name, virtual_server_setup.namespace)
93+
delete_gc(kube_apis.custom_objects, gc_resource, "nginx-ingress")
94+
self.restore_default_vs(kube_apis, virtual_server_setup)
95+
96+
assert resp1.status_code == 200 and resp2.status_code == 200
97+
assert resp3.status_code == 404 and resp4.status_code == 404

0 commit comments

Comments
 (0)
0