Skip to content

Commit

Permalink
[ENG-3867] Create Storage Regions on post migration signal (#9965)
Browse files Browse the repository at this point in the history
* Remove storage region configuration from the migration stream and add to config file
* Only ensure default provider and remove yaml config
* Remove default storage region backfill
* Region gets or creates, but not updates
* Use _id and name as positional arguments and fix osf_settings

Co-authored-by: John Tordoff <>
Co-authored-by: Longze Chen <[email protected]>
  • Loading branch information
Johnetordoff and cslzchen committed Sep 22, 2022
1 parent 574059d commit 1e81182
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions osf/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
update_blocked_email_domains,
update_license,
update_permission_groups,
update_storage_regions,
update_waffle_flags,
)

Expand Down Expand Up @@ -53,3 +54,8 @@ def ready(self):
update_blocked_email_domains,
dispatch_uid='osf.apps.update_blocked_email_domains'
)

post_migrate.connect(
update_storage_regions,
dispatch_uid='osf.apps.update_storage_regions'
)
1 change: 0 additions & 1 deletion osf/migrations/0099_add_default_storage_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(add_osfstorage_addon, remove_osfstorage_addon),
]
21 changes: 21 additions & 0 deletions osf/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import sys
import logging

from django.apps import apps
from django.db.utils import ProgrammingError
from django.core.management import call_command

from addons.osfstorage.settings import DEFAULT_REGION_ID, DEFAULT_REGION_NAME
from api.base import settings as api_settings
from osf.management.commands.manage_switch_flags import manage_waffle
from osf.utils.migrations import ensure_schemas, map_schemas_to_schemablocks
Expand Down Expand Up @@ -162,3 +164,22 @@ def update_blocked_email_domains(sender, verbosity=0, **kwargs):
domain=domain,
defaults={'note': NotableEmailDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION},
)


def update_storage_regions(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
ensure_default_storage_region()


def ensure_default_storage_region():
osfstorage_config = apps.get_app_config('addons_osfstorage')
Region = apps.get_model('addons_osfstorage', 'Region')
Region.objects.get_or_create(
_id=DEFAULT_REGION_ID,
name=DEFAULT_REGION_NAME,
defaults={
'waterbutler_credentials': osfstorage_config.WATERBUTLER_CREDENTIALS,
'waterbutler_settings': osfstorage_config.WATERBUTLER_SETTINGS,
'waterbutler_url': osf_settings.WATERBUTLER_URL
}
)
1 change: 1 addition & 0 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2111,4 +2111,5 @@ def from_node_usage(cls, usage_bytes, private_limit=None, public_limit=None):
CAS_LOG_LEVEL = 3 # ERROR

PREPRINT_METRICS_START_DATE = datetime.datetime(2019, 1, 1)

WAFFLE_VALUES_YAML = 'osf/features.yaml'

0 comments on commit 1e81182

Please sign in to comment.