Merge "Fix race condition for test_flavors_extra_specs"
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index 303bc0c..0bb0460 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -15,6 +15,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import fixtures
+
 from tempest.api.compute import base
 from tempest.common.utils.data_utils import rand_name
 from tempest import exceptions
@@ -22,6 +24,16 @@
 from tempest.test import attr
 
 
+class LockFixture(fixtures.Fixture):
+    def __init__(self, name):
+        self.mgr = lockutils.lock(name, 'tempest-', True)
+
+    def setUp(self):
+        super(LockFixture, self).setUp()
+        self.addCleanup(self.mgr.__exit__, None, None, None)
+        self.mgr.__enter__()
+
+
 class AggregatesAdminTestJSON(base.BaseComputeAdminTest):
 
     """
@@ -146,9 +158,9 @@
                           self.client.get_aggregate, -1)
 
     @attr(type='gate')
-    @lockutils.synchronized('availability_zone', 'tempest-', True)
     def test_aggregate_add_remove_host(self):
         # Add an host to the given aggregate and remove.
+        self.useFixture(LockFixture('availability_zone'))
         aggregate_name = rand_name(self.aggregate_name_prefix)
         resp, aggregate = self.client.create_aggregate(aggregate_name)
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -168,9 +180,9 @@
         self.assertNotIn(self.host, body['hosts'])
 
     @attr(type='gate')
-    @lockutils.synchronized('availability_zone', 'tempest-', True)
     def test_aggregate_add_host_list(self):
         # Add an host to the given aggregate and list.
+        self.useFixture(LockFixture('availability_zone'))
         aggregate_name = rand_name(self.aggregate_name_prefix)
         resp, aggregate = self.client.create_aggregate(aggregate_name)
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -186,9 +198,9 @@
         self.assertIn(self.host, agg['hosts'])
 
     @attr(type='gate')
-    @lockutils.synchronized('availability_zone', 'tempest-', True)
     def test_aggregate_add_host_get_details(self):
         # Add an host to the given aggregate and get details.
+        self.useFixture(LockFixture('availability_zone'))
         aggregate_name = rand_name(self.aggregate_name_prefix)
         resp, aggregate = self.client.create_aggregate(aggregate_name)
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -201,9 +213,9 @@
         self.assertIn(self.host, body['hosts'])
 
     @attr(type='gate')
-    @lockutils.synchronized('availability_zone', 'tempest-', True)
     def test_aggregate_add_host_create_server_with_az(self):
         # Add an host to the given aggregate and create a server.
+        self.useFixture(LockFixture('availability_zone'))
         aggregate_name = rand_name(self.aggregate_name_prefix)
         az_name = rand_name(self.az_name_prefix)
         resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
@@ -248,9 +260,9 @@
                           aggregate['id'], self.host)
 
     @attr(type=['negative', 'gate'])
-    @lockutils.synchronized('availability_zone', 'tempest-', True)
     def test_aggregate_remove_host_as_user(self):
         # Regular user is not allowed to remove a host from an aggregate.
+        self.useFixture(LockFixture('availability_zone'))
         aggregate_name = rand_name(self.aggregate_name_prefix)
         resp, aggregate = self.client.create_aggregate(aggregate_name)
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
diff --git a/tempest/api/compute/volumes/test_attach_volume.py b/tempest/api/compute/volumes/test_attach_volume.py
index 5c1ad0d..ee1ad9e 100644
--- a/tempest/api/compute/volumes/test_attach_volume.py
+++ b/tempest/api/compute/volumes/test_attach_volume.py
@@ -26,7 +26,6 @@
 class AttachVolumeTestJSON(base.BaseComputeTest):
     _interface = 'json'
     run_ssh = tempest.config.TempestConfig().compute.run_ssh
-    device = tempest.config.TempestConfig().compute.volume_device_name
 
     def __init__(self, *args, **kwargs):
         super(AttachVolumeTestJSON, self).__init__(*args, **kwargs)
@@ -37,7 +36,7 @@
     @classmethod
     def setUpClass(cls):
         super(AttachVolumeTestJSON, cls).setUpClass()
-
+        cls.device = cls.config.compute.volume_device_name
         if not cls.config.service_available.cinder:
             skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
             raise cls.skipException(skip_msg)
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 62bd8cf..924ebc9 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -65,6 +65,10 @@
     message = 'Unauthorized'
 
 
+class InvalidServiceTag(RestClientException):
+    message = "Invalid service tag"
+
+
 class TimeoutException(TempestException):
     message = "Request timed out"
 
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 90b3fca..d3c2a18 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -28,6 +28,7 @@
 from neutronclient.common import exceptions as exc
 import neutronclient.v2_0.client
 import novaclient.client
+from novaclient import exceptions as nova_exceptions
 
 from tempest.api.network import common as net_common
 from tempest.common import isolated_creds
@@ -276,27 +277,57 @@
         expected status to show. At any time, if the returned
         status of the thing is ERROR, fail out.
         """
