Handle 404 on Zaqar Queue delete

Change-Id: Iacff8adadc59693e9f8e4132f369bf08956affe3
Closes-Bug: 1404375
This commit is contained in:
Randall Burt 2014-12-22 13:37:37 -06:00
parent 0bb1334c39
commit bee9efee53
3 changed files with 39 additions and 3 deletions

View File

@ -18,14 +18,18 @@ LOG = logging.getLogger(__name__)
try: try:
from zaqarclient.queues.v1 import client as zaqarclient from zaqarclient.queues.v1 import client as zaqarclient
from zaqarclient.transport import errors as zaqar_errors
except ImportError: except ImportError:
zaqarclient = None zaqarclient = None
zaqar_errors = None
from heat.engine.clients import client_plugin from heat.engine.clients import client_plugin
class ZaqarClientPlugin(client_plugin.ClientPlugin): class ZaqarClientPlugin(client_plugin.ClientPlugin):
exception_module = zaqar_errors
def _create(self): def _create(self):
con = self.context con = self.context
@ -47,3 +51,6 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin):
client = zaqarclient.Client(url=endpoint, conf=conf) client = zaqarclient.Client(url=endpoint, conf=conf)
return client return client
def is_not_found(self, ex):
return isinstance(ex, zaqar_errors.ResourceNotFound)

View File

@ -104,9 +104,12 @@ class ZaqarQueue(resource.Resource):
"""Delete a zaqar message queue.""" """Delete a zaqar message queue."""
if not self.resource_id: if not self.resource_id:
return return
try:
queue = self.client().queue(self.resource_id, auto_create=False) queue = self.client().queue(self.resource_id, auto_create=False)
queue.delete() except Exception as exc:
self.client_plugin().ignore_not_found(exc)
else:
queue.delete()
def href(self): def href(self):
api_endpoint = self.client().api_url api_endpoint = self.client().api_url

View File

@ -11,12 +11,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mock
import six import six
from heat.common import exception from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import parser from heat.engine import parser
from heat.engine import resource from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import template from heat.engine import template
from heat.tests import common from heat.tests import common
@ -24,6 +26,11 @@ from heat.tests import utils
from ..resources import queue # noqa from ..resources import queue # noqa
try:
from zaqarclient.transport.errors import ResourceNotFound # noqa
except ImportError:
ResourceNotFound = Exception
wp_template = ''' wp_template = '''
{ {
"AWSTemplateFormatVersion" : "2010-09-09", "AWSTemplateFormatVersion" : "2010-09-09",
@ -183,6 +190,25 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
scheduler.TaskRunner(queue.delete)() scheduler.TaskRunner(queue.delete)()
self.m.VerifyAll() self.m.VerifyAll()
@mock.patch.object(queue.ZaqarQueue, "client")
@mock.patch.object(queue.ZaqarQueue, "client_plugin")
def test_delete_not_found(self, mockplugin, mockclient):
mock_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None
mockclient.return_value.queue.side_effect = ResourceNotFound
mockplugin.return_value.ignore_not_found.return_value = None
zplugin = queue.ZaqarQueue("test_delete_not_found", mock_def,
mock_stack)
zplugin.resource_id = "test_delete_not_found"
zplugin.handle_delete()
mockclient.return_value.queue.assert_called_once_with(
"test_delete_not_found", auto_create=False)
mockplugin.return_value.ignore_not_found.assert_called_once_with(
mock.ANY)
def test_update_in_place(self): def test_update_in_place(self):
t = template_format.parse(wp_template) t = template_format.parse(wp_template)
self.parse_stack(t) self.parse_stack(t)