Skip to content

Commit cde9aee

Browse files
committed
Updated pr.
1 parent 3b6f1a2 commit cde9aee

File tree

3 files changed

+54
-107
lines changed

3 files changed

+54
-107
lines changed

ads/jobs/builders/infrastructure/dsc_file_system.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DSCFileSystem:
2020
src: str = None
2121
dsc: str = None
2222
storage_type: str = None
23+
destination_directory_name: str = None
2324

2425
def to_dict(self) -> dict:
2526
"""Converts the object to dictionary."""
@@ -42,7 +43,9 @@ def update_from_dsc_model(cls, dsc_model: dict) -> "DSCFileSystem":
4243
class OCIFileStorage(DSCFileSystem):
4344

4445
mount_target_id: str = None
46+
mount_target: str = None
4547
export_id: str = None
48+
export_path: str = None
4649
storage_type: str = FILE_STORAGE_TYPE
4750

4851
def __post_init__(self):
@@ -58,9 +61,10 @@ def __post_init__(self):
5861
)
5962

6063
if not self.dsc:
61-
raise ValueError(
62-
"Parameter `src` is required for mounting file storage system."
63-
)
64+
if not self.destination_directory_name:
65+
raise ValueError(
66+
"Parameter `dsc` is required for mounting file storage system."
67+
)
6468

6569
def update_to_dsc_model(self) -> dict:
6670
"""Updates arguments to dsc model.
@@ -79,7 +83,7 @@ def update_to_dsc_model(self) -> dict:
7983
arguments["mountTargetId"] = self._get_mount_target_id(arguments)
8084

8185
arguments.pop("src")
82-
arguments["destination_directory_name"] = arguments.pop("dsc")[5:]
86+
arguments["destinationDirectoryName"] = arguments.pop("dsc")
8387

8488
return arguments
8589

@@ -141,11 +145,7 @@ def _get_resource(self, ip: str) -> oci.resource_search.models.ResourceSummary:
141145
search_details=oci.resource_search.models.FreeTextSearchDetails(
142146
text=ip,
143147
matching_context_type="NONE"
144-
),
145-
#limit=440,
146-
#page="EXAMPLE-page-Value",
147-
#tenant_id="ocid1.test.oc1..<unique_ID>EXAMPLE-tenantId-Value",
148-
#opc_request_id="4DLA5ESGCPUPH3J3NAMC<unique_ID>"
148+
)
149149
).data.items
150150

151151
resource = sorted(resource, key=lambda resource_summary: resource_summary.time_created)
@@ -193,15 +193,17 @@ def update_from_dsc_model(cls, dsc_model: dict) -> DSCFileSystem:
193193

194194

195195
class DSCFileSystemManager:
196-
storage_mount_type_dict = {FILE_STORAGE_TYPE: OCIFileStorage}
197196

198197
@classmethod
199198
def initialize(cls, arguments: dict) -> DSCFileSystem:
200199
if "src" in arguments:
201200
try:
201+
# case <ip_address>:<export_path>
202202
ipaddress.IPv4Network(arguments["src"].split(":")[0])
203-
return OCIFileStorage(arguments)
203+
return OCIFileStorage(**arguments)
204204
except:
205205
pass
206206
elif "mount_target_id" in arguments or "export_id" in arguments:
207-
return OCIFileStorage(arguments)
207+
return OCIFileStorage(**arguments)
208+
209+
raise ValueError("Invalid dict for mounting file systems. Specify a valid one.")

ads/jobs/builders/infrastructure/dsc_job.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -845,11 +845,10 @@ class DataScienceJob(Infrastructure):
845845
.with_block_storage_size(50)
846846
# A list of file systems to be mounted
847847
.with_storage_mount(
848-
OCIFileStorage(
849-
destination_directory_name="test_mount",
850-
mount_target="test_mount_target",
851-
export_path="test_export_path"
852-
),
848+
{
849+
"src" : "<mount_target_ip_address>:<export_path>",
850+
"dest" : "<destination_directory_name>"
851+
}
853852
)
854853
)
855854
@@ -1723,11 +1722,5 @@ def _build_file_storage(self, file_system: dict) -> DSCFileSystem:
17231722
DSCFileSystem
17241723
A DSCFileSystem object.
17251724
"""
1726-
storage_type = file_system.get("storageType", None)
1727-
if not storage_type:
1728-
raise ValueError(
1729-
"Parameter storage type must be provided for each file system to be mounted."
1730-
)
1731-
if storage_type not in self.storage_mount_type_dict:
1732-
raise ValueError(f"Storage type {storage_type} is not supprted.")
1733-
return self.storage_mount_type_dict[storage_type].from_dict(file_system)
1725+
file_system = {utils.camel_to_snake(k): v for k, v in file_system.items()}
1726+
return DSCFileSystemManager.initialize(file_system)

tests/unitary/default_setup/jobs/test_jobs_mount_file_system.py

