Merge "Refactor Zaqar plugin client access"

This commit is contained in:
Jenkins 2014-12-24 17:05:10 +00:00 committed by Gerrit Code Review
commit ae825661b3
2 changed files with 18 additions and 19 deletions

View File

@ -29,6 +29,8 @@ def resource_mapping():
class ZaqarQueue(resource.Resource): class ZaqarQueue(resource.Resource):
default_client_name = "zaqar"
PROPERTIES = ( PROPERTIES = (
NAME, METADATA, NAME, METADATA,
) = ( ) = (
@ -63,16 +65,13 @@ class ZaqarQueue(resource.Resource):
), ),
} }
def zaqar(self):
return self.clients.client('zaqar')
def physical_resource_name(self): def physical_resource_name(self):
return self.properties[self.NAME] return self.properties[self.NAME]
def handle_create(self): def handle_create(self):
"""Create a zaqar message queue.""" """Create a zaqar message queue."""
queue_name = self.physical_resource_name() 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 # Zaqar client doesn't report an error if an queue with the same
# id/name already exists, which can cause issue with stack update. # id/name already exists, which can cause issue with stack update.
if queue.exists(): if queue.exists():
@ -97,7 +96,7 @@ class ZaqarQueue(resource.Resource):
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."""
if 'metadata' in prop_diff: 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'] metadata = prop_diff['metadata']
queue.metadata(new_meta=metadata) queue.metadata(new_meta=metadata)
@ -106,11 +105,11 @@ class ZaqarQueue(resource.Resource):
if not self.resource_id: if not self.resource_id:
return return
queue = self.zaqar().queue(self.resource_id, auto_create=False) queue = self.client().queue(self.resource_id, auto_create=False)
queue.delete() queue.delete()
def href(self): def href(self):
api_endpoint = self.zaqar().api_url api_endpoint = self.client().api_url
queue_name = self.physical_resource_name() queue_name = self.physical_resource_name()
if api_endpoint.endswith('/'): if api_endpoint.endswith('/'):
return '%squeues/%s' % (api_endpoint, queue_name) return '%squeues/%s' % (api_endpoint, queue_name)

View File

@ -90,8 +90,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.parse_stack(t) self.parse_stack(t)
queue = self.stack['MyQueue2'] queue = self.stack['MyQueue2']
self.m.StubOutWithMock(queue, 'zaqar') self.m.StubOutWithMock(queue, 'client')
queue.zaqar().MultipleTimes().AndReturn(self.fc) queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False) fake_q = FakeQueue(queue.physical_resource_name(), auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue') self.m.StubOutWithMock(self.fc, 'queue')
@ -120,8 +120,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.parse_stack(t) self.parse_stack(t)
queue = self.stack['MyQueue2'] queue = self.stack['MyQueue2']
self.m.StubOutWithMock(queue, 'zaqar') self.m.StubOutWithMock(queue, 'client')
queue.zaqar().MultipleTimes().AndReturn(self.fc) queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue("myqueue", auto_create=False) fake_q = FakeQueue("myqueue", auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue') self.m.StubOutWithMock(self.fc, 'queue')
@ -141,8 +141,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.parse_stack(t) self.parse_stack(t)
queue = self.stack['MyQueue2'] queue = self.stack['MyQueue2']
self.m.StubOutWithMock(queue, 'zaqar') self.m.StubOutWithMock(queue, 'client')
queue.zaqar().MultipleTimes().AndReturn(self.fc) queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue("myqueue", auto_create=False) fake_q = FakeQueue("myqueue", auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue') self.m.StubOutWithMock(self.fc, 'queue')
@ -167,8 +167,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
queue = self.stack['MyQueue2'] queue = self.stack['MyQueue2']
queue.resource_id_set(queue.properties.get('name')) queue.resource_id_set(queue.properties.get('name'))
self.m.StubOutWithMock(queue, 'zaqar') self.m.StubOutWithMock(queue, 'client')
queue.zaqar().MultipleTimes().AndReturn(self.fc) queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue("myqueue", auto_create=False) fake_q = FakeQueue("myqueue", auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue') self.m.StubOutWithMock(self.fc, 'queue')
@ -188,8 +188,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.parse_stack(t) self.parse_stack(t)
queue = self.stack['MyQueue2'] queue = self.stack['MyQueue2']
queue.resource_id_set(queue.properties.get('name')) queue.resource_id_set(queue.properties.get('name'))
self.m.StubOutWithMock(queue, 'zaqar') self.m.StubOutWithMock(queue, 'client')
queue.zaqar().MultipleTimes().AndReturn(self.fc) queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue('myqueue', auto_create=False) fake_q = FakeQueue('myqueue', auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue') self.m.StubOutWithMock(self.fc, 'queue')
self.fc.queue('myqueue', self.fc.queue('myqueue',
@ -216,8 +216,8 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
self.parse_stack(t) self.parse_stack(t)
queue = self.stack['MyQueue2'] queue = self.stack['MyQueue2']
queue.resource_id_set(queue.properties.get('name')) queue.resource_id_set(queue.properties.get('name'))
self.m.StubOutWithMock(queue, 'zaqar') self.m.StubOutWithMock(queue, 'client')
queue.zaqar().MultipleTimes().AndReturn(self.fc) queue.client().MultipleTimes().AndReturn(self.fc)
fake_q = FakeQueue('myqueue', auto_create=False) fake_q = FakeQueue('myqueue', auto_create=False)
self.m.StubOutWithMock(self.fc, 'queue') self.m.StubOutWithMock(self.fc, 'queue')
self.fc.queue('myqueue', self.fc.queue('myqueue',