Skip to content

Commit 837229a

Browse files
committed
Updated pr.
1 parent fc8cca9 commit 837229a

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

ads/common/dsc_file_system.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66
import ads
77
import oci
8+
import os
89
import ipaddress
910

1011
from dataclasses import dataclass
@@ -51,6 +52,10 @@ def update_from_dsc_model(cls, dsc_model) -> dict:
5152
@staticmethod
5253
def get_destination_path_and_name(dest: str) -> (str, str):
5354
"""Gets the destination path and destination directory name from dest.
55+
Example:
56+
dir - "fss" & path - "/opc" : mount happens under "/opc/fss"
57+
dir - "fss" & path - "/" : mount happens under "/fss"
58+
dir - "fss" & path - omitted : mount happens under "/mnt/fss" (for backward compatibility)
5459
5560
Parameters
5661
----------
@@ -62,10 +67,10 @@ def get_destination_path_and_name(dest: str) -> (str, str):
6267
tuple
6368
A tuple of destination path and destination directory name.
6469
"""
65-
directory_index = dest.rfind("/")
66-
directory_name = dest[directory_index+1:]
67-
path = "/" if directory_index <= 0 else dest[:directory_index]
68-
return (path, directory_name)
70+
return (
71+
os.path.dirname(dest.rstrip("/")),
72+
os.path.basename(dest.rstrip("/"))
73+
)
6974

7075

7176
@dataclass
@@ -199,14 +204,10 @@ def update_from_dsc_model(cls, dsc_model) -> dict:
199204
raise ValueError(
200205
"Missing parameter `destination_directory_name` from service. Check service log to see the error."
201206
)
202-
if not dsc_model.destination_path:
203-
raise ValueError(
204-
"Missing parameter `destination_path` from service. Check service log to see the error."
205-
)
206207

207208
return {
208209
"src" : f"{dsc_model.mount_target_id}:{dsc_model.export_id}",
209-
"dest" : f"{dsc_model.destination_path.rstrip('/')}/{dsc_model.destination_directory_name}"
210+
"dest" : f"{(dsc_model.destination_path or '').rstrip('/')}/{dsc_model.destination_directory_name}"
210211
}
211212

212213
@dataclass
@@ -247,14 +248,10 @@ def update_from_dsc_model(cls, dsc_model) -> dict:
247248
raise ValueError(
248249
"Missing parameter `destination_directory_name` from service. Check service log to see the error."
249250
)
250-
if not dsc_model.destination_path:
251-
raise ValueError(
252-
"Missing parameter `destination_path` from service. Check service log to see the error."
253-
)
254251

255252
return {
256253
"src" : f"oci://{dsc_model.bucket}@{dsc_model.namespace}/{dsc_model.prefix or ''}",
257-
"dest" : f"{dsc_model.destination_path.rstrip('/')}/{dsc_model.destination_directory_name}"
254+
"dest" : f"{(dsc_model.destination_path or '').rstrip('/')}/{dsc_model.destination_directory_name}"
258255
}
259256

260257

tests/unitary/default_setup/jobs/test_jobs_mount_file_system.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ def test_dsc_object_storage_error(self):
392392
"namespace" : "Missing parameter `namespace` from service. Check service log to see the error.",
393393
"bucket" : "Missing parameter `bucket` from service. Check service log to see the error.",
394394
"destination_directory_name" : "Missing parameter `destination_directory_name` from service. Check service log to see the error.",
395-
"destination_path" : "Missing parameter `destination_path` from service. Check service log to see the error."
396395
}
397396

398397
dsc_model_dict = {
@@ -509,7 +508,6 @@ def test_dsc_file_storage_error(self):
509508
"mount_target_id" : "Missing parameter `mount_target_id` from service. Check service log to see the error.",
510509
"export_id" : "Missing parameter `export_id` from service. Check service log to see the error.",
511510
"destination_directory_name" : "Missing parameter `destination_directory_name` from service. Check service log to see the error.",
512-
"destination_path" : "Missing parameter `destination_path` from service. Check service log to see the error."
513511
}
514512

515513
dsc_model_dict = {
@@ -529,4 +527,25 @@ def test_dsc_file_storage_error(self):
529527
dsc_model_copy.pop(error)
530528
OCIFileStorage.update_from_dsc_model(
531529
FileStorageMountConfigurationDetails(**dsc_model_copy)
532-
)
530+
)
531+
532+
def test_get_destination_path_and_name(self):
533+
path, directory = OCIFileStorage.get_destination_path_and_name("abc")
534+
535+
assert path == ""
536+
assert directory == "abc"
537+
538+
path, directory = OCIFileStorage.get_destination_path_and_name("/abc")
539+
540+
assert path == "/"
541+
assert directory == "abc"
542+
543+
path, directory = OCIFileStorage.get_destination_path_and_name("/abc/def")
544+
545+
assert path == "/abc"
546+
assert directory == "def"
547+
548+
path, directory = OCIFileStorage.get_destination_path_and_name("/abc/def/ghi")
549+
550+
assert path == "/abc/def"
551+
assert directory == "ghi"

0 commit comments

Comments
 (0)