From 01908d64db5443f750ca78deff06f25f6bc7ee83 Mon Sep 17 00:00:00 2001 From: Michaela Lang <94735640+michaelalang@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:35:02 +0200 Subject: [PATCH] workers(quotaregistrysize): fixed wrong condition to run quotasizeworker from PROJQUAY-8086 (PROJQUAY-9460) (#4313) PROJQUAY-9460 (fix): Total Registry Size Calculation return 0 KB and always queued --- workers/quotaregistrysizeworker.py | 2 +- workers/test/test_quotaregistrysizeworker.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/workers/quotaregistrysizeworker.py b/workers/quotaregistrysizeworker.py index b0749405c..5fa608850 100644 --- a/workers/quotaregistrysizeworker.py +++ b/workers/quotaregistrysizeworker.py @@ -39,7 +39,7 @@ if __name__ == "__main__": time.sleep(100000) # Registry size is only viewable by superusers, don't calculate if not used - if not all( + if not any( [ any( [ diff --git a/workers/test/test_quotaregistrysizeworker.py b/workers/test/test_quotaregistrysizeworker.py index b6cb0b380..ca0ae425b 100644 --- a/workers/test/test_quotaregistrysizeworker.py +++ b/workers/test/test_quotaregistrysizeworker.py @@ -4,6 +4,10 @@ import features from test.fixtures import * from workers.quotaregistrysizeworker import QuotaRegistrySizeWorker +# since all checks are happening only when the worker is the main process `if __name__ == "__main__:` +# we need to re-implement the call/not-call logic as duplicate. +# Considering to move it into the `_calculate_registry_size` instead is dropped as dependencies are not clear + def test_registrysizeworker(initialized_db): with patch( @@ -31,6 +35,7 @@ def test_registrysizeworker_recovery(initialized_db): def test_registrysizeworker_no_quotamanagement(initialized_db): # we expect to fail since we do not have quota management enabled features.QUOTA_MANAGEMENT = False + features.SUPER_USERS = True app.config.update({"SUPER_USERS": ["someone"]}) if features.QUOTA_MANAGEMENT: with patch( @@ -43,8 +48,10 @@ def test_registrysizeworker_no_quotamanagement(initialized_db): def test_registrysizeworker_no_superusers(initialized_db): # we expect to fail since we do not have any superusers - app.config.update({"SUPER_USERS": [""]}) - if features.QUOTA_MANAGEMENT: + features.QUOTA_MANAGEMENT = True + features.SUPER_USERS = True + app.config.update({"SUPER_USERS": []}) + if all([features.QUOTA_MANAGEMENT, features.SUPER_USERS, len(app.config["SUPER_USERS"]) > 0]): with patch( "workers.quotaregistrysizeworker.calculate_registry_size", MagicMock() ) as mock_calculate_registry_size: @@ -55,9 +62,11 @@ def test_registrysizeworker_no_superusers(initialized_db): def test_registrysizeworker_ldap_superusers(initialized_db): # we expect to succeed since LDAP_SUPERUSERS_FILTER is not empty + features.QUOTA_MANAGEMENT = False + features.SUPER_USERS = True app.config.update({"LDAP_SUPERUSER_FILTER": "(objectClass=*)"}) app.config.update({"SUPER_USERS": []}) - if not all( + if not any( [ any( [