Merge "Refactor Zaqar plugin client access"
This commit is contained in:
commit
ae825661b3
@ -29,6 +29,8 @@ def resource_mapping():
|
||||
|
||||
class ZaqarQueue(resource.Resource):
|
||||
|
||||
default_client_name = "zaqar"
|
||||
|
||||
PROPERTIES = (
|
||||
NAME, METADATA,
|
||||
) = (
|
||||
@ -63,16 +65,13 @@ class ZaqarQueue(resource.Resource):
|
||||
),
|
||||
}
|
||||
|
||||
def zaqar(self):
|
||||
return self.clients.client('zaqar')
|
||||
|
||||
def physical_resource_name(self):
|
||||
return self.properties[self.NAME]
|
||||
|
||||
def handle_create(self):
|
||||
"""Create a zaqar message queue."""
|
||||
queue_name = self.physical_resource_name()
|
||||
queue = self.zaqar().queue(queue_name, auto_create=False)
|
||||
queue = self.client().queue(queue_name, auto_create=False)
|
||||
# Zaqar client doesn't report an error if an queue with the same
|
||||
# id/name already exists, which can cause issue with stack update.
|
||||
if queue.exists():
|
||||
@ -97,7 +96,7 @@ class ZaqarQueue(resource.Resource):
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
"""Update queue metadata."""
|
||||
if 'metadata' in prop_diff:
|
||||
queue = self.zaqar().queue(self.resource_id, auto_create=False)
|
||||
queue = self.client().queue(self.resource_id, auto_create=False)
|
||||
metadata = prop_diff['metadata']
|
||||
queue.metadata(new_meta=metadata)
|
||||
|
||||
@ -106,11 +105,11 @@ class ZaqarQueue(resource.Resource):
|
||||
if not self.resource_id:
|
||||
return
|
||||
|
||||
queue = self.zaqar().queue(self.resource_id, auto_create=False)
|
||||
queue = self.client().queue(self.resource_id, auto_create=False)
|
||||
queue.delete()
|
||||
|
||||
def href(self):
|
||||
api_endpoint = self.zaqar().api_url
|
||||
api_endpoint = self.client().api_url
|
||||
queue_name = self.physical_resource_name()
|
||||
if api_endpoint.endswith('/'):
|
||||
return '%squeues/%s' % (api_endpoint, queue_name)
|
||||
|
@ -90,8 +90,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
self.parse_stack(t)
|
||||
|
||||
queue = self.stack['MyQueue2']
|
||||
self.m.StubOutWithMock(queue, 'zaqar')
|
||||
queue.zaqar().MultipleTimes().AndReturn(self.fc)
|
||||
self.m.StubOutWithMock(queue, 'client')
|
||||
queue.client().MultipleTimes().AndReturn(self.fc)
|
||||
|
||||
fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
|
||||
self.m.StubOutWithMock(self.fc, 'queue')
|
||||
@ -120,8 +120,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
self.parse_stack(t)
|
||||
|
||||
queue = self.stack['MyQueue2']
|
||||
self.m.StubOutWithMock(queue, 'zaqar')
|
||||
queue.zaqar().MultipleTimes().AndReturn(self.fc)
|
||||
self.m.StubOutWithMock(queue, 'client')
|
||||
queue.client().MultipleTimes().AndReturn(self.fc)
|
||||
|
||||
fake_q = FakeQueue("myqueue", auto_create=False)
|
||||
self.m.StubOutWithMock(self.fc, 'queue')
|
||||
@ -141,8 +141,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
self.parse_stack(t)
|
||||
|
||||
queue = self.stack['MyQueue2']
|
||||
self.m.StubOutWithMock(queue, 'zaqar')
|
||||
queue.zaqar().MultipleTimes().AndReturn(self.fc)
|
||||
self.m.StubOutWithMock(queue, 'client')
|
||||
queue.client().MultipleTimes().AndReturn(self.fc)
|
||||
|
||||
fake_q = FakeQueue("myqueue", auto_create=False)
|
||||
self.m.StubOutWithMock(self.fc, 'queue')
|
||||
@ -167,8 +167,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
|
||||
queue = self.stack['MyQueue2']
|
||||
queue.resource_id_set(queue.properties.get('name'))
|
||||
self.m.StubOutWithMock(queue, 'zaqar')
|
||||
queue.zaqar().MultipleTimes().AndReturn(self.fc)
|
||||
self.m.StubOutWithMock(queue, 'client')
|
||||
queue.client().MultipleTimes().AndReturn(self.fc)
|
||||
|
||||
fake_q = FakeQueue("myqueue", auto_create=False)
|
||||
self.m.StubOutWithMock(self.fc, 'queue')
|
||||
@ -188,8 +188,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
self.parse_stack(t)
|
||||
queue = self.stack['MyQueue2']
|
||||
queue.resource_id_set(queue.properties.get('name'))
|
||||
self.m.StubOutWithMock(queue, 'zaqar')
|
||||
queue.zaqar().MultipleTimes().AndReturn(self.fc)
|
||||
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',
|
||||
@ -216,8 +216,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
self.parse_stack(t)
|
||||
queue = self.stack['MyQueue2']
|
||||
queue.resource_id_set(queue.properties.get('name'))
|
||||
self.m.StubOutWithMock(queue, 'zaqar')
|
||||
queue.zaqar().MultipleTimes().AndReturn(self.fc)
|
||||
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',
|
||||
|
Loading…
Reference in New Issue
Block a user