Merge "Fixing ImagesOneServerTestXml issue"
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions.py b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
index b747b46..a5a361e 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
@@ -15,8 +15,10 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import uuid
+
 from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
 from tempest import exceptions
 from tempest.test import attr
 
@@ -46,7 +48,9 @@
         for i in range(len(body)):
             cls.floating_ip_ids.append(body[i]['id'])
         while True:
-            cls.non_exist_id = rand_name('999')
+            cls.non_exist_id = data_utils.rand_int_id(start=999)
+            if cls.config.service_available.neutron:
+                cls.non_exist_id = str(uuid.uuid4())
             if cls.non_exist_id not in cls.floating_ip_ids:
                 break
 
diff --git a/tempest/api/compute/floating_ips/test_list_floating_ips.py b/tempest/api/compute/floating_ips/test_list_floating_ips.py
index 3c76069..fb9610a 100644
--- a/tempest/api/compute/floating_ips/test_list_floating_ips.py
+++ b/tempest/api/compute/floating_ips/test_list_floating_ips.py
@@ -15,8 +15,10 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import uuid
+
 from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
 from tempest import exceptions
 from tempest.test import attr
 
@@ -87,7 +89,9 @@
             floating_ip_id.append(body[i]['id'])
         # Creating a non-existent floatingIP id
         while True:
