mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
fix(computes): a failed bulk migration does not also say it was stopped
The worker hands a failed job that made changes to recovery, whose outcome joins the job's error. The bulk migration's recovery said "the bulk migration stopped ... the other VMs stay" after its own "These VMs did not migrate", as if the worker had left it. A job that ends itself now records so, and recovery then adds nothing; it still says so for a job the worker left.
This commit is contained in:
parent
25e3794cc9
commit
027896c3d4
2 changed files with 19 additions and 5 deletions
|
|
@ -69,6 +69,12 @@ class BulkMigrate(Kind):
|
|||
started, refused = {}, [] # VM: its migrate job; the VMs whose job was refused, and why
|
||||
ctx.record_intent()
|
||||
ctx.set_phase(gettext_noop("Migrating the VMs"))
|
||||
|
||||
def stop(text, **values):
|
||||
"""End the job failed; recovery, which the worker hands such a job, adds nothing."""
|
||||
ctx.record_intent(stopped=True)
|
||||
raise util.OperationError(text, **values)
|
||||
|
||||
while True:
|
||||
running = list(Operation.objects.filter(pk__in=started.values(), state__in=Operation.ACTIVE)
|
||||
.values_list("pk", flat=True))
|
||||
|
|
@ -81,11 +87,9 @@ class BulkMigrate(Kind):
|
|||
# the worker's slots may have been lowered: this job waits in one, its migrations need others;
|
||||
# once it ends, the migrations it queued run
|
||||
if parallel_limit() < 1:
|
||||
raise util.OperationError(gettext_noop(
|
||||
"The worker now runs one job at a time: the VMs not yet started stay on the host"))
|
||||
stop(gettext_noop("The worker now runs one job at a time: the VMs not yet started stay on the host"))
|
||||
if waiting and _where(p) != op.intent["where"]:
|
||||
raise util.OperationError(gettext_noop(
|
||||
"A host was changed or deleted: the VMs not yet started stay on the host"))
|
||||
stop(gettext_noop("A host was changed or deleted: the VMs not yet started stay on the host"))
|
||||
for pk in list(waiting):
|
||||
if len(running) >= min(p["parallel"], parallel_limit()):
|
||||
break
|
||||
|
|
@ -114,7 +118,7 @@ class BulkMigrate(Kind):
|
|||
.values_list("pk", flat=True))
|
||||
failed = refused + [names[vm] for vm, job in started.items() if job not in migrated]
|
||||
if failed:
|
||||
raise util.OperationError(gettext_noop("These VMs did not migrate: %(vms)s"), vms=", ".join(failed))
|
||||
stop(gettext_noop("These VMs did not migrate: %(vms)s"), vms=", ".join(failed))
|
||||
return {}
|
||||
|
||||
def progress(self, op):
|
||||
|
|
@ -125,6 +129,8 @@ class BulkMigrate(Kind):
|
|||
"""run sees the cancel and cancels the migrations that run."""
|
||||
|
||||
def reconcile(self, op):
|
||||
if op.intent.get("stopped"):
|
||||
return Outcome(Operation.FAILED) # its own error says why
|
||||
return Outcome(Operation.FAILED, error=utils.say(gettext_noop(
|
||||
"The bulk migration stopped: the migrations it started go on as their own jobs; the other VMs stay")))
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ class BulkMigrateJobTests(TestCase):
|
|||
job.state = ends(job)
|
||||
job.save()
|
||||
|
||||
self.op = op
|
||||
with patch("computes.jobs.time.sleep", side_effect=round_ends):
|
||||
try:
|
||||
return BulkMigrate().run(op, Ctx(op)), max(most)
|
||||
|
|
@ -154,6 +155,13 @@ class BulkMigrateJobTests(TestCase):
|
|||
with self.assertRaisesRegex(util.OperationError, "did not migrate"):
|
||||
self.run_job(1, lambda job: Operation.FAILED if job.params["instance"] == fail else Operation.SUCCEEDED)
|
||||
self.assertEqual(self.migrations.count(), 3)
|
||||
# the worker hands a failed job that made changes to recovery: it adds no "stopped" message
|
||||
outcome = BulkMigrate().reconcile(self.op)
|
||||
self.assertEqual((outcome.state, outcome.error), (Operation.FAILED, []))
|
||||
|
||||
def test_a_bulk_migration_the_worker_left_says_it_stopped(self):
|
||||
op = Operation(kind="host.bulk_migrate", intent={"migrations": {}})
|
||||
self.assertIn("stopped", BulkMigrate().reconcile(op).error[0]["text"])
|
||||
|
||||
def test_a_create_waits_for_the_migrations(self):
|
||||
Operation.objects.all().delete()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue