|
40 | 40 | Authentication, |
41 | 41 | KubeConfigFileAuthentication, |
42 | 42 | config_check, |
43 | | - api_config_handler, |
44 | 43 | ) |
45 | 44 | from codeflare_sdk.utils.openshift_oauth import create_openshift_oauth_objects |
46 | 45 | from codeflare_sdk.utils.pretty_print import ( |
|
76 | 75 | createDDPJob_with_cluster, |
77 | 76 | ) |
78 | 77 |
|
| 78 | +import codeflare_sdk.utils.kube_api_helpers |
| 79 | + |
79 | 80 | import openshift |
80 | 81 | from openshift.selector import Selector |
81 | 82 | import ray |
@@ -2295,7 +2296,6 @@ def test_export_env(): |
2295 | 2296 | ) |
2296 | 2297 |
|
2297 | 2298 |
|
2298 | | -# TODO add checks to make sure that when calling generate oauth objects that the fields that are expected to match do |
2299 | 2299 | def test_create_openshift_oauth(mocker: MockerFixture): |
2300 | 2300 | create_namespaced_service_account = MagicMock() |
2301 | 2301 | create_cluster_role_binding = MagicMock() |
@@ -2345,6 +2345,88 @@ def test_create_openshift_oauth(mocker: MockerFixture): |
2345 | 2345 | ) |
2346 | 2346 |
|
2347 | 2347 |
|
| 2348 | +def test_replace_openshift_oauth(mocker: MockerFixture): |
| 2349 | + # not_found_exception = client.ApiException(reason="Conflict") |
| 2350 | + create_namespaced_service_account = MagicMock( |
| 2351 | + side_effect=client.ApiException(reason="Conflict") |
| 2352 | + ) |
| 2353 | + create_cluster_role_binding = MagicMock( |
| 2354 | + side_effect=client.ApiException(reason="Conflict") |
| 2355 | + ) |
| 2356 | + create_namespaced_service = MagicMock( |
| 2357 | + side_effect=client.ApiException(reason="Conflict") |
| 2358 | + ) |
| 2359 | + create_namespaced_ingress = MagicMock( |
| 2360 | + side_effect=client.ApiException(reason="Conflict") |
| 2361 | + ) |
| 2362 | + mocker.patch.object( |
| 2363 | + client.CoreV1Api, |
| 2364 | + "create_namespaced_service_account", |
| 2365 | + create_namespaced_service_account, |
| 2366 | + ) |
| 2367 | + mocker.patch.object( |
| 2368 | + client.RbacAuthorizationV1Api, |
| 2369 | + "create_cluster_role_binding", |
| 2370 | + create_cluster_role_binding, |
| 2371 | + ) |
| 2372 | + mocker.patch.object( |
| 2373 | + client.CoreV1Api, "create_namespaced_service", create_namespaced_service |
| 2374 | + ) |
| 2375 | + mocker.patch.object( |
| 2376 | + client.NetworkingV1Api, "create_namespaced_ingress", create_namespaced_ingress |
| 2377 | + ) |
| 2378 | + mocker.patch( |
| 2379 | + "codeflare_sdk.utils.openshift_oauth._get_api_host", return_value="foo.com" |
| 2380 | + ) |
| 2381 | + replace_namespaced_service_account = MagicMock() |
| 2382 | + replace_cluster_role_binding = MagicMock() |
| 2383 | + replace_namespaced_service = MagicMock() |
| 2384 | + replace_namespaced_ingress = MagicMock() |
| 2385 | + mocker.patch.object( |
| 2386 | + client.CoreV1Api, |
| 2387 | + "replace_namespaced_service_account", |
| 2388 | + replace_namespaced_service_account, |
| 2389 | + ) |
| 2390 | + mocker.patch.object( |
| 2391 | + client.RbacAuthorizationV1Api, |
| 2392 | + "replace_cluster_role_binding", |
| 2393 | + replace_cluster_role_binding, |
| 2394 | + ) |
| 2395 | + mocker.patch.object( |
| 2396 | + client.CoreV1Api, "replace_namespaced_service", replace_namespaced_service |
| 2397 | + ) |
| 2398 | + mocker.patch.object( |
| 2399 | + client.NetworkingV1Api, "replace_namespaced_ingress", replace_namespaced_ingress |
| 2400 | + ) |
| 2401 | + create_openshift_oauth_objects("foo", "bar") |
| 2402 | + replace_namespaced_service_account.assert_called_once() |
| 2403 | + replace_cluster_role_binding.assert_called_once() |
| 2404 | + replace_namespaced_service.assert_called_once() |
| 2405 | + replace_namespaced_ingress.assert_called_once() |
| 2406 | + |
| 2407 | + |
| 2408 | +def test_gen_app_wrapper_with_oauth(mocker: MockerFixture): |
| 2409 | + mocker.patch( |
| 2410 | + "codeflare_sdk.utils.generate_yaml._get_api_host", return_value="foo.com" |
| 2411 | + ) |
| 2412 | + mocker.patch( |
| 2413 | + "codeflare_sdk.cluster.cluster.get_current_namespace", |
| 2414 | + return_value="opendatahub", |
| 2415 | + ) |
| 2416 | + write_user_appwrapper = MagicMock() |
| 2417 | + mocker.patch( |
| 2418 | + "codeflare_sdk.utils.generate_yaml.write_user_appwrapper", write_user_appwrapper |
| 2419 | + ) |
| 2420 | + Cluster(ClusterConfiguration("test_cluster", openshift_oauth=True)) |
| 2421 | + user_yaml = write_user_appwrapper.call_args.args[0] |
| 2422 | + assert any( |
| 2423 | + container["name"] == "oauth-proxy" |
| 2424 | + for container in user_yaml["spec"]["resources"]["GenericItems"][0][ |
| 2425 | + "generictemplate" |
| 2426 | + ]["spec"]["headGroupSpec"]["template"]["spec"]["containers"] |
| 2427 | + ) |
| 2428 | + |
| 2429 | + |
2348 | 2430 | # Make sure to always keep this function last |
2349 | 2431 | def test_cleanup(): |
2350 | 2432 | os.remove("unit-test-cluster.yaml") |
|
0 commit comments