Skip to content

Commit cde98fd

Browse files
committed
fix kube-api tests
1 parent 7aac554 commit cde98fd

File tree

9 files changed

+37
-19
lines changed

9 files changed

+37
-19
lines changed

microservices/gatewayJobScheduler/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def transform_data_by_ns(routes, certs):
3535

3636
for host in route_obj['hosts']:
3737
# Look for a matching certificate by SNI for custom domains
38-
cert_id = None
38+
cert_id = 'default'
3939
custom_cert_found = False
4040
if is_host_custom_domain(host):
4141
logger.debug("%s - Searching for custom cert for %s" % (namespace, host))
@@ -54,7 +54,7 @@ def transform_data_by_ns(routes, certs):
5454
"sessionCookieEnabled": session_cookie_enabled,
5555
"dataClass": data_class,
5656
"dataPlane": os.getenv('DATA_PLANE'),
57-
"customCertificateId": cert_id})
57+
"sslCertificateId": cert_id})
5858
return ns_dict
5959
except Exception as err:
6060
traceback.print_exc()

microservices/gatewayJobScheduler/tests/test_transform_data_by_ns.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_happy_transform_data_by_ns():
1616
}
1717
]
1818
certs = []
19-
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.api.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.api.gov.bc.ca", "sessionCookieEnabled": false, "dataClass": null, "dataPlane": "test-dp", "customCertificateId": null}]}'
19+
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.api.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.api.gov.bc.ca", "sessionCookieEnabled": false, "dataClass": null, "dataPlane": "test-dp", "sslCertificateId": "default"}]}'
2020

2121
def test_happy_transform_data_by_ns_with_override_session_cookie():
2222
with mock.patch('clients.namespace.admin_api') as mock_admin_api:
@@ -32,7 +32,7 @@ def test_happy_transform_data_by_ns_with_override_session_cookie():
3232
}
3333
]
3434
certs = []
35-
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.api.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.api.gov.bc.ca", "sessionCookieEnabled": true, "dataClass": null, "dataPlane": "test-dp", "customCertificateId": null}]}'
35+
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.api.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.api.gov.bc.ca", "sessionCookieEnabled": true, "dataClass": null, "dataPlane": "test-dp", "sslCertificateId": "default"}]}'
3636

3737
def test_happy_transform_data_by_ns_with_override_data_plane():
3838
with mock.patch('clients.namespace.admin_api') as mock_admin_api:
@@ -48,7 +48,7 @@ def test_happy_transform_data_by_ns_with_override_data_plane():
4848
}
4949
]
5050
certs = []
51-
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.api.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.api.gov.bc.ca", "sessionCookieEnabled": false, "dataClass": "high", "dataPlane": "test-dp", "customCertificateId": null}]}'
51+
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.api.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.api.gov.bc.ca", "sessionCookieEnabled": false, "dataClass": "high", "dataPlane": "test-dp", "sslCertificateId": "default"}]}'
5252

5353
def test_happy_transform_data_by_ns_with_custom_domain():
5454
with mock.patch('clients.namespace.admin_api') as mock_admin_api:
@@ -76,7 +76,7 @@ def test_happy_transform_data_by_ns_with_custom_domain():
7676
"key": "KEY"
7777
}
7878
]
79-
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.custom.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.custom.gov.bc.ca", "sessionCookieEnabled": false, "dataClass": null, "dataPlane": "test-dp", "customCertificateId": "41d14845-669f-4dcd-aff2-926fb32a4b25"}]}'
79+
assert json.dumps(transform_data_by_ns(routes, certs)) == '{"ns1": [{"name": "wild-ns-ns1-test.custom.gov.bc.ca", "selectTag": "ns.ns1", "host": "test.custom.gov.bc.ca", "sessionCookieEnabled": false, "dataClass": null, "dataPlane": "test-dp", "sslCertificateId": "41d14845-669f-4dcd-aff2-926fb32a4b25"}]}'
8080

8181

8282
def set_mock_admin_api_response(dt):

