@@ -355,7 +355,7 @@ def test_file_manager_process_data_error(self):
355355 for mount_file_system in test_mount_file_system_list :
356356 DSCFileSystemManager .initialize (mount_file_system )
357357
358- def test_dsc_file_storage (self ):
358+ def test_dsc_object_storage (self ):
359359 object_storage = OCIObjectStorage (
360360 src = "oci://bucket@namespace/prefix" ,
361361 dest = "test_dest" ,
@@ -377,6 +377,144 @@ def test_dsc_file_storage(self):
377377 "prefix" : "prefix"
378378 }
379379 )
380+
380381 result = OCIObjectStorage .update_from_dsc_model (dsc_model )
381382 assert result ["src" ] == "oci://bucket@namespace/prefix"
382383 assert result ["dest" ] == "test_destination_directory_name_from_dsc"
384+
385+ def test_dsc_object_storage_error (self ):
386+ error_messages = {
387+ "namespace" : "Missing parameter `namespace` from service. Check service log to see the error." ,
388+ "bucket" : "Missing parameter `bucket` from service. Check service log to see the error." ,
389+ "destination_directory_name" : "Missing parameter `destination_directory_name` from service. Check service log to see the error."
390+ }
391+
392+ dsc_model_dict = {
393+ "destination_directory_name" : "test_destination_directory_name_from_dsc" ,
394+ "storage_type" : "OBJECT_STORAGE" ,
395+ "bucket" : "bucket" ,
396+ "namespace" : "namespace" ,
397+ "prefix" : "prefix"
398+ }
399+
400+ for error in error_messages :
401+ with pytest .raises (
402+ ValueError ,
403+ match = error_messages [error ]
404+ ):
405+ dsc_model_copy = copy .deepcopy (dsc_model_dict )
406+ dsc_model_copy .pop (error )
407+ OCIObjectStorage .update_from_dsc_model (
408+ ObjectStorageMountConfigurationDetails (** dsc_model_copy )
409+ )
410+
411+ @patch .object (oci .resource_search .ResourceSearchClient , "search_resources" )
412+ def test_dsc_file_storage (self , mock_search_resources ):
413+ file_storage = OCIFileStorage (
414+ src = "ocid1.mounttarget.oc1.iad.xxxx:ocid1.export.oc1.iad.xxxx" ,
415+ dest = "test_dest" ,
416+ )
417+ file_storage = file_storage .update_to_dsc_model ()
418+ assert file_storage == {
419+ "destinationDirectoryName" : "test_dest" ,
420+ "exportId" : "ocid1.export.oc1.iad.xxxx" ,
421+ "mountTargetId" : "ocid1.mounttarget.oc1.iad.xxxx" ,
422+ "storageType" : "FILE_STORAGE"
423+ }
424+
425+ file_storage = OCIFileStorage (
426+ src = "1.1.1.1:/test_export" ,
427+ dest = "test_dest" ,
428+ )
429+
430+ items = [
431+ oci .resource_search .models .resource_summary .ResourceSummary (
432+ ** {
433+ "additional_details" : {},
434+ "availability_domain" : "null" ,
435+ "compartment_id" : "ocid1.compartment.oc1..aaaaaaaapvb3hearqum6wjvlcpzm5ptfxqa7xfftpth4h72xx46ygavkqteq" ,
436+ "defined_tags" : {},
437+ "display_name" : "test_name" ,
438+ "freeform_tags" : {
439+ "oci:compute:instanceconfiguration" : "ocid1.instanceconfiguration.oc1.iad.xxxx"
440+ },
441+ "identifier" : "ocid1.mounttarget.oc1.iad.xxxx" ,
442+ "identity_context" : {},
443+ "lifecycle_state" : "AVAILABLE" ,
444+ "resource_type" : "MountTarget" ,
445+ "search_context" : "null" ,
446+ "system_tags" : {},
447+ "time_created" : "2020-09-25T22:43:48.301000+00:00"
448+ }
449+ ),
450+ oci .resource_search .models .resource_summary .ResourceSummary (
451+ ** {
452+ "additional_details" : {},
453+ "availability_domain" : "null" ,
454+ "compartment_id" : "ocid1.compartment.oc1..aaaaaaaapvb3hearqum6wjvlcpzm5ptfxqa7xfftpth4h72xx46ygavkqteq" ,
455+ "defined_tags" : {},
456+ "display_name" : "test_name" ,
457+ "freeform_tags" : {
458+ "oci:compute:instanceconfiguration" : "ocid1.instanceconfiguration.oc1.iad.xxxx"
459+ },
460+ "identifier" : "ocid1.export.oc1.iad.xxxx" ,
461+ "identity_context" : {},
462+ "lifecycle_state" : "AVAILABLE" ,
463+ "resource_type" : "Export" ,
464+ "search_context" : "null" ,
465+ "system_tags" : {},
466+ "time_created" : "2020-09-25T22:43:48.301000+00:00"
467+ }
468+ )
469+ ]
470+
471+ data = MagicMock ()
472+ data .items = items
473+ return_value = MagicMock ()
474+ return_value .data = data
475+ mock_search_resources .return_value = return_value
476+
477+ file_storage = file_storage .update_to_dsc_model ()
478+ assert file_storage == {
479+ "destinationDirectoryName" : "test_dest" ,
480+ "exportId" : "ocid1.export.oc1.iad.xxxx" ,
481+ "mountTargetId" : "ocid1.mounttarget.oc1.iad.xxxx" ,
482+ "storageType" : "FILE_STORAGE"
483+ }
484+
485+ dsc_model = FileStorageMountConfigurationDetails (
486+ ** {
487+ "destination_directory_name" : "test_dest" ,
488+ "storage_type" : "FILE_STORAGE" ,
489+ "export_id" : "ocid1.export.oc1.iad.xxxx" ,
490+ "mount_target_id" : "ocid1.mounttarget.oc1.iad.xxxx"
491+ }
492+ )
493+ result = OCIFileStorage .update_from_dsc_model (dsc_model )
494+ assert result ["src" ] == "ocid1.mounttarget.oc1.iad.xxxx:ocid1.export.oc1.iad.xxxx"
495+ assert result ["dest" ] == "test_dest"
496+
497+ def test_dsc_file_storage_error (self ):
498+ error_messages = {
499+ "mount_target_id" : "Missing parameter `mount_target_id` from service. Check service log to see the error." ,
500+ "export_id" : "Missing parameter `export_id` from service. Check service log to see the error." ,
501+ "destination_directory_name" : "Missing parameter `destination_directory_name` from service. Check service log to see the error."
502+ }
503+
504+ dsc_model_dict = {
505+ "destination_directory_name" : "test_destination_directory_name_from_dsc" ,
506+ "storage_type" : "FILE_STORAGE" ,
507+ "mount_target_id" : "ocid1.mounttarget.oc1.iad.xxxx" ,
508+ "export_id" : "ocid1.export.oc1.iad.xxxx" ,
509+ }
510+
511+ for error in error_messages :
512+ with pytest .raises (
513+ ValueError ,
514+ match = error_messages [error ]
515+ ):
516+ dsc_model_copy = copy .deepcopy (dsc_model_dict )
517+ dsc_model_copy .pop (error )
518+ OCIFileStorage .update_from_dsc_model (
519+ FileStorageMountConfigurationDetails (** dsc_model_copy )
520+ )
0 commit comments