mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +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()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ from django.db import close_old_connections
|
|||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from appsettings.settings import get_settings
|
||||
|
||||
from . import claims, jobs, utils
|
||||
from .models import Claim, LeaseLost, Operation, acquire, fenced, renew
|
||||
|
||||
|
|
@ -272,6 +274,7 @@ def execute(worker, op_id):
|
|||
op = Operation.objects.get(pk=op_id)
|
||||
kind = jobs.get_kind(op.kind)
|
||||
ctx = jobs.Context(op, worker)
|
||||
get_settings() # the Settings page values; only requests load them otherwise (middleware)
|
||||
try:
|
||||
with claims.adopted(op):
|
||||
kind.precheck(op, ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue