Skip to content

Commit e56403f

Browse files
gerrod3cursoragent
authored andcommitted
Migrate to Django 5 STORAGES and get_domain()
Assisted by: cursor composer-1.5 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4612d21 commit e56403f

10 files changed

Lines changed: 98 additions & 61 deletions

File tree

.ci/assets/ci_constraints.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Pulpcore versions without the openapi command do no longer work in the CI
2-
pulpcore>=3.21.30,!=3.23.*,!=3.24.*,!=3.25.*,!=3.26.*,!=3.27.*,!=3.29.*,!=3.30.*,!=3.31.*,!=3.32.*,!=3.33.*,!=3.34.*,!=3.35.*,!=3.36.*,!=3.37.*,!=3.38.*,!=3.40.*,!=3.41.*,!=3.42.*,!=3.43.*,!=3.44.*,!=3.45.*,!=3.46.*,!=3.47.*,!=3.48.*,!=3.50.*,!=3.51.*,!=3.52.*,!=3.53.*,!=3.54.*
2+
# Pulpcore versions without the django 5 storage compatibility will fail, >3.63,<3.70
3+
pulpcore>=3.21.30,!=3.23.*,!=3.24.*,!=3.25.*,!=3.26.*,!=3.27.*,!=3.29.*,!=3.30.*,!=3.31.*,!=3.32.*,!=3.33.*,!=3.34.*,!=3.35.*,!=3.36.*,!=3.37.*,!=3.38.*,!=3.40.*,!=3.41.*,!=3.42.*,!=3.43.*,!=3.44.*,!=3.45.*,!=3.46.*,!=3.47.*,!=3.48.*,!=3.50.*,!=3.51.*,!=3.52.*,!=3.53.*,!=3.54.*,!=3.64.*,!=3.65.*,!=3.66.*,!=3.67.*,!=3.68.*,!=3.69.*
34

45

56
tablib!=3.6.0

.ci/scripts/check_release.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#!/usr/bin/env python
2+
# /// script
3+
# requires-python = ">=3.13"
4+
# dependencies = [
5+
# "gitpython>=3.1.46,<3.2.0",
6+
# "packaging>=26.0,<26.1",
7+
# "pyyaml>=6.0.3,<6.1.0",
8+
# ]
9+
# ///
210

311
import argparse
412
import re
513
import os
614
import tomllib
7-
import yaml
815
from pathlib import Path
16+
17+
import yaml
918
from packaging.version import Version
1019
from git import Repo
1120

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ jobs:
9494
run_docs: ${{ needs.check-changes.outputs.run_docs }}
9595

9696
lint:
97-
needs:
98-
- "check-changes"
99-
if: needs.check-changes.outputs.run_tests == '1'
10097
uses: "./.github/workflows/lint.yml"
10198

10299
build:
103-
needs: "lint"
100+
needs:
101+
- "check-changes"
102+
- "lint"
103+
if: needs.check-changes.outputs.run_tests == '1'
104104
uses: "./.github/workflows/build.yml"
105105

106106
test:

