Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit ec85262

Browse files
Add USE_MINIO feature flag (#477)
* add USE_MINIO feature flag * remove useless django_db marks * refactor feature flag in storage.__init__ logic
1 parent 191837f commit ec85262

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

shared/rollouts/features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
BUNDLE_THRESHOLD_FLAG = Feature("bundle_threshold_flag")
44
INCLUDE_GITHUB_COMMENT_ACTIONS_BY_OWNER = Feature("include_github_comment_actions")
55
USE_NEW_MINIO = Feature("use_new_minio")
6+
USE_MINIO = Feature("use_minio")

shared/storage/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from shared.config import get_config
2-
from shared.rollouts.features import USE_NEW_MINIO
2+
from shared.rollouts.features import USE_MINIO, USE_NEW_MINIO
33
from shared.storage.aws import AWSStorageService
44
from shared.storage.base import BaseStorageService
55
from shared.storage.fallback import StorageWithFallbackService
@@ -15,13 +15,12 @@ def get_appropriate_storage_service(
1515
) -> BaseStorageService:
1616
chosen_storage: str = get_config("services", "chosen_storage", default="minio") # type: ignore
1717

18-
# TODO: remove this later, as it's temporary for testing the new_minio client
19-
if (
20-
chosen_storage == "minio"
21-
and repoid
22-
and USE_NEW_MINIO.check_value(repoid, default=False)
23-
):
24-
chosen_storage = "new_minio"
18+
if repoid:
19+
if USE_MINIO.check_value(repoid, default=False):
20+
chosen_storage = "minio"
21+
22+
if USE_NEW_MINIO.check_value(repoid, default=False):
23+
chosen_storage = "new_minio"
2524

2625
if chosen_storage not in _storage_service_cache:
2726
_storage_service_cache[chosen_storage] = (

tests/unit/storage/test_init.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from shared.rollouts.features import USE_NEW_MINIO
1+
from shared.rollouts.features import USE_MINIO, USE_NEW_MINIO
22
from shared.storage import get_appropriate_storage_service
33
from shared.storage.aws import AWSStorageService
44
from shared.storage.fallback import StorageWithFallbackService
@@ -123,6 +123,37 @@ def test_get_appropriate_storage_service_new_minio(
123123
"minio": minio_config,
124124
}
125125
mocker.patch.object(USE_NEW_MINIO, "check_value", return_value=True)
126+
mocker.patch.object(USE_MINIO, "check_value", return_value=False)
127+
res = get_appropriate_storage_service(repoid=123)
128+
assert isinstance(res, NewMinioStorageService)
129+
assert res.minio_config == minio_config
130+
131+
def test_get_appropriate_storage_service_use_minio(
132+
self, mock_configuration, mocker
133+
):
134+
mock_configuration.params["services"] = {
135+
"chosen_storage": "minio",
136+
"gcp": gcp_config,
137+
"aws": aws_config,
138+
"minio": minio_config,
139+
}
140+
mocker.patch.object(USE_MINIO, "check_value", return_value=True)
141+
mocker.patch.object(USE_NEW_MINIO, "check_value", return_value=False)
142+
res = get_appropriate_storage_service(repoid=123)
143+
assert isinstance(res, MinioStorageService)
144+
assert res.minio_config == minio_config
145+
146+
def test_get_appropriate_storage_service_use_minio_and_new_minio(
147+
self, mock_configuration, mocker
148+
):
149+
mock_configuration.params["services"] = {
150+
"chosen_storage": "minio",
151+
"gcp": gcp_config,
152+
"aws": aws_config,
153+
"minio": minio_config,
154+
}
155+
mocker.patch.object(USE_MINIO, "check_value", return_value=True)
156+
mocker.patch.object(USE_NEW_MINIO, "check_value", return_value=True)
126157
res = get_appropriate_storage_service(repoid=123)
127158
assert isinstance(res, NewMinioStorageService)
128159
assert res.minio_config == minio_config
@@ -137,6 +168,7 @@ def test_get_appropriate_storage_service_new_minio_false(
137168
"minio": minio_config,
138169
}
139170
mocker.patch.object(USE_NEW_MINIO, "check_value", return_value=False)
171+
mocker.patch.object(USE_MINIO, "check_value", return_value=False)
140172
res = get_appropriate_storage_service(repoid=123)
141173
assert isinstance(res, MinioStorageService)
142174
assert res.minio_config == minio_config
@@ -152,6 +184,7 @@ def test_get_appropriate_storage_service_new_minio_cached(
152184
}
153185

154186
mocker.patch.object(USE_NEW_MINIO, "check_value", return_value=False)
187+
mocker.patch.object(USE_MINIO, "check_value", return_value=False)
155188

156189
res = get_appropriate_storage_service(repoid=123)
157190

0 commit comments

Comments
 (0)