Skip to content

Commit 1f43ebf

Browse files
committed
Added unit tests.
1 parent 0335597 commit 1f43ebf

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

ads/common/dsc_file_system.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def update_from_dsc_model(cls, dsc_model) -> dict:
228228

229229
class DSCFileSystemManager:
230230

231+
storage_mount_dest = set()
232+
231233
@classmethod
232234
def initialize(cls, arguments: dict) -> dict:
233235
"""Initialize and update arguments to dsc model.
@@ -247,6 +249,12 @@ def initialize(cls, arguments: dict) -> dict:
247249
"Parameter `dest` is required for mounting file storage system."
248250
)
249251

252+
if arguments["dest"] in cls.storage_mount_dest:
253+
raise ValueError(
254+
"Duplicate `dest` found. Please specify different `dest` for each file system to be mounted."
255+
)
256+
cls.storage_mount_dest.add(arguments["dest"])
257+
250258
# case oci://bucket@namespace/prefix
251259
if arguments["src"].startswith("oci://") and "@" in arguments["src"]:
252260
return OCIObjectStorage(**arguments).update_to_dsc_model()

tests/unitary/default_setup/jobs/test_jobs_mount_file_system.py

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
import unittest
1010
import pytest
1111

12-
from ads.common.dsc_file_system import OCIFileStorage
12+
from ads.common.dsc_file_system import DSCFileSystemManager, OCIFileStorage, OCIObjectStorage
1313
from ads.jobs.ads_job import Job
1414
from ads.jobs.builders.infrastructure import DataScienceJob
1515
from ads.jobs.builders.runtimes.python_runtime import PythonRuntime
1616

1717
try:
1818
from oci.data_science.models import JobStorageMountConfigurationDetails
19+
from oci.data_science.models import FileStorageMountConfigurationDetails
20+
from oci.data_science.models import ObjectStorageMountConfigurationDetails
1921
except (ImportError, AttributeError) as e:
2022
raise unittest.SkipTest(
2123
"Support for mounting file systems to OCI Job is not available. Skipping the Job tests."
@@ -45,15 +47,15 @@
4547
},
4648
),
4749
job_storage_mount_configuration_details_list=[
48-
oci.data_science.models.FileStorageMountConfigurationDetails(
50+
FileStorageMountConfigurationDetails(
4951
**{
5052
"destination_directory_name": "test_destination_directory_name_from_dsc",
5153
"export_id": "export_id_from_dsc",
5254
"mount_target_id": "mount_target_id_from_dsc",
5355
"storage_type": "FILE_STORAGE",
5456
},
5557
),
56-
oci.data_science.models.FileStorageMountConfigurationDetails(
58+
FileStorageMountConfigurationDetails(
5759
**{
5860
"destination_directory_name": "test_destination_directory_name_from_dsc",
5961
"export_id": "export_id_from_dsc",
@@ -295,3 +297,86 @@ def test_update_job_infra(
295297
"mountTargetId": "test_mount_target_id_one",
296298
"storageType": "FILE_STORAGE",
297299
}
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

Comments
 (0)