microservices/kubeApi/clients/ocp_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def prepare_apply_routes(ns, select_tag, hosts, root_path, data_plane, ns_templa
182182

183183
# Modified certificate selection logic
184184
ssl_ref = "tls"
185-
cert_id = ''
185+
custom_cert_label= ''
186186
custom_cert_found = False
187187

188188
if is_host_custom_domain(host):

microservices/kubeApi/routers/routes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class BulkSyncRequest(BaseModel):
4444
sessionCookieEnabled: bool
4545
# Data class for Emerald Cluster routes
4646
dataClass: str
47+
# SSL Certificate ID for custom domains
48+
sslCertificateId: str
4749

4850

4951
@router.put("/namespaces/{namespace}/routes", status_code=201, dependencies=[Depends(verify_credentials)])
@@ -176,7 +178,7 @@ async def verify_and_create_routes(namespace: str, request: Request):
176178
"dataPlane": route["spec"]["to"]["name"],
177179
"sessionCookieEnabled": True if route["metadata"]["labels"].get("aps-template-version") == "v1" else False,
178180
"dataClass": route["metadata"]["annotations"].get("aviinfrasetting.ako.vmware.com/name").split("-")[-1] if route["metadata"]["annotations"].get("aviinfrasetting.ako.vmware.com/name") else None,
179-
"customCertificateId": route["metadata"]["labels"].get("aps-certificate-id")
181+
"sslCertificateId": route["metadata"]["labels"].get("aps-certificate-id", "default")
180182
}
181183
)
182184

@@ -267,7 +269,7 @@ def in_list(match, list):
267269
return False
268270

269271
def build_ref(v):
270-
return "%s%s%s%s%s%s" % (v['name'], v['selectTag'], v['host'], v['dataPlane'], v['sessionCookieEnabled'], v['dataClass'], v['customCertificateId'])
272+
return f"{v['name']}{v['selectTag']}{v['host']}{v['dataPlane']}{v['sessionCookieEnabled']}{v['dataClass']}{v['sslCertificateId']}"
271273

272274
def in_list_by_name(match, list):
273275
for item in list:

microservices/kubeApi/tests/routers/test_add_route.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
aps-ssl: "data-api.tls"
2222
aps-data-plane: "data-plane-1"
2323
aps-template-version: "v2"
24+
2425
spec:
2526
host: abc.api.gov.bc.ca
2627
port:

microservices/kubeApi/tests/routers/test_add_route_override.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
aps-ssl: "data-api.tls"
2020
aps-data-plane: "data-plane-1"
2121
aps-template-version: "v1"
22+
2223
spec:
2324
host: abc.api.gov.bc.ca
2425
port:
@@ -105,6 +106,7 @@ def test_add_route_override_session_cookie(client):
105106
aps-ssl: "data-api.tls"
106107
aps-data-plane: "data-plane-1"
107108
aps-template-version: "v2"
109+
108110
spec:
109111
host: abc.api.gov.bc.ca
110112
port:

microservices/kubeApi/tests/routers/test_bulk_sync.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def test_bulk_sync(client):
3333
"dataPlane": "data-plane-1",
3434
"host": "abc.api.gov.bc.ca",
3535
"sessionCookieEnabled": False,
36-
"dataClass": None
36+
"dataClass": None,
37+
"sslCertificateId": "default"
3738
}]
3839
response = client.post('/namespaces/examplens/routes/sync', json=data)
3940
assert response.status_code == 200
@@ -80,7 +81,8 @@ def test_bulk_sync_change_host(client):
8081
"dataPlane": "data-plane-1",
8182
"host": "abc.api.gov.bc.ca",
8283
"sessionCookieEnabled": False,
83-
"dataClass": None
84+
"dataClass": None,
85+
"sslCertificateId": "default"
8486
}]
8587
response = client.post('/namespaces/examplens/routes/sync', json=data)
8688
assert response.status_code == 200

microservices/kubeApi/tests/routers/test_bulk_sync_new_route.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
aps-ssl: "data-api.tls"
2222
aps-data-plane: "data-plane-1"
2323
aps-template-version: "v2"
24+
2425
spec:
2526
host: abc.api.gov.bc.ca
2627
port:
@@ -75,7 +76,8 @@ def test_bulk_sync_new_route(client):
7576
"dataPlane": "data-plane-1",
7677
"host": "abc.api.gov.bc.ca",
7778
"sessionCookieEnabled": False,
78-
"dataClass": None
79+
"dataClass": None,
80+
"sslCertificateId": "default"
7981
}]
8082
response = client.post('/namespaces/examplens/routes/sync', json=data)
8183
assert response.status_code == 200

