From 94f262bea4eafb48ef70690d1a042c816f889554 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Fri, 13 Dec 2024 17:28:04 -0300 Subject: [PATCH] Update CI settings to partially use new storage settings --- .ci/ansible/settings.py.j2 | 31 ++++++++++++++++++++---------- pulpcore/app/serializers/domain.py | 5 ++++- pulpcore/pytest_plugin.py | 26 ++++++++++++++++--------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/.ci/ansible/settings.py.j2 b/.ci/ansible/settings.py.j2 index 4ed28f42ad..9b5f5f4be4 100644 --- a/.ci/ansible/settings.py.j2 +++ b/.ci/ansible/settings.py.j2 @@ -27,19 +27,30 @@ API_ROOT = {{ api_root | repr }} {% endif %} {% if s3_test | default(false) %} -DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" -MEDIA_ROOT = "" -AWS_ACCESS_KEY_ID = "{{ minio_access_key }}" -AWS_SECRET_ACCESS_KEY = "{{ minio_secret_key }}" -AWS_S3_REGION_NAME = "eu-central-1" -AWS_S3_ADDRESSING_STYLE = "path" +MEDIA_ROOT: "" S3_USE_SIGV4 = True -AWS_S3_SIGNATURE_VERSION = "s3v4" -AWS_STORAGE_BUCKET_NAME = "pulp3" -AWS_S3_ENDPOINT_URL = "http://minio:9000" -AWS_DEFAULT_ACL = "@none None" +STORAGES = { + "default": { + "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", + "OPTIONS": { + "access_key": "{{ minio_access_key }}", + "secret_key": "{{ minio_secret_key }}", + "region_name": "eu-central-1", + "addressing_style": "path", + "signature_version": "s3v4", + "bucket_name": "pulp3", + "endpoint_url": "http://minio:9000", + "default_acl": "@none None", + }, + }, + "staticfiles": { + "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", + }, +} {% endif %} +# This is using DEFAULT_FILE_STORAGE to test both usages. +# Remove when DEFAULT_FILE_STORAGE is completely removed. {% if azure_test | default(false) %} DEFAULT_FILE_STORAGE = "storages.backends.azure_storage.AzureStorage" MEDIA_ROOT = "" diff --git a/pulpcore/app/serializers/domain.py b/pulpcore/app/serializers/domain.py index 54a21b5044..cd38598a8e 100644 --- a/pulpcore/app/serializers/domain.py +++ b/pulpcore/app/serializers/domain.py @@ -42,7 +42,10 @@ def to_representation(self, instance): # Should I convert back the saved settings to their Setting names for to_representation? if getattr(self.context.get("domain", None), "name", None) == "default": for setting_name, field in self.SETTING_MAPPING.items(): - if value := getattr(settings, setting_name.upper(), None): + value = getattr(settings, setting_name, None) or settings.STORAGES["default"].get( + "OPTIONS", {} + ).get(field) + if value: instance[field] = value return super().to_representation(instance) diff --git a/pulpcore/pytest_plugin.py b/pulpcore/pytest_plugin.py index cf9f216782..87b2f7bd02 100644 --- a/pulpcore/pytest_plugin.py +++ b/pulpcore/pytest_plugin.py @@ -603,13 +603,13 @@ def _settings_factory(storage_class=None, storage_settings=None): keys = dict() keys["pulpcore.app.models.storage.FileSystem"] = ["MEDIA_ROOT", "MEDIA_URL"] keys["storages.backends.s3boto3.S3Boto3Storage"] = [ - "AWS_ACCESS_KEY_ID", - "AWS_SECRET_ACCESS_KEY", - "AWS_S3_ENDPOINT_URL", - "AWS_S3_ADDRESSING_STYLE", - "AWS_S3_SIGNATURE_VERSION", - "AWS_S3_REGION_NAME", - "AWS_STORAGE_BUCKET_NAME", + "access_key", + "secret_key", + "endpoint_url", + "addressing_style", + "signature_version", + "region_name", + "bucket_name", ] keys["storages.backends.azure_storage.AzureStorage"] = [ "AZURE_ACCOUNT_NAME", @@ -622,8 +622,16 @@ def _settings_factory(storage_class=None, storage_settings=None): ] settings = storage_settings or dict() backend = storage_class or pulp_settings.STORAGES["default"]["BACKEND"] - for key in keys[backend]: - if key not in settings: + not_defined_settings = (k for k in keys[backend] if k not in settings) + # The CI configures s3 with STORAGES and Azure with legacy + # Move all to STORAGES structure on DEFAULT_FILE_STORAGE removal + if backend == "storages.backends.s3boto3.S3Boto3Storage": + storages_dict = getattr(pulp_settings, "STORAGES", {}) + storage_options = storages_dict.get("default", {}).get("OPTIONS", {}) + for key in not_defined_settings: + settings[key] = storage_options.get(key) + else: + for key in not_defined_settings: settings[key] = getattr(pulp_settings, key, None) return backend, settings