-            non_exist_id = rand_name('999')
+            non_exist_id = data_utils.rand_int_id(start=999)
+            if self.config.service_available.neutron:
+                non_exist_id = str(uuid.uuid4())
             if non_exist_id not in floating_ip_id:
                 break
         self.assertRaises(exceptions.NotFound,
diff --git a/tempest/api/compute/security_groups/test_security_group_rules.py b/tempest/api/compute/security_groups/test_security_group_rules.py
index cbc0080..5faa9a4 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules.py
@@ -16,7 +16,7 @@
 #    under the License.
 
 from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
 from tempest import config
 from tempest import exceptions
 from tempest.test import attr
@@ -36,8 +36,8 @@
         # Positive test: Creation of Security Group rule
         # should be successful
         # Creating a Security Group to add rules to it
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = \
             self.client.create_security_group(s_name, s_description)
         securitygroup_id = securitygroup['id']
@@ -63,15 +63,15 @@
         secgroup1 = None
         secgroup2 = None
         # Creating a Security Group to add rules to it
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = \
             self.client.create_security_group(s_name, s_description)
         secgroup1 = securitygroup['id']
         self.addCleanup(self.client.delete_security_group, secgroup1)
         # Creating a Security Group so as to assign group_id to the rule
-        s_name2 = rand_name('securitygroup-')
-        s_description2 = rand_name('description-')
+        s_name2 = data_utils.rand_name('securitygroup-')
+        s_description2 = data_utils.rand_name('description-')
         resp, securitygroup = \
             self.client.create_security_group(s_name2, s_description2)
         secgroup2 = securitygroup['id']
@@ -100,7 +100,7 @@
         # Negative test: Creation of Security Group rule should FAIL
         # with invalid Parent group id
         # Adding rules to the invalid Security Group id
-        parent_group_id = rand_name('999')
+        parent_group_id = data_utils.rand_int_id(start=999)
         ip_protocol = 'tcp'
         from_port = 22
         to_port = 22
@@ -113,13 +113,13 @@
         # Negative test: Creation of Security Group rule should FAIL
         # with invalid ip_protocol
         # Creating a Security Group to add rule to it
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = self.client.create_security_group(s_name,
                                                                 s_description)
         # Adding rules to the created Security Group
         parent_group_id = securitygroup['id']
-        ip_protocol = rand_name('999')
+        ip_protocol = data_utils.rand_name('999')
         from_port = 22
         to_port = 22
 
@@ -133,14 +133,14 @@
         # Negative test: Creation of Security Group rule should FAIL
         # with invalid from_port
         # Creating a Security Group to add rule to it
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = self.client.create_security_group(s_name,
                                                                 s_description)
         # Adding rules to the created Security Group
         parent_group_id = securitygroup['id']
         ip_protocol = 'tcp'
-        from_port = rand_name('999')
+        from_port = data_utils.rand_int_id(start=999, end=65535)
         to_port = 22
         self.addCleanup(self.client.delete_security_group, securitygroup['id'])
         self.assertRaises(exceptions.BadRequest,
@@ -150,17 +150,17 @@
     @attr(type=['negative', 'gate'])
     def test_security_group_rules_create_with_invalid_to_port(self):
         # Negative test: Creation of Security Group rule should FAIL
-        # with invalid from_port
+        # with invalid to_port
         # Creating a Security Group to add rule to it
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = self.client.create_security_group(s_name,
                                                                 s_description)
         # Adding rules to the created Security Group
         parent_group_id = securitygroup['id']
         ip_protocol = 'tcp'
         from_port = 22
-        to_port = rand_name('999')
+        to_port = data_utils.rand_int_id(start=65536)
         self.addCleanup(self.client.delete_security_group, securitygroup['id'])
         self.assertRaises(exceptions.BadRequest,
                           self.client.create_security_group_rule,
@@ -171,8 +171,8 @@
         # Negative test: Creation of Security Group rule should FAIL
         # with invalid port range.
         # Creating a Security Group to add rule to it.
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = self.client.create_security_group(s_name,
                                                                 s_description)
         # Adding a rule to the created Security Group
@@ -193,15 +193,15 @@
         # with invalid rule id
         self.assertRaises(exceptions.NotFound,
                           self.client.delete_security_group_rule,
-                          rand_name('999'))
+                          data_utils.rand_int_id(start=999))
 
     @attr(type='gate')
     def test_security_group_rules_list(self):
         # Positive test: Created Security Group rules should be
         # in the list of all rules
         # Creating a Security Group to add rules to it
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = \
             self.client.create_security_group(s_name, s_description)
         securitygroup_id = securitygroup['id']
diff --git a/tempest/api/compute/security_groups/test_security_groups.py b/tempest/api/compute/security_groups/test_security_groups.py
index fba2f53..2d9c62d 100644
--- a/tempest/api/compute/security_groups/test_security_groups.py
+++ b/tempest/api/compute/security_groups/test_security_groups.py
@@ -18,7 +18,7 @@
 import testtools
 
 from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
 from tempest import config
 from tempest import exceptions
 from tempest.test import attr
@@ -43,8 +43,8 @@
         # Create 3 Security Groups
         security_group_list = list()
         for i in range(3):
-            s_name = rand_name('securitygroup-')
-            s_description = rand_name('description-')
+            s_name = data_utils.rand_name('securitygroup-')
+            s_description = data_utils.rand_name('description-')
             resp, securitygroup = \
                 self.client.create_security_group(s_name, s_description)
             self.assertEqual(200, resp.status)
@@ -68,8 +68,8 @@
     @attr(type='gate')
     def test_security_group_create_delete(self):
         # Security Group should be created, verified and deleted
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = \
             self.client.create_security_group(s_name, s_description)
         self.assertIn('id', securitygroup)
@@ -87,8 +87,8 @@
     @attr(type='gate')
     def test_security_group_create_get_delete(self):
         # Security Group should be created, fetched and deleted
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, securitygroup = \
             self.client.create_security_group(s_name, s_description)
         self.addCleanup(self._delete_security_group,
@@ -120,7 +120,7 @@
             security_group_id.append(body[i]['id'])
         # Creating a non-existent Security Group id
         while True:
-            non_exist_id = rand_name('999')
+            non_exist_id = data_utils.rand_int_id(start=999)
             if non_exist_id not in security_group_id:
                 break
         self.assertRaises(exceptions.NotFound, self.client.get_security_group,
@@ -132,7 +132,7 @@
     def test_security_group_create_with_invalid_group_name(self):
         # Negative test: Security Group should not be created with group name
         # as an empty string/with white spaces/chars more than 255
-        s_description = rand_name('description-')
+        s_description = data_utils.rand_name('description-')
         # Create Security Group with empty string as group name
         self.assertRaises(exceptions.BadRequest,
                           self.client.create_security_group, "", s_description)
@@ -152,7 +152,7 @@
     def test_security_group_create_with_invalid_group_description(self):
         # Negative test:Security Group should not be created with description
         # as an empty string/with white spaces/chars more than 255
-        s_name = rand_name('securitygroup-')
+        s_name = data_utils.rand_name('securitygroup-')
         # Create Security Group with empty string as description
         self.assertRaises(exceptions.BadRequest,
                           self.client.create_security_group, s_name, "")
@@ -171,8 +171,8 @@
     def test_security_group_create_with_duplicate_name(self):
         # Negative test:Security Group with duplicate name should not
         # be created
-        s_name = rand_name('securitygroup-')
-        s_description = rand_name('description-')
+        s_name = data_utils.rand_name('securitygroup-')
+        s_description = data_utils.rand_name('description-')
         resp, security_group =\
             self.client.create_security_group(s_name, s_description)
         self.assertEqual(200, resp.status)
@@ -209,7 +209,7 @@
             security_group_id.append(body[i]['id'])
         # Creating non-existent Security Group
         while True:
-            non_exist_id = rand_name('999')
+            non_exist_id = data_utils.rand_int_id(start=999)
             if non_exist_id not in security_group_id:
                 break
         self.assertRaises(exceptions.NotFound,
@@ -228,19 +228,19 @@
         # and not deleted if the server is active.
         # Create a couple security groups that we will use
         # for the server resource this test creates
-        sg_name = rand_name('sg')
-        sg_desc = rand_name('sg-desc')
+        sg_name = data_utils.rand_name('sg')
+        sg_desc = data_utils.rand_name('sg-desc')
         resp, sg = self.client.create_security_group(sg_name, sg_desc)
         sg_id = sg['id']
 
-        sg2_name = rand_name('sg')
-        sg2_desc = rand_name('sg-desc')
+        sg2_name = data_utils.rand_name('sg')
+        sg2_desc = data_utils.rand_name('sg-desc')
         resp, sg2 = self.client.create_security_group(sg2_name, sg2_desc)
         sg2_id = sg2['id']
 
         # Create server and add the security group created
         # above to the server we just created
-        server_name = rand_name('server')
+        server_name = data_utils.rand_name('server')
         resp, server = self.servers_client.create_server(server_name,
                                                          self.image_ref,
                                                          self.flavor_ref)
diff --git a/tempest/api/compute/servers/test_server_metadata.py b/tempest/api/compute/servers/test_server_metadata.py
index 5ea3cbf..15c3e6b 100644
--- a/tempest/api/compute/servers/test_server_metadata.py
+++ b/tempest/api/compute/servers/test_server_metadata.py
@@ -81,14 +81,6 @@
 
         # no teardown - all creates should fail
 
-    @attr(type=['negative', 'gate'])
-    def test_create_metadata_key_error(self):
-        # Blank key should trigger an error.
-        meta = {'': 'data1'}
-        self.assertRaises(exceptions.BadRequest,
-                          self.create_server,
-                          meta=meta)
-
     @attr(type='gate')
     def test_update_server_metadata(self):
         # The server's metadata values should be updated to the
@@ -147,62 +139,48 @@
         self.assertEqual(expected, resp_metadata)
 
     @attr(type=['negative', 'gate'])
-    def test_get_nonexistant_server_metadata_item(self):
-        # Negative test: GET on a non-existent server should not succeed
+    def test_server_metadata_negative(self):
+        # Blank key should trigger an error.
+        meta = {'': 'data1'}
+        self.assertRaises(exceptions.BadRequest,
+                          self.create_server,
+                          meta=meta)
+
+        # GET on a non-existent server should not succeed
         self.assertRaises(exceptions.NotFound,
                           self.client.get_server_metadata_item, 999, 'test2')
 
-    @attr(type=['negative', 'gate'])
-    def test_list_nonexistant_server_metadata(self):
-        # Negative test:List metadata on a non-existent server should
-        # not succeed
+        # List metadata on a non-existent server should not succeed
         self.assertRaises(exceptions.NotFound,
                           self.client.list_server_metadata, 999)
 
-    @attr(type=['negative', 'gate'])
-    def test_set_server_metadata_item_incorrect_uri_key(self):
         # Raise BadRequest if key in uri does not match
         # the key passed in body.
-
         meta = {'testkey': 'testvalue'}
         self.assertRaises(exceptions.BadRequest,
                           self.client.set_server_metadata_item,
                           self.server_id, 'key', meta)
 
-    @attr(type=['negative', 'gate'])
-    def test_set_nonexistant_server_metadata(self):
-        # Negative test: Set metadata on a non-existent server should not
-        # succeed
+        # Set metadata on a non-existent server should not succeed
         meta = {'meta1': 'data1'}
         self.assertRaises(exceptions.NotFound,
                           self.client.set_server_metadata, 999, meta)
 
-    @attr(type=['negative', 'gate'])
-    def test_update_nonexistant_server_metadata(self):
-        # Negative test: An update should not happen for a non-existent image
+        # An update should not happen for a non-existent image
         meta = {'key1': 'value1', 'key2': 'value2'}
         self.assertRaises(exceptions.NotFound,
                           self.client.update_server_metadata, 999, meta)
 
-    @attr(type=['negative', 'gate'])
-    def test_update_metadata_key_error(self):
-        # Blank key should trigger an error.
+        # Blank key should trigger an error
         meta = {'': 'data1'}
         self.assertRaises(exceptions.BadRequest,
                           self.client.update_server_metadata,
                           self.server_id, meta=meta)
 
-    @attr(type=['negative', 'gate'])
-    def test_delete_nonexistant_server_metadata_item(self):
-        # Negative test: Should not be able to delete metadata item from a
-        #  non-existent server
-
-        # Delete the metadata item
+        # Should not be able to delete metadata item from a non-existent server
         self.assertRaises(exceptions.NotFound,
                           self.client.delete_server_metadata_item, 999, 'd')
 
-    @attr(type=['negative', 'gate'])
-    def test_set_server_metadata_too_long(self):
         # Raise a 413 OverLimit exception while exceeding metadata items limit
         # for tenant.
         _, quota_set = self.quotas.get_quota_set(self.tenant_id)
@@ -214,21 +192,12 @@
                           self.client.set_server_metadata,
                           self.server_id, req_metadata)
 
-    @attr(type=['negative', 'gate'])
-    def test_update_server_metadata_too_long(self):
         # Raise a 413 OverLimit exception while exceeding metadata items limit
-        # for tenant.
-        _, quota_set = self.quotas.get_quota_set(self.tenant_id)
-        quota_metadata = quota_set['metadata_items']
-        req_metadata = {}
-        for num in range(1, quota_metadata + 2):
-            req_metadata['key' + str(num)] = 'val' + str(num)
+        # for tenant (update).
         self.assertRaises(exceptions.OverLimit,
                           self.client.update_server_metadata,
                           self.server_id, req_metadata)
 
-    @attr(type=['negative', 'gate'])
-    def test_update_all_metadata_field_error(self):
         # Raise a bad request error for blank key.
         # set_server_metadata will replace all metadata with new value
         meta = {'': 'data1'}
@@ -236,6 +205,13 @@
                           self.client.set_server_metadata,
                           self.server_id, meta=meta)
 
+        # Raise a bad request error for a missing metadata field
+        # set_server_metadata will replace all metadata with new value
+        meta = {'meta1': 'data1'}
+        self.assertRaises(exceptions.BadRequest,
+                          self.client.set_server_metadata,
+                          self.server_id, meta=meta, no_metadata_field=True)
+
 
 class ServerMetadataTestXML(ServerMetadataTestJSON):
     _interface = 'xml'
diff --git a/tempest/api/compute/volumes/test_volumes_negative.py b/tempest/api/compute/volumes/test_volumes_negative.py
index 9ca1380..90e6946 100644
--- a/tempest/api/compute/volumes/test_volumes_negative.py
+++ b/tempest/api/compute/volumes/test_volumes_negative.py
@@ -15,8 +15,10 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import uuid
+
 from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
 from tempest import exceptions
 from tempest.test import attr
 
@@ -36,39 +38,23 @@
     def test_volume_get_nonexistant_volume_id(self):
         # Negative: Should not be able to get details of nonexistant volume
         # Creating a nonexistant volume id
-        volume_id_list = list()
-        resp, body = self.client.list_volumes()
-        for i in range(len(body)):
-            volume_id_list.append(body[i]['id'])
-        while True:
-            non_exist_id = rand_name('999')
-            if non_exist_id not in volume_id_list:
-                break
         # Trying to GET a non existant volume
         self.assertRaises(exceptions.NotFound, self.client.get_volume,
-                          non_exist_id)
+                          str(uuid.uuid4()))
 
     @attr(type=['negative', 'gate'])
     def test_volume_delete_nonexistant_volume_id(self):
         # Negative: Should not be able to delete nonexistant Volume
         # Creating nonexistant volume id
-        volume_id_list = list()
-        resp, body = self.client.list_volumes()
-        for i in range(len(body)):
-            volume_id_list.append(body[i]['id'])
-        while True:
-            non_exist_id = rand_name('999')
-            if non_exist_id not in volume_id_list:
-                break
         # Trying to DELETE a non existant volume
         self.assertRaises(exceptions.NotFound, self.client.delete_volume,
-                          non_exist_id)
+                          str(uuid.uuid4()))
 
     @attr(type=['negative', 'gate'])
     def test_create_volume_with_invalid_size(self):
         # Negative: Should not be able to create volume with invalid size
         # in request
-        v_name = rand_name('Volume-')
+        v_name = data_utils.rand_name('Volume-')
         metadata = {'Type': 'work'}
         self.assertRaises(exceptions.BadRequest, self.client.create_volume,
                           size='#$%', display_name=v_name, metadata=metadata)
@@ -77,7 +63,7 @@
     def test_create_volume_with_out_passing_size(self):
         # Negative: Should not be able to create volume without passing size
         # in request
-        v_name = rand_name('Volume-')
+        v_name = data_utils.rand_name('Volume-')
         metadata = {'Type': 'work'}
         self.assertRaises(exceptions.BadRequest, self.client.create_volume,
                           size='', display_name=v_name, metadata=metadata)
@@ -85,7 +71,7 @@
     @attr(type=['negative', 'gate'])
     def test_create_volume_with_size_zero(self):
         # Negative: Should not be able to create volume with size zero
-        v_name = rand_name('Volume-')
+        v_name = data_utils.rand_name('Volume-')
         metadata = {'Type': 'work'}
         self.assertRaises(exceptions.BadRequest, self.client.create_volume,
                           size='0', display_name=v_name, metadata=metadata)
diff --git a/tempest/api/identity/admin/test_tenant_negative.py b/tempest/api/identity/admin/test_tenant_negative.py
new file mode 100644
index 0000000..6875bf5
--- /dev/null
+++ b/tempest/api/identity/admin/test_tenant_negative.py
@@ -0,0 +1,148 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 Huawei Technologies Co.,LTD.
+# All Rights Reserved.
+#
+#    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.
+
+import uuid
+
+from tempest.api.identity import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest.test import attr
+
+
+class TenantsNegativeTestJSON(base.BaseIdentityAdminTest):
+    _interface = 'json'
+
+    @attr(type=['negative', 'gate'])
+    def test_list_tenants_by_unauthorized_user(self):
+        # Non-administrator user should not be able to list tenants
+        self.assertRaises(exceptions.Unauthorized,
+                          self.non_admin_client.list_tenants)
+
+    @attr(type=['negative', 'gate'])
+    def test_list_tenant_request_without_token(self):
+        # Request to list tenants without a valid token should fail
+        token = self.client.get_auth()
+        self.client.delete_token(token)
+        self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
+        self.client.clear_auth()
+
+    @attr(type=['negative', 'gate'])
+    def test_tenant_delete_by_unauthorized_user(self):
+        # Non-administrator user should not be able to delete a tenant
+        tenant_name = data_utils.rand_name(name='tenant-')
+        resp, tenant = self.client.create_tenant(tenant_name)
+        self.assertEqual(200, resp.status)
+        self.data.tenants.append(tenant)
+        self.assertRaises(exceptions.Unauthorized,
+                          self.non_admin_client.delete_tenant, tenant['id'])
+
+    @attr(type=['negative', 'gate'])
+    def test_tenant_delete_request_without_token(self):
+        # Request to delete a tenant without a valid token should fail
+        tenant_name = data_utils.rand_name(name='tenant-')
+        resp, tenant = self.client.create_tenant(tenant_name)
+        self.assertEqual(200, resp.status)
+        self.data.tenants.append(tenant)
+        token = self.client.get_auth()
+        self.client.delete_token(token)
+        self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
+                          tenant['id'])
+        self.client.clear_auth()
+
+    @attr(type=['negative', 'gate'])
+    def test_delete_non_existent_tenant(self):
+        # Attempt to delete a non existent tenant should fail
+        self.assertRaises(exceptions.NotFound, self.client.delete_tenant,
+                          str(uuid.uuid4().hex))
+
+    @attr(type=['negative', 'gate'])
+    def test_tenant_create_duplicate(self):
+        # Tenant names should be unique
+        tenant_name = data_utils.rand_name(name='tenant-')
+        resp, body = self.client.create_tenant(tenant_name)
+        self.assertEqual(200, resp.status)
+        tenant = body
+        self.data.tenants.append(tenant)
+        tenant1_id = body.get('id')
+
+        self.addCleanup(self.client.delete_tenant, tenant1_id)
+        self.addCleanup(self.data.tenants.remove, tenant)
+        self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
+                          tenant_name)
+
+    @attr(type=['negative', 'gate'])
+    def test_create_tenant_by_unauthorized_user(self):
+        # Non-administrator user should not be authorized to create a tenant
+        tenant_name = data_utils.rand_name(name='tenant-')
+        self.assertRaises(exceptions.Unauthorized,
+                          self.non_admin_client.create_tenant, tenant_name)
+
+    @attr(type=['negative', 'gate'])
+    def test_create_tenant_request_without_token(self):
+        # Create tenant request without a token should not be authorized
+        tenant_name = data_utils.rand_name(name='tenant-')
+        token = self.client.get_auth()
+        self.client.delete_token(token)
+        self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
+                          tenant_name)
+        self.client.clear_auth()
+
+    @attr(type=['negative', 'gate'])
+    def test_create_tenant_with_empty_name(self):
+        # Tenant name should not be empty
+        self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
+                          name='')
+
+    @attr(type=['negative', 'gate'])
+    def test_create_tenants_name_length_over_64(self):
+        # Tenant name length should not be greater than 64 characters
+        tenant_name = 'a' * 65
+        self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
+                          tenant_name)
+
+    @attr(type=['negative', 'gate'])
+    def test_update_non_existent_tenant(self):
+        # Attempt to update a non existent tenant should fail
+        self.assertRaises(exceptions.NotFound, self.client.update_tenant,
+                          str(uuid.uuid4().hex))
+
+    @attr(type=['negative', 'gate'])
+    def test_tenant_update_by_unauthorized_user(self):
+        # Non-administrator user should not be able to update a tenant
+        tenant_name = data_utils.rand_name(name='tenant-')
+        resp, tenant = self.client.create_tenant(tenant_name)
+        self.assertEqual(200, resp.status)
+        self.data.tenants.append(tenant)
+        self.assertRaises(exceptions.Unauthorized,
+                          self.non_admin_client.update_tenant, tenant['id'])
+
+    @attr(type=['negative', 'gate'])
+    def test_tenant_update_request_without_token(self):
+        # Request to update a tenant without a valid token should fail
+        tenant_name = data_utils.rand_name(name='tenant-')
+        resp, tenant = self.client.create_tenant(tenant_name)
+        self.assertEqual(200, resp.status)
+        self.data.tenants.append(tenant)
+        token = self.client.get_auth()
+        self.client.delete_token(token)
+        self.assertRaises(exceptions.Unauthorized, self.client.update_tenant,
+                          tenant['id'])
+        self.client.clear_auth()
+
+
+class TenantsNegativeTestXML(TenantsNegativeTestJSON):
+    _interface = 'xml'
diff --git a/tempest/api/identity/admin/test_tenants.py b/tempest/api/identity/admin/test_tenants.py
index 486b739..e36b543 100644
--- a/tempest/api/identity/admin/test_tenants.py
+++ b/tempest/api/identity/admin/test_tenants.py
@@ -16,8 +16,7 @@
 #    under the License.
 
 from tempest.api.identity import base
