Convert deferred_delete v3 plugin to v2.1 API
Changes required to have v3 plugin natively support the V2.1 API The force_delete action is reverted back to forceDelete Partially implements blueprint v2-on-v3-api Change-Id: I0b050d3328338923cf05521b9ef5cc3b1c50a586
This commit is contained in:
parent
6f2b36815e
commit
2c8685b07f
@ -1,3 +1,3 @@
|
||||
{
|
||||
"force_delete": null
|
||||
}
|
||||
"forceDelete": null
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class DeferredDeleteController(wsgi.Controller):
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@extensions.expected_errors((404, 409))
|
||||
@wsgi.action('force_delete')
|
||||
@wsgi.action('forceDelete')
|
||||
def _force_delete(self, req, id, body):
|
||||
"""Force delete of instance before deferred cleanup."""
|
||||
context = req.environ["nova.context"]
|
||||
@ -64,7 +64,7 @@ class DeferredDeleteController(wsgi.Controller):
|
||||
self.compute_api.force_delete(context, instance)
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'force_delete')
|
||||
'forceDelete')
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.compute.contrib import deferred_delete
|
||||
from nova.api.openstack.compute.plugins.v3 import deferred_delete as dd_v21
|
||||
from nova.compute import api as compute_api
|
||||
from nova import context
|
||||
from nova import exception
|
||||
@ -27,14 +28,16 @@ class FakeRequest(object):
|
||||
self.environ = {'nova.context': context}
|
||||
|
||||
|
||||
class DeferredDeleteExtensionTest(test.NoDBTestCase):
|
||||
class DeferredDeleteExtensionTestV21(test.NoDBTestCase):
|
||||
ext_ver = dd_v21.DeferredDeleteController
|
||||
|
||||
def setUp(self):
|
||||
super(DeferredDeleteExtensionTest, self).setUp()
|
||||
self.extension = deferred_delete.DeferredDeleteController()
|
||||
super(DeferredDeleteExtensionTestV21, self).setUp()
|
||||
self.fake_input_dict = {}
|
||||
self.fake_uuid = 'fake_uuid'
|
||||
self.fake_context = context.RequestContext('fake', 'fake')
|
||||
self.fake_req = FakeRequest(self.fake_context)
|
||||
self.extension = self.ext_ver()
|
||||
|
||||
def test_force_delete(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
@ -105,6 +108,18 @@ class DeferredDeleteExtensionTest(test.NoDBTestCase):
|
||||
self.fake_input_dict)
|
||||
self.assertEqual(res.status_int, 202)
|
||||
|
||||
def test_restore_instance_not_found(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndRaise(
|
||||
exception.InstanceNotFound(instance_id='instance-0000'))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.extension._restore,
|
||||
self.fake_req, self.fake_uuid,
|
||||
self.fake_input_dict)
|
||||
|
||||
def test_restore_raises_conflict_on_invalid_state(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
self.mox.StubOutWithMock(compute_api.API, 'restore')
|
||||
@ -123,3 +138,7 @@ class DeferredDeleteExtensionTest(test.NoDBTestCase):
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(webob.exc.HTTPConflict, self.extension._restore,
|
||||
self.fake_req, self.fake_uuid, self.fake_input_dict)
|
||||
|
||||
|
||||
class DeferredDeleteExtensionTestV2(DeferredDeleteExtensionTestV21):
|
||||
ext_ver = deferred_delete.DeferredDeleteController
|
||||
|
@ -1,136 +0,0 @@
|
||||
# Copyright 2011 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.api.openstack.compute.plugins.v3 import deferred_delete
|
||||
from nova.compute import api as compute_api
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import test
|
||||
|
||||
|
||||
class FakeRequest(object):
|
||||
def __init__(self, context):
|
||||
self.environ = {'nova.context': context}
|
||||
|
||||
|
||||
class DeferredDeleteExtensionTest(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
super(DeferredDeleteExtensionTest, self).setUp()
|
||||
self.extension = deferred_delete.DeferredDeleteController()
|
||||
self.fake_input_dict = {}
|
||||
self.fake_uuid = 'fake_uuid'
|
||||
self.fake_context = context.RequestContext('fake', 'fake')
|
||||
self.fake_req = FakeRequest(self.fake_context)
|
||||
|
||||
def test_force_delete(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
self.mox.StubOutWithMock(compute_api.API, 'force_delete')
|
||||
|
||||
fake_instance = 'fake_instance'
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndReturn(
|
||||
fake_instance)
|
||||
compute_api.API.force_delete(self.fake_context, fake_instance)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
res = self.extension._force_delete(self.fake_req, self.fake_uuid,
|
||||
self.fake_input_dict)
|
||||
self.assertEqual(res.status_int, 202)
|
||||
|
||||
def test_force_delete_instance_not_found(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndRaise(
|
||||
exception.InstanceNotFound(instance_id='instance-0000'))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.extension._force_delete,
|
||||
self.fake_req,
|
||||
self.fake_uuid,
|
||||
self.fake_input_dict)
|
||||
|
||||
def test_force_delete_raises_conflict_on_invalid_state(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
self.mox.StubOutWithMock(compute_api.API, 'force_delete')
|
||||
|
||||
fake_instance = 'fake_instance'
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndReturn(
|
||||
fake_instance)
|
||||
|
||||
exc = exception.InstanceInvalidState(attr='fake_attr',
|
||||
state='fake_state', method='fake_method',
|
||||
instance_uuid='fake')
|
||||
|
||||
compute_api.API.force_delete(self.fake_context, fake_instance)\
|
||||
.AndRaise(exc)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.extension._force_delete, self.fake_req, self.fake_uuid,
|
||||
self.fake_input_dict)
|
||||
|
||||
def test_restore(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
self.mox.StubOutWithMock(compute_api.API, 'restore')
|
||||
|
||||
fake_instance = 'fake_instance'
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndReturn(
|
||||
fake_instance)
|
||||
compute_api.API.restore(self.fake_context, fake_instance)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
res = self.extension._restore(self.fake_req, self.fake_uuid,
|
||||
self.fake_input_dict)
|
||||
self.assertEqual(res.status_int, 202)
|
||||
|
||||
def test_restore_instance_not_found(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndRaise(
|
||||
exception.InstanceNotFound(instance_id='instance-0000'))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.extension._restore,
|
||||
self.fake_req, self.fake_uuid,
|
||||
self.fake_input_dict)
|
||||
|
||||
def test_restore_raises_conflict_on_invalid_state(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
self.mox.StubOutWithMock(compute_api.API, 'restore')
|
||||
|
||||
fake_instance = 'fake_instance'
|
||||
exc = exception.InstanceInvalidState(attr='fake_attr',
|
||||
state='fake_state', method='fake_method',
|
||||
instance_uuid='fake')
|
||||
|
||||
compute_api.API.get(self.fake_context, self.fake_uuid,
|
||||
expected_attrs=None, want_objects=True).AndReturn(
|
||||
fake_instance)
|
||||
compute_api.API.restore(self.fake_context, fake_instance).AndRaise(
|
||||
exc)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(webob.exc.HTTPConflict, self.extension._restore,
|
||||
self.fake_req, self.fake_uuid, self.fake_input_dict)
|
@ -510,7 +510,7 @@ class ServersTest(integrated_helpers._IntegratedTestBase):
|
||||
|
||||
|
||||
class ServersTestV3(client.TestOpenStackClientV3Mixin, ServersTest):
|
||||
_force_delete_parameter = 'force_delete'
|
||||
_force_delete_parameter = 'forceDelete'
|
||||
_api_version = 'v3'
|
||||
_image_ref_parameter = 'image_ref'
|
||||
_flavor_ref_parameter = 'flavor_ref'
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"force_delete": null
|
||||
"forceDelete": null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user