1
- # Copyright 2024 IBM, Red Hat
1
+ # Copyright 2022 IBM, Red Hat
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
13
13
# limitations under the License.
14
14
15
15
16
- from pathlib import Path
17
- import sys
18
16
import filecmp
19
17
import os
20
18
import re
19
+ import sys
21
20
import uuid
22
- from io import StringIO
23
-
24
- from codeflare_sdk .ray .cluster import cluster
21
+ from pathlib import Path
25
22
26
23
parent = Path (__file__ ).resolve ().parents [1 ]
27
24
aw_dir = os .path .expanduser ("~/.codeflare/resources/" )
28
25
sys .path .append (str (parent ) + "/src" )
29
26
30
- from kubernetes import client , config , dynamic
27
+ from unittest .mock import MagicMock , patch
28
+
29
+ import openshift
30
+ import pandas as pd
31
+ import pytest
32
+ import ray
33
+ import yaml
34
+ from kubernetes import client , config
35
+ from pytest_mock import MockerFixture
36
+ from ray .job_submission import JobSubmissionClient
37
+
38
+ import codeflare_sdk .common .widgets .widgets as cf_widgets
39
+ from codeflare_sdk .common .kubernetes_cluster import (
40
+ Authentication ,
41
+ KubeConfigFileAuthentication ,
42
+ TokenAuthentication ,
43
+ config_check ,
44
+ )
45
+ from codeflare_sdk .common .utils .generate_cert import (
46
+ export_env ,
47
+ generate_ca_cert ,
48
+ generate_tls_cert ,
49
+ )
31
50
from codeflare_sdk .ray .appwrapper .awload import AWManager
51
+ from codeflare_sdk .ray .appwrapper .status import AppWrapper , AppWrapperStatus
52
+ from codeflare_sdk .ray .client .ray_jobs import RayJobClient
32
53
from codeflare_sdk .ray .cluster .cluster import (
33
54
Cluster ,
34
55
ClusterConfiguration ,
56
+ _app_wrapper_status ,
57
+ _copy_to_ray ,
35
58
_map_to_ray_cluster ,
59
+ _ray_cluster_status ,
60
+ get_cluster ,
36
61
list_all_clusters ,
37
62
list_all_queued ,
38
- _copy_to_ray ,
39
- get_cluster ,
40
- _app_wrapper_status ,
41
- _ray_cluster_status ,
42
- )
43
- from codeflare_sdk .common .kubernetes_cluster import (
44
- TokenAuthentication ,
45
- Authentication ,
46
- KubeConfigFileAuthentication ,
47
- config_check ,
48
63
)
64
+ from codeflare_sdk .ray .cluster .generate_yaml import gen_names , is_openshift_cluster
49
65
from codeflare_sdk .ray .cluster .pretty_print import (
50
- print_no_resources_found ,
51
66
print_app_wrappers_status ,
52
67
print_cluster_status ,
53
68
print_clusters ,
54
- )
55
- from codeflare_sdk .ray .appwrapper .status import (
56
- AppWrapper ,
57
- AppWrapperStatus ,
69
+ print_no_resources_found ,
58
70
)
59
71
from codeflare_sdk .ray .cluster .status import (
72
+ CodeFlareClusterStatus ,
60
73
RayCluster ,
61
74
RayClusterStatus ,
62
- CodeFlareClusterStatus ,
63
75
)
64
- from codeflare_sdk .common .utils .generate_cert import (
65
- generate_ca_cert ,
66
- generate_tls_cert ,
67
- export_env ,
68
- )
69
-
70
76
from tests .unit_test_support import (
71
- createClusterWithConfig ,
72
77
createClusterConfig ,
78
+ createClusterWithConfig ,
73
79
createClusterWrongType ,
74
80
get_package_and_version ,
75
81
)
76
82
77
- import codeflare_sdk .common .kubernetes_cluster .kube_api_helpers
78
- from codeflare_sdk .ray .cluster .generate_yaml import (
79
- gen_names ,
80
- is_openshift_cluster ,
81
- )
82
-
83
- import codeflare_sdk .common .widgets .widgets as cf_widgets
84
- import pandas as pd
85
-
86
- import openshift
87
- from openshift .selector import Selector
88
- import ray
89
- import pytest
90
- import yaml
91
- from unittest .mock import MagicMock , patch
92
- from pytest_mock import MockerFixture
93
- from ray .job_submission import JobSubmissionClient
94
- from codeflare_sdk .ray .client .ray_jobs import RayJobClient
95
-
96
83
# For mocking openshift client results
97
84
fake_res = openshift .Result ("fake" )
98
85
@@ -156,7 +143,7 @@ def test_token_auth_creation():
156
143
assert token_auth .skip_tls == False
157
144
assert token_auth .ca_cert_path == f"{ parent } /tests/auth-test.crt"
158
145
159
- except Exception as e :
146
+ except Exception :
160
147
assert 0 == 1
161
148
162
149
@@ -204,7 +191,7 @@ def test_config_check_no_config_file(mocker):
204
191
mocker .patch ("codeflare_sdk.common.kubernetes_cluster.auth.config_path" , None )
205
192
mocker .patch ("codeflare_sdk.common.kubernetes_cluster.auth.api_client" , None )
206
193
207
- with pytest .raises (PermissionError ) as e :
194
+ with pytest .raises (PermissionError ):
208
195
config_check ()
209
196
210
197
@@ -282,7 +269,7 @@ def test_config_creation():
282
269
283
270
def test_config_creation_wrong_type ():
284
271
with pytest .raises (TypeError ):
285
- config = createClusterWrongType ()
272
+ createClusterWrongType ()
286
273
287
274
288
275
def test_cluster_creation (mocker ):
@@ -890,7 +877,7 @@ def test_ray_job_wrapping(mocker):
890
877
def test_print_no_resources (capsys ):
891
878
try :
892
879
print_no_resources_found ()
893
- except :
880
+ except Exception :
894
881
assert 1 == 0
895
882
captured = capsys .readouterr ()
896
883
assert captured .out == (
@@ -903,7 +890,7 @@ def test_print_no_resources(capsys):
903
890
def test_print_no_cluster (capsys ):
904
891
try :
905
892
print_cluster_status (None )
906
- except :
893
+ except Exception :
907
894
assert 1 == 0
908
895
captured = capsys .readouterr ()
909
896
assert captured .out == (
@@ -924,7 +911,7 @@ def test_print_appwrappers(capsys):
924
911
)
925
912
try :
926
913
print_app_wrappers_status ([aw1 , aw2 ])
927
- except :
914
+ except Exception :
928
915
assert 1 == 0
929
916
captured = capsys .readouterr ()
930
917
assert captured .out == (
@@ -997,7 +984,7 @@ def test_ray_details(mocker, capsys):
997
984
print_clusters ([ray1 , ray2 ])
998
985
print_cluster_status (ray1 )
999
986
print_cluster_status (ray2 )
1000
- except :
987
+ except Exception :
1001
988
assert 0 == 1
1002
989
captured = capsys .readouterr ()
1003
990
assert captured .out == (
@@ -2602,13 +2589,14 @@ def test_AWManager_submit_remove(mocker, capsys):
2602
2589
assert testaw .submitted == False
2603
2590
2604
2591
2605
- from cryptography .x509 import load_pem_x509_certificate
2606
2592
import base64
2593
+
2607
2594
from cryptography .hazmat .primitives .serialization import (
2608
- load_pem_private_key ,
2609
2595
Encoding ,
2610
2596
PublicFormat ,
2597
+ load_pem_private_key ,
2611
2598
)
2599
+ from cryptography .x509 import load_pem_x509_certificate
2612
2600
2613
2601
2614
2602
def test_generate_ca_cert ():
0 commit comments