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 | |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 13 | |
| 14 | from heat_integrationtests.functional import functional_base |
| 15 | |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 16 | |
| 17 | class LoadBalancerv2Test(functional_base.FunctionalTestsBase): |
| 18 | |
| 19 | create_template = ''' |
| 20 | heat_template_version: 2016-04-08 |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 21 | parameters: |
| 22 | subnet: |
| 23 | type: string |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 24 | resources: |
| 25 | loadbalancer: |
| 26 | type: OS::Neutron::LBaaS::LoadBalancer |
| 27 | properties: |
| 28 | description: aLoadBalancer |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 29 | vip_subnet: { get_param: subnet } |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 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 |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 51 | subnet: { get_param: subnet } |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 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 |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 82 | subnet: { get_param: subnet } |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 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): |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 92 | parameters = { |
| 93 | 'subnet': self.conf.fixed_subnet_name, |
| 94 | } |
| 95 | stack_identifier = self.stack_create(template=self.create_template, |
| 96 | parameters=parameters) |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 97 | stack = self.client.stacks.get(stack_identifier) |
| 98 | output = self._stack_output(stack, 'loadbalancer') |
| 99 | self.assertEqual('ONLINE', output['operating_status']) |
| 100 | |
| 101 | template = self.create_template.replace('ROUND_ROBIN', 'SOURCE_IP') |
| 102 | template = template.replace('3', '6') |
| 103 | template = template.replace('255', '256') |
| 104 | template = template.replace('5555', '7777') |
| 105 | template = template.replace('aLoadBalancer', 'updatedLoadBalancer') |
| 106 | template = template.replace('aPool', 'updatedPool') |
| 107 | template = template.replace('aListener', 'updatedListener') |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 108 | self.update_stack(stack_identifier, template=template, |
| 109 | parameters=parameters) |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 110 | stack = self.client.stacks.get(stack_identifier) |
| 111 | |
| 112 | output = self._stack_output(stack, 'loadbalancer') |
| 113 | self.assertEqual('ONLINE', output['operating_status']) |
| 114 | self.assertEqual('updatedLoadBalancer', output['description']) |
| 115 | output = self._stack_output(stack, 'pool') |
| 116 | self.assertEqual('SOURCE_IP', output['lb_algorithm']) |
| 117 | self.assertEqual('updatedPool', output['description']) |
| 118 | output = self._stack_output(stack, 'poolmember') |
| 119 | self.assertEqual(256, output['weight']) |
| 120 | output = self._stack_output(stack, 'healthmonitor') |
| 121 | self.assertEqual(6, output['delay']) |
| 122 | self.assertEqual(6, output['timeout']) |
| 123 | self.assertEqual(6, output['max_retries']) |
| 124 | output = self._stack_output(stack, 'listener') |
| 125 | self.assertEqual(7777, output['connection_limit']) |
| 126 | self.assertEqual('updatedListener', output['description']) |
| 127 | |
| 128 | def test_add_delete_poolmember(self): |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 129 | parameters = { |
| 130 | 'subnet': self.conf.fixed_subnet_name, |
| 131 | } |
| 132 | stack_identifier = self.stack_create(template=self.create_template, |
| 133 | parameters=parameters) |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 134 | stack = self.client.stacks.get(stack_identifier) |
| 135 | output = self._stack_output(stack, 'loadbalancer') |
| 136 | self.assertEqual('ONLINE', output['operating_status']) |
| 137 | output = self._stack_output(stack, 'pool') |
| 138 | self.assertEqual(1, len(output['members'])) |
| 139 | # add pool member |
| 140 | template = self.create_template.replace('# pm2', self.add_member) |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 141 | self.update_stack(stack_identifier, template=template, |
| 142 | parameters=parameters) |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 143 | stack = self.client.stacks.get(stack_identifier) |
| 144 | output = self._stack_output(stack, 'loadbalancer') |
| 145 | self.assertEqual('ONLINE', output['operating_status']) |
| 146 | output = self._stack_output(stack, 'pool') |
| 147 | self.assertEqual(2, len(output['members'])) |
| 148 | # delete pool member |
Anant Patil | e452f7a | 2016-06-07 15:18:35 +0530 | [diff] [blame] | 149 | self.update_stack(stack_identifier, template=self.create_template, |
| 150 | parameters=parameters) |
Mark Vanderwiel | 74690ce | 2016-03-14 16:49:03 -0500 | [diff] [blame] | 151 | stack = self.client.stacks.get(stack_identifier) |
| 152 | output = self._stack_output(stack, 'loadbalancer') |
| 153 | self.assertEqual('ONLINE', output['operating_status']) |
| 154 | output = self._stack_output(stack, 'pool') |
| 155 | self.assertEqual(1, len(output['members'])) |