mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
fix(operations): jobs see the Settings page values
Only the request middleware loaded the Settings page values, so in the worker process app_settings stayed empty: a VM create job failed reading the default volume format, and the snapshot free-space check fell back to its defaults. The worker now loads them before each job.
This commit is contained in:
parent
aabce6b037
commit
1fb709ea05
2 changed files with 17 additions and 0 deletions
|
|
@ -13,6 +13,8 @@ from django.contrib.auth import get_user_model
|
|||
from django.db import OperationalError, connection
|
||||
from django.test import TransactionTestCase
|
||||
|
||||
from appsettings.models import AppSettings
|
||||
from appsettings.settings import app_settings
|
||||
from operations import jobs
|
||||
from operations.models import Claim, Operation, WorkerLease
|
||||
from operations.tests import fakes
|
||||
|
|
@ -63,6 +65,18 @@ class WorkerTestCase(TransactionTestCase):
|
|||
self.assertTrue(wait_for(lambda: state(op) == Operation.SUCCEEDED))
|
||||
self.assertFalse(Claim.objects.exists())
|
||||
|
||||
def test_a_job_sees_the_settings_page_values(self):
|
||||
# the worker has no settings middleware: it loads the values itself
|
||||
AppSettings.objects.create(name="t", key="TEST_WORKER_VALUE", value="42", choices="")
|
||||
if hasattr(app_settings, "TEST_WORKER_VALUE"):
|
||||
del app_settings.TEST_WORKER_VALUE
|
||||
op = self.submit("test.noop", {}, "key-00000009")
|
||||
with patch.object(fakes.NoopKind, "run", lambda kind, op, ctx: {"value": app_settings.TEST_WORKER_VALUE}):
|
||||
self.start()
|
||||
self.assertTrue(wait_for(lambda: state(op) in Operation.TERMINAL))
|
||||
op.refresh_from_db()
|
||||
self.assertEqual((op.state, op.result), (Operation.SUCCEEDED, {"value": "42"}), op.error)
|
||||
|
||||
def test_an_error_before_effects_fails_the_job(self):
|
||||
op = self.submit("test.scripted", {"fail_before": True}, "key-00000001")
|
||||
self.start()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue