Handle InstanceInvalidState exception
When instance task state is 'deleting' or 'migrating', then get_vnc_console throws 500 error, as InstanceInvalidState exception is not handled there. This change handles InstanceInvalidState in api layer in get_vnc_console call. Closes-Bug: #1968618 Change-Id: Ia738a0972b050f549f446c85171d3f33e60ada4f
This commit is contained in:
parent
d8b4b7bebd
commit
ec40d5aee3
|
@ -56,6 +56,9 @@ class RemoteConsolesController(wsgi.Controller):
|
|||
raise webob.exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.InstanceNotReady as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as e:
|
||||
common.raise_http_conflict_for_instance_invalid_state(
|
||||
e, 'get_vnc_console', id)
|
||||
except NotImplementedError:
|
||||
common.raise_feature_not_supported()
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from nova.compute import api as compute
|
||||
from nova import exception
|
||||
from nova.tests.functional.api_sample_tests import test_servers
|
||||
|
||||
HTTP_RE = r'(https?://)([\w\d:#@%/;$()~_?\+-=\\.&](#!)?)*'
|
||||
|
@ -38,6 +42,22 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
|
|||
self._verify_response('get-vnc-console-post-resp', {'url': HTTP_RE},
|
||||
response, 200)
|
||||
|
||||
@mock.patch.object(compute.API, 'get_vnc_console')
|
||||
def test_get_vnc_console_instance_invalid_state(self,
|
||||
mock_get_vnc_console):
|
||||
uuid = self._post_server()
|
||||
|
||||
def fake_get_vnc_console(*args, **kwargs):
|
||||
raise exception.InstanceInvalidState(
|
||||
attr='fake_attr', state='fake_state', method='fake_method',
|
||||
instance_uuid=uuid)
|
||||
|
||||
mock_get_vnc_console.side_effect = fake_get_vnc_console
|
||||
response = self._do_post('servers/%s/action' % uuid,
|
||||
'get-vnc-console-post-req',
|
||||
{'action': 'os-getVNCConsole'})
|
||||
self.assertEqual(409, response.status_code)
|
||||
|
||||
def test_get_spice_console(self):
|
||||
uuid = self._post_server()
|
||||
response = self._do_post('servers/%s/action' % uuid,
|
||||
|
|
|
@ -104,6 +104,18 @@ class ConsolesExtensionTestV21(test.NoDBTestCase):
|
|||
'get_vnc_console',
|
||||
exception.InstanceNotFound(instance_id=fakes.FAKE_UUID))
|
||||
|
||||
def test_get_vnc_console_instance_invalid_state(self):
|
||||
body = {'os-getVNCConsole': {'type': 'novnc'}}
|
||||
self._check_console_failure(
|
||||
self.controller.get_vnc_console,
|
||||
webob.exc.HTTPConflict,
|
||||
body,
|
||||
'get_vnc_console',
|
||||
exception.InstanceInvalidState(
|
||||
attr='fake-attr', state='fake-state', method='fake-method',
|
||||
instance_uuid=fakes.FAKE_UUID)
|
||||
)
|
||||
|
||||
def test_get_vnc_console_invalid_type(self):
|
||||
body = {'os-getVNCConsole': {'type': 'invalid'}}
|
||||
self._check_console_failure(
|
||||
|
|
Loading…
Reference in New Issue