diff options
| author | Anthony Young <sleepsonthefloor@gmail.com> | 2011-12-22 21:39:21 +0000 |
|---|---|---|
| committer | Anthony Young <sleepsonthefloor@gmail.com> | 2012-01-17 14:18:31 -0800 |
| commit | 8d010cacb520786fa12794801bc31eddd23b2af7 (patch) | |
| tree | 51609a7c80b6a62128a9819fadb0064209e17a81 /nova/tests | |
| parent | 5987ed97ffb90e52acb7a7d9e0a915d072aadaed (diff) | |
Implements blueprint vnc-console-cleanup
* Creates a unified way to access vnc consoles for xenserver and libvirt
* Now supports both java and websocket clients
* Removes nova-vncproxy - a replacement version of this (nova-novncproxy) can be found as described in vncconsole.rst
* Adds nova-xvpvncproxy, which supports a java vnc client
* Adds api extension to access java and novnc access_urls
* Fixes proxy server to close/shutdown sockets more cleanly
* Address style feedback
* Use new-style extension format
* Fix setup.py
* utils.gen_uuid must be wrapped like str(utils.gen_uuid()) or it can't be serialized
Change-Id: I5e42e2f160e8e3476269bd64b0e8aa77e66c918c
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_consoles.py | 97 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_extensions.py | 1 | ||||
| -rw-r--r-- | nova/tests/test_compute.py | 39 | ||||
| -rw-r--r-- | nova/tests/test_consoleauth.py | 59 | ||||
| -rw-r--r-- | nova/tests/test_virt_drivers.py | 2 |
5 files changed, 192 insertions, 6 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_consoles.py b/nova/tests/api/openstack/compute/contrib/test_consoles.py new file mode 100644 index 000000000..0ed177a33 --- /dev/null +++ b/nova/tests/api/openstack/compute/contrib/test_consoles.py @@ -0,0 +1,97 @@ +# Copyright 2012 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import json + +import webob + +from nova import compute +from nova import exception +from nova import test +from nova.tests.api.openstack import fakes + + +def fake_get_vnc_console(self, _context, _instance, _console_type): + return {'url': 'http://fake'} + + +def fake_get_vnc_console_invalid_type(self, _context, + _instance, _console_type): + raise exception.ConsoleTypeInvalid() + + +def fake_get(self, context, instance_uuid): + return {'uuid': instance_uuid} + + +def fake_get_not_found(self, context, instance_uuid): + raise exception.NotFound() + + +class ConsolesExtensionTest(test.TestCase): + + def setUp(self): + super(ConsolesExtensionTest, self).setUp() + self.stubs.Set(compute.API, 'get_vnc_console', + fake_get_vnc_console) + self.stubs.Set(compute.API, 'get', fake_get) + + def test_get_vnc_console(self): + body = {'os-getVNCConsole': {'type': 'novnc'}} + req = webob.Request.blank('/v2/fake/servers/1/action') + req.method = "POST" + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + output = json.loads(res.body) + self.assertEqual(res.status_int, 200) + self.assertEqual(output, + {u'console': {u'url': u'http://fake', u'type': u'novnc'}}) + + def test_get_vnc_console_no_type(self): + self.stubs.Set(compute.API, 'get', fake_get) + body = {'os-getVNCConsole': {}} + req = webob.Request.blank('/v2/fake/servers/1/action') + req.method = "POST" + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) + + def test_get_vnc_console_no_instance(self): + self.stubs.Set(compute.API, 'get', fake_get_not_found) + body = {'os-getVNCConsole': {'type': 'novnc'}} + req = webob.Request.blank('/v2/fake/servers/1/action') + req.method = "POST" + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 404) + + def test_get_vnc_console_invalid_type(self): + self.stubs.Set(compute.API, 'get', fake_get) + body = {'os-getVNCConsole': {'type': 'invalid'}} + self.stubs.Set(compute.API, 'get_vnc_console', + fake_get_vnc_console_invalid_type) + req = webob.Request.blank('/v2/fake/servers/1/action') + req.method = "POST" + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) diff --git a/nova/tests/api/openstack/compute/test_extensions.py b/nova/tests/api/openstack/compute/test_extensions.py index 4e41caa69..02356bc44 100644 --- a/nova/tests/api/openstack/compute/test_extensions.py +++ b/nova/tests/api/openstack/compute/test_extensions.py @@ -157,6 +157,7 @@ class ExtensionControllerTest(ExtensionTestCase): "AdminActions", "Cloudpipe", "Console_output", + "Consoles", "Createserverext", "DeferredDelete", "DiskConfig", diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 06eaf8ef5..17cf46ceb 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -696,15 +696,40 @@ class ComputeTestCase(BaseTestCase): self.assert_(set(['token', 'host', 'port']).issubset(console.keys())) self.compute.terminate_instance(self.context, instance['uuid']) - def test_vnc_console(self): + def test_novnc_vnc_console(self): """Make sure we can a vnc console for an instance.""" instance = self._create_fake_instance() self.compute.run_instance(self.context, instance['uuid']) - console = self.compute.get_vnc_console(self.context, instance['uuid']) + console = self.compute.get_vnc_console(self.context, + instance['uuid'], + 'novnc') self.assert_(console) self.compute.terminate_instance(self.context, instance['uuid']) + def test_xvpvnc_vnc_console(self): + """Make sure we can a vnc console for an instance.""" + instance = self._create_fake_instance() + self.compute.run_instance(self.context, instance['uuid']) + + console = self.compute.get_vnc_console(self.context, + instance['uuid'], + 'xvpvnc') + self.assert_(console) + self.compute.terminate_instance(self.context, instance['uuid']) + + def test_invalid_vnc_console_type(self): + """Make sure we can a vnc console for an instance.""" + instance = self._create_fake_instance() + self.compute.run_instance(self.context, instance['uuid']) + + self.assertRaises(exception.ConsoleTypeInvalid, + self.compute.get_vnc_console, + self.context, + instance['uuid'], + 'invalid') + self.compute.terminate_instance(self.context, instance['uuid']) + def test_diagnostics(self): """Make sure we can get diagnostics for an instance.""" instance = self._create_fake_instance() @@ -2831,16 +2856,20 @@ class ComputeAPITestCase(BaseTestCase): def test_vnc_console(self): """Make sure we can a vnc console for an instance.""" def vnc_rpc_call_wrapper(*args, **kwargs): - return {'token': 'asdf', 'host': '0.0.0.0', 'port': 8080} + return {'token': 'asdf', 'host': '0.0.0.0', + 'port': 8080, 'access_url': None, + 'internal_access_path': None} self.stubs.Set(rpc, 'call', vnc_rpc_call_wrapper) instance = self._create_fake_instance() - console = self.compute_api.get_vnc_console(self.context, instance) + console = self.compute_api.get_vnc_console(self.context, + instance, + 'novnc') self.compute_api.delete(self.context, instance) def test_ajax_console(self): - """Make sure we can a vnc console for an instance.""" + """Make sure we can an ajax console for an instance.""" def ajax_rpc_call_wrapper(*args, **kwargs): return {'token': 'asdf', 'host': '0.0.0.0', 'port': 8080} diff --git a/nova/tests/test_consoleauth.py b/nova/tests/test_consoleauth.py new file mode 100644 index 000000000..41aefa7fd --- /dev/null +++ b/nova/tests/test_consoleauth.py @@ -0,0 +1,59 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 OpenStack LLC. +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +Tests for Consoleauth Code. + +""" + +import time + +from nova import context +from nova import db +from nova import flags +from nova import log as logging +from nova import test +from nova import utils +from nova.consoleauth import manager + + +FLAGS = flags.FLAGS +LOG = logging.getLogger('nova.tests.consoleauth') + + +class ConsoleauthTestCase(test.TestCase): + """Test Case for consoleauth.""" + + def setUp(self): + super(ConsoleauthTestCase, self).setUp() + self.manager = utils.import_object(FLAGS.consoleauth_manager) + self.context = context.get_admin_context() + self.old_ttl = FLAGS.console_token_ttl + + def tearDown(self): + super(ConsoleauthTestCase, self).tearDown() + FLAGS.console_token_ttl = self.old_ttl + + def test_tokens_expire(self): + """Test that tokens expire correctly.""" + token = 'mytok' + FLAGS.console_token_ttl = 1 + self.manager.authorize_console(self.context, token, 'novnc', + '127.0.0.1', 'host', '') + self.assertTrue(self.manager.check_token(self.context, token)) + time.sleep(1.1) + self.assertFalse(self.manager.check_token(self.context, token)) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 9c17b3b0a..adf8f8eb8 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -294,7 +294,7 @@ class _VirtDriverTestCase(test.TestCase): def test_get_vnc_console(self): instance_ref, network_info = self._get_running_instance() vnc_console = self.connection.get_vnc_console(instance_ref) - self.assertIn('token', vnc_console) + self.assertIn('internal_access_path', vnc_console) self.assertIn('host', vnc_console) self.assertIn('port', vnc_console) |