+        self._status_timeout(things, thing_id, expected_status=expected_status)
+
+    def delete_timeout(self, things, thing_id):
+        """
+        Given a thing, do a loop, sleeping
+        for a configurable amount of time, checking for the
+        deleted status to show. At any time, if the returned
+        status of the thing is ERROR, fail out.
+        """
+        self._status_timeout(things,
+                             thing_id,
+                             allow_notfound=True)
+
+    def _status_timeout(self,
+                        things,
+                        thing_id,
+                        expected_status=None,
+                        allow_notfound=False):
+
+        log_status = expected_status if expected_status else ''
+        if allow_notfound:
+            log_status += ' or NotFound' if log_status != '' else 'NotFound'
+
         def check_status():
             # python-novaclient has resources available to its client
             # that all implement a get() method taking an identifier
             # for the singular resource to retrieve.
-            thing = things.get(thing_id)
+            try:
+                thing = things.get(thing_id)
+            except nova_exceptions.NotFound:
+                if allow_notfound:
+                    return True
+                else:
+                    raise
+
             new_status = thing.status
             if new_status == 'ERROR':
                 message = "%s failed to get to expected status. \
                           In ERROR state." % (thing)
                 raise exceptions.BuildErrorException(message)
-            elif new_status == expected_status:
+            elif new_status == expected_status and expected_status is not None:
                 return True  # All good.
             LOG.debug("Waiting for %s to get to %s status. "
                       "Currently in %s status",
-                      thing, expected_status, new_status)
+                      thing, log_status, new_status)
         if not tempest.test.call_until_true(
             check_status,
             self.config.compute.build_timeout,
             self.config.compute.build_interval):
             message = "Timed out waiting for thing %s \
-                      to become %s" % (thing_id, expected_status)
+                      to become %s" % (thing_id, log_status)
             raise exceptions.TimeoutException(message)
 
     def create_loginable_secgroup_rule(self, client=None, secgroup_id=None):
diff --git a/tempest/scenario/orchestration/test_autoscaling.py b/tempest/scenario/orchestration/test_autoscaling.py
index 78025ee..b31a0a7 100644
--- a/tempest/scenario/orchestration/test_autoscaling.py
+++ b/tempest/scenario/orchestration/test_autoscaling.py
@@ -12,10 +12,11 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import time
+
 from tempest.scenario import manager
 from tempest.test import attr
 from tempest.test import call_until_true
-import time
 
 
 class AutoScalingTest(manager.OrchestrationScenarioTest):
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 70939f6..930ffae 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -19,9 +19,12 @@
 from tempest.api.network import common as net_common
 from tempest.common.utils.data_utils import rand_name
 from tempest import config
+from tempest.openstack.common import log as logging
 from tempest.scenario import manager
 from tempest.test import attr
 
+LOG = logging.getLogger(__name__)
+
 
 class TestNetworkBasicOps(manager.NetworkScenarioTest):
 
@@ -158,18 +161,15 @@
         self.set_resource(name, router)
         return router
 
-    @attr(type='smoke')
-    def test_001_create_keypairs(self):
+    def _create_keypairs(self):
         self.keypairs[self.tenant_id] = self.create_keypair(
             name=rand_name('keypair-smoke-'))
 
-    @attr(type='smoke')
-    def test_002_create_security_groups(self):
+    def _create_security_groups(self):
         self.security_groups[self.tenant_id] = self._create_security_group(
             self.compute_client)
 