-from tempest.common.utils.data_utils import rand_name
-from tempest import exceptions
+from tempest.common.utils import data_utils
 from tempest.test import attr
 
 
@@ -25,25 +24,13 @@
     _interface = 'json'
 
     @attr(type='gate')
-    def test_list_tenants_by_unauthorized_user(self):
-        # Non-administrator user should not be able to list tenants
-        self.assertRaises(exceptions.Unauthorized,
-                          self.non_admin_client.list_tenants)
-
-    @attr(type='gate')
-    def test_list_tenant_request_without_token(self):
-        # Request to list tenants without a valid token should fail
-        token = self.client.get_auth()
-        self.client.delete_token(token)
-        self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
-        self.client.clear_auth()
-
-    @attr(type='gate')
     def test_tenant_list_delete(self):
         # Create several tenants and delete them
         tenants = []
         for _ in xrange(3):
-            resp, tenant = self.client.create_tenant(rand_name('tenant-new'))
+            tenant_name = data_utils.rand_name(name='tenant-new')
+            resp, tenant = self.client.create_tenant(tenant_name)
+            self.assertEqual(200, resp.status)
             self.data.tenants.append(tenant)
             tenants.append(tenant)
         tenant_ids = map(lambda x: x['id'], tenants)
@@ -62,37 +49,10 @@
         self.assertFalse(any(found), 'Tenants failed to delete')
 
     @attr(type='gate')
-    def test_tenant_delete_by_unauthorized_user(self):
-        # Non-administrator user should not be able to delete a tenant
-        tenant_name = rand_name('tenant-')
-        resp, tenant = self.client.create_tenant(tenant_name)
-        self.data.tenants.append(tenant)
-        self.assertRaises(exceptions.Unauthorized,
-                          self.non_admin_client.delete_tenant, tenant['id'])
-
-    @attr(type='gate')
-    def test_tenant_delete_request_without_token(self):
-        # Request to delete a tenant without a valid token should fail
-        tenant_name = rand_name('tenant-')
-        resp, tenant = self.client.create_tenant(tenant_name)
-        self.data.tenants.append(tenant)
-        token = self.client.get_auth()
-        self.client.delete_token(token)
-        self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
-                          tenant['id'])
-        self.client.clear_auth()
-
-    @attr(type='gate')
-    def test_delete_non_existent_tenant(self):
-        # Attempt to delete a non existent tenant should fail
-        self.assertRaises(exceptions.NotFound, self.client.delete_tenant,
-                          'junk_tenant_123456abc')
-
-    @attr(type='gate')
     def test_tenant_create_with_description(self):
         # Create tenant with a description
-        tenant_name = rand_name('tenant-')
-        tenant_desc = rand_name('desc-')
+        tenant_name = data_utils.rand_name(name='tenant-')
+        tenant_desc = data_utils.rand_name(name='desc-')
         resp, body = self.client.create_tenant(tenant_name,
                                                description=tenant_desc)
         tenant = body