microservices/kubeApi/tests/routers/test_bulk_sync_override.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def test_bulk_sync_no_change(client):
3232
"dataPlane": "data-plane-1",
3333
"host": "abc.api.gov.bc.ca",
3434
"sessionCookieEnabled": True,
35-
"dataClass": None
35+
"dataClass": None,
36+
"sslCertificateId": "default"
3637
}]
3738
response = client.post('/namespaces/examplens/routes/sync', json=data)
3839
assert response.status_code == 200
@@ -56,6 +57,7 @@ def test_bulk_sync_no_change(client):
5657
aps-ssl: "data-api.tls"
5758
aps-data-plane: "data-plane-1"
5859
aps-template-version: "v1"
60+
5961
spec:
6062
host: abc.api.gov.bc.ca
6163
port:
@@ -109,7 +111,8 @@ def test_bulk_sync_new_route_session_cookie(client):
109111
"dataPlane": "data-plane-1",
110112
"host": "abc.api.gov.bc.ca",
111113
"sessionCookieEnabled": True,
112-
"dataClass": None
114+
"dataClass": None,
115+
"sslCertificateId": "default"
113116
}]
114117
response = client.post('/namespaces/examplens/routes/sync', json=data)
115118
assert response.status_code == 200
@@ -154,7 +157,8 @@ def test_bulk_sync_change_session_cookie(client):
154157
"dataPlane": "data-plane-1",
155158
"host": "abc.api.gov.bc.ca",
156159
"sessionCookieEnabled": True,
157-
"dataClass": None
160+
"dataClass": None,
161+
"sslCertificateId": "default"
158162
}]
159163
response = client.post('/namespaces/examplens/routes/sync', json=data)
160164
assert response.status_code == 200
@@ -182,6 +186,7 @@ def test_bulk_sync_change_session_cookie(client):
182186
aps-ssl: "data-api.tls"
183187
aps-data-plane: "data-plane-1"
184188
aps-template-version: "v2"
189+
185190
spec:
186191
host: abc.api.gov.bc.ca
187192
port:
@@ -236,7 +241,8 @@ def test_bulk_sync_new_route_data_class(client):
236241
"dataPlane": "data-plane-1",
237242
"host": "abc.api.gov.bc.ca",
238243
"sessionCookieEnabled": False,
239-
"dataClass": "high"
244+
"dataClass": "high",
245+
"sslCertificateId": "default"
240246
}]
241247
response = client.post('/namespaces/examplens/routes/sync', json=data)
242248
assert response.status_code == 200
@@ -281,7 +287,8 @@ def test_bulk_sync_add_data_class(client):
281287
"dataPlane": "data-plane-1",
282288
"host": "abc.api.gov.bc.ca",
283289
"sessionCookieEnabled": False,
284-
"dataClass": "high"
290+
"dataClass": "high",
291+
"sslCertificateId": "default"
285292
}]
286293
response = client.post('/namespaces/examplens/routes/sync', json=data)
287294
assert response.status_code == 200
@@ -328,7 +335,8 @@ def test_bulk_sync_remove_data_class(client):
328335
"dataPlane": "data-plane-1",
329336
"host": "abc.api.gov.bc.ca",
330337
"sessionCookieEnabled": True,
331-
"dataClass": None
338+
"dataClass": None,
339+
"sslCertificateId": "default"
332340
}]
333341
response = client.post('/namespaces/examplens/routes/sync', json=data)
334342
assert response.status_code == 200
@@ -375,7 +383,8 @@ def test_bulk_sync_change_data_class(client):
375383
"dataPlane": "data-plane-1",
376384
"host": "abc.api.gov.bc.ca",
377385
"sessionCookieEnabled": False,
378-
"dataClass": "high"
386+
"dataClass": "high",
387+
"sslCertificateId": "default"
379388
}]
380389
response = client.post('/namespaces/examplens/routes/sync', json=data)
381390
assert response.status_code == 200

0 commit comments

Comments
 (0)