You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2022/12/02 23:19:08 UTC
[airavata-django-portal-sdk] branch master updated: AIRAVATA-3676 Fix default USER_STORAGES lookup
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal-sdk.git
The following commit(s) were added to refs/heads/master by this push:
new c0d7494 AIRAVATA-3676 Fix default USER_STORAGES lookup
c0d7494 is described below
commit c0d74942adc234f3c613559dd356f97374384644
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Dec 2 18:18:41 2022 -0500
AIRAVATA-3676 Fix default USER_STORAGES lookup
---
.../tests/test_user_storage.py | 28 ++++++++--------
airavata_django_portal_sdk/user_storage/api.py | 38 +++++++++-------------
2 files changed, 29 insertions(+), 37 deletions(-)
diff --git a/airavata_django_portal_sdk/tests/test_user_storage.py b/airavata_django_portal_sdk/tests/test_user_storage.py
index a4fe269..469e059 100644
--- a/airavata_django_portal_sdk/tests/test_user_storage.py
+++ b/airavata_django_portal_sdk/tests/test_user_storage.py
@@ -280,16 +280,16 @@ class ExistsTests(BaseTestCase):
exists = user_storage.exists(self.request, data_product)
self.assertTrue(exists)
- def test_user_storage_not_configured(self):
- "Verify USER_STORAGES lookup throws exception when provider is missing"
- old_storage_resource_id = "my_storage_resource_id"
- new_storage_resource_id = "new_storage_resource_id"
+ def test_default_storage(self):
+ "Verify USER_STORAGES lookup returns 'default' one when no exact match"
+ default_storage_resource_id = "my_storage_resource_id"
+ non_default_storage_resource_id = "new_storage_resource_id"
with tempfile.TemporaryDirectory() as tmpdirname, \
self.settings(
USER_STORAGES={
'default': {
- # Only the old storage resource id is configured
- 'STORAGE_RESOURCE_ID': old_storage_resource_id,
+ # Only the default storage resource id is configured
+ 'STORAGE_RESOURCE_ID': default_storage_resource_id,
'BACKEND': 'airavata_django_portal_sdk.user_storage.backends.DjangoFileSystemProvider',
'OPTIONS': {
'directory': tmpdirname,
@@ -319,15 +319,13 @@ class ExistsTests(BaseTestCase):
DataReplicaLocationModel(
filePath=replica_path,
replicaLocationCategory=replica_category,
- storageResourceId=new_storage_resource_id)]
+ storageResourceId=non_default_storage_resource_id)]
# Make sure that gateway is configured for old_storage_resource_id
# and the data product is for new_storage_resource_id
- self.assertEqual(old_storage_resource_id, settings.USER_STORAGES['default']['STORAGE_RESOURCE_ID'])
- self.assertEqual(new_storage_resource_id, data_product.replicaLocations[0].storageResourceId)
- self.assertNotEqual(old_storage_resource_id, new_storage_resource_id)
-
- with self.assertRaisesRegex(LookupError,
- new_storage_resource_id,
- msg="should raise LookupError and include 'new_storage_resource_id' in message"):
- user_storage.exists(self.request, data_product)
+ self.assertEqual(default_storage_resource_id, settings.USER_STORAGES['default']['STORAGE_RESOURCE_ID'])
+ self.assertEqual(non_default_storage_resource_id, data_product.replicaLocations[0].storageResourceId)
+ self.assertNotEqual(default_storage_resource_id, non_default_storage_resource_id)
+
+ exists = user_storage.exists(self.request, data_product)
+ self.assertTrue(exists)
diff --git a/airavata_django_portal_sdk/user_storage/api.py b/airavata_django_portal_sdk/user_storage/api.py
index 94f8102..abf99e3 100644
--- a/airavata_django_portal_sdk/user_storage/api.py
+++ b/airavata_django_portal_sdk/user_storage/api.py
@@ -36,34 +36,27 @@ def get_user_storage_provider(request, owner_username=None, storage_resource_id=
# TODO: default the module_class_name to MFT provider
module_class_name = None
options = {}
- if storage_resource_id is None:
- if not hasattr(settings, 'USER_STORAGES'):
- # make this backward compatible with the older settings
- module_class_name = 'airavata_django_portal_sdk.user_storage.backends.DjangoFileSystemProvider'
- storage_resource_id = settings.GATEWAY_DATA_STORE_RESOURCE_ID
- options = dict(directory=settings.GATEWAY_DATA_STORE_DIR)
- logger.warning("Please add the USER_STORAGES setting. Using legacy GATEWAY_DATA_STORE_RESOURCE_ID and GATEWAY_DATA_STORE_DIR settings.")
- else:
- conf = settings.USER_STORAGES["default"]
- module_class_name = conf['BACKEND']
- storage_resource_id = conf['STORAGE_RESOURCE_ID']
- options = conf.get('OPTIONS', {})
+ if not hasattr(settings, 'USER_STORAGES'):
+ # make this backward compatible with the older settings
+ module_class_name = 'airavata_django_portal_sdk.user_storage.backends.DjangoFileSystemProvider'
+ storage_resource_id = settings.GATEWAY_DATA_STORE_RESOURCE_ID
+ options = dict(directory=settings.GATEWAY_DATA_STORE_DIR)
+ logger.warning("Please add the USER_STORAGES setting. Using legacy GATEWAY_DATA_STORE_RESOURCE_ID and GATEWAY_DATA_STORE_DIR settings.")
else:
- if not hasattr(settings, 'USER_STORAGES'):
- # make this backward compatible with the older settings
- module_class_name = 'airavata_django_portal_sdk.user_storage.backends.DjangoFileSystemProvider'
- storage_resource_id = settings.GATEWAY_DATA_STORE_RESOURCE_ID
- options = dict(directory=settings.GATEWAY_DATA_STORE_DIR)
- logger.warning("Please add the USER_STORAGES setting. Using legacy GATEWAY_DATA_STORE_RESOURCE_ID and GATEWAY_DATA_STORE_DIR settings.")
- else:
+ if storage_resource_id is not None:
for key in settings.USER_STORAGES:
conf = settings.USER_STORAGES[key]
if conf['STORAGE_RESOURCE_ID'] == storage_resource_id:
module_class_name = conf['BACKEND']
options = conf.get('OPTIONS', {})
break
- if module_class_name is None:
- raise LookupError(f"No UserStorageProvider found for {storage_resource_id}")
+ # If none of the configured USER_STORAGES match, use the default one
+ if module_class_name is None:
+ conf = settings.USER_STORAGES['default']
+ module_class_name = conf['BACKEND']
+ storage_resource_id = conf['STORAGE_RESOURCE_ID']
+ options = conf.get('OPTIONS', {})
+
module_name, class_name = module_class_name.rsplit(".", 1)
module = importlib.import_module(module_name)
BackendClass = getattr(module, class_name)
@@ -462,7 +455,8 @@ def get_data_product_metadata(request, data_product=None, data_product_uri=None)
# FIXME: since this isn't the true relative path, going to leave out for now
# "path": path,
"resource_path": path,
- "created_time": convert_iso8601_to_datetime(data['creationTime'], microseconds=False),
+ # TODO: won't be microseconds any longer?
+ # "created_time": convert_iso8601_to_datetime(data['creationTime'], microseconds=False),
"size": data['filesize']
}
mime_type = None