@@ -113,7 +73,7 @@
     @attr(type='gate')
     def test_tenant_create_enabled(self):
         # Create a tenant that is enabled
-        tenant_name = rand_name('tenant-')
+        tenant_name = data_utils.rand_name(name='tenant-')
         resp, body = self.client.create_tenant(tenant_name, enabled=True)
         tenant = body
         self.data.tenants.append(tenant)
@@ -131,7 +91,7 @@
     @attr(type='gate')
     def test_tenant_create_not_enabled(self):
         # Create a tenant that is not enabled
-        tenant_name = rand_name('tenant-')
+        tenant_name = data_utils.rand_name(name='tenant-')
         resp, body = self.client.create_tenant(tenant_name, enabled=False)
         tenant = body
         self.data.tenants.append(tenant)
@@ -149,61 +109,18 @@
         self.data.tenants.remove(tenant)
 
     @attr(type='gate')
-    def test_tenant_create_duplicate(self):
-        # Tenant names should be unique
-        tenant_name = rand_name('tenant-dup-')
-        resp, body = self.client.create_tenant(tenant_name)
-        tenant = body
-        self.data.tenants.append(tenant)
-        tenant1_id = body.get('id')
-
-        self.addCleanup(self.client.delete_tenant, tenant1_id)
-        self.addCleanup(self.data.tenants.remove, tenant)
-        self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
-                          tenant_name)
-
-    @attr(type='gate')
-    def test_create_tenant_by_unauthorized_user(self):
-        # Non-administrator user should not be authorized to create a tenant
-        tenant_name = rand_name('tenant-')
-        self.assertRaises(exceptions.Unauthorized,
-                          self.non_admin_client.create_tenant, tenant_name)
-
-    @attr(type='gate')
-    def test_create_tenant_request_without_token(self):
-        # Create tenant request without a token should not be authorized
-        tenant_name = rand_name('tenant-')
-        token = self.client.get_auth()
-        self.client.delete_token(token)
-        self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
-                          tenant_name)
-        self.client.clear_auth()
-
-    @attr(type='gate')
-    def test_create_tenant_with_empty_name(self):
-        # Tenant name should not be empty
-        self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
-                          name='')
-
-    @attr(type='gate')
-    def test_create_tenants_name_length_over_64(self):
-        # Tenant name length should not be greater than 64 characters
-        tenant_name = 'a' * 65
-        self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
-                          tenant_name)
-
-    @attr(type='gate')
     def test_tenant_update_name(self):
         # Update name attribute of a tenant
