blob: 8f769efe3eaffb373e27a563b7227c29f917ce2b [file] [log] [blame]
kairat_kushaev0ab3d7c2015-01-27 21:48:46 +03001# 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
13from heat_integrationtests.common import test
14
15test_template = '''
16heat_template_version: 2014-10-16
17
18description: Auto-scaling Test
19
20parameters:
21 image_id:
22 type: string
23 label: Image ID
24 description: Image ID from configurations
25 capacity:
26 type: string
27 label: Capacity
28 description: Auto-scaling group desired capacity
29 fixed_subnet_name:
30 type: string
31 label: fixed subnetwork ID
32 description: subnetwork ID used for autoscaling
33 instance_type:
34 type: string
35 label: instance_type
36 description: type of instance to launch
37
38resources:
39 test_pool:
40 type: OS::Neutron::Pool
41 properties:
42 description: Test Pool
43 lb_method: ROUND_ROBIN
44 name: test_pool
45 protocol: HTTP
46 subnet: { get_param: fixed_subnet_name }
47 vip: {
48 "description": "Test VIP",
49 "protocol_port": 80,
50 "name": "test_vip"
51 }
52 load_balancer:
53 type: OS::Neutron::LoadBalancer
54 properties:
55 protocol_port: 80
56 pool_id: { get_resource: test_pool }
57 launch_config:
58 type: AWS::AutoScaling::LaunchConfiguration
59 properties:
60 ImageId: { get_param: image_id }
61 InstanceType: { get_param: instance_type }
62 server_group:
63 type: AWS::AutoScaling::AutoScalingGroup
64 properties:
65 AvailabilityZones : ["nova"]
66 LaunchConfigurationName : { get_resource : launch_config }
67 MinSize : 1
68 MaxSize : 5
69 DesiredCapacity: { get_param: capacity }
70 LoadBalancerNames : [ { get_resource : load_balancer } ]
71'''
72
73
74class NeutronAutoscalingTest(test.HeatIntegrationTest):
75 """"
76 The class is responsible for testing of neutron resources autoscaling.
77 """
78
79 def setUp(self):
80 super(NeutronAutoscalingTest, self).setUp()
81 self.client = self.orchestration_client
82 if not self.conf.minimal_image_ref:
83 raise self.skipException("No minimal image configured to test")
84 if not self.conf.instance_type:
85 raise self.skipException("No flavor configured to test")
86 if not self.conf.fixed_subnet_name:
87 raise self.skipException("No sub-network configured to test")
88
89 def test_neutron_autoscaling(self):
90 """
91 Check autoscaling of load balancer members in heat.
92
93 The alternative scenario is the following:
94 1. Initialize environment variables.
95 2. Create a stack with a load balancer.
96 3. Check that the load balancer created
97 one load balancer member for stack.
98 4. Update stack definition: increase desired capacity of stack.
99 5. Check that number of members in load balancer was increased.
100 """
101
102 # Init env variables
103 env = {'parameters': {"image_id": self.conf.minimal_image_ref,
104 "capacity": "1",
105 "instance_type": self.conf.instance_type,
106 "fixed_subnet_name":
107 self.conf.fixed_subnet_name,
108 }}
109
110 # Create stack
111 stack_id = self.stack_create(template=test_template,
112 environment=env)
113
114 members = self.network_client.list_members()
115 self.assertEqual(1, len(members["members"]))
116
117 # Increase desired capacity and update the stack
118 env["parameters"]["capacity"] = "2"
119 self.update_stack(stack_id,
120 template=test_template,
121 environment=env)
122
123 upd_members = self.network_client.list_members()
124 self.assertEqual(2, len(upd_members["members"]))