mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(backups): a schedule of every VM of a compute reads the host's VMs
The schedule took a compute's VMs from the database, which learns of a VM made with virsh only when a page reads the host. When its time comes, the compute's own schedule task reads the host first, once a day per compute and day; the new VM is backed up a pass later. refresh_instance_database now says whether it synchronized: a host that did not answer, was busy or failed is read again at the next pass, and the known VMs are backed up meanwhile. A host in maintenance is not read.
This commit is contained in:
parent
1d880acb17
commit
2e3ffba851
4 changed files with 95 additions and 12 deletions
|
|
@ -138,9 +138,13 @@ class ComputeConcurrencyTestCase(TransactionTestCase):
|
|||
compute.status = True
|
||||
|
||||
claims.admit({claims.compute_key(compute.id): Claim.EXCLUSIVE}, holder="other")
|
||||
refresh_instance_database(compute)
|
||||
self.assertIsNone(refresh_instance_database(compute)) # not synchronized: the caller may try again
|
||||
self.assertEqual(Instance.objects.filter(compute=compute).count(), 1)
|
||||
mock_proxy.wvm.listAllDomains.assert_called_once() # the pre-check's read; no reconcile
|
||||
Claim.objects.all().delete()
|
||||
self.assertIs(refresh_instance_database(compute), True) # synchronized
|
||||
self.assertEqual(Instance.objects.filter(compute=compute).count(), 0)
|
||||
self.assertIs(refresh_instance_database(compute), True) # already matching
|
||||
|
||||
def _reconcile_compute(self, name, domains):
|
||||
"""A compute whose database differs from libvirt (a VM libvirt no
|
||||
|
|
|
|||
|
|
@ -184,6 +184,8 @@ def refresh_instance_database(compute):
|
|||
UserInstance permission relationships (matched by UUID).
|
||||
- If libvirt is unreachable (connection/network error), the database is left
|
||||
untouched to avoid false deletions.
|
||||
True when the database matches the host's VMs afterwards; None when it was
|
||||
not synchronized (host not answering, busy or changed meanwhile).
|
||||
"""
|
||||
compute_pk = getattr(compute, "pk", getattr(compute, "id", None))
|
||||
if not compute_pk:
|
||||
|
|
@ -202,7 +204,7 @@ def refresh_instance_database(compute):
|
|||
cutoff = timezone.now() - timedelta(days=retention)
|
||||
if (dict(Instance.objects.filter(compute_id=compute_pk).values_list("uuid", "name")) == host_domains
|
||||
and not InstanceTombstone.objects.filter(removed__lt=cutoff).exists()):
|
||||
return
|
||||
return True
|
||||
|
||||
try:
|
||||
# The compute shared: VM operations and jobs on it go on; changes of
|
||||
|
|
@ -260,6 +262,7 @@ def refresh_instance_database(compute):
|
|||
)
|
||||
if created and not Instance.objects.filter(uuid=uuid).exclude(compute=compute).exists():
|
||||
_restore(inst)
|
||||
return True
|
||||
except claims.Busy:
|
||||
logger.debug("Compute %s is busy; not synchronized now", compute_pk)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue