|
9 | 9 | import unittest
|
10 | 10 | import pytest
|
11 | 11 |
|
12 |
| -from ads.common.dsc_file_system import OCIFileStorage |
| 12 | +from ads.common.dsc_file_system import DSCFileSystemManager, OCIFileStorage, OCIObjectStorage |
13 | 13 | from ads.jobs.ads_job import Job
|
14 | 14 | from ads.jobs.builders.infrastructure import DataScienceJob
|
15 | 15 | from ads.jobs.builders.runtimes.python_runtime import PythonRuntime
|
16 | 16 |
|
17 | 17 | try:
|
18 | 18 | from oci.data_science.models import JobStorageMountConfigurationDetails
|
| 19 | + from oci.data_science.models import FileStorageMountConfigurationDetails |
| 20 | + from oci.data_science.models import ObjectStorageMountConfigurationDetails |
19 | 21 | except (ImportError, AttributeError) as e:
|
20 | 22 | raise unittest.SkipTest(
|
21 | 23 | "Support for mounting file systems to OCI Job is not available. Skipping the Job tests."
|
|
45 | 47 | },
|
46 | 48 | ),
|
47 | 49 | job_storage_mount_configuration_details_list=[
|
48 |
| - oci.data_science.models.FileStorageMountConfigurationDetails( |
| 50 | + FileStorageMountConfigurationDetails( |
49 | 51 | **{
|
50 | 52 | "destination_directory_name": "test_destination_directory_name_from_dsc",
|
51 | 53 | "export_id": "export_id_from_dsc",
|
52 | 54 | "mount_target_id": "mount_target_id_from_dsc",
|
53 | 55 | "storage_type": "FILE_STORAGE",
|
54 | 56 | },
|
55 | 57 | ),
|
56 |
| - oci.data_science.models.FileStorageMountConfigurationDetails( |
| 58 | + FileStorageMountConfigurationDetails( |
57 | 59 | **{
|
58 | 60 | "destination_directory_name": "test_destination_directory_name_from_dsc",
|
59 | 61 | "export_id": "export_id_from_dsc",
|
@@ -295,3 +297,86 @@ def test_update_job_infra(
|
295 | 297 | "mountTargetId": "test_mount_target_id_one",
|
296 | 298 | "storageType": "FILE_STORAGE",
|
297 | 299 | }
|
| 300 | + |
| 301 | + @patch.object(OCIObjectStorage, "update_to_dsc_model") |
| 302 | + @patch.object(OCIFileStorage, "update_to_dsc_model") |
| 303 | + def test_file_manager_process_data(self, mock_fss_update_to_dsc_model, mock_oss_update_to_dsc_model): |
| 304 | + test_mount_file_system = { |
| 305 | + "src" : "1.1.1.1:/test_export", |
| 306 | + "dest" : "test_dest_one" |
| 307 | + } |
| 308 | + |
| 309 | + DSCFileSystemManager.initialize(test_mount_file_system) |
| 310 | + mock_fss_update_to_dsc_model.assert_called() |
| 311 | + |
| 312 | + test_mount_file_system = { |
| 313 | + "src" : "ocid1.mounttarget.xxx:ocid1.export.xxx", |
| 314 | + "dest" : "test_dest_two" |
| 315 | + } |
| 316 | + |
| 317 | + DSCFileSystemManager.initialize(test_mount_file_system) |
| 318 | + mock_fss_update_to_dsc_model.assert_called() |
| 319 | + |
| 320 | + test_mount_file_system = { |
| 321 | + "src" : "oci://bucket@namespace/prefix", |
| 322 | + "dest" : "test_dest_three" |
| 323 | + } |
| 324 | + |
| 325 | + DSCFileSystemManager.initialize(test_mount_file_system) |
| 326 | + mock_oss_update_to_dsc_model.assert_called() |
| 327 | + |
| 328 | + def test_file_manager_process_data_error(self): |
| 329 | + test_mount_file_system = {} |
| 330 | + with pytest.raises( |
| 331 | + ValueError, |
| 332 | + match="Parameter `src` is required for mounting file storage system." |
| 333 | + ): |
| 334 | + DSCFileSystemManager.initialize(test_mount_file_system) |
| 335 | + |
| 336 | + test_mount_file_system["src"] = "test_src" |
| 337 | + with pytest.raises( |
| 338 | + ValueError, |
| 339 | + match="Parameter `dest` is required for mounting file storage system." |
| 340 | + ): |
| 341 | + DSCFileSystemManager.initialize(test_mount_file_system) |
| 342 | + |
| 343 | + test_mount_file_system["dest"] = "test_dest_four" |
| 344 | + with pytest.raises( |
| 345 | + ValueError, |
| 346 | + match="Invalid dict for mounting file systems. Specify a valid one." |
| 347 | + ): |
| 348 | + DSCFileSystemManager.initialize(test_mount_file_system) |
| 349 | + |
| 350 | + test_mount_file_system_list = [test_mount_file_system] * 2 |
| 351 | + with pytest.raises( |
| 352 | + ValueError, |
| 353 | + match="Duplicate `dest` found. Please specify different `dest` for each file system to be mounted." |
| 354 | + ): |
| 355 | + for mount_file_system in test_mount_file_system_list: |
| 356 | + DSCFileSystemManager.initialize(mount_file_system) |
| 357 | + |
| 358 | + def test_dsc_file_storage(self): |
| 359 | + object_storage = OCIObjectStorage( |
| 360 | + src="oci://bucket@namespace/prefix", |
| 361 | + dest="test_dest", |
| 362 | + ) |
| 363 | + |
| 364 | + result = object_storage.update_to_dsc_model() |
| 365 | + assert result["bucket"] == "bucket" |
| 366 | + assert result["namespace"] == "namespace" |
| 367 | + assert result["prefix"] == "prefix" |
| 368 | + assert result["storageType"] == "OBJECT_STORAGE" |
| 369 | + assert result["destinationDirectoryName"] == "test_dest" |
| 370 | + |
| 371 | + dsc_model = ObjectStorageMountConfigurationDetails( |
| 372 | + **{ |
| 373 | + "destination_directory_name": "test_destination_directory_name_from_dsc", |
| 374 | + "storage_type": "OBJECT_STORAGE", |
| 375 | + "bucket": "bucket", |
| 376 | + "namespace": "namespace", |
| 377 | + "prefix": "prefix" |
| 378 | + } |
| 379 | + ) |
| 380 | + result = OCIObjectStorage.update_from_dsc_model(dsc_model) |
| 381 | + assert result["src"] == "oci://bucket@namespace/prefix" |
| 382 | + assert result["dest"] == "test_destination_directory_name_from_dsc" |
0 commit comments