Skip to content

Commit 603ff5b

Browse files
committed
updated unit tests
1 parent 1f08a6d commit 603ff5b

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/codeflare_sdk/cluster/cluster.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def is_dashboard_ready(self) -> bool:
342342
timeout=5,
343343
verify=self._client_verify_tls,
344344
)
345-
except requests.exceptions.SSLError:
345+
except requests.exceptions.SSLError: # pragma no cover
346346
# SSL exception occurs when oauth ingress has been created but cluster is not up
347347
return False
348348
if response.status_code == 200:
@@ -407,7 +407,7 @@ def cluster_dashboard_uri(self) -> str:
407407
config_check()
408408
api_instance = client.NetworkingV1Api(api_config_handler())
409409
ingresses = api_instance.list_namespaced_ingress(self.config.namespace)
410-
except Exception as e:
410+
except Exception as e: # pragma no cover
411411
return _kube_api_error_handling(e)
412412

413413
for ingress in ingresses.items:
@@ -770,7 +770,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
770770
config_check()
771771
api_instance = client.NetworkingV1Api(api_config_handler())
772772
ingresses = api_instance.list_namespaced_ingress(rc["metadata"]["namespace"])
773-
except Exception as e:
773+
except Exception as e: # pragma no cover
774774
return _kube_api_error_handling(e)
775775
ray_ingress = None
776776
for ingress in ingresses.items:

tests/unit_test.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
KubeConfigFileAuthentication,
4444
config_check,
4545
)
46-
from codeflare_sdk.utils.openshift_oauth import create_openshift_oauth_objects
46+
from codeflare_sdk.utils.openshift_oauth import (
47+
create_openshift_oauth_objects,
48+
delete_openshift_oauth_objects,
49+
)
4750
from codeflare_sdk.utils.pretty_print import (
4851
print_no_resources_found,
4952
print_app_wrappers_status,
@@ -489,13 +492,44 @@ def test_rc_status(mocker):
489492
assert rc == None
490493

491494

495+
def test_delete_openshift_oauth_objects(mocker):
496+
mocker.patch.object(client.CoreV1Api, "delete_namespaced_service_account")
497+
mocker.patch.object(client.CoreV1Api, "delete_namespaced_service")
498+
mocker.patch.object(client.NetworkingV1Api, "delete_namespaced_ingress")
499+
mocker.patch.object(client.RbacAuthorizationV1Api, "delete_cluster_role_binding")
500+
delete_openshift_oauth_objects("test-cluster", "test-namespace")
501+
502+
client.CoreV1Api.delete_namespaced_service_account.assert_called_with(
503+
name="test-cluster-oauth-proxy", namespace="test-namespace"
504+
)
505+
client.CoreV1Api.delete_namespaced_service.assert_called_with(
506+
name="test-cluster-oauth", namespace="test-namespace"
507+
)
508+
client.NetworkingV1Api.delete_namespaced_ingress.assert_called_with(
509+
name="test-cluster-ingress", namespace="test-namespace"
510+
)
511+
client.RbacAuthorizationV1Api.delete_cluster_role_binding.assert_called_with(
512+
name="test-cluster-rb"
513+
)
514+
515+
492516
def test_cluster_uris(mocker):
493517
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
494518
mocker.patch(
495519
"codeflare_sdk.cluster.cluster._get_ingress_domain",
496520
return_value="apps.cluster.awsroute.org",
497521
)
498522
cluster = cluster = createClusterWithConfig(mocker)
523+
mocker.patch(
524+
"kubernetes.client.NetworkingV1Api.list_namespaced_ingress",
525+
return_value=ingress_retrieval(
526+
port=8265, annotations={"route.openshift.io/termination": "passthrough"}
527+
),
528+
)
529+
assert (
530+
cluster.cluster_dashboard_uri()
531+
== "https://ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org"
532+
)
499533
mocker.patch(
500534
"kubernetes.client.NetworkingV1Api.list_namespaced_ingress",
501535
return_value=ingress_retrieval(port=8265),
@@ -543,13 +577,15 @@ def ray_addr(self, *args):
543577
return self._address
544578

545579

546-
def ingress_retrieval(port):
580+
def ingress_retrieval(port, annotations=None):
547581
if port == 10001:
548582
serviceName = "client"
549583
else:
550584
serviceName = "dashboard"
551585
mock_ingress = client.V1Ingress(
552-
metadata=client.V1ObjectMeta(name=f"ray-{serviceName}-unit-test-cluster"),
586+
metadata=client.V1ObjectMeta(
587+
name=f"ray-{serviceName}-unit-test-cluster", annotations=annotations
588+
),
553589
spec=client.V1IngressSpec(
554590
rules=[
555591
client.V1IngressRule(

0 commit comments

Comments
 (0)