mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
fix(instances): a DRBD status the compute did not tell is Unknown, not None DRBD
A drbdadm query that timed out, could not start ssh or failed showed "None DRBD", as for a VM without DRBD resources. It now shows Unknown, in the same red badge as a DRBD status that is not OK.
This commit is contained in:
parent
89035038e1
commit
076804be15
2 changed files with 15 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""drbd_status runs ssh with the compute's login@hostname; a compute whose
|
||||
values would inject an ssh option (an existing or bypassed row) is skipped,
|
||||
and a compute that does not answer in time leaves the status unknown."""
|
||||
and a compute that does not answer in time, or an ssh that fails, leaves
|
||||
the status unknown, not "None DRBD"."""
|
||||
|
||||
import subprocess
|
||||
import unittest
|
||||
|
|
@ -24,9 +25,16 @@ class DrbdTargetTestCase(unittest.TestCase):
|
|||
with patch("instances.views.get_instance", return_value=vm), patch(
|
||||
"instances.views.subprocess.run", side_effect=subprocess.TimeoutExpired("ssh", DRBD_STATUS_TIMEOUT)
|
||||
) as run:
|
||||
self.assertEqual(drbd_status(SimpleNamespace(user=None), 1), "None DRBD")
|
||||
self.assertEqual(drbd_status(SimpleNamespace(user=None), 1), "Unknown")
|
||||
self.assertEqual(run.call_args.kwargs["timeout"], DRBD_STATUS_TIMEOUT)
|
||||
|
||||
def test_a_failed_ssh_leaves_the_status_unknown(self):
|
||||
vm = SimpleNamespace(name="vm1", compute=SimpleNamespace(type=2, login="root", hostname="192.0.2.1"))
|
||||
with patch("instances.views.get_instance", return_value=vm), patch(
|
||||
"instances.views.subprocess.run", return_value=SimpleNamespace(returncode=255, stdout="")
|
||||
):
|
||||
self.assertEqual(drbd_status(SimpleNamespace(user=None), 1), "Unknown")
|
||||
|
||||
|
||||
STATUS = """webserver role:Primary
|
||||
disk:UpToDate
|
||||
|
|
@ -41,7 +49,7 @@ class DrbdStatusTestCase(unittest.TestCase):
|
|||
def status(self, name, stdout=STATUS):
|
||||
vm = SimpleNamespace(name=name, compute=SimpleNamespace(type=2, login="root", hostname="192.0.2.1"))
|
||||
with patch("instances.views.get_instance", return_value=vm), patch(
|
||||
"instances.views.subprocess.run", return_value=SimpleNamespace(stdout=stdout)
|
||||
"instances.views.subprocess.run", return_value=SimpleNamespace(returncode=0, stdout=stdout)
|
||||
):
|
||||
return drbd_status(SimpleNamespace(user=None), 1)
|
||||
|
||||
|
|
|
|||
|
|
@ -415,8 +415,10 @@ def drbd_status(request, pk):
|
|||
text=True,
|
||||
timeout=DRBD_STATUS_TIMEOUT,
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
return result
|
||||
except (subprocess.TimeoutExpired, OSError):
|
||||
return _("Unknown") # not "None DRBD": the compute did not tell
|
||||
if remoteDrbdStatus.returncode != 0:
|
||||
return _("Unknown")
|
||||
|
||||
# the VM's resources are its name or its name_SUFFIX, at the start of a line
|
||||
instanceFindDrbd = re.compile(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue