Merge "Copy template version when update fails"
diff --git a/common/test.py b/common/test.py
index f52cda3..f2e7dd7 100644
--- a/common/test.py
+++ b/common/test.py
@@ -655,10 +655,14 @@
                     return matched
             time.sleep(build_interval)
 
-    def check_autoscale_complete(self, stack_id, expected_num):
+    def check_autoscale_complete(self, stack_id, expected_num, parent_stack,
+                                 policy):
         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
+        if all_res and all_res_complete:
+            metadata = self.client.resources.metadata(parent_stack, policy)
+            return not metadata.get('scaling_in_progress')
+        return False
diff --git a/functional/test_heat_autoscaling.py b/functional/test_heat_autoscaling.py
index 25ceb1c..608fd1d 100644
--- a/functional/test_heat_autoscaling.py
+++ b/functional/test_heat_autoscaling.py
@@ -114,10 +114,13 @@
         for num in range(asg_size+1, max_size+2):
             expected_resources = num if num <= max_size else max_size
             self.client.resources.signal(stack_id, 'scale_up_policy')
-            test.call_until_true(self.conf.build_timeout,
-                                 self.conf.build_interval,
-                                 self.check_autoscale_complete,
-                                 asg.physical_resource_id, expected_resources)
+            self.assertTrue(
+                test.call_until_true(self.conf.build_timeout,
+                                     self.conf.build_interval,
+                                     self.check_autoscale_complete,
+                                     asg.physical_resource_id,
+                                     expected_resources, stack_id,
+                                     'scale_up_policy'))
 
     def test_asg_scale_down_min_size(self):
         stack_id = self.stack_create(template=self.template,
@@ -133,10 +136,13 @@
         for num in range(asg_size-1, 0, -1):
             expected_resources = num if num >= min_size else min_size
             self.client.resources.signal(stack_id, 'scale_down_policy')
-            test.call_until_true(self.conf.build_timeout,
-                                 self.conf.build_interval,
-                                 self.check_autoscale_complete,
-                                 asg.physical_resource_id, expected_resources)
+            self.assertTrue(
+                test.call_until_true(self.conf.build_timeout,
+                                     self.conf.build_interval,
+                                     self.check_autoscale_complete,
+                                     asg.physical_resource_id,
+                                     expected_resources, stack_id,
+                                     'scale_down_policy'))
 
     def test_asg_cooldown(self):
         cooldown_tmpl = self.template.replace('cooldown: 0',
@@ -153,10 +159,13 @@
         asg = self.client.resources.get(stack_id, 'random_group')
         expected_resources = 3
         self.client.resources.signal(stack_id, 'scale_up_policy')
-        test.call_until_true(self.conf.build_timeout,
-                             self.conf.build_interval,
-                             self.check_autoscale_complete,
-                             asg.physical_resource_id, expected_resources)
+        self.assertTrue(
+            test.call_until_true(self.conf.build_timeout,
+                                 self.conf.build_interval,
+                                 self.check_autoscale_complete,
+                                 asg.physical_resource_id,
+                                 expected_resources, stack_id,
+                                 'scale_up_policy'))
 
     def test_path_attrs(self):
         stack_id = self.stack_create(template=self.template)
diff --git a/functional/test_notifications.py b/functional/test_notifications.py
index 924ef0c..69029a7 100644
--- a/functional/test_notifications.py
+++ b/functional/test_notifications.py
@@ -180,12 +180,14 @@
                                 auto_declare=False):
 
             requests.post(scale_up_url, verify=self.verify_cert)
-            test.call_until_true(20, 0, self.consume_events, handler, 2)
+            self.assertTrue(
+                test.call_until_true(20, 0, self.consume_events, handler, 2))
             notifications += handler.notifications
 
             handler.clear()
             requests.post(scale_down_url, verify=self.verify_cert)
-            test.call_until_true(20, 0, self.consume_events, handler, 2)
+            self.assertTrue(
+                test.call_until_true(20, 0, self.consume_events, handler, 2))
             notifications += handler.notifications
 
         self.assertEqual(2, notifications.count(ASG_NOTIFICATIONS[0]))
diff --git a/scenario/test_autoscaling_lb.py b/scenario/test_autoscaling_lb.py
index 833e9a8..5e8ad27 100644
--- a/scenario/test_autoscaling_lb.py
+++ b/scenario/test_autoscaling_lb.py
@@ -104,7 +104,7 @@
         test.call_until_true(self.conf.build_timeout,
                              self.conf.build_interval,
                              self.check_autoscale_complete,
-                             asg.physical_resource_id, 2)
+                             asg.physical_resource_id, 2, sid, 'scale_up')
 
         # Check number of distinctive responses, must now be 2
         self.check_num_responses(lb_url, 2)
diff --git a/scenario/test_autoscaling_lbv2.py b/scenario/test_autoscaling_lbv2.py
index 78cde53..4ddc21e 100644
--- a/scenario/test_autoscaling_lbv2.py
+++ b/scenario/test_autoscaling_lbv2.py
@@ -104,7 +104,7 @@
         test.call_until_true(self.conf.build_timeout,
                              self.conf.build_interval,
                              self.check_autoscale_complete,
-                             asg.physical_resource_id, 2)
+                             asg.physical_resource_id, 2, sid, 'scale_up')
 
         # Check number of distinctive responses, must now be 2
         self.check_num_responses(lb_url, 2)