-    @attr(type='smoke')
-    def test_003_create_networks(self):
+    def _create_networks(self):
         network = self._create_network(self.tenant_id)
         router = self._get_router(self.tenant_id)
         subnet = self._create_subnet(network)
@@ -178,8 +178,7 @@
         self.subnets.append(subnet)
         self.routers.append(router)
 
-    @attr(type='smoke')
-    def test_004_check_networks(self):
+    def _check_networks(self):
         # Checks that we see the newly created network/subnet/router via
         # checking the result of list_[networks,routers,subnets]
         seen_nets = self._list_networks()
@@ -202,10 +201,7 @@
             self.assertIn(myrouter.name, seen_router_names)
             self.assertIn(myrouter.id, seen_router_ids)
 
-    @attr(type='smoke')
-    def test_005_create_servers(self):
-        if not (self.keypairs or self.security_groups or self.networks):
-            raise self.skipTest('Necessary resources have not been defined')
+    def _create_servers(self):
         for i, network in enumerate(self.networks):
             tenant_id = network.tenant_id
             name = rand_name('server-smoke-%d-' % i)
@@ -222,13 +218,11 @@
                                         create_kwargs=create_kwargs)
             self.servers.append(server)
 
-    @attr(type='smoke')
-    def test_006_check_tenant_network_connectivity(self):
+    def _check_tenant_network_connectivity(self):
         if not self.config.network.tenant_networks_reachable:
             msg = 'Tenant networks not configured to be reachable.'
-            raise self.skipTest(msg)
-        if not self.servers:
-            raise self.skipTest("No VM's have been created")
+            LOG.info(msg)
+            return
         # The target login is assumed to have been configured for
         # key-based authentication by cloud-init.
         ssh_login = self.config.compute.image_ssh_user
@@ -239,22 +233,14 @@
                     self._check_vm_connectivity(ip_address, ssh_login,
                                                 private_key)
 
-    @attr(type='smoke')
-    def test_007_assign_floating_ips(self):
+    def _assign_floating_ips(self):
         public_network_id = self.config.network.public_network_id
-        if not public_network_id:
-            raise self.skipTest('Public network not configured')
-        if not self.servers:
-            raise self.skipTest("No VM's have been created")
         for server in self.servers:
             floating_ip = self._create_floating_ip(server, public_network_id)
             self.floating_ips.setdefault(server, [])
             self.floating_ips[server].append(floating_ip)
 
-    @attr(type='smoke')
-    def test_008_check_public_network_connectivity(self):
-        if not self.floating_ips:
-            raise self.skipTest('No floating ips have been allocated.')
+    def _check_public_network_connectivity(self):
         # The target login is assumed to have been configured for
         # key-based authentication by cloud-init.
         ssh_login = self.config.compute.image_ssh_user
@@ -263,3 +249,14 @@
             for floating_ip in floating_ips:
                 ip_address = floating_ip.floating_ip_address
                 self._check_vm_connectivity(ip_address, ssh_login, private_key)
+
+    @attr(type='smoke')
+    def test_network_basic_ops(self):
+        self._create_keypairs()
+        self._create_security_groups()
+        self._create_networks()
+        self._check_networks()
+        self._create_servers()
+        self._check_tenant_network_connectivity()
+        self._assign_floating_ips()
+        self._check_public_network_connectivity()
diff --git a/tempest/scenario/test_network_quotas.py b/tempest/scenario/test_network_quotas.py
index 267aff6..8259feb 100644
--- a/tempest/scenario/test_network_quotas.py
+++ b/tempest/scenario/test_network_quotas.py
@@ -16,6 +16,7 @@
 #    under the License.
 
 from neutronclient.common import exceptions as exc