Lines changed: 34 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,14 @@
7171
.with_shape_config_details(memory_in_gbs=16, ocpus=1)
7272
.with_block_storage_size(50)
7373
.with_storage_mount(
74-
OCIFileStorage(
75-
destination_directory_name="test_mount_one",
76-
mount_target="test_mount_target_one",
77-
export_path="test_export_path_one",
78-
),
7974
{
80-
"destination_directory_name": "test_mount_two",
81-
"mount_target": "test_mount_target_two",
82-
"export_path": "test_export_path_two",
83-
"storage_type": "FILE_STORAGE",
75+
"src" : "1.1.1.1:test_export_path_one",
76+
"dsc" : "test_mount_one",
8477
},
78+
{
79+
"src" : "2.2.2.2:test_export_path_two",
80+
"dsc" : "test_mount_two",
81+
},
8582
)
8683
)
8784
.with_runtime(
@@ -105,14 +102,10 @@
105102
ocpus: 1
106103
shapeName: VM.Standard.E3.Flex
107104
storageMount:
108-
- destinationDirectoryName: test_mount_one
109-
mountTarget: test_mount_target_one
110-
exportPath: test_export_path_one
111-
storageType: FILE_STORAGE
112-
- destinationDirectoryName: test_mount_two
113-
mountTarget: test_mount_target_two
114-
exportPath: test_export_path_two
115-
storageType: FILE_STORAGE
105+
- src: 1.1.1.1:test_export_path_one
106+
dsc: test_mount_one
107+
- src: 2.2.2.2:test_export_path_two
108+
dsc: test_mount_two
116109
subnetId: ocid1.subnet.oc1.iad.xxxx
117110
type: dataScienceJob
118111
name: My Job
@@ -136,16 +129,14 @@ def test_data_science_job_initialize(self):
136129
dsc_file_storage_one = job.infrastructure.storage_mount[0]
137130
assert isinstance(dsc_file_storage_one, OCIFileStorage)
138131
assert dsc_file_storage_one.storage_type == "FILE_STORAGE"
139-
assert dsc_file_storage_one.destination_directory_name == "test_mount_one"
140-
assert dsc_file_storage_one.mount_target == "test_mount_target_one"
141-
assert dsc_file_storage_one.export_path == "test_export_path_one"
132+
assert dsc_file_storage_one.src == "1.1.1.1:test_export_path_one"
133+
assert dsc_file_storage_one.dsc == "test_mount_one"
142134

143135
dsc_file_storage_two = job.infrastructure.storage_mount[1]
144136
assert isinstance(dsc_file_storage_two, OCIFileStorage)
145137
assert dsc_file_storage_two.storage_type == "FILE_STORAGE"
146-
assert dsc_file_storage_two.destination_directory_name == "test_mount_two"
147-
assert dsc_file_storage_two.mount_target == "test_mount_target_two"
148-
assert dsc_file_storage_two.export_path == "test_export_path_two"
138+
assert dsc_file_storage_two.src == "2.2.2.2:test_export_path_two"
139+
assert dsc_file_storage_two.dsc == "test_mount_two"
149140

150141
def test_data_science_job_from_yaml(self):
151142
job_from_yaml = Job.from_yaml(job_yaml_string)
@@ -154,16 +145,14 @@ def test_data_science_job_from_yaml(self):
154145
dsc_file_storage_one = job_from_yaml.infrastructure.storage_mount[0]
155146
assert isinstance(dsc_file_storage_one, OCIFileStorage)
156147
assert dsc_file_storage_one.storage_type == "FILE_STORAGE"
157-
assert dsc_file_storage_one.destination_directory_name == "test_mount_one"
158-
assert dsc_file_storage_one.mount_target == "test_mount_target_one"
159-
assert dsc_file_storage_one.export_path == "test_export_path_one"
148+
assert dsc_file_storage_one.src == "1.1.1.1:test_export_path_one"
149+
assert dsc_file_storage_one.dsc == "test_mount_one"
160150

161151
dsc_file_storage_two = job.infrastructure.storage_mount[1]
162152
assert isinstance(dsc_file_storage_two, OCIFileStorage)
163153
assert dsc_file_storage_two.storage_type == "FILE_STORAGE"
164-
assert dsc_file_storage_two.destination_directory_name == "test_mount_two"
165-
assert dsc_file_storage_two.mount_target == "test_mount_target_two"
166-
assert dsc_file_storage_two.export_path == "test_export_path_two"
154+
assert dsc_file_storage_two.src == "2.2.2.2:test_export_path_two"
155+
assert dsc_file_storage_two.dsc == "test_mount_two"
167156

168157
def test_data_science_job_to_dict(self):
169158
assert job.to_dict() == {
@@ -192,15 +181,13 @@ def test_data_science_job_to_dict(self):
192181
"blockStorageSize": 50,
193182
"storageMount": [
194183
{
195-
"destinationDirectoryName": "test_mount_one",
196-
"mountTarget": "test_mount_target_one",
197-
"exportPath": "test_export_path_one",
184+
"src" : "1.1.1.1:test_export_path_one",
185+
"dsc" : "test_mount_one",
198186
"storageType": "FILE_STORAGE",
199187
},
200188
{
201-
"destinationDirectoryName": "test_mount_two",
202-
"mountTarget": "test_mount_target_two",
203-
"exportPath": "test_export_path_two",
189+
"src" : "2.2.2.2:test_export_path_two",
190+
"dsc" : "test_mount_two",
204191
"storageType": "FILE_STORAGE",
205192
},
206193
],
@@ -212,37 +199,31 @@ def test_data_science_job_to_dict(self):
212199
def test_mount_file_system_failed(self):
213200
with pytest.raises(
214201
ValueError,
215-
match="Either parameter `export_path` or `export_id` must be provided to mount file system.",
202+
match="Missing required parameter. Either `src` or `mount_target_id` is required for mounting file storage system.",
216203
):
217-
OCIFileStorage(
218-
destination_directory_name="test_mount",
219-
mount_target_id="ocid1.mounttarget.oc1.iad.xxxx",
220-
)
204+
OCIFileStorage()
221205

222206
with pytest.raises(
223207
ValueError,
224-
match="Either parameter `mount_target` or `mount_target_id` must be provided to mount file system.",
208+
match="Missing required parameter. Either `src` or `export_id` is required for mounting file storage system.",
225209
):
226210
OCIFileStorage(
227-
destination_directory_name="test_mount",
228-
export_id="ocid1.export.oc1.iad.xxxx",
211+
mount_target_id="test_mount_target_id"
229212
)
230213

231214
with pytest.raises(
232215
ValueError,
233-
match="Parameter `destination_directory_name` must be provided to mount file system.",
216+
match="Parameter `dsc` is required for mounting file storage system.",
234217
):
235218
OCIFileStorage(
236-
mount_target_id="ocid1.mounttarget.oc1.iad.xxxx",
237-
export_id="ocid1.export.oc1.iad.xxxx",
219+
src="1.1.1.1:test_export_path"
238220
)
239221

240222
job_copy = copy.deepcopy(job)
241-
dsc_file_storage = OCIFileStorage(
242-
destination_directory_name="test_mount",
243-
mount_target="test_mount_target",
244-
export_id="ocid1.export.oc1.iad.xxxx",
245-
)
223+
dsc_file_storage = {
224+
"src" : "1.1.1.1:test_export_path",
225+
"dsc" : "test_mount",
226+
}
246227
storage_mount_list = [dsc_file_storage] * 6
247228
with pytest.raises(
248229
ValueError,
@@ -253,39 +234,10 @@ def test_mount_file_system_failed(self):
253234
job_copy = copy.deepcopy(job)
254235
with pytest.raises(
255236
ValueError,
256-
match="Parameter `storage_mount` should be a list of either DSCFileSystem instances or dictionaries.",
237+
match="Parameter `storage_mount` should be a list of dictionaries.",
257238
):
258239
job_copy.infrastructure.with_storage_mount(dsc_file_storage, [1, 2, 3])
259240

260-
job_copy = copy.deepcopy(job)
261-
with pytest.raises(
262-
ValueError,
263-
match="Parameter `storage_type` must be provided for each file system to be mounted.",
264-
):
265-
job_copy.infrastructure.with_storage_mount(
266-
dsc_file_storage,
267-
{
268-
"destination_directory_name": "test_mount",
269-
"mount_target_id": "ocid1.mounttarget.oc1.iad.xxxx",
270-
"export_id": "ocid1.export.oc1.iad.xxxx",
271-
},
272-
)
273-
274-
job_copy = copy.deepcopy(job)
275-
wrong_type = "WRONG_TYPE"
276-
wrong_file_system_dict = {
277-
"destination_directory_name": "test_mount",
278-
"mount_target_id": "ocid1.mounttarget.oc1.iad.xxxx",
279-
"export_id": "ocid1.export.oc1.iad.xxxx",
280-
"storage_type": wrong_type,
281-
}
282-
with pytest.raises(
283-
ValueError, match=f"Storage type {wrong_type} is not supprted."
284-
):
285-
job_copy.infrastructure.with_storage_mount(
286-
dsc_file_storage, wrong_file_system_dict
287-
)
288-
289241
@patch.object(oci.file_storage.FileStorageClient, "get_export")
290242
@patch.object(oci.file_storage.FileStorageClient, "get_mount_target")
291243
def test_update_storage_mount_from_dsc_model(
@@ -378,7 +330,7 @@ def test_update_job_infra(
378330
infrastructure = job_copy.infrastructure
379331
with pytest.raises(
380332
ValueError,
381-
match="No `mount_target` with value test_mount_target_two found under compartment test_compartment_id.",
333+
match="Can't find the compartment id or identifier from ip 1.1.1.1. Specify a valid `src`.",
382334
):
383335
infrastructure._update_job_infra(dsc_job_payload_copy)
384336

0 commit comments

Comments
 (0)