diff --git a/conf/daemon/consolecallback b/conf/daemon/consolecallback index d7351ae5..e8e659d5 100755 --- a/conf/daemon/consolecallback +++ b/conf/daemon/consolecallback @@ -115,7 +115,10 @@ def main(): if os.environ.get("CONSOLECALLBACK_LOG_FD"): log.addHandler(logging.StreamHandler(os.fdopen(int(os.environ["CONSOLECALLBACK_LOG_FD"]), "w", buffering=1))) log.propagate = False - instance = Instance.objects.select_related("compute").get(pk=int(sys.argv[1])) + instance = Instance.objects.select_related("compute").filter(pk=int(sys.argv[1])).first() + if instance is None: # deleted since socketiod accepted the token + say("The VM is no longer in the panel") + sys.exit(1) user_id = int(sys.argv[2]) c = instance.compute try: diff --git a/console/tests/test_consolecallback.py b/console/tests/test_consolecallback.py index 623e9695..5e6b62ad 100644 --- a/console/tests/test_consolecallback.py +++ b/console/tests/test_consolecallback.py @@ -106,3 +106,10 @@ class AccessTests(DjangoTestCase): ownership.delete() self.assertFalse(cb.may_still_open(owner.pk, vm)) self.assertFalse(cb.may_still_open(999999, vm)) + + def test_a_vm_deleted_since_the_connect_is_told_not_a_traceback(self): + cb = load() + with patch.object(cb.sys, "argv", ["consolecallback", "999999", "1"]), patch.object(cb, "say") as say, \ + self.assertRaises(SystemExit): + cb.main() + say.assert_called_once_with("The VM is no longer in the panel")