+
 from tempest.scenario.manager import NetworkScenarioTest
 
 MAX_REASONABLE_ITERATIONS = 51  # more than enough. Default for port is 50.
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
new file mode 100644
index 0000000..09c1cb7
--- /dev/null
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -0,0 +1,161 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+#    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 tempest.common.utils.data_utils import rand_name
+from tempest.scenario import manager
+
+
+class TestVolumeBootPattern(manager.OfficialClientTest):
+
+    """
+    This test case attempts to reproduce the following steps:
+
+     * Create in Cinder some bootable volume importing a Glance image
+     * Boot an instance from the bootable volume
+     * Write content to the volume
+     * Delete an instance and Boot a new instance from the volume
+     * Check written content in the instance
+     * Create a volume snapshot while the instance is running
+     * Boot an additional instance from the new snapshot based volume
+     * Check written content in the instance booted from snapshot
+    """
+
+    def _create_volume_from_image(self):
+        img_uuid = self.config.compute.image_ref
+        vol_name = rand_name('volume-origin')
+        return self.create_volume(name=vol_name, imageRef=img_uuid)
+
+    def _boot_instance_from_volume(self, vol_id, keypair):
+        # NOTE(gfidente): the syntax for block_device_mapping is
+        # dev_name=id:type:size:delete_on_terminate
+        # where type needs to be "snap" if the server is booted
+        # from a snapshot, size instead can be safely left empty
+        bd_map = {
+            'vda': vol_id + ':::0'
+        }
+        create_kwargs = {
+            'block_device_mapping': bd_map,
+            'key_name': keypair.name
+        }
+        return self.create_server(self.compute_client,
+                                  create_kwargs=create_kwargs)
+
+    def _create_snapshot_from_volume(self, vol_id):
+        volume_snapshots = self.volume_client.volume_snapshots
+        snap_name = rand_name('snapshot')
+        snap = volume_snapshots.create(volume_id=vol_id,
+                                       force=True,
+                                       display_name=snap_name)
+        self.set_resource(snap.id, snap)
+        self.status_timeout(volume_snapshots,
+                            snap.id,
+                            'available')
+        return snap
+
+    def _create_volume_from_snapshot(self, snap_id):
+        vol_name = rand_name('volume')
+        return self.create_volume(name=vol_name, snapshot_id=snap_id)
+
+    def _stop_instances(self, instances):
+        # NOTE(gfidente): two loops so we do not wait for the status twice
+        for i in instances:
+            self.compute_client.servers.stop(i)
+        for i in instances:
+            self.status_timeout(self.compute_client.servers,
+                                i.id,
+                                'SHUTOFF')
+
+    def _detach_volumes(self, volumes):
+        # NOTE(gfidente): two loops so we do not wait for the status twice
+        for v in volumes:
+            self.volume_client.volumes.detach(v)
+        for v in volumes:
+            self.status_timeout(self.volume_client.volumes,
+                                v.id,
+                                'available')
+
+    def _ssh_to_server(self, server, keypair):
+        if self.config.compute.use_floatingip_for_ssh:
+            floating_ip = self.compute_client.floating_ips.create()
+            fip_name = rand_name('scenario-fip')
+            self.set_resource(fip_name, floating_ip)
+            server.add_floating_ip(floating_ip)
+            ip = floating_ip.ip
+        else:
+            network_name_for_ssh = self.config.compute.network_for_ssh
+            ip = server.networks[network_name_for_ssh][0]
+
+        client = self.get_remote_client(ip,
+                                        private_key=keypair.private_key)
+        return client.ssh_client
+
+    def _get_content(self, ssh_client):
+        return ssh_client.exec_command('cat /tmp/text')
+
+    def _write_text(self, ssh_client):
+        text = rand_name('text-')
+        ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text))
+
+        return self._get_content(ssh_client)
+
+    def _delete_server(self, server):
+        self.compute_client.servers.delete(server)
+        self.delete_timeout(self.compute_client.servers, server.id)
+
+    def _check_content_of_written_file(self, ssh_client, expected):
+        actual = self._get_content(ssh_client)
+        self.assertEqual(expected, actual)
+
+    def test_volume_boot_pattern(self):
+        keypair = self.create_keypair()
+        self.create_loginable_secgroup_rule()
+
+        # create an instance from volume
+        volume_origin = self._create_volume_from_image()
+        instance_1st = self._boot_instance_from_volume(volume_origin.id,
+                                                       keypair)
+
+        # write content to volume on instance
+        ssh_client_for_instance_1st = self._ssh_to_server(instance_1st,
+                                                          keypair)
+        text = self._write_text(ssh_client_for_instance_1st)
+
+        # delete instance
+        self._delete_server(instance_1st)
+
+        # create a 2nd instance from volume
+        instance_2nd = self._boot_instance_from_volume(volume_origin.id,
+                                                       keypair)
+
+        # check the content of written file
+        ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd,
+                                                          keypair)
+        self._check_content_of_written_file(ssh_client_for_instance_2nd, text)
+
+        # snapshot a volume
+        snapshot = self._create_snapshot_from_volume(volume_origin.id)
+
+        # create a 3rd instance from snapshot
+        volume = self._create_volume_from_snapshot(snapshot.id)
+        instance_from_snapshot = self._boot_instance_from_volume(volume.id,
+                                                                 keypair)
+
+        # check the content of written file
+        ssh_client = self._ssh_to_server(instance_from_snapshot, keypair)
+        self._check_content_of_written_file(ssh_client, text)
+
+        # NOTE(gfidente): ensure resources are in clean state for
+        # deletion operations to succeed
+        self._stop_instances([instance_2nd, instance_from_snapshot])
+        self._detach_volumes([volume_origin, volume])
diff --git a/tempest/scenario/test_volume_snapshot_pattern.py b/tempest/scenario/test_volume_snapshot_pattern.py
deleted file mode 100644
index d873d30..0000000
--- a/tempest/scenario/test_volume_snapshot_pattern.py
+++ /dev/null
@@ -1,92 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-#    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 tempest.common.utils.data_utils import rand_name
-from tempest.scenario import manager
-
-
-class TestVolumeSnapshotPattern(manager.OfficialClientTest):
-
-    """
-    This test case attempts to reproduce the following steps:
-
-     * Create in Cinder some bootable volume importing a Glance image
-     * Boot an instance from the bootable volume
-     * Create a volume snapshot while the instance is running
-     * Boot an additional instance from the new snapshot based volume
-    """
-
-    def _create_volume_from_image(self):
-        img_uuid = self.config.compute.image_ref
-        vol_name = rand_name('volume-origin')
-        return self.create_volume(name=vol_name, imageRef=img_uuid)
-
-    def _boot_instance_from_volume(self, vol_id):
-        # NOTE(gfidente): the syntax for block_device_mapping is
-        # dev_name=id:type:size:delete_on_terminate
-        # where type needs to be "snap" if the server is booted
-        # from a snapshot, size instead can be safely left empty
-        bd_map = {
-            'vda': vol_id + ':::0'
-        }
-        create_kwargs = {
-            'block_device_mapping': bd_map
-        }
-        return self.create_server(self.compute_client,
-                                  create_kwargs=create_kwargs)
-
-    def _create_snapshot_from_volume(self, vol_id):
-        volume_snapshots = self.volume_client.volume_snapshots
-        snap_name = rand_name('snapshot')
-        snap = volume_snapshots.create(volume_id=vol_id,
-                                       force=True,
-                                       display_name=snap_name)
-        self.set_resource(snap.id, snap)
-        self.status_timeout(volume_snapshots,
-                            snap.id,
-                            'available')
-        return snap
-
-    def _create_volume_from_snapshot(self, snap_id):
-        vol_name = rand_name('volume')
-        return self.create_volume(name=vol_name, snapshot_id=snap_id)
-
-    def _stop_instances(self, instances):
-        # NOTE(gfidente): two loops so we do not wait for the status twice
-        for i in instances:
-            self.compute_client.servers.stop(i)
-        for i in instances:
-            self.status_timeout(self.compute_client.servers,
-                                i.id,
-                                'SHUTOFF')
-
-    def _detach_volumes(self, volumes):
-        # NOTE(gfidente): two loops so we do not wait for the status twice
-        for v in volumes:
-            self.volume_client.volumes.detach(v)
-        for v in volumes:
-            self.status_timeout(self.volume_client.volumes,
-                                v.id,
-                                'available')
-
-    def test_volume_snapshot_pattern(self):
-        volume_origin = self._create_volume_from_image()
-        i_origin = self._boot_instance_from_volume(volume_origin.id)
-        snapshot = self._create_snapshot_from_volume(volume_origin.id)
-        volume = self._create_volume_from_snapshot(snapshot.id)
-        i = self._boot_instance_from_volume(volume.id)
-        # NOTE(gfidente): ensure resources are in clean state for
-        # deletion operations to succeed
-        self._stop_instances([i_origin, i])
-        self._detach_volumes([volume_origin, volume])
diff --git a/tempest/services/compute/xml/servers_client.py b/tempest/services/compute/xml/servers_client.py
index ec9464a..6f17611 100644
--- a/tempest/services/compute/xml/servers_client.py
+++ b/tempest/services/compute/xml/servers_client.py
@@ -46,9 +46,14 @@
     # expanded xml namespace.
     type_ns_prefix = ('{http://docs.openstack.org/compute/ext/extended_ips/'
                       'api/v1.1}type')
