Thomas Herve | 3b7e3d8 | 2016-01-25 10:37:41 +0100 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | import json |
| 14 | |
| 15 | from keystoneclient.v3 import client as keystoneclient |
| 16 | from zaqarclient.queues.v1 import client as zaqarclient |
| 17 | |
| 18 | from heat_integrationtests.functional import functional_base |
| 19 | |
| 20 | |
| 21 | class ZaqarWaitConditionTest(functional_base.FunctionalTestsBase): |
| 22 | template = ''' |
| 23 | heat_template_version: "2013-05-23" |
| 24 | |
| 25 | resources: |
| 26 | wait_condition: |
| 27 | type: OS::Heat::WaitCondition |
| 28 | properties: |
| 29 | handle: {get_resource: wait_handle} |
| 30 | timeout: 120 |
| 31 | wait_handle: |
| 32 | type: OS::Heat::WaitConditionHandle |
| 33 | properties: |
| 34 | signal_transport: ZAQAR_SIGNAL |
| 35 | |
| 36 | outputs: |
| 37 | wait_data: |
| 38 | value: {'Fn::Select': ['data_id', {get_attr: [wait_condition, data]}]} |
| 39 | ''' |
| 40 | |
| 41 | def test_signal_queues(self): |
| 42 | stack_identifier = self.stack_create( |
| 43 | template=self.template, |
| 44 | expected_status=None) |
| 45 | self._wait_for_resource_status(stack_identifier, 'wait_handle', |
| 46 | 'CREATE_COMPLETE') |
| 47 | resource = self.client.resources.get(stack_identifier, 'wait_handle') |
| 48 | signal = json.loads(resource.attributes['signal']) |
| 49 | ks = keystoneclient.Client( |
| 50 | auth_url=signal['auth_url'], |
| 51 | user_id=signal['user_id'], |
| 52 | password=signal['password'], |
| 53 | project_id=signal['project_id']) |
| 54 | endpoint = ks.service_catalog.url_for( |
| 55 | service_type='messaging', endpoint_type='publicURL') |
| 56 | conf = { |
| 57 | 'auth_opts': { |
| 58 | 'backend': 'keystone', |
| 59 | 'options': { |
| 60 | 'os_auth_token': ks.auth_token, |
| 61 | 'os_project_id': signal['project_id'] |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | zaqar = zaqarclient.Client(endpoint, conf=conf, version=1.1) |
| 67 | |
| 68 | queue = zaqar.queue(signal['queue_id']) |
| 69 | queue.post({'body': {'data': 'here!', 'id': 'data_id'}, 'ttl': 600}) |
| 70 | self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 71 | stack = self.client.stacks.get(stack_identifier) |
| 72 | self.assertEqual('here!', stack.outputs[0]['output_value']) |