1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

refactor(vrtManager): remove the wvmConnect.close() that did nothing

Its body was a pass: connections are kept by the connection manager, not closed per object. The calls to it, and the finally blocks and None guards that only called it, are removed.
This commit is contained in:
catborise 2026-11-08 12:19:29 +03:00
parent 4d37e65c03
commit faa896ca54
11 changed files with 10 additions and 60 deletions

View file

@ -264,8 +264,6 @@ def _remove_clone_nvram(op):
except libvirtError as err:
if err.get_error_code() != VIR_ERR_NO_STORAGE_VOL:
raise # unreachable: recovery waits and retries
finally:
host.close()
def _clone_made(op, result):
@ -1045,8 +1043,6 @@ def _remove_copies(op):
source, _sep, name = op.resource_label.rpartition("/")
write(op.username, source, name, f"VM {name}: remove the partial disk copies on {target.name}: "
f"{safe_text(err)}", False, op.client_ip, op.intent["uuid"])
finally:
dest.close()
def _moved(op, dest):

View file

@ -203,7 +203,6 @@ class MigrateJobTestCase(TransactionTestCase):
self.assertIn("/nfs/new.qcow2</span>:\n on storage both hosts share", page)
# a disk that cannot go keeps the form from being sent, as does a destination that does not answer
self.assertEqual(page.count("data-refused"), 2)
dest.close.assert_called_once_with()
with patch("instances.views.wvmInstances", side_effect=libvirtError("no answer")):
page = self.client.get(reverse("instances:migrate_plan", args=[self.vm.pk]),
{"compute_id": self.dest.pk}).content.decode()

View file

@ -265,7 +265,6 @@ def migrate_instance(
message = f"VM {instance.name}: {action}" + (f": {reason(error, user)}" if error is not None else "")
write(user.username, source.name, instance.name, message, error is None, ip, instance.uuid)
conn_migrate = None
try:
conn_migrate = wvmInstances(
new_compute.hostname,
@ -291,9 +290,6 @@ def migrate_instance(
except Exception as error:
log(f"migrate to {target}", error)
raise
finally:
if conn_migrate is not None:
conn_migrate.close()
# The VM runs on new_compute now: what follows must not stop it
# from being recorded there.
@ -301,7 +297,6 @@ def migrate_instance(
if on_moved is not None: # its row is written: a later step that raises does not undo it
on_moved()
if autostart:
conn_new = None
try:
conn_new = wvmInstance(
new_compute.hostname,
@ -314,9 +309,6 @@ def migrate_instance(
conn_new.set_autostart(1)
except (libvirtError, OSError) as error:
log(f"restore autostart on {target}", error)
finally:
if conn_new is not None:
conn_new.close()
for path, copy in copied:
# shared storage: a VM or volume of any compute may use it; the destination's
@ -335,7 +327,6 @@ def migrate_instance(
# libvirt keeps the NVRAM file on the source; a VM created there
# later with the same name would start with these variables.
if nvram:
conn_new = None
try:
conn_new = wvmInstances(
new_compute.hostname, new_compute.login, new_compute.password, new_compute.type
@ -343,9 +334,6 @@ def migrate_instance(
instance.proxy.remove_nvram(nvram, conn_new)
except Exception as error: # the migration stands and is recorded
log(f"remove NVRAM file {nvram} on the source", error)
finally:
if conn_new is not None:
conn_new.close()
try:
record_migration(instance, new_compute)

View file

@ -965,7 +965,6 @@ def migrate_plan(request, pk):
if not compute_id.isdigit():
raise Http404
target = get_object_or_404(Compute, pk=compute_id)
dest = None
try:
dest = wvmInstances(target.hostname, target.login, target.password, target.type)
pools = [{"name": name, "free": pool.info()[3]} for name, (pool, directory) in sorted(dest.file_pools().items())]
@ -974,9 +973,6 @@ def migrate_plan(request, pk):
context = {"disks": disks, "pending": pending, "pools": pools, "shut_off": instance.proxy.get_status() == 5}
except libvirtError as err:
context = {"error": error_text(request, err)}
finally:
if dest is not None:
dest.close()
return render(request, "instances/migrate_plan.html", context)
@ -2600,7 +2596,6 @@ def create_instance(request, compute_id, arch, machine):
)
jobs.remember_job(request, op)
return redirect(reverse("instances", args=[compute.id]))
conn.close()
except libvirtError as lib_err:
messages.error(request, lib_err)