Merge "Fix zaqar queue creation workflow"

This commit is contained in:
Jenkins 2016-02-12 18:52:04 +00:00 committed by Gerrit Code Review
commit 681df8eb00
2 changed files with 3 additions and 83 deletions

View File

@ -11,7 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from heat.common import exception
from heat.common.i18n import _
from heat.engine import attributes
from heat.engine import properties
@ -85,26 +84,10 @@ class ZaqarQueue(resource.Resource):
"""Create a zaqar message queue."""
queue_name = self.physical_resource_name()
queue = self.client().queue(queue_name, auto_create=False)
# Zaqar client doesn't report an error if a queue with the same
# id/name already exists, which can cause issue with stack update.
if queue.exists():
raise exception.Error(_('Message queue %s already exists.')
% queue_name)
queue.ensure_exists()
metadata = self.properties.get('metadata')
if metadata:
queue.metadata(new_meta=metadata)
self.resource_id_set(queue_name)
return queue_name
def check_create_complete(self, queue_name):
"""Set metadata of the newly created queue."""
queue = self.client().queue(queue_name, auto_create=False)
if queue.exists():
metadata = self.properties.get('metadata')
if metadata:
queue.metadata(new_meta=metadata)
return True
else:
raise exception.Error(_('Message queue %s creation failed.')
% queue_name)
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
"""Update queue metadata."""

View File

@ -63,12 +63,6 @@ class FakeQueue(object):
self._auto_create = auto_create
self._exists = False
def exists(self):
return self._exists
def ensure_exists(self):
self._exists = True
def metadata(self, new_meta=None):
pass
@ -101,13 +95,6 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.m.StubOutWithMock(self.fc, 'queue')
self.fc.queue(queue.physical_resource_name(),
auto_create=False).AndReturn(fake_q)
self.m.StubOutWithMock(fake_q, 'exists')
fake_q.exists().AndReturn(False)
self.m.StubOutWithMock(fake_q, 'ensure_exists')
fake_q.ensure_exists()
self.fc.queue(queue.physical_resource_name(),
auto_create=False).AndReturn(fake_q)
fake_q.exists().AndReturn(True)
self.m.StubOutWithMock(fake_q, 'metadata')
fake_q.metadata(new_meta=queue.properties.get('metadata'))
@ -120,56 +107,6 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.m.VerifyAll()
def test_create_existing_queue(self):
t = template_format.parse(wp_template)
self.parse_stack(t)
queue = self.stack['MyQueue2']
self.m.StubOutWithMock(queue, 'client')
queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue("myqueue", auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue')
self.fc.queue("myqueue", auto_create=False).AndReturn(fake_q)
self.m.StubOutWithMock(fake_q, 'exists')
fake_q.exists().AndReturn(True)
self.m.ReplayAll()
err = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(queue.create))
self.assertEqual("Error: resources.MyQueue2: "
"Message queue myqueue already exists.",
six.text_type(err))
self.m.VerifyAll()
def test_create_failed(self):
t = template_format.parse(wp_template)
self.parse_stack(t)
queue = self.stack['MyQueue2']
self.m.StubOutWithMock(queue, 'client')
queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue("myqueue", auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue')
self.fc.queue("myqueue", auto_create=False).AndReturn(fake_q)
self.m.StubOutWithMock(fake_q, 'exists')
fake_q.exists().AndReturn(False)
self.m.StubOutWithMock(fake_q, 'ensure_exists')
self.fc.queue(queue.physical_resource_name(),
auto_create=False).AndReturn(fake_q)
fake_q.ensure_exists()
fake_q.exists().AndReturn(False)
self.m.ReplayAll()
err = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(queue.create))
self.assertEqual("Error: resources.MyQueue2: "
"Message queue myqueue creation failed.",
six.text_type(err))
self.m.VerifyAll()
def test_delete(self):
t = template_format.parse(wp_template)
self.parse_stack(t)