Changes V3 remote_console extension into v2.1
This patch changes v3 remote_console API to v2.1 and makes v2 unit tests share between v2 and v2.1. The differences between v2 and v3 are described on the wiki page https://wiki.openstack.org/wiki/NovaAPIv2tov3. Partially implements blueprint v2-on-v3-api Change-Id: I5f15ec39d7201b2da3d7afbf1d0774e64e68c8fe
This commit is contained in:
parent
82f0c41bda
commit
333af0fd44
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_rdp_console": {
|
||||
"os-getRDPConsole": {
|
||||
"type": "rdp-html5"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_rdp_console": {
|
||||
"os-getRDPConsole": {
|
||||
"type": "rdp-html5"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_spice_console": {
|
||||
"os-getSPICEConsole": {
|
||||
"type": "spice-html5"
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_vnc_console": {
|
||||
"os-getVNCConsole": {
|
||||
"type": "novnc"
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
super(RemoteConsolesController, self).__init__(*args, **kwargs)
|
||||
|
||||
@extensions.expected_errors((400, 404, 409, 501))
|
||||
@wsgi.action('get_vnc_console')
|
||||
@wsgi.action('os-getVNCConsole')
|
||||
@validation.schema(remote_consoles.get_vnc_console)
|
||||
def get_vnc_console(self, req, id, body):
|
||||
"""Get text console output."""
|
||||
@ -42,7 +42,7 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
authorize(context)
|
||||
|
||||
# If type is not supplied or unknown, get_vnc_console below will cope
|
||||
console_type = body['get_vnc_console'].get('type')
|
||||
console_type = body['os-getVNCConsole'].get('type')
|
||||
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
@ -63,7 +63,7 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
return {'console': {'type': console_type, 'url': output['url']}}
|
||||
|
||||
@extensions.expected_errors((400, 404, 409, 501))
|
||||
@wsgi.action('get_spice_console')
|
||||
@wsgi.action('os-getSPICEConsole')
|
||||
@validation.schema(remote_consoles.get_spice_console)
|
||||
def get_spice_console(self, req, id, body):
|
||||
"""Get text console output."""
|
||||
@ -71,7 +71,7 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
authorize(context)
|
||||
|
||||
# If type is not supplied or unknown, get_spice_console below will cope
|
||||
console_type = body['get_spice_console'].get('type')
|
||||
console_type = body['os-getSPICEConsole'].get('type')
|
||||
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
@ -93,7 +93,7 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
return {'console': {'type': console_type, 'url': output['url']}}
|
||||
|
||||
@extensions.expected_errors((400, 404, 409, 501))
|
||||
@wsgi.action('get_rdp_console')
|
||||
@wsgi.action('os-getRDPConsole')
|
||||
@validation.schema(remote_consoles.get_rdp_console)
|
||||
def get_rdp_console(self, req, id, body):
|
||||
"""Get text console output."""
|
||||
@ -101,7 +101,7 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
authorize(context)
|
||||
|
||||
# If type is not supplied or unknown, get_rdp_console below will cope
|
||||
console_type = body['get_rdp_console'].get('type')
|
||||
console_type = body['os-getRDPConsole'].get('type')
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
want_objects=True)
|
||||
|
@ -15,7 +15,7 @@
|
||||
get_vnc_console = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'get_vnc_console': {
|
||||
'os-getVNCConsole': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'type': {
|
||||
@ -27,14 +27,14 @@ get_vnc_console = {
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
'required': ['get_vnc_console'],
|
||||
'required': ['os-getVNCConsole'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
get_spice_console = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'get_spice_console': {
|
||||
'os-getSPICEConsole': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'type': {
|
||||
@ -46,14 +46,14 @@ get_spice_console = {
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
'required': ['get_spice_console'],
|
||||
'required': ['os-getSPICEConsole'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
get_rdp_console = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'get_rdp_console': {
|
||||
'os-getRDPConsole': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'type': {
|
||||
@ -65,6 +65,6 @@ get_rdp_console = {
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
'required': ['get_rdp_console'],
|
||||
'required': ['os-getRDPConsole'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
@ -98,10 +98,15 @@ def fake_get_not_found(self, context, instance_uuid, want_objects=False,
|
||||
raise exception.InstanceNotFound(instance_id=instance_uuid)
|
||||
|
||||
|
||||
class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
class ConsolesExtensionTestV21(test.NoDBTestCase):
|
||||
url = '/v3/servers/1/action'
|
||||
|
||||
def _setup_wsgi(self):
|
||||
self.app = fakes.wsgi_app_v3(init_only=('servers',
|
||||
'os-remote-consoles'))
|
||||
|
||||
def setUp(self):
|
||||
super(ConsolesExtensionTest, self).setUp()
|
||||
super(ConsolesExtensionTestV21, self).setUp()
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console)
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
@ -109,15 +114,11 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console)
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get)
|
||||
self.flags(
|
||||
osapi_compute_extension=[
|
||||
'nova.api.openstack.compute.contrib.select_extensions'],
|
||||
osapi_compute_ext_list=['Consoles'])
|
||||
self.app = fakes.wsgi_app(init_only=('servers',))
|
||||
self._setup_wsgi()
|
||||
|
||||
def test_get_vnc_console(self):
|
||||
body = {'os-getVNCConsole': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -132,7 +133,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_not_ready)
|
||||
body = {'os-getVNCConsole': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -145,7 +146,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_invalid_type)
|
||||
body = {'os-getVNCConsole': {}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -156,7 +157,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
def test_get_vnc_console_no_instance(self):
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get_not_found)
|
||||
body = {'os-getVNCConsole': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -168,7 +169,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_not_found)
|
||||
body = {'os-getVNCConsole': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -180,7 +181,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
body = {'os-getVNCConsole': {'type': 'invalid'}}
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_invalid_type)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -189,10 +190,10 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_vnc_console_type_unavailable(self):
|
||||
body = {'get_vnc_console': {'type': 'unavailable'}}
|
||||
body = {'os-getVNCConsole': {'type': 'unavailable'}}
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_type_unavailable)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -205,7 +206,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
fakes.fake_not_implemented)
|
||||
|
||||
body = {'os-getVNCConsole': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -215,7 +216,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
|
||||
def test_get_spice_console(self):
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -230,7 +231,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_not_ready)
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -243,7 +244,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_invalid_type)
|
||||
body = {'os-getSPICEConsole': {}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -254,7 +255,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
def test_get_spice_console_no_instance(self):
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get_not_found)
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -266,7 +267,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_not_found)
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -278,7 +279,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
body = {'os-getSPICEConsole': {'type': 'invalid'}}
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_invalid_type)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -290,7 +291,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5'}}
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fakes.fake_not_implemented)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -299,10 +300,10 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.assertEqual(res.status_int, 501)
|
||||
|
||||
def test_get_spice_console_type_unavailable(self):
|
||||
body = {'get_spice_console': {'type': 'unavailable'}}
|
||||
body = {'os-getSPICEConsole': {'type': 'unavailable'}}
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_type_unavailable)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -312,7 +313,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
|
||||
def test_get_rdp_console(self):
|
||||
body = {'os-getRDPConsole': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -327,7 +328,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_not_ready)
|
||||
body = {'os-getRDPConsole': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -340,7 +341,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_invalid_type)
|
||||
body = {'os-getRDPConsole': {}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -351,7 +352,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
def test_get_rdp_console_no_instance(self):
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get_not_found)
|
||||
body = {'os-getRDPConsole': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -363,7 +364,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_not_found)
|
||||
body = {'os-getRDPConsole': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -375,7 +376,7 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
body = {'os-getRDPConsole': {'type': 'invalid'}}
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_invalid_type)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -384,13 +385,61 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_rdp_console_type_unavailable(self):
|
||||
body = {'get_rdp_console': {'type': 'unavailable'}}
|
||||
body = {'os-getRDPConsole': {'type': 'unavailable'}}
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_type_unavailable)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_vnc_console_with_undefined_param(self):
|
||||
body = {'os-getVNCConsole': {'type': 'novnc', 'undefined': 'foo'}}
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_spice_console_with_undefined_param(self):
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5',
|
||||
'undefined': 'foo'}}
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_rdp_console_with_undefined_param(self):
|
||||
body = {'os-getRDPConsole': {'type': 'rdp-html5', 'undefined': 'foo'}}
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
|
||||
class ConsolesExtensionTestV2(ConsolesExtensionTestV21):
|
||||
url = '/v2/fake/servers/1/action'
|
||||
|
||||
def _setup_wsgi(self):
|
||||
self.flags(
|
||||
osapi_compute_extension=[
|
||||
'nova.api.openstack.compute.contrib.select_extensions'],
|
||||
osapi_compute_ext_list=['Consoles'])
|
||||
self.app = fakes.wsgi_app(init_only=('servers',))
|
||||
|
||||
def test_get_vnc_console_with_undefined_param(self):
|
||||
pass
|
||||
|
||||
def test_get_spice_console_with_undefined_param(self):
|
||||
pass
|
||||
|
||||
def test_get_rdp_console_with_undefined_param(self):
|
||||
pass
|
||||
|
@ -1,421 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# 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 webob
|
||||
|
||||
from nova.compute import api as compute_api
|
||||
from nova import exception
|
||||
from nova.openstack.common import jsonutils
|
||||
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_spice_console(self, _context, _instance, _console_type):
|
||||
return {'url': 'http://fake'}
|
||||
|
||||
|
||||
def fake_get_rdp_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(console_type=_console_type)
|
||||
|
||||
|
||||
def fake_get_spice_console_invalid_type(self, _context,
|
||||
_instance, _console_type):
|
||||
raise exception.ConsoleTypeInvalid(console_type=_console_type)
|
||||
|
||||
|
||||
def fake_get_rdp_console_invalid_type(self, _context,
|
||||
_instance, _console_type):
|
||||
raise exception.ConsoleTypeInvalid(console_type=_console_type)
|
||||
|
||||
|
||||
def fake_get_vnc_console_type_unavailable(self, _context,
|
||||
_instance, _console_type):
|
||||
raise exception.ConsoleTypeUnavailable(console_type=_console_type)
|
||||
|
||||
|
||||
def fake_get_spice_console_type_unavailable(self, _context,
|
||||
_instance, _console_type):
|
||||
raise exception.ConsoleTypeUnavailable(console_type=_console_type)
|
||||
|
||||
|
||||
def fake_get_rdp_console_type_unavailable(self, _context,
|
||||
_instance, _console_type):
|
||||
raise exception.ConsoleTypeUnavailable(console_type=_console_type)
|
||||
|
||||
|
||||
def fake_get_vnc_console_not_ready(self, _context, instance, _console_type):
|
||||
raise exception.InstanceNotReady(instance_id=instance["uuid"])
|
||||
|
||||
|
||||
def fake_get_spice_console_not_ready(self, _context, instance, _console_type):
|
||||
raise exception.InstanceNotReady(instance_id=instance["uuid"])
|
||||
|
||||
|
||||
def fake_get_rdp_console_not_ready(self, _context, instance, _console_type):
|
||||
raise exception.InstanceNotReady(instance_id=instance["uuid"])
|
||||
|
||||
|
||||
def fake_get_vnc_console_not_found(self, _context, instance, _console_type):
|
||||
raise exception.InstanceNotFound(instance_id=instance["uuid"])
|
||||
|
||||
|
||||
def fake_get_spice_console_not_found(self, _context, instance, _console_type):
|
||||
raise exception.InstanceNotFound(instance_id=instance["uuid"])
|
||||
|
||||
|
||||
def fake_get_rdp_console_not_found(self, _context, instance, _console_type):
|
||||
raise exception.InstanceNotFound(instance_id=instance["uuid"])
|
||||
|
||||
|
||||
def fake_get(self, context, instance_uuid, expected_attrs=None,
|
||||
want_objects=False):
|
||||
return {'uuid': instance_uuid}
|
||||
|
||||
|
||||
def fake_get_not_found(self, context, instance_uuid, **kwargs):
|
||||
raise exception.InstanceNotFound(instance_id=instance_uuid)
|
||||
|
||||
|
||||
class ConsolesExtensionTest(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ConsolesExtensionTest, self).setUp()
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console)
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console)
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console)
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get)
|
||||
self.app = fakes.wsgi_app_v3(init_only=('servers',
|
||||
'os-remote-consoles'))
|
||||
|
||||
def test_get_vnc_console(self):
|
||||
body = {'get_vnc_console': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
output = jsonutils.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_not_ready(self):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_not_ready)
|
||||
body = {'get_vnc_console': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
jsonutils.loads(res.body)
|
||||
self.assertEqual(res.status_int, 409)
|
||||
|
||||
def test_get_vnc_console_no_type(self):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_invalid_type)
|
||||
body = {'get_vnc_console': {}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_vnc_console_no_instance(self):
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get_not_found)
|
||||
body = {'get_vnc_console': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 404)
|
||||
|
||||
def test_get_vnc_console_no_instance_on_console_get(self):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_not_found)
|
||||
body = {'get_vnc_console': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 404)
|
||||
|
||||
def test_get_vnc_console_invalid_type(self):
|
||||
body = {'get_vnc_console': {'type': 'invalid'}}
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_invalid_type)
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_vnc_console_type_unavailable(self):
|
||||
body = {'get_vnc_console': {'type': 'unavailable'}}
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fake_get_vnc_console_type_unavailable)
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_vnc_console_not_implemented(self):
|
||||
self.stubs.Set(compute_api.API, 'get_vnc_console',
|
||||
fakes.fake_not_implemented)
|
||||
|
||||
body = {'get_vnc_console': {'type': 'novnc'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 501)
|
||||
|
||||
def test_get_vnc_console_with_undefined_param(self):
|
||||
body = {'get_vnc_console': {'type': 'novnc', 'undefined': 'foo'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_spice_console(self):
|
||||
body = {'get_spice_console': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
output = jsonutils.loads(res.body)
|
||||
self.assertEqual(res.status_int, 200)
|
||||
self.assertEqual(output,
|
||||
{u'console': {u'url': u'http://fake', u'type': u'spice-html5'}})
|
||||
|
||||
def test_get_spice_console_not_implemented(self):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fakes.fake_not_implemented)
|
||||
|
||||
body = {'get_spice_console': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 501)
|
||||
|
||||
def test_get_spice_console_not_ready(self):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_not_ready)
|
||||
body = {'get_spice_console': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
jsonutils.loads(res.body)
|
||||
self.assertEqual(res.status_int, 409)
|
||||
|
||||
def test_get_spice_console_no_type(self):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_invalid_type)
|
||||
body = {'get_spice_console': {}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_spice_console_no_instance(self):
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get_not_found)
|
||||
body = {'get_spice_console': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 404)
|
||||
|
||||
def test_get_spice_console_no_instance_on_console_get(self):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_not_found)
|
||||
body = {'get_spice_console': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 404)
|
||||
|
||||
def test_get_spice_console_invalid_type(self):
|
||||
body = {'get_spice_console': {'type': 'invalid'}}
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_invalid_type)
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_spice_console_type_unavailable(self):
|
||||
body = {'get_spice_console': {'type': 'unavailable'}}
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_type_unavailable)
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_spice_console_with_undefined_param(self):
|
||||
body = {'get_spice_console': {'type': 'spice-html5',
|
||||
'undefined': 'foo'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_rdp_console(self):
|
||||
body = {'get_rdp_console': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
output = jsonutils.loads(res.body)
|
||||
self.assertEqual(res.status_int, 200)
|
||||
self.assertEqual(output,
|
||||
{u'console': {u'url': u'http://fake', u'type': u'rdp-html5'}})
|
||||
|
||||
def test_get_rdp_console_not_ready(self):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_not_ready)
|
||||
body = {'get_rdp_console': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
jsonutils.loads(res.body)
|
||||
self.assertEqual(res.status_int, 409)
|
||||
|
||||
def test_get_rdp_console_no_type(self):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_invalid_type)
|
||||
body = {'get_rdp_console': {}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_rdp_console_no_instance(self):
|
||||
self.stubs.Set(compute_api.API, 'get', fake_get_not_found)
|
||||
body = {'get_rdp_console': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 404)
|
||||
|
||||
def test_get_rdp_console_no_instance_on_console_get(self):
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_not_found)
|
||||
body = {'get_rdp_console': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 404)
|
||||
|
||||
def test_get_rdp_console_invalid_type(self):
|
||||
body = {'get_rdp_console': {'type': 'invalid'}}
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_invalid_type)
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_rdp_console_type_unavailable(self):
|
||||
body = {'get_rdp_console': {'type': 'unavailable'}}
|
||||
self.stubs.Set(compute_api.API, 'get_rdp_console',
|
||||
fake_get_rdp_console_type_unavailable)
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_get_rdp_console_with_undefined_param(self):
|
||||
body = {'get_rdp_console': {'type': 'rdp-html5', 'undefined': 'foo'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(400, res.status_int)
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_rdp_console": {
|
||||
"os-getRDPConsole": {
|
||||
"type": "rdp-html5"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_rdp_console": {
|
||||
"os-getRDPConsole": {
|
||||
"type": "rdp-html5"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_spice_console": {
|
||||
"os-getSPICEConsole": {
|
||||
"type": "spice-html5"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"get_vnc_console": {
|
||||
"os-getVNCConsole": {
|
||||
"type": "novnc"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user