-        t_name1 = rand_name('tenant-')
+        t_name1 = data_utils.rand_name(name='tenant-')
         resp, body = self.client.create_tenant(t_name1)
+        self.assertEqual(200, resp.status)
         tenant = body
         self.data.tenants.append(tenant)
 
         t_id = body['id']
         resp1_name = body['name']
 
-        t_name2 = rand_name('tenant2-')
+        t_name2 = data_utils.rand_name(name='tenant2-')
         resp, body = self.client.update_tenant(t_id, name=t_name2)
         st2 = resp['status']
         resp2_name = body['name']
@@ -223,16 +140,17 @@
     @attr(type='gate')
     def test_tenant_update_desc(self):
         # Update description attribute of a tenant
-        t_name = rand_name('tenant-')
-        t_desc = rand_name('desc-')
+        t_name = data_utils.rand_name(name='tenant-')
+        t_desc = data_utils.rand_name(name='desc-')
         resp, body = self.client.create_tenant(t_name, description=t_desc)
+        self.assertEqual(200, resp.status)
         tenant = body
         self.data.tenants.append(tenant)
 
         t_id = body['id']
         resp1_desc = body['description']
 
-        t_desc2 = rand_name('desc2-')
+        t_desc2 = data_utils.rand_name(name='desc2-')
         resp, body = self.client.update_tenant(t_id, description=t_desc2)
         st2 = resp['status']
         resp2_desc = body['description']
