Skip to content

Commit 6b3adac

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Handle InstanceInvalidState exception" into stable/zed
2 parents 1cf650b + 7185516 commit 6b3adac

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

nova/api/openstack/compute/remote_consoles.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def get_vnc_console(self, req, id, body):
5656
raise webob.exc.HTTPNotFound(explanation=e.format_message())
5757
except exception.InstanceNotReady as e:
5858
raise webob.exc.HTTPConflict(explanation=e.format_message())
59+
except exception.InstanceInvalidState as e:
60+
common.raise_http_conflict_for_instance_invalid_state(
61+
e, 'get_vnc_console', id)
5962
except NotImplementedError:
6063
common.raise_feature_not_supported()
6164

nova/tests/functional/api_sample_tests/test_remote_consoles.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# License for the specific language governing permissions and limitations
1414
# under the License.
1515

16+
from unittest import mock
17+
18+
from nova.compute import api as compute
19+
from nova import exception
1620
from nova.tests.functional.api_sample_tests import test_servers
1721

1822
HTTP_RE = r'(https?://)([\w\d:#@%/;$()~_?\+-=\\.&](#!)?)*'
@@ -38,6 +42,22 @@ def test_get_vnc_console(self):
3842
self._verify_response('get-vnc-console-post-resp', {'url': HTTP_RE},
3943
response, 200)
4044

45+
@mock.patch.object(compute.API, 'get_vnc_console')
46+
def test_get_vnc_console_instance_invalid_state(self,
47+
mock_get_vnc_console):
48+
uuid = self._post_server()
49+
50+
def fake_get_vnc_console(*args, **kwargs):
51+
raise exception.InstanceInvalidState(
52+
attr='fake_attr', state='fake_state', method='fake_method',
53+
instance_uuid=uuid)
54+
55+
mock_get_vnc_console.side_effect = fake_get_vnc_console
56+
response = self._do_post('servers/%s/action' % uuid,
57+
'get-vnc-console-post-req',
58+
{'action': 'os-getVNCConsole'})
59+
self.assertEqual(409, response.status_code)
60+
4161
def test_get_spice_console(self):
4262
uuid = self._post_server()
4363
response = self._do_post('servers/%s/action' % uuid,

nova/tests/unit/api/openstack/compute/test_remote_consoles.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ def test_get_vnc_console_no_instance_on_console_get(self):
104104
'get_vnc_console',
105105
exception.InstanceNotFound(instance_id=fakes.FAKE_UUID))
106106

107+
def test_get_vnc_console_instance_invalid_state(self):
108+
body = {'os-getVNCConsole': {'type': 'novnc'}}
109+
self._check_console_failure(
110+
self.controller.get_vnc_console,
111+
webob.exc.HTTPConflict,
112+
body,
113+
'get_vnc_console',
114+
exception.InstanceInvalidState(
115+
attr='fake-attr', state='fake-state', method='fake-method',
116+
instance_uuid=fakes.FAKE_UUID)
117+
)
118+
107119
def test_get_vnc_console_invalid_type(self):
108120
body = {'os-getVNCConsole': {'type': 'invalid'}}
109121
self._check_console_failure(

0 commit comments

Comments
 (0)