Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [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 | from oslo_log import log as logging |
| 14 | |
| 15 | from heat_integrationtests.functional import functional_base |
| 16 | |
| 17 | LOG = logging.getLogger(__name__) |
| 18 | |
| 19 | |
| 20 | class LoadBalancerv2Test(functional_base.FunctionalTestsBase): |
| 21 | |
| 22 | create_template = ''' |
| 23 | heat_template_version: 2016-04-08 |
| 24 | resources: |
| 25 | loadbalancer: |
| 26 | type: OS::Neutron::LBaaS::LoadBalancer |
| 27 | properties: |
| 28 | description: aLoadBalancer |
| 29 | vip_subnet: private-subnet |
| 30 | listener: |
| 31 | type: OS::Neutron::LBaaS::Listener |
| 32 | properties: |
| 33 | description: aListener |
| 34 | loadbalancer: { get_resource: loadbalancer } |
| 35 | protocol: HTTP |
| 36 | protocol_port: 80 |
| 37 | connection_limit: 5555 |
| 38 | pool: |
| 39 | type: OS::Neutron::LBaaS::Pool |
| 40 | properties: |
| 41 | description: aPool |
| 42 | lb_algorithm: ROUND_ROBIN |
| 43 | protocol: HTTP |
| 44 | listener: { get_resource: listener } |
| 45 | poolmember: |
| 46 | type: OS::Neutron::LBaaS::PoolMember |
| 47 | properties: |
| 48 | address: 1.1.1.1 |
| 49 | pool: { get_resource: pool } |
| 50 | protocol_port: 1111 |
| 51 | subnet: private-subnet |
| 52 | weight: 255 |
| 53 | # pm2 |
| 54 | healthmonitor: |
| 55 | type: OS::Neutron::LBaaS::HealthMonitor |
| 56 | properties: |
| 57 | delay: 3 |
| 58 | type: HTTP |
| 59 | timeout: 3 |
| 60 | max_retries: 3 |
| 61 | pool: { get_resource: pool } |
| 62 | outputs: |
| 63 | loadbalancer: |
| 64 | value: { get_attr: [ loadbalancer, show ] } |
| 65 | pool: |
| 66 | value: { get_attr: [ pool, show ] } |
| 67 | poolmember: |
| 68 | value: { get_attr: [ poolmember, show ] } |
| 69 | listener: |
| 70 | value: { get_attr: [ listener, show ] } |
| 71 | healthmonitor: |
| 72 | value: { get_attr: [ healthmonitor, show ] } |
| 73 | ''' |
| 74 | |
| 75 | add_member = ''' |
| 76 | poolmember2: |
| 77 | type: OS::Neutron::LBaaS::PoolMember |
| 78 | properties: |
| 79 | address: 2.2.2.2 |
| 80 | pool: { get_resource: pool } |
| 81 | protocol_port: 2222 |
| 82 | subnet: private-subnet |
| 83 | weight: 222 |
| 84 | ''' |
| 85 | |
| 86 | def setUp(self): |
| 87 | super(LoadBalancerv2Test, self).setUp() |
| 88 | if not self.is_network_extension_supported('lbaasv2'): |
| 89 | self.skipTest('LBaasv2 extension not available, skipping') |
| 90 | |
| 91 | def test_create_update_loadbalancer(self): |
| 92 | stack_identifier = self.stack_create(template=self.create_template) |
| 93 | stack = self.client.stacks.get(stack_identifier) |
| 94 | output = self._stack_output(stack, 'loadbalancer') |
| 95 | self.assertEqual('ONLINE', output['operating_status']) |
| 96 | |
| 97 | template = self.create_template.replace('ROUND_ROBIN', 'SOURCE_IP') |
| 98 | template = template.replace('3', '6') |
| 99 | template = template.replace('255', '256') |
| 100 | template = template.replace('5555', '7777') |
| 101 | template = template.replace('aLoadBalancer', 'updatedLoadBalancer') |
| 102 | template = template.replace('aPool', 'updatedPool') |
| 103 | template = template.replace('aListener', 'updatedListener') |
| 104 | self.update_stack(stack_identifier, template=template) |
| 105 | stack = self.client.stacks.get(stack_identifier) |
| 106 | |
| 107 | output = self._stack_output(stack, 'loadbalancer') |
| 108 | self.assertEqual('ONLINE', output['operating_status']) |
| 109 | self.assertEqual('updatedLoadBalancer', output['description']) |
| 110 | output = self._stack_output(stack, 'pool') |
| 111 | self.assertEqual('SOURCE_IP', output['lb_algorithm']) |
| 112 | self.assertEqual('updatedPool', output['description']) |
| 113 | output = self._stack_output(stack, 'poolmember') |
| 114 | self.assertEqual(256, output['weight']) |
| 115 | output = self._stack_output(stack, 'healthmonitor') |
| 116 | self.assertEqual(6, output['delay']) |
| 117 | self.assertEqual(6, output['timeout']) |
| 118 | self.assertEqual(6, output['max_retries']) |
| 119 | output = self._stack_output(stack, 'listener') |
| 120 | self.assertEqual(7777, output['connection_limit']) |
| 121 | self.assertEqual('updatedListener', output['description']) |
| 122 | |
| 123 | def test_add_delete_poolmember(self): |
| 124 | stack_identifier = self.stack_create(template=self.create_template) |
| 125 | stack = self.client.stacks.get(stack_identifier) |
| 126 | output = self._stack_output(stack, 'loadbalancer') |
| 127 | self.assertEqual('ONLINE', output['operating_status']) |
| 128 | output = self._stack_output(stack, 'pool') |
| 129 | self.assertEqual(1, len(output['members'])) |
| 130 | # add pool member |
| 131 | template = self.create_template.replace('# pm2', self.add_member) |
| 132 | self.update_stack(stack_identifier, template=template) |
| 133 | stack = self.client.stacks.get(stack_identifier) |
| 134 | output = self._stack_output(stack, 'loadbalancer') |
| 135 | self.assertEqual('ONLINE', output['operating_status']) |
| 136 | output = self._stack_output(stack, 'pool') |
| 137 | self.assertEqual(2, len(output['members'])) |
| 138 | # delete pool member |
| 139 | self.update_stack(stack_identifier, template=self.create_template) |
| 140 | stack = self.client.stacks.get(stack_identifier) |
| 141 | output = self._stack_output(stack, 'loadbalancer') |
| 142 | self.assertEqual('ONLINE', output['operating_status']) |
| 143 | output = self._stack_output(stack, 'pool') |
| 144 | self.assertEqual(1, len(output['members'])) |