Add lbaas v2 scenario test

Make use of the new lbaas v2 resources.
This is an experimental gate job.

Will use the lbaas v2 namespace-haproxy driver instead of octavia.  Octavia
requires nested vms which is very slow and causes timeouts in devstack gates.

Change-Id: I7ea6e50a1da46622bdddcfccaf82203f473bfacc
diff --git a/scenario/test_autoscaling_lbv2.py b/scenario/test_autoscaling_lbv2.py
index 861943a..89c4877 100644
--- a/scenario/test_autoscaling_lbv2.py
+++ b/scenario/test_autoscaling_lbv2.py
@@ -11,6 +11,11 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import time
+
+import requests
+
+from heat_integrationtests.common import test
 from heat_integrationtests.scenario import scenario_base
 
 
@@ -29,6 +34,28 @@
         if not self.is_network_extension_supported('lbaasv2'):
             self.skipTest('LBaasv2 extension not available, skipping')
 
+    def check_num_responses(self, url, expected_num, retries=20):
+        resp = set()
+        for count in range(retries):
+            time.sleep(2)
+            try:
+                r = requests.get(url, verify=self.verify_cert)
+            except requests.exceptions.ConnectionError:
+                # The LB may not be up yet, let's retry
+                continue
+            # skip unsuccessful requests
+            if r.status_code == 200:
+                resp.add(r.text)
+        self.assertEqual(expected_num, len(resp))
+
+    def autoscale_complete(self, stack_id, expected_num):
+        res_list = self.client.resources.list(stack_id)
+        all_res_complete = all(res.resource_status in ('UPDATE_COMPLETE',
+                                                       'CREATE_COMPLETE')
+                               for res in res_list)
+        all_res = len(res_list) == expected_num
+        return all_res and all_res_complete
+
     def test_autoscaling_loadbalancer_neutron(self):
         """Check work of AutoScaing and Neutron LBaaS v2 resource in Heat.
 
@@ -43,5 +70,47 @@
                loadbalanced IP.
         """
 
-        # TODO(MRV): Place holder for AutoScaing and Neutron LBaaS v2 test
-        pass
+        parameters = {
+            'flavor': self.conf.minimal_instance_type,
+            'image': self.conf.minimal_image_ref,
+            'net': self.conf.fixed_network_name,
+            'subnet': self.conf.fixed_subnet_name,
+            'public_net': self.conf.floating_network_name
+        }
+
+        app_server_template = self._load_template(
+            __file__, self.app_server_template_name, self.sub_dir
+        )
+        webapp_template = self._load_template(
+            __file__, self.webapp_template_name, self.sub_dir
+        )
+        files = {'appserver.yaml': app_server_template,
+                 'webapp.yaml': webapp_template}
+        env = {'resource_registry':
+               {'OS::Test::NeutronAppServer': 'appserver.yaml',
+                'OS::Test::WebAppConfig': 'webapp.yaml'}}
+
+        # Launch stack
+        sid = self.launch_stack(
+            template_name=self.template_name,
+            parameters=parameters,
+            files=files,
+            environment=env
+        )
+        stack = self.client.stacks.get(sid)
+        lb_url = self._stack_output(stack, 'lburl')
+        # Check number of distinctive responces, must be 1
+        self.check_num_responses(lb_url, 1)
+
+        # Signal the scaling hook
+        self.client.resources.signal(sid, 'scale_up')
+
+        # Wait for AutoScalingGroup update to finish
+        asg = self.client.resources.get(sid, 'asg')
+        test.call_until_true(self.conf.build_timeout,
+                             self.conf.build_interval,
+                             self.autoscale_complete,
+                             asg.physical_resource_id, 2)
+
+        # Check number of distinctive responses, must now be 2
+        self.check_num_responses(lb_url, 2)