@@ -252,9 +170,10 @@
     @attr(type='gate')
     def test_tenant_update_enable(self):
         # Update the enabled attribute of a tenant
-        t_name = rand_name('tenant-')
+        t_name = data_utils.rand_name(name='tenant-')
         t_en = False
         resp, body = self.client.create_tenant(t_name, enabled=t_en)
+        self.assertEqual(200, resp.status)
         tenant = body
         self.data.tenants.append(tenant)
 
diff --git a/tempest/api/identity/admin/test_users.py b/tempest/api/identity/admin/test_users.py
index 66d35cb..906fad3 100644
--- a/tempest/api/identity/admin/test_users.py
+++ b/tempest/api/identity/admin/test_users.py
@@ -18,7 +18,7 @@
 from testtools.matchers import Contains
 
 from tempest.api.identity import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
 from tempest.test import attr
 
 
@@ -28,11 +28,11 @@
     @classmethod
     def setUpClass(cls):
         super(UsersTestJSON, cls).setUpClass()
-        cls.alt_user = rand_name('test_user_')
-        cls.alt_password = rand_name('pass_')
+        cls.alt_user = data_utils.rand_name('test_user_')
+        cls.alt_password = data_utils.rand_name('pass_')
         cls.alt_email = cls.alt_user + '@testmail.tm'
-        cls.alt_tenant = rand_name('test_tenant_')
-        cls.alt_description = rand_name('desc_')
+        cls.alt_tenant = data_utils.rand_name('test_tenant_')
+        cls.alt_description = data_utils.rand_name('desc_')
 
     @attr(type='smoke')
     def test_create_user(self):
@@ -49,7 +49,7 @@
     def test_create_user_with_enabled(self):
         # Create a user with enabled : False
         self.data.setup_test_tenant()
-        name = rand_name('test_user_')
+        name = data_utils.rand_name('test_user_')
         resp, user = self.client.create_user(name, self.alt_password,
                                              self.data.tenant['id'],
                                              self.alt_email, enabled=False)
@@ -62,7 +62,7 @@
     @attr(type='smoke')
     def test_update_user(self):
         # Test case to check if updating of user attributes is successful.
