From fa16d173938b30af4e1cc6b312a75b12aff6c424 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 17 Aug 2012 15:21:36 -0400 Subject: [PATCH] Fix get_vnc_console race. There exists a window between a server create is done and when the host is assigned by the scheduler that a request to get the vnc console will result in a 500 error. This patch adds a check in the compute API to ensure that the instance has a host assigned before try to execute a rpc on the compute node. If not, it raises InstanceNotReady (which translates to a 409 in the OS API). Fix bug 1037809. Change-Id: I3f5af90d57ae84f98f787e14ccb66f1841ac0c6d --- nova/compute/api.py | 3 +++ nova/tests/compute/test_compute.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/nova/compute/api.py b/nova/compute/api.py index e7f9368eacb5..ebf67729da34 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1627,6 +1627,9 @@ class API(base.Base): @wrap_check_policy def get_vnc_console(self, context, instance, console_type): """Get a url to an instance Console.""" + if not instance['host']: + raise exception.InstanceNotReady(instance=instance) + connect_info = self.compute_rpcapi.get_vnc_console(context, instance=instance, console_type=console_type) diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 8a46d51ec03d..64d7fb960130 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3896,6 +3896,15 @@ class ComputeAPITestCase(BaseTestCase): fake_instance, fake_console_type) self.assertEqual(console, {'url': 'fake_console_url'}) + def test_get_vnc_console_no_host(self): + instance = self._create_fake_instance(params={'host': ''}) + + self.assertRaises(exception.InstanceNotReady, + self.compute_api.get_vnc_console, + self.context, instance, 'novnc') + + db.instance_destroy(self.context, instance['uuid']) + def test_console_output(self): fake_instance = {'uuid': 'fake_uuid', 'host': 'fake_compute_host'}