27
27
CURR_WORKING_DIR = "/user/set/workdir"
28
28
TEST_DEPENDENCIES_PATH = "/user/set/workdir/sagemaker_remote_function_workspace"
29
29
TEST_PYTHON_VERSION = "3.10"
30
+ TEST_SAGEMAKER_PYSDK_VERSION = "2.205.0"
30
31
TEST_WORKSPACE_ARCHIVE_DIR_PATH = "/opt/ml/input/data/sm_rf_user_ws"
31
32
TEST_WORKSPACE_ARCHIVE_PATH = "/opt/ml/input/data/sm_rf_user_ws/workspace.zip"
32
33
TEST_EXECUTION_ID = "test_execution_id"
@@ -44,6 +45,8 @@ def args_for_remote():
44
45
TEST_JOB_CONDA_ENV ,
45
46
"--client_python_version" ,
46
47
TEST_PYTHON_VERSION ,
48
+ "--client_sagemaker_pysdk_version" ,
49
+ TEST_SAGEMAKER_PYSDK_VERSION ,
47
50
"--dependency_settings" ,
48
51
_DependencySettings (TEST_DEPENDENCY_FILE_NAME ).to_string (),
49
52
]
@@ -55,6 +58,8 @@ def args_for_step():
55
58
TEST_JOB_CONDA_ENV ,
56
59
"--client_python_version" ,
57
60
TEST_PYTHON_VERSION ,
61
+ "--client_sagemaker_pysdk_version" ,
62
+ TEST_SAGEMAKER_PYSDK_VERSION ,
58
63
"--pipeline_execution_id" ,
59
64
TEST_EXECUTION_ID ,
60
65
"--func_step_s3_dir" ,
@@ -63,6 +68,10 @@ def args_for_step():
63
68
64
69
65
70
@patch ("sys.exit" )
71
+ @patch (
72
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
73
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
74
+ )
66
75
@patch (
67
76
"sagemaker.remote_function.runtime_environment.runtime_environment_manager."
68
77
"RuntimeEnvironmentManager._validate_python_version"
@@ -90,12 +99,75 @@ def test_main_success_remote_job_with_root_user(
90
99
run_pre_exec_script ,
91
100
bootstrap_runtime ,
92
101
validate_python ,
102
+ validate_sagemaker ,
93
103
_exit_process ,
94
104
):
95
105
bootstrap .main (args_for_remote ())
96
106
97
107
change_dir_permission .assert_not_called ()
98
108
validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
109
+ validate_sagemaker .assert_called_once_with (TEST_SAGEMAKER_PYSDK_VERSION )
110
+ bootstrap_remote .assert_called_once_with (
111
+ TEST_PYTHON_VERSION ,
112
+ TEST_JOB_CONDA_ENV ,
113
+ _DependencySettings (TEST_DEPENDENCY_FILE_NAME ),
114
+ )
115
+ run_pre_exec_script .assert_not_called ()
116
+ bootstrap_runtime .assert_not_called ()
117
+ _exit_process .assert_called_with (0 )
118
+
119
+
120
+ @patch ("sys.exit" )
121
+ @patch (
122
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
123
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
124
+ )
125
+ @patch (
126
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
127
+ "RuntimeEnvironmentManager._validate_python_version"
128
+ )
129
+ @patch (
130
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
131
+ "RuntimeEnvironmentManager.bootstrap"
132
+ )
133
+ @patch (
134
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
135
+ "RuntimeEnvironmentManager.run_pre_exec_script"
136
+ )
137
+ @patch (
138
+ "sagemaker.remote_function.runtime_environment.bootstrap_runtime_environment."
139
+ "_bootstrap_runtime_env_for_remote_function"
140
+ )
141
+ @patch ("getpass.getuser" , MagicMock (return_value = "root" ))
142
+ @patch (
143
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
144
+ "RuntimeEnvironmentManager.change_dir_permission"
145
+ )
146
+ def test_main_success_with_obsoleted_args_that_missing_sagemaker_version (
147
+ change_dir_permission ,
148
+ bootstrap_remote ,
149
+ run_pre_exec_script ,
150
+ bootstrap_runtime ,
151
+ validate_python ,
152
+ validate_sagemaker ,
153
+ _exit_process ,
154
+ ):
155
+ # This test is to test the backward compatibility
156
+ # In old version of SDK, the client side sagemaker_pysdk_version is not passed to job
157
+ # thus it would be None and would not lead to the warning
158
+ obsoleted_args = [
159
+ "--job_conda_env" ,
160
+ TEST_JOB_CONDA_ENV ,
161
+ "--client_python_version" ,
162
+ TEST_PYTHON_VERSION ,
163
+ "--dependency_settings" ,
164
+ _DependencySettings (TEST_DEPENDENCY_FILE_NAME ).to_string (),
165
+ ]
166
+ bootstrap .main (obsoleted_args )
167
+
168
+ change_dir_permission .assert_not_called ()
169
+ validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
170
+ validate_sagemaker .assert_called_once_with (None )
99
171
bootstrap_remote .assert_called_once_with (
100
172
TEST_PYTHON_VERSION ,
101
173
TEST_JOB_CONDA_ENV ,
@@ -107,6 +179,10 @@ def test_main_success_remote_job_with_root_user(
107
179
108
180
109
181
@patch ("sys.exit" )
182
+ @patch (
183
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
184
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
185
+ )
110
186
@patch (
111
187
"sagemaker.remote_function.runtime_environment.runtime_environment_manager."
112
188
"RuntimeEnvironmentManager._validate_python_version"
@@ -134,11 +210,13 @@ def test_main_success_pipeline_step_with_root_user(
134
210
run_pre_exec_script ,
135
211
bootstrap_runtime ,
136
212
validate_python ,
213
+ validate_sagemaker ,
137
214
_exit_process ,
138
215
):
139
216
bootstrap .main (args_for_step ())
140
217
change_dir_permission .assert_not_called ()
141
218
validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
219
+ validate_sagemaker .assert_called_once_with (TEST_SAGEMAKER_PYSDK_VERSION )
142
220
bootstrap_step .assert_called_once_with (
143
221
TEST_PYTHON_VERSION ,
144
222
FUNC_STEP_WORKSPACE ,
@@ -150,6 +228,10 @@ def test_main_success_pipeline_step_with_root_user(
150
228
_exit_process .assert_called_with (0 )
151
229
152
230
231
+ @patch (
232
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
233
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
234
+ )
153
235
@patch (
154
236
"sagemaker.remote_function.runtime_environment.runtime_environment_manager."
155
237
"RuntimeEnvironmentManager._validate_python_version"
@@ -178,6 +260,7 @@ def test_main_failure_remote_job_with_root_user(
178
260
write_failure ,
179
261
_exit_process ,
180
262
validate_python ,
263
+ validate_sagemaker ,
181
264
):
182
265
runtime_err = RuntimeEnvironmentError ("some failure reason" )
183
266
bootstrap_runtime .side_effect = runtime_err
@@ -186,12 +269,17 @@ def test_main_failure_remote_job_with_root_user(
186
269
187
270
change_dir_permission .assert_not_called ()
188
271
validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
272
+ validate_sagemaker .assert_called_once_with (TEST_SAGEMAKER_PYSDK_VERSION )
189
273
run_pre_exec_script .assert_not_called ()
190
274
bootstrap_runtime .assert_called ()
191
275
write_failure .assert_called_with (str (runtime_err ))
192
276
_exit_process .assert_called_with (1 )
193
277
194
278
279
+ @patch (
280
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
281
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
282
+ )
195
283
@patch (
196
284
"sagemaker.remote_function.runtime_environment.runtime_environment_manager."
197
285
"RuntimeEnvironmentManager._validate_python_version"
@@ -220,6 +308,7 @@ def test_main_failure_pipeline_step_with_root_user(
220
308
write_failure ,
221
309
_exit_process ,
222
310
validate_python ,
311
+ validate_sagemaker ,
223
312
):
224
313
runtime_err = RuntimeEnvironmentError ("some failure reason" )
225
314
bootstrap_runtime .side_effect = runtime_err
@@ -228,13 +317,18 @@ def test_main_failure_pipeline_step_with_root_user(
228
317
229
318
change_dir_permission .assert_not_called ()
230
319
validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
320
+ validate_sagemaker .assert_called_once_with (TEST_SAGEMAKER_PYSDK_VERSION )
231
321
run_pre_exec_script .assert_not_called ()
232
322
bootstrap_runtime .assert_called ()
233
323
write_failure .assert_called_with (str (runtime_err ))
234
324
_exit_process .assert_called_with (1 )
235
325
236
326
237
327
@patch ("sys.exit" )
328
+ @patch (
329
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
330
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
331
+ )
238
332
@patch (
239
333
"sagemaker.remote_function.runtime_environment.runtime_environment_manager."
240
334
"RuntimeEnvironmentManager._validate_python_version"
@@ -262,6 +356,7 @@ def test_main_remote_job_with_non_root_user(
262
356
run_pre_exec_script ,
263
357
bootstrap_runtime ,
264
358
validate_python ,
359
+ validate_sagemaker ,
265
360
_exit_process ,
266
361
):
267
362
bootstrap .main (args_for_remote ())
@@ -270,6 +365,7 @@ def test_main_remote_job_with_non_root_user(
270
365
dirs = bootstrap .JOB_OUTPUT_DIRS , new_permission = "777"
271
366
)
272
367
validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
368
+ validate_sagemaker .assert_called_once_with (TEST_SAGEMAKER_PYSDK_VERSION )
273
369
bootstrap_remote .assert_called_once_with (
274
370
TEST_PYTHON_VERSION ,
275
371
TEST_JOB_CONDA_ENV ,
@@ -281,6 +377,10 @@ def test_main_remote_job_with_non_root_user(
281
377
282
378
283
379
@patch ("sys.exit" )
380
+ @patch (
381
+ "sagemaker.remote_function.runtime_environment.runtime_environment_manager."
382
+ "RuntimeEnvironmentManager._validate_sagemaker_pysdk_version"
383
+ )
284
384
@patch (
285
385
"sagemaker.remote_function.runtime_environment.runtime_environment_manager."
286
386
"RuntimeEnvironmentManager._validate_python_version"
@@ -308,6 +408,7 @@ def test_main_pipeline_step_with_non_root_user(
308
408
run_pre_exec_script ,
309
409
bootstrap_runtime ,
310
410
validate_python ,
411
+ validate_sagemaker ,
311
412
_exit_process ,
312
413
):
313
414
bootstrap .main (args_for_step ())
@@ -316,6 +417,7 @@ def test_main_pipeline_step_with_non_root_user(
316
417
dirs = bootstrap .JOB_OUTPUT_DIRS , new_permission = "777"
317
418
)
318
419
validate_python .assert_called_once_with (TEST_PYTHON_VERSION , TEST_JOB_CONDA_ENV )
420
+ validate_sagemaker .assert_called_once_with (TEST_SAGEMAKER_PYSDK_VERSION )
319
421
bootstrap_step .assert_called_once_with (
320
422
TEST_PYTHON_VERSION ,
321
423
FUNC_STEP_WORKSPACE ,
0 commit comments