Merge "orchestration add resource limit API test"
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 1755d4c..c4dad7e 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -736,6 +736,10 @@
 # (integer value)
 #max_template_size=524288
 
+# Value must match heat configuration of the same name.
+# (integer value)
+#max_resources_per_stack=1000
+
 
 [queuing]
 
diff --git a/tempest/api/orchestration/stacks/test_limits.py b/tempest/api/orchestration/stacks/test_limits.py
index 893dcc4..283ab2b 100644
--- a/tempest/api/orchestration/stacks/test_limits.py
+++ b/tempest/api/orchestration/stacks/test_limits.py
@@ -37,3 +37,17 @@
         ex = self.assertRaises(exceptions.BadRequest, self.create_stack,
                                stack_name, template)
         self.assertIn('Template exceeds maximum allowed size', str(ex))
+
+    @attr(type='gate')
+    def test_exceed_max_resources_per_stack(self):
+        stack_name = data_utils.rand_name('heat')
+        # Create a big template, one resource more than the limit
+        template = 'heat_template_version: \'2013-05-23\'\nresources:\n'
+        rsrc_snippet = '  random%s:\n    type: \'OS::Heat::RandomString\'\n'
+        num_resources = CONF.orchestration.max_resources_per_stack + 1
+        for i in range(num_resources):
+            template += rsrc_snippet % i
+
+        ex = self.assertRaises(exceptions.BadRequest, self.create_stack,
+                               stack_name, template)
+        self.assertIn('Maximum resources per stack exceeded', str(ex))
diff --git a/tempest/config.py b/tempest/config.py
index b6218d2..af96132 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -572,6 +572,9 @@
     cfg.IntOpt('max_template_size',
                default=524288,
                help="Value must match heat configuration of the same name."),
+    cfg.IntOpt('max_resources_per_stack',
+               default=1000,
+               help="Value must match heat configuration of the same name."),
 ]