.github/workflows/scripts/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if [ "$TEST" = "s3" ]; then
9595
sed -i -e '$a s3_test: true\
9696
minio_access_key: "'$MINIO_ACCESS_KEY'"\
9797
minio_secret_key: "'$MINIO_SECRET_KEY'"\
98-
pulp_scenario_settings: {"flatpak_index": false, "token_auth_disabled": true}\
98+
pulp_scenario_settings: {"MEDIA_ROOT": "", "STORAGES": {"default": {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage", "OPTIONS": {"access_key": "AKIAIT2Z5TDYPX3ARJBA", "addressing_style": "path", "bucket_name": "pulp3", "default_acl": "@none", "endpoint_url": "http://minio:9000", "region_name": "eu-central-1", "secret_key": "fqRvjWaPU5o0fCqQuUWbj9Fainj2pVZtBCiDiieS", "signature_version": "s3v4"}}, "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}}, "flatpak_index": false, "token_auth_disabled": true}\
9999
pulp_scenario_env: {}\
100100
' vars/main.yaml
101101
export PULP_API_ROOT="/rerouted/djnd/"
@@ -109,7 +109,7 @@ if [ "$TEST" = "azure" ]; then
109109
- ./azurite:/etc/pulp\
110110
command: "azurite-blob --skipApiVersionCheck --blobHost 0.0.0.0"' vars/main.yaml
111111
sed -i -e '$a azure_test: true\
112-
pulp_scenario_settings: {"flatpak_index": true}\
112+
pulp_scenario_settings: {"MEDIA_ROOT": "", "STORAGES": {"default": {"BACKEND": "storages.backends.azure_storage.AzureStorage", "OPTIONS": {"account_key": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "account_name": "devstoreaccount1", "azure_container": "pulp-test", "connection_string": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://ci-azurite:10000/devstoreaccount1;", "expiration_secs": 120, "location": "pulp3", "overwrite_files": true}}, "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}}, "flatpak_index": true}\
113113
pulp_scenario_env: {}\
114114
' vars/main.yaml
115115
fi

pulp_container/app/registry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
from aiohttp.web_exceptions import HTTPTooManyRequests
1313
from django_guid import set_guid
1414
from django_guid.utils import generate_guid
15-
from django.conf import settings
1615
from django.core.exceptions import ObjectDoesNotExist
1716
from django.db import IntegrityError
1817
from multidict import MultiDict
1918

2019
from pulpcore.plugin.content import Handler, PathNotResolved
20+
from pulpcore.plugin.util import get_domain
2121
from pulpcore.plugin.models import RemoteArtifact, Content, ContentArtifact
2222
from pulpcore.plugin.content import ArtifactResponse
2323
from pulpcore.plugin.tasking import dispatch
@@ -83,9 +83,10 @@ async def _dispatch(artifact, headers):
8383
full_headers["Docker-Content-Digest"] = headers["Docker-Content-Digest"]
8484
full_headers["Docker-Distribution-API-Version"] = "registry/2.0"
8585

86-
if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem":
86+
domain = get_domain()
87+
if domain.storage_class == "pulpcore.app.models.storage.FileSystem":
8788
file = artifact.file
88-
path = os.path.join(settings.MEDIA_ROOT, file.name)
89+
path = os.path.join(domain.get_storage().location, file.name)
8990
if not os.path.exists(path):
9091
raise Exception("Expected path '{}' is not found".format(path))
9192
return web.FileResponse(path, headers=full_headers)

pulp_container/app/registry_api.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from tempfile import NamedTemporaryFile
1919

2020
from django.core.exceptions import ObjectDoesNotExist
21-
from django.core.files.storage import default_storage as storage
2221
from django.core.files.base import ContentFile, File
2322
from django.db import IntegrityError, transaction
2423
from django.db.models import F, Value
@@ -30,7 +29,7 @@
3029
from pulpcore.plugin.models import Artifact, ContentArtifact, UploadChunk
3130
from pulpcore.plugin.files import PulpTemporaryUploadedFile
3231
from pulpcore.plugin.tasking import add_and_remove, dispatch
33-
from pulpcore.plugin.util import get_objects_for_user, get_url
32+
from pulpcore.plugin.util import get_objects_for_user, get_url, get_domain
3433
from pulpcore.plugin.exceptions import TimeoutException
3534

3635
from rest_framework.exceptions import (
@@ -596,7 +595,7 @@ def get_manifest_config(self, manifest):
596595
except Artifact.DoesNotExist:
597596
log.warning(f"Manifest {manifest.pk}'s config blob was not found.")
598597
else:
599-
with storage.open(config_artifact.file.name) as file:
598+
with get_domain().get_storage().open(config_artifact.file.name) as file:
600599
raw_data = file.read()
601600
config_data = json.loads(raw_data)
602601
config["labels"] = config_data.get("config", {}).get("Labels")
@@ -989,14 +988,15 @@ def __init__(self, *args, **kwargs):
989988
"""
990989
super().__init__(*args, **kwargs)
991990

991+
domain = get_domain()
992992
if (
993-
settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem"
994-
or not settings.REDIRECT_TO_OBJECT_STORAGE
993+
domain.storage_class == "pulpcore.app.models.storage.FileSystem"
994+
or not domain.redirect_to_object_storage
995995
):
996996
self.redirects_class = FileStorageRedirects
997-
elif settings.DEFAULT_FILE_STORAGE == "storages.backends.s3boto3.S3Boto3Storage":
997+
elif domain.storage_class == "storages.backends.s3boto3.S3Boto3Storage":
998998
self.redirects_class = S3StorageRedirects
999-
elif settings.DEFAULT_FILE_STORAGE == "storages.backends.azure_storage.AzureStorage":
999+
elif domain.storage_class == "storages.backends.azure_storage.AzureStorage":
10001000
self.redirects_class = AzureStorageRedirects
10011001
else:
10021002
raise NotImplementedError()
@@ -1195,6 +1195,8 @@ def put(self, request, path, pk=None):
11951195
"""
11961196
Responds with the actual manifest
11971197
"""
1198+
domain = get_domain()
1199+
storage = domain.get_storage()
11981200
# iterate over all the layers and create
11991201
chunk = request.META["wsgi.input"]
12001202
artifact = self.receive_artifact(chunk)

pulp_container/app/tasks/sign.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.db.models import Q
99

1010
from pulpcore.plugin.models import Repository
11+
from pulpcore.plugin.util import get_domain
1112

1213
from pulp_container.app.models import (
1314
ManifestSignature,
@@ -106,7 +107,7 @@ async def create_signature(manifest, reference, signing_service):
106107
if not manifest.data:
107108
# TODO: BACKWARD COMPATIBILITY - remove after fully migrating to artifactless manifest
108109
artifact = await manifest._artifacts.aget()
109-
if settings.DEFAULT_FILE_STORAGE != "pulpcore.app.models.storage.FileSystem":
110+
if get_domain().storage_class != "pulpcore.app.models.storage.FileSystem":
110111
async with tempfile.NamedTemporaryFile(dir=".", mode="wb", delete=False) as tf:
111112
await tf.write(await sync_to_async(artifact.file.read)())
112113
await tf.flush()

pulp_container/app/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from asgiref.sync import sync_to_async
1212
from jsonschema import Draft7Validator, validate, ValidationError
13-
from django.core.files.storage import default_storage as storage
13+
from pulpcore.plugin.util import get_domain
1414
from django.db import IntegrityError
1515
from functools import partial
1616
from rest_framework.exceptions import Throttled
@@ -310,6 +310,7 @@ async def save_artifact(artifact_attributes):
310310

311311

312312
def get_content_data(saved_artifact):
313+
storage = get_domain().get_storage()
313314
with storage.open(saved_artifact.file.name, mode="rb") as file:
314315
raw_data = file.read()
315316
content_data = json.loads(raw_data)

pulp_container/tests/functional/api/test_content_cache.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@
3030

3131
from pulp_container.constants import MEDIA_TYPE
3232

33-
STANDARD_FILE_STORAGE_FRAMEWORKS = [
34-
"django.core.files.storage.FileSystemStorage",
35-
"pulpcore.app.models.storage.FileSystem",
36-
]
37-
3833
cli_client = cli.Client(config.get_config())
39-
DEFAULT_FILE_STORAGE = utils.get_pulp_setting(cli_client, "DEFAULT_FILE_STORAGE")
4034
CACHE_ENABLED = utils.get_pulp_setting(cli_client, "CACHE_ENABLED")
4135

4236
PULP_CONTENT_HOST_BASE_URL = config.get_config().get_base_url()
@@ -190,13 +184,10 @@ def check_cache(self, url, expected_metadata, headers):
190184

191185
def fetch_response_metadata(self, response):
192186
"""Retrieve metadata from the passed response and normalize status code for redirects."""
193-
if DEFAULT_FILE_STORAGE in STANDARD_FILE_STORAGE_FRAMEWORKS:
194-
return response.status_code, response.headers.get("X-PULP-CACHE")
195-
else:
196-
if response.history:
197-
response = response.history[0]
198-
response.status_code = 200
199-
return response.status_code, response.headers.get("X-PULP-CACHE")
187+
if response.history:
188+
response = response.history[0]
189+
response.status_code = 200
190+
return response.status_code, response.headers.get("X-PULP-CACHE")
200191

201192

202193
def cache_status_first_func(i):

template_config.yml

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
# were not present before running plugin-template have been added with their default values.
33

44
# generated with plugin_template
5+
#
6+
# After editing this file please always reapply the plugin template before committing any changes.
57

6-
api_root: /pulp/
8+
---
9+
api_root: "/pulp/"
710
black: true
811
check_commit_message: true
912
check_gettext: true
1013
check_manifest: true
1114
check_stray_pulpcore_imports: true
12-
ci_base_image: ghcr.io/pulp/pulp-ci-centos9
15+
ci_base_image: "ghcr.io/pulp/pulp-ci-centos9"
1316
ci_env: {}
14-
ci_trigger: '{pull_request: {branches: [''*'']}}'
15-
cli_package: pulp-cli
16-
cli_repo: https://github.com/pulp/pulp-cli.git
17+
ci_trigger: "{pull_request: {branches: ['*']}}"
18+
cli_package: "pulp-cli"
19+
cli_repo: "https://github.com/pulp/pulp-cli.git"
1720
core_import_allowed: []
1821
deploy_client_to_pypi: true
1922
deploy_client_to_rubygems: true
@@ -23,54 +26,81 @@ docker_fixtures: false
2326
extra_files: []
2427
flake8: true
2528
flake8_ignore: []
26-
github_org: pulp
27-
latest_release_branch: '2.21'
29+
github_org: "pulp"
30+
latest_release_branch: "2.21"
2831
lint_requirements: true
2932
os_required_packages: []
3033
parallel_test_workers: 8
31-
plugin_app_label: container
32-
plugin_default_branch: main
33-
plugin_name: pulp_container
34+
plugin_app_label: "container"
35+
plugin_default_branch: "main"
36+
plugin_name: "pulp_container"
3437
plugins:
35-
- app_label: container
36-
name: pulp_container
37-
post_job_template: null
38-
pre_job_template: null
38+
- app_label: "container"
39+
name: "pulp_container"
3940
pulp_env: {}
4041
pulp_env_azure: {}
4142
pulp_env_gcp: {}
4243
pulp_env_s3: {}
43-
pulp_scheme: https
44+
pulp_scheme: "https"
4445
pulp_settings:
4546
allowed_content_checksums:
46-
- sha1
47-
- sha224
48-
- sha256
49-
- sha384
50-
- sha512
47+
- "sha1"
48+
- "sha224"
49+
- "sha256"
50+
- "sha384"
51+
- "sha512"
5152
allowed_export_paths:
52-
- /tmp
53+
- "/tmp"
5354
allowed_import_paths:
54-
- /tmp
55+
- "/tmp"
5556
flatpak_index: true
5657
pulp_settings_azure:
58+
MEDIA_ROOT: ""
59+
STORAGES:
60+
default:
61+
BACKEND: "storages.backends.azure_storage.AzureStorage"
62+
OPTIONS:
63+
account_key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
64+
account_name: "devstoreaccount1"
65+
azure_container: "pulp-test"
66+
connection_string: "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://ci-azurite:10000/devstoreaccount1;"
67+
expiration_secs: 120
68+
location: "pulp3"
69+
overwrite_files: true
70+
staticfiles:
71+
BACKEND: "django.contrib.staticfiles.storage.StaticFilesStorage"
5772
flatpak_index: true
5873
pulp_settings_gcp: null
5974
pulp_settings_s3:
75+
MEDIA_ROOT: ""
76+
STORAGES:
77+
default:
78+
BACKEND: "storages.backends.s3boto3.S3Boto3Storage"
79+
OPTIONS:
80+
access_key: "AKIAIT2Z5TDYPX3ARJBA"
81+
addressing_style: "path"
82+
bucket_name: "pulp3"
83+
default_acl: "@none"
84+
endpoint_url: "http://minio:9000"
85+
region_name: "eu-central-1"
86+
secret_key: "fqRvjWaPU5o0fCqQuUWbj9Fainj2pVZtBCiDiieS"
87+
signature_version: "s3v4"
88+
staticfiles:
89+
BACKEND: "django.contrib.staticfiles.storage.StaticFilesStorage"
6090
flatpak_index: false
6191
token_auth_disabled: true
6292
pydocstyle: true
63-
release_email: pulp-infra@redhat.com
64-
release_user: pulpbot
93+
release_email: "pulp-infra@redhat.com"
94+
release_user: "pulpbot"
6595
stalebot: true
6696
stalebot_days_until_close: 30
6797
stalebot_days_until_stale: 90
6898
stalebot_limit_to_pulls: true
6999
supported_release_branches:
70-
- '2.14'
71-
- '2.15'
72-
- '2.16'
73-
- '2.20'
100+
- "2.14"
101+
- "2.15"
102+
- "2.16"
103+
- "2.20"
74104
sync_ci: true
75105
test_azure: true
76106
test_cli: true
@@ -81,4 +111,5 @@ test_performance: false
81111
test_reroute: true
82112
test_s3: true
83113
use_issue_template: true
114+
...
84115

0 commit comments

Comments
 (0)