+    mac_ns_prefix = ('{http://docs.openstack.org/compute/ext/extended_ips_mac'
+                     '/api/v1.1}mac_addr')
+
     if type_ns_prefix in ip:
-        ip['OS-EXT-IPS:type'] = ip[type_ns_prefix]
-        ip.pop(type_ns_prefix)
+        ip['OS-EXT-IPS:type'] = ip.pop(type_ns_prefix)
+
+    if mac_ns_prefix in ip:
+        ip['OS-EXT-IPS-MAC:mac_addr'] = ip.pop(mac_ns_prefix)
     return ip
 
 
@@ -101,11 +106,35 @@
         json['addresses'] = json_addresses
     else:
         json = xml_to_json(xml_dom)
-    diskConfig = '{http://docs.openstack.org/compute/ext/disk_config/api/v1.1'\
-                 '}diskConfig'
+    diskConfig = ('{http://docs.openstack.org'
+                  '/compute/ext/disk_config/api/v1.1}diskConfig')
+    terminated_at = ('{http://docs.openstack.org/'
+                     'compute/ext/server_usage/api/v1.1}terminated_at')
+    launched_at = ('{http://docs.openstack.org'
+                   '/compute/ext/server_usage/api/v1.1}launched_at')
+    power_state = ('{http://docs.openstack.org'
+                   '/compute/ext/extended_status/api/v1.1}power_state')
+    availability_zone = ('{http://docs.openstack.org'
+                         '/compute/ext/extended_availability_zone/api/v2}'
+                         'availability_zone')
+    vm_state = ('{http://docs.openstack.org'
+                '/compute/ext/extended_status/api/v1.1}vm_state')
+    task_state = ('{http://docs.openstack.org'
+                  '/compute/ext/extended_status/api/v1.1}task_state')
     if diskConfig in json:
