summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-08-17 15:21:36 -0400
committerRussell Bryant <rbryant@redhat.com>2012-08-17 15:33:36 -0400
commitfa16d173938b30af4e1cc6b312a75b12aff6c424 (patch)
treeb94c47ad8b5f3776fcb705b5ffb9595436d84cf6
parent275b97a33a843be620cd348796c1d1aac72f007b (diff)
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
-rw-r--r--nova/compute/api.py3
-rw-r--r--nova/tests/compute/test_compute.py9
2 files changed, 12 insertions, 0 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index e7f9368ea..ebf67729d 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 8a46d51ec..64d7fb960 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'}