Merge "Test auto-scaling for neutron"
diff --git a/common/config.py b/common/config.py
index 562b80b..31a996b 100644
--- a/common/config.py
+++ b/common/config.py
@@ -68,6 +68,9 @@
     cfg.StrOpt('fixed_network_name',
                default='private',
                help="Visible fixed network name "),
+    cfg.StrOpt('fixed_subnet_name',
+               default='private-subnet',
+               help="Visible fixed sub-network name "),
     cfg.IntOpt('ssh_timeout',
                default=300,
                help="Timeout in seconds to wait for authentication to "
diff --git a/scenario/test_neutron_autoscaling.py b/scenario/test_neutron_autoscaling.py
new file mode 100644
index 0000000..8f769ef
--- /dev/null
+++ b/scenario/test_neutron_autoscaling.py
@@ -0,0 +1,124 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from heat_integrationtests.common import test
+
+test_template = '''
+heat_template_version: 2014-10-16
+
+description: Auto-scaling Test
+
+parameters:
+  image_id:
+    type: string
+    label: Image ID
+    description: Image ID from configurations
+  capacity:
+    type: string
+    label: Capacity
+    description: Auto-scaling group desired capacity
+  fixed_subnet_name:
+    type: string
+    label: fixed subnetwork ID
+    description: subnetwork ID used for autoscaling
+  instance_type:
+    type: string
+    label: instance_type
+    description: type of instance to launch
+
+resources:
+  test_pool:
+    type: OS::Neutron::Pool
+    properties:
+      description: Test Pool
+      lb_method: ROUND_ROBIN
+      name: test_pool
+      protocol: HTTP
+      subnet: { get_param: fixed_subnet_name }
+      vip: {
+        "description": "Test VIP",
+        "protocol_port": 80,
+        "name": "test_vip"
+      }
+  load_balancer:
+    type: OS::Neutron::LoadBalancer
+    properties:
+      protocol_port: 80
+      pool_id: { get_resource: test_pool }
+  launch_config:
+    type: AWS::AutoScaling::LaunchConfiguration
+    properties:
+      ImageId: { get_param: image_id }
+      InstanceType: { get_param: instance_type }
+  server_group:
+    type: AWS::AutoScaling::AutoScalingGroup
+    properties:
+      AvailabilityZones : ["nova"]
+      LaunchConfigurationName : { get_resource : launch_config }
+      MinSize : 1
+      MaxSize : 5
+      DesiredCapacity: { get_param: capacity }
+      LoadBalancerNames : [ { get_resource : load_balancer } ]
+'''
+
+
+class NeutronAutoscalingTest(test.HeatIntegrationTest):
+    """"
+    The class is responsible for testing of neutron resources autoscaling.
+    """
+
+    def setUp(self):
+        super(NeutronAutoscalingTest, self).setUp()
+        self.client = self.orchestration_client
+        if not self.conf.minimal_image_ref:
+            raise self.skipException("No minimal image configured to test")
+        if not self.conf.instance_type:
+            raise self.skipException("No flavor configured to test")
+        if not self.conf.fixed_subnet_name:
+            raise self.skipException("No sub-network configured to test")
+
+    def test_neutron_autoscaling(self):
+        """
+        Check autoscaling of load balancer members  in heat.
+
+        The alternative scenario is the following:
+            1. Initialize environment variables.
+            2. Create a stack with a load balancer.
+            3. Check that the load balancer created
+            one load balancer member for stack.
+            4. Update stack definition: increase desired capacity of stack.
+            5. Check that number of members in load balancer was increased.
+        """
+
+        # Init env variables
+        env = {'parameters': {"image_id": self.conf.minimal_image_ref,
+                              "capacity": "1",
+                              "instance_type": self.conf.instance_type,
+                              "fixed_subnet_name":
+                                  self.conf.fixed_subnet_name,
+                              }}
+
+        # Create stack
+        stack_id = self.stack_create(template=test_template,
+                                     environment=env)
+
+        members = self.network_client.list_members()
+        self.assertEqual(1, len(members["members"]))
+
+        # Increase desired capacity and update the stack
+        env["parameters"]["capacity"] = "2"
+        self.update_stack(stack_id,
+                          template=test_template,
+                          environment=env)
+
+        upd_members = self.network_client.list_members()
+        self.assertEqual(2, len(upd_members["members"]))
\ No newline at end of file