-        json['OS-DCF:diskConfig'] = json[diskConfig]
-        del json[diskConfig]
+        json['OS-DCF:diskConfig'] = json.pop(diskConfig)
+    if terminated_at in json:
+        json['OS-SRV-USG:terminated_at'] = json.pop(terminated_at)
+    if launched_at in json:
+        json['OS-SRV-USG:launched_at'] = json.pop(launched_at)
+    if power_state in json:
+        json['OS-EXT-STS:power_state'] = json.pop(power_state)
+    if availability_zone in json:
+        json['OS-EXT-AZ:availability_zone'] = json.pop(availability_zone)
+    if vm_state in json:
+        json['OS-EXT-STS:vm_state'] = json.pop(vm_state)
+    if task_state in json:
+        json['OS-EXT-STS:task_state'] = json.pop(task_state)
     return json
 
 
diff --git a/tempest/test.py b/tempest/test.py
index decae94..24c4489 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -26,6 +26,7 @@
 
 from tempest import clients
 from tempest import config
+from tempest import exceptions
 from tempest.openstack.common import log as logging
 
 LOG = logging.getLogger(__name__)
@@ -57,6 +58,25 @@
     return decorator
 
 
+def services(*args, **kwargs):
+    """A decorator used to set an attr for each service used in a test case
+
+    This decorator applies a testtools attr for each service that gets
+    exercised by a test case.
+    """
+    valid_service_list = ['compute', 'image', 'volume', 'orchestration',
+                          'network', 'identity', 'object', 'dashboard']
+
+    def decorator(f):
+        for service in args:
+            if service not in valid_service_list:
+                raise exceptions.InvalidServiceTag('%s is not a valid service'
+                                                   % service)
+        attr(type=list(args))(f)
+        return f
+    return decorator
+
+
 def stresstest(*args, **kwargs):
     """Add stress test decorator