Skip to content

Commit

Permalink
only check route name for building delete list
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyjux committed Oct 21, 2024
1 parent fabbbb9 commit e8ac803
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
10 changes: 8 additions & 2 deletions microservices/kubeApi/routers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async def verify_and_create_routes(namespace: str, request: Request):
)

insert_batch = [x for x in source_routes if not in_list(x, existing_routes)]
delete_batch = [y for y in existing_routes if not in_list(y, source_routes)]
delete_batch = [y for y in existing_routes if not in_list_by_name(y, source_routes)]

logger.debug("insert batch: " + str(insert_batch))

Expand Down Expand Up @@ -250,7 +250,7 @@ def get_data_plane(ns_attributes):
def get_template_version(ns_attributes):
return ns_attributes.get('template-version', ["v2"])[0]

def in_list (match, list):
def in_list(match, list):
match_ref = build_ref(match)
for item in list:
if build_ref(item) == match_ref:
Expand All @@ -259,3 +259,9 @@ def in_list (match, list):

def build_ref(v):
return "%s%s%s%s%s" % (v['name'], v['selectTag'], v['host'], v['dataPlane'], v['sessionCookieEnabled'])

def in_list_by_name(match, list):
for item in list:
if item['name'] == match['name']:
return True
return False
44 changes: 44 additions & 0 deletions microservices/kubeApi/tests/routers/test_bulk_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,47 @@ def test_bulk_sync(client):
assert response.json()['inserted_count'] == 0
assert response.json()['deleted_count'] == 0

def test_bulk_sync_change_host(client):
with mock.patch("routers.routes.get_gwa_ocp_routes") as call:
call.return_value = [{
"metadata": {
"name": "wild-ns-example-xyz",
"labels": {
"aps-select-tag": "ns.EXAMPLE-NS",
"aps-template-version": "v2"
}
},
"spec": {
"host": "xyz.api.gov.bc.ca",
"to": {
"name": "data-plane-1"
}
}
}]


with mock.patch("routers.routes.prepare_apply_routes") as call_apply:
call_apply.return_value = 1

with mock.patch("routers.routes.apply_routes") as call_mismatch_routes:
call_mismatch_routes.return_value = None

with mock.patch("routers.routes.delete_route") as mock_delete_route:
mock_delete_route.return_value = None # Simulate successful deletion

with mock.patch("routers.routes.kubectl_delete") as mock_kubectl_delete:
mock_kubectl_delete.return_value = None # Simulate successful kubectl deletion

data = [{
"name": "wild-ns-example-abc",
"selectTag": "ns.EXAMPLE-NS",
"dataPlane": "data-plane-1",
"host": "abc.api.gov.bc.ca",
"sessionCookieEnabled": False
}]
response = client.post('/namespaces/examplens/routes/sync', json=data)
assert response.status_code == 200
assert response.json()['message'] == 'synced'
assert response.json()['inserted_count'] == 1
assert response.json()['deleted_count'] == 1

Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def test_bulk_sync_session_cookie_change(client):
assert response.status_code == 200
assert response.json()['message'] == 'synced'
assert response.json()['inserted_count'] == 1
assert response.json()['deleted_count'] == 1
assert response.json()['deleted_count'] == 0

0 comments on commit e8ac803

Please sign in to comment.