Merge "Fix zaqar queue creation workflow"
This commit is contained in:
commit
681df8eb00
@ -11,7 +11,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.common.i18n import _
|
from heat.common.i18n import _
|
||||||
from heat.engine import attributes
|
from heat.engine import attributes
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
@ -85,26 +84,10 @@ class ZaqarQueue(resource.Resource):
|
|||||||
"""Create a zaqar message queue."""
|
"""Create a zaqar message queue."""
|
||||||
queue_name = self.physical_resource_name()
|
queue_name = self.physical_resource_name()
|
||||||
queue = self.client().queue(queue_name, auto_create=False)
|
queue = self.client().queue(queue_name, auto_create=False)
|
||||||
# Zaqar client doesn't report an error if a queue with the same
|
metadata = self.properties.get('metadata')
|
||||||
# id/name already exists, which can cause issue with stack update.
|
if metadata:
|
||||||
if queue.exists():
|
queue.metadata(new_meta=metadata)
|
||||||
raise exception.Error(_('Message queue %s already exists.')
|
|
||||||
% queue_name)
|
|
||||||
queue.ensure_exists()
|
|
||||||
self.resource_id_set(queue_name)
|
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):
|
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||||
"""Update queue metadata."""
|
"""Update queue metadata."""
|
||||||
|
@ -63,12 +63,6 @@ class FakeQueue(object):
|
|||||||
self._auto_create = auto_create
|
self._auto_create = auto_create
|
||||||
self._exists = False
|
self._exists = False
|
||||||
|
|
||||||
def exists(self):
|
|
||||||
return self._exists
|
|
||||||
|
|
||||||
def ensure_exists(self):
|
|
||||||
self._exists = True
|
|
||||||
|
|
||||||
def metadata(self, new_meta=None):
|
def metadata(self, new_meta=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -101,13 +95,6 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
|||||||
self.m.StubOutWithMock(self.fc, 'queue')
|
self.m.StubOutWithMock(self.fc, 'queue')
|
||||||
self.fc.queue(queue.physical_resource_name(),
|
self.fc.queue(queue.physical_resource_name(),
|
||||||
auto_create=False).AndReturn(fake_q)
|
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')
|
self.m.StubOutWithMock(fake_q, 'metadata')
|
||||||
fake_q.metadata(new_meta=queue.properties.get('metadata'))
|
fake_q.metadata(new_meta=queue.properties.get('metadata'))
|
||||||
|
|
||||||
@ -120,56 +107,6 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
|||||||
|
|
||||||
self.m.VerifyAll()
|
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):
|
def test_delete(self):
|
||||||
t = template_format.parse(wp_template)
|
t = template_format.parse(wp_template)
|
||||||
self.parse_stack(t)
|
self.parse_stack(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user