-        test_user = rand_name('test_user_')
+        test_user = data_utils.rand_name('test_user_')
         self.data.setup_test_tenant()
         resp, user = self.client.create_user(test_user, self.alt_password,
                                              self.data.tenant['id'],
@@ -70,7 +70,7 @@
         # Delete the User at the end of this method
         self.addCleanup(self.client.delete_user, user['id'])
         # Updating user details with new values
-        u_name2 = rand_name('user2-')
+        u_name2 = data_utils.rand_name('user2-')
         u_email2 = u_name2 + '@testmail.tm'
         resp, update_user = self.client.update_user(user['id'], name=u_name2,
                                                     email=u_email2,
@@ -90,7 +90,7 @@
     @attr(type='smoke')
     def test_delete_user(self):
         # Delete a user
-        test_user = rand_name('test_user_')
+        test_user = data_utils.rand_name('test_user_')
         self.data.setup_test_tenant()
         resp, user = self.client.create_user(test_user, self.alt_password,
                                              self.data.tenant['id'],
@@ -144,7 +144,7 @@
         self.data.setup_test_tenant()
         user_ids = list()
         fetched_user_ids = list()
-        alt_tenant_user1 = rand_name('tenant_user1_')
+        alt_tenant_user1 = data_utils.rand_name('tenant_user1_')
         resp, user1 = self.client.create_user(alt_tenant_user1, 'password1',
                                               self.data.tenant['id'],
                                               'user1@123')
@@ -152,7 +152,7 @@
         user_ids.append(user1['id'])
         self.data.users.append(user1)
 
-        alt_tenant_user2 = rand_name('tenant_user2_')
+        alt_tenant_user2 = data_utils.rand_name('tenant_user2_')
         resp, user2 = self.client.create_user(alt_tenant_user2, 'password2',
                                               self.data.tenant['id'],
                                               'user2@123')
@@ -187,7 +187,7 @@
                                                   role['id'])
         self.assertEqual('200', resp['status'])
 
-        alt_user2 = rand_name('second_user_')
+        alt_user2 = data_utils.rand_name('second_user_')
         resp, second_user = self.client.create_user(alt_user2, 'password1',
                                                     self.data.tenant['id'],
                                                     'user2@123')
diff --git a/tempest/scenario/orchestration/test_autoscaling.py b/tempest/scenario/orchestration/test_autoscaling.py
index 658e9bb..e843793 100644
--- a/tempest/scenario/orchestration/test_autoscaling.py
+++ b/tempest/scenario/orchestration/test_autoscaling.py
@@ -12,6 +12,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import heatclient.exc as heat_exceptions
 import time
 
 from tempest.scenario import manager
@@ -74,7 +75,8 @@
 
         self.assertEqual('CREATE', self.stack.action)
         # wait for create to complete.
-        self.status_timeout(self.client.stacks, sid, 'COMPLETE')
+        self.status_timeout(self.client.stacks, sid, 'COMPLETE',
+                            error_status='FAILED')
 
         self.stack.get()
         self.assertEqual('CREATE_COMPLETE', self.stack.stack_status)
@@ -96,8 +98,10 @@
             call_until_true(lambda: server_count() == to_servers,
                             timeout, interval)
             self.assertEqual(to_servers, self.server_count,
-                             'Failed scaling from %d to %d servers' % (
-                                 from_servers, to_servers))
+                             'Failed scaling from %d to %d servers. '
+                             'Current server count: %s' % (
+                                 from_servers, to_servers,
+                                 self.server_count))
 
         # he marched them up to the top of the hill
         assertScale(1, 2)
@@ -106,3 +110,15 @@
         # and he marched them down again
         assertScale(3, 2)
         assertScale(2, 1)
+
+        # delete stack on completion
+        self.stack.delete()
+        self.status_timeout(self.client.stacks, sid, 'COMPLETE',
+                            error_status='FAILED',
+                            not_found_exception=heat_exceptions.NotFound)
+
+        try:
+            self.stack.get()
+            self.assertEqual('DELETE_COMPLETE', self.stack.stack_status)
+        except heat_exceptions.NotFound:
+            pass
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index eda0ede..dfbc01c 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -236,8 +236,11 @@
         body = json.loads(body)
         return resp, body['metadata']
 
-    def set_server_metadata(self, server_id, meta):
-        post_body = json.dumps({'metadata': meta})
+    def set_server_metadata(self, server_id, meta, no_metadata_field=False):
+        if no_metadata_field:
+            post_body = ""
+        else:
+            post_body = json.dumps({'metadata': meta})
         resp, body = self.put('servers/%s/metadata' % str(server_id),
                               post_body, self.headers)
         body = json.loads(body)
diff --git a/tempest/services/compute/xml/servers_client.py b/tempest/services/compute/xml/servers_client.py
index cb21c61..ada0398 100644
--- a/tempest/services/compute/xml/servers_client.py
+++ b/tempest/services/compute/xml/servers_client.py
@@ -494,14 +494,15 @@
         body = self._parse_key_value(etree.fromstring(body))
         return resp, body
 
-    def set_server_metadata(self, server_id, meta):
+    def set_server_metadata(self, server_id, meta, no_metadata_field=False):
         doc = Document()
-        metadata = Element("metadata")
-        doc.append(metadata)
-        for k, v in meta.items():
-            meta_element = Element("meta", key=k)
-            meta_element.append(Text(v))
-            metadata.append(meta_element)
+        if not no_metadata_field:
+            metadata = Element("metadata")
+            doc.append(metadata)
+            for k, v in meta.items():
+                meta_element = Element("meta", key=k)
+                meta_element.append(Text(v))
+                metadata.append(meta_element)
         resp, body = self.put('servers/%s/metadata' % str(server_id),
                               str(doc), self.headers)
         return resp, xml_to_json(etree.fromstring(body))