summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-25 14:17:11 +0000
committerGerrit Code Review <review@openstack.org>2013-03-25 14:17:11 +0000
commit2d02ce3ba00c3e4300bb841483d00d18210f79ff (patch)
tree8771971d0fe8dcf53ea10d5ee7ef6429d115d5a8
parent1a5ee2e695c652c93ef32771bb92e419d9715cc6 (diff)
parente136de1aea8d1469465272942fa3d2769cbe3a80 (diff)
downloadnova-2d02ce3ba00c3e4300bb841483d00d18210f79ff.tar.gz
nova-2d02ce3ba00c3e4300bb841483d00d18210f79ff.tar.xz
nova-2d02ce3ba00c3e4300bb841483d00d18210f79ff.zip
Merge "xenapi: fix console for rescued instance"
-rw-r--r--nova/tests/test_xenapi.py56
-rw-r--r--nova/virt/xenapi/vmops.py17
2 files changed, 68 insertions, 5 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 275abfaea..8d00aa924 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -419,6 +419,62 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
expected = self.conn.get_diagnostics(instance)
self.assertThat(fake_diagnostics, matchers.DictMatches(expected))
+ def test_get_vnc_console(self):
+ instance = self._create_instance()
+ session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass',
+ fake.FakeVirtAPI())
+ conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
+ vm_ref = vm_utils.lookup(session, instance['name'])
+
+ console = conn.get_vnc_console(instance)
+
+ # Note(sulo): We dont care about session id in test
+ # they will always differ so strip that out
+ actual_path = console['internal_access_path'].split('&')[0]
+ expected_path = "/console?ref=%s" % str(vm_ref)
+
+ self.assertEqual(expected_path, actual_path)
+
+ def test_get_vnc_console_for_rescue(self):
+ instance = self._create_instance()
+ session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass',
+ fake.FakeVirtAPI())
+ conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
+ rescue_vm = xenapi_fake.create_vm(instance['name'] + '-rescue',
+ 'Running')
+ # Set instance state to rescued
+ instance['vm_state'] = 'rescued'
+
+ console = conn.get_vnc_console(instance)
+
+ # Note(sulo): We dont care about session id in test
+ # they will always differ so strip that out
+ actual_path = console['internal_access_path'].split('&')[0]
+ expected_path = "/console?ref=%s" % str(rescue_vm)
+
+ self.assertEqual(expected_path, actual_path)
+
+ def test_get_vnc_console_instance_not_ready(self):
+ instance = {}
+ # set instance name and state
+ instance['name'] = 'fake-instance'
+ instance['uuid'] = '00000000-0000-0000-0000-000000000000'
+ instance['vm_state'] = 'building'
+
+ conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
+ self.assertRaises(exception.InstanceNotFound,
+ conn.get_vnc_console, instance)
+
+ def test_get_vnc_console_rescue_not_ready(self):
+ instance = {}
+ instance['name'] = 'fake-rescue'
+ instance['uuid'] = '00000000-0000-0000-0000-000000000001'
+ instance['vm_state'] = 'rescued'
+
+ conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
+ self.assertRaises(exception.InstanceNotReady,
+ conn.get_vnc_console, instance)
+
def test_instance_snapshot_fails_with_no_primary_vdi(self):
def create_bad_vbd(session, vm_ref, vdi_ref, userdevice,
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 8728a46a4..ce3301fd9 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -33,6 +33,7 @@ from nova.compute import instance_types
from nova.compute import power_state
from nova.compute import task_states
from nova.compute import vm_mode
+from nova.compute import vm_states
from nova import context as nova_context
from nova import exception
from nova.openstack.common import excutils
@@ -1365,11 +1366,17 @@ class VMOps(object):
def get_vnc_console(self, instance):
"""Return connection info for a vnc console."""
- try:
- vm_ref = self._get_vm_opaque_ref(instance)
- except exception.NotFound:
- # The compute manager expects InstanceNotFound for this case.
- raise exception.InstanceNotFound(instance_id=instance['uuid'])
+ if instance['vm_state'] == vm_states.RESCUED:
+ name = '%s-rescue' % instance['name']
+ vm_ref = vm_utils.lookup(self._session, name)
+ if vm_ref is None:
+ # The rescue instance might not be ready at this point.
+ raise exception.InstanceNotReady(instance_id=instance['uuid'])
+ else:
+ vm_ref = vm_utils.lookup(self._session, instance['name'])
+ if vm_ref is None:
+ # The compute manager expects InstanceNotFound for this case.
+ raise exception.InstanceNotFound(instance_id=instance['uuid'])
session_id = self._session.get_session_id()
path = "/console?ref=%s&session_id=%s" % (str(vm_ref), session_id)