Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-3867] Create Storage Regions on post migration signal #9965

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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':
cslzchen marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -2108,4 +2108,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'