Merge "boto: instance teardown wait until instance is gone"
diff --git a/tempest/tests/compute/__init__.py b/tempest/tests/compute/__init__.py
index 0258708..190cb5f 100644
--- a/tempest/tests/compute/__init__.py
+++ b/tempest/tests/compute/__init__.py
@@ -21,6 +21,7 @@
 
 from tempest import clients
 from tempest import config
+from tempest.exceptions import InvalidConfiguration
 
 LOG = logging.getLogger(__name__)
 
@@ -51,19 +52,15 @@
     # Validate reference data exists
     # If not, we raise the exception here and prevent
     # going forward...
-    try:
-        image_ref = CONFIG.compute.image_ref
-        image_ref_alt = CONFIG.compute.image_ref_alt
-        images_client.get_image(image_ref)
-        images_client.get_image(image_ref_alt)
+    image_ref = CONFIG.compute.image_ref
+    image_ref_alt = CONFIG.compute.image_ref_alt
+    images_client.get_image(image_ref)
+    images_client.get_image(image_ref_alt)
 
-        flavor_ref = CONFIG.compute.flavor_ref
-        flavor_ref_alt = CONFIG.compute.flavor_ref_alt
-        flavors_client.get_flavor_details(flavor_ref)
-        flavors_client.get_flavor_details(flavor_ref_alt)
-    except Exception as e:
-        msg = "Failed basic configuration: %s" % e
-        raise nose.SkipTest(msg)
+    flavor_ref = CONFIG.compute.flavor_ref
+    flavor_ref_alt = CONFIG.compute.flavor_ref_alt
+    flavors_client.get_flavor_details(flavor_ref)
+    flavors_client.get_flavor_details(flavor_ref_alt)
 
     # Determine if there are two regular users that can be
     # used in testing. If the test cases are allowed to create
@@ -79,6 +76,7 @@
             user2_tenant_name = CONFIG.compute.alt_tenant_name
             if not user2_password or not user2_tenant_name:
                 msg = ("Alternate user specified but not alternate "
-                       "tenant or password")
-                raise nose.SkipTest(msg)
+                       "tenant or password: alt_tenant_name=%s alt_password=%s"
+                       % (user2_tenant_name, user2_password))
+                raise InvalidConfiguration(msg)
             MULTI_USER = True
diff --git a/tempest/tests/compute/images/test_images.py b/tempest/tests/compute/images/test_images.py
index 95678a2..2557f16 100644
--- a/tempest/tests/compute/images/test_images.py
+++ b/tempest/tests/compute/images/test_images.py
@@ -42,40 +42,6 @@
             self.client.delete_image(image_id)
             self.image_ids.remove(image_id)
 
-    @attr(type='smoke')
-    @unittest.skipUnless(compute.CREATE_IMAGE_ENABLED,
-                         'Environment unable to create images.')
-    def test_create_delete_image(self):
-        # An image for the provided server should be created
-        server_name = rand_name('server')
-        resp, server = self.servers_client.create_server(server_name,
-                                                         self.image_ref,
-                                                         self.flavor_ref)
-        self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
-
-        # Create a new image
-        name = rand_name('image')
-        meta = {'image_type': 'test'}
-        resp, body = self.client.create_image(server['id'], name, meta)
-        self.assertEqual(202, resp.status)
-        image_id = parse_image_id(resp['location'])
-        self.client.wait_for_image_resp_code(image_id, 200)
-        self.client.wait_for_image_status(image_id, 'ACTIVE')
-
-        # Verify the image was created correctly
-        resp, image = self.client.get_image(image_id)
-        self.assertEqual(name, image['name'])
-        self.assertEqual('test', image['metadata']['image_type'])
-
-        # Verify minRAM and minDisk values are the same as the original image
-        resp, original_image = self.client.get_image(self.image_ref)
-        self.assertEqual(original_image['minRam'], image['minRam'])
-        self.assertEqual(original_image['minDisk'], image['minDisk'])
-
-        # Teardown
-        self.client.delete_image(image['id'])
-        self.servers_client.delete_server(server['id'])
-
     @attr(type='negative')
     def test_create_image_from_deleted_server(self):
         # An image should not be created if the server instance is removed
@@ -126,13 +92,13 @@
                           "with invalid server id")
 
     @attr(type='negative')
-    @unittest.skipUnless(compute.MULTI_USER, 'Second user not configured')
-    def test_create_image_for_server_in_another_tenant(self):
-        # Creating image of another tenant's server should be return error
+    def test_create_image_when_server_is_terminating(self):
+        # Return an error when creating image of server that is terminating
         server = self.create_server()
+        self.servers_client.delete_server(server['id'])
 
         snapshot_name = rand_name('test-snap-')
-        self.assertRaises(exceptions.NotFound, self.alt_client.create_image,
+        self.assertRaises(exceptions.Duplicate, self.client.create_image,
                           server['id'], snapshot_name)
 
     @attr(type='negative')
@@ -159,52 +125,6 @@
                           server['id'], snapshot_name)
 
     @attr(type='negative')
-    def test_create_image_when_server_is_terminating(self):
-        # Return an error when creating image of server that is terminating
-        server = self.create_server()
-        self.servers_client.delete_server(server['id'])
-
-        snapshot_name = rand_name('test-snap-')
-        self.assertRaises(exceptions.Duplicate, self.client.create_image,
-                          server['id'], snapshot_name)
-
-    @attr(type='negative')
-    def test_create_second_image_when_first_image_is_being_saved(self):
-        # Disallow creating another image when first image is being saved
-        server = self.create_server()
-
-        try:
-            # Create first snapshot
-            snapshot_name = rand_name('test-snap-')
-            resp, body = self.client.create_image(server['id'], snapshot_name)
-            image_id = parse_image_id(resp['location'])
-            self.image_ids.append(image_id)
-
-            # Create second snapshot
-            alt_snapshot_name = rand_name('test-snap-')
-            self.client.create_image(server['id'], alt_snapshot_name)
-        except exceptions.Duplicate:
-            pass
-
-        else:
-            self.fail("Should allow creating an image when another image of"
-                      "the server is still being saved")
-
-    @attr(type='negative')
-    @unittest.skip("Until Bug 1004564 is fixed")
-    def test_create_image_specify_name_over_256_chars(self):
-        # Return an error if snapshot name over 256 characters is passed
-        server = self.create_server()
-
-        try:
-            snapshot_name = rand_name('a' * 260)
-            self.assertRaises(exceptions.BadRequest, self.client.create_image,
-                              server['id'], snapshot_name)
-        except Exception:
-            self.fail("Should return 400 Bad Request if image name is over 256"
-                      " characters")
-
-    @attr(type='negative')
     def test_create_image_specify_uuid_35_characters_or_less(self):
         # Return an error if Image ID passed is 35 characters or less
         try:
@@ -229,51 +149,6 @@
                       " characters or more")
 
     @attr(type='negative')
-    @unittest.skip("Until Bug 1006725 is fixed")
-    def test_create_image_specify_multibyte_character_image_name(self):
-        # Return an error if the image name has multi-byte characters
-        server = self.create_server()
-
-        try:
-            snapshot_name = rand_name('\xef\xbb\xbf')
-            self.assertRaises(exceptions.BadRequest,
-                              self.client.create_image, server['id'],
-                              snapshot_name)
-        except Exception:
-            self.fail("Should return 400 Bad Request if multi byte characters"
-                      " are used for image name")
-
-    @attr(type='negative')
-    @unittest.skip("Until Bug 1005423 is fixed")
-    def test_create_image_specify_invalid_metadata(self):
-        # Return an error when creating image with invalid metadata
-        server = self.create_server()
-
-        try:
-            snapshot_name = rand_name('test-snap-')
-            meta = {'': ''}
-            self.assertRaises(exceptions.BadRequest, self.client.create_image,
-                              server['id'], snapshot_name, meta)
-
-        except Exception:
-            self.fail("Should raise 400 Bad Request if meta data is invalid")
-
-    @attr(type='negative')
-    @unittest.skip("Until Bug 1005423 is fixed")
-    def test_create_image_specify_metadata_over_limits(self):
-        # Return an error when creating image with meta data over 256 chars
-        server = self.create_server()
-
-        try:
-            snapshot_name = rand_name('test-snap-')
-            meta = {'a' * 260: 'b' * 260}
-            self.assertRaises(exceptions.OverLimit, self.client.create_image,
-                              server['id'], snapshot_name, meta)
-
-        except Exception:
-            self.fail("Should raise 413 Over Limit if meta data was too long")
-
-    @attr(type='negative')
     def test_delete_image_with_invalid_image_id(self):
         # An image should not be deleted with invalid image id
         try:
@@ -337,42 +212,6 @@
             self.fail("Did not return HTTP 404 NotFound for image id that "
                       "exceeds 35 character ID length limit")
 
-    @attr(type='negative')
-    @unittest.skipUnless(compute.MULTI_USER, 'Second user not configured')
-    def test_delete_image_of_another_tenant(self):
-        # Return an error while trying to delete another tenant's image
-
-        server = self.create_server()
-
-        snapshot_name = rand_name('test-snap-')
-        resp, body = self.client.create_image(server['id'], snapshot_name)
-        image_id = parse_image_id(resp['location'])
-        self.image_ids.append(image_id)
-        self.client.wait_for_image_resp_code(image_id, 200)
-        self.client.wait_for_image_status(image_id, 'ACTIVE')
-
-        # Delete image
-        self.assertRaises(exceptions.NotFound,
-                          self.alt_client.delete_image, image_id)
-
-    @attr(type='negative')
-    def test_delete_image_that_is_not_yet_active(self):
-        # Return an error while trying to delete an active that is creating
-
-        server = self.create_server()
-
-        snapshot_name = rand_name('test-snap-')
-        resp, body = self.client.create_image(server['id'], snapshot_name)
-        image_id = parse_image_id(resp['location'])
-        self.image_ids.append(image_id)
-
-        # Do not wait, attempt to delete the image, ensure it's successful
-        resp, body = self.client.delete_image(image_id)
-        self.assertEqual('204', resp['status'])
-        self.image_ids.remove(image_id)
-
-        self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
-
 
 class ImagesTestJSON(base.BaseComputeTestJSON,
                      ImagesTestBase):
@@ -381,7 +220,6 @@
 
     @classmethod
     def setUpClass(cls):
-        raise nose.SkipTest("Until Bug 1046870 is fixed")
         super(ImagesTestJSON, cls).setUpClass()
         cls.client = cls.images_client
         cls.servers_client = cls.servers_client
@@ -408,7 +246,6 @@
 
     @classmethod
     def setUpClass(cls):
-        raise nose.SkipTest("Until Bug 1046870 is fixed")
         super(ImagesTestXML, cls).setUpClass()
         cls.client = cls.images_client
         cls.servers_client = cls.servers_client
diff --git a/tempest/tests/compute/images/test_images_oneserver.py b/tempest/tests/compute/images/test_images_oneserver.py
new file mode 100644
index 0000000..2841a21
--- /dev/null
+++ b/tempest/tests/compute/images/test_images_oneserver.py
@@ -0,0 +1,239 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 OpenStack, LLC
+# 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 nose
+from nose.plugins.attrib import attr
+import unittest2 as unittest
+
+from tempest import clients
+from tempest.common.utils.data_utils import parse_image_id
+from tempest.common.utils.data_utils import rand_name
+import tempest.config
+from tempest import exceptions
+from tempest.tests import compute
+from tempest.tests.compute import base
+
+
+class ImagesOneServerTestBase(object):
+    def tearDownClass(cls):
+        """Terminate test instances created after a test is executed."""
+        resp, body = self.servers_client.delete_server(cls.server['id'])
+        if resp['status'] == '204':
+            self.servers.remove(server)
+            self.servers_client.wait_for_server_termination(cls.server['id'])
+
+    def tearDown(self):
+        """Terminate test instances created after a test is executed."""
+        for image_id in self.image_ids:
+            self.client.delete_image(image_id)
+            self.image_ids.remove(image_id)
+
+    @attr(type='negative')
+    @unittest.skip("Until Bug 1006725 is fixed")
+    def test_create_image_specify_multibyte_character_image_name(self):
+        # Return an error if the image name has multi-byte characters
+        try:
+            snapshot_name = rand_name('\xef\xbb\xbf')
+            self.assertRaises(exceptions.BadRequest,
+                              self.client.create_image, self.server['id'],
+                              snapshot_name)
+        except Exception:
+            self.fail("Should return 400 Bad Request if multi byte characters"
+                      " are used for image name")
+
+    @attr(type='negative')
+    @unittest.skip("Until Bug 1005423 is fixed")
+    def test_create_image_specify_invalid_metadata(self):
+        # Return an error when creating image with invalid metadata
+        try:
+            snapshot_name = rand_name('test-snap-')
+            meta = {'': ''}
+            self.assertRaises(exceptions.BadRequest, self.client.create_image,
+                              self.server['id'], snapshot_name, meta)
+
+        except Exception:
+            self.fail("Should raise 400 Bad Request if meta data is invalid")
+
+    @attr(type='negative')
+    @unittest.skip("Until Bug 1005423 is fixed")
+    def test_create_image_specify_metadata_over_limits(self):
+        # Return an error when creating image with meta data over 256 chars
+        try:
+            snapshot_name = rand_name('test-snap-')
+            meta = {'a' * 260: 'b' * 260}
+            self.assertRaises(exceptions.OverLimit, self.client.create_image,
+                              self.server['id'], snapshot_name, meta)
+
+        except Exception:
+            self.fail("Should raise 413 Over Limit if meta data was too long")
+
+    @attr(type='negative')
+    def test_delete_image_of_another_tenant(self):
+        # Return an error while trying to delete another tenant's image
+        self.servers_client.wait_for_server_status(self.server['id'], 'ACTIVE')
+        snapshot_name = rand_name('test-snap-')
+        resp, body = self.client.create_image(self.server['id'], snapshot_name)
+        image_id = parse_image_id(resp['location'])
+        self.image_ids.append(image_id)
+        self.client.wait_for_image_resp_code(image_id, 200)
+        self.client.wait_for_image_status(image_id, 'ACTIVE')
+
+        # Delete image
+        self.assertRaises(exceptions.NotFound,
+                          self.alt_client.delete_image, image_id)
+
+    @attr(type='smoke')
+    @unittest.skipUnless(compute.CREATE_IMAGE_ENABLED,
+                         'Environment unable to create images.')
+    def test_create_delete_image(self):
+
+        # Create a new image
+        name = rand_name('image')
+        meta = {'image_type': 'test'}
+        resp, body = self.client.create_image(self.server['id'], name, meta)
+        self.assertEqual(202, resp.status)
+        image_id = parse_image_id(resp['location'])
+        self.client.wait_for_image_resp_code(image_id, 200)
+        self.client.wait_for_image_status(image_id, 'ACTIVE')
+
+        # Verify the image was created correctly
+        resp, image = self.client.get_image(image_id)
+        self.assertEqual(name, image['name'])
+        self.assertEqual('test', image['metadata']['image_type'])
+
+        # Verify minRAM and minDisk values are the same as the original image
+        resp, original_image = self.client.get_image(self.image_ref)
+        self.assertEqual(original_image['minRam'], image['minRam'])
+        self.assertEqual(original_image['minDisk'], image['minDisk'])
+
+    @attr(type='negative')
+    def test_create_image_for_server_in_another_tenant(self):
+        # Creating image of another tenant's server should be return error
+
+        snapshot_name = rand_name('test-snap-')
+        self.assertRaises(exceptions.NotFound, self.alt_client.create_image,
+                          self.server['id'], snapshot_name)
+
+    @attr(type='negative')
+    def test_create_second_image_when_first_image_is_being_saved(self):
+        # Disallow creating another image when first image is being saved
+
+        try:
+            # Create first snapshot
+            snapshot_name = rand_name('test-snap-')
+            resp, body = self.client.create_image(self.server['id'],
+                                                  snapshot_name)
+            self.assertEqual(202, resp.status)
+            image_id = parse_image_id(resp['location'])
+            self.image_ids.append(image_id)
+
+            # Create second snapshot
+            alt_snapshot_name = rand_name('test-snap-')
+            self.client.create_image(self.server['id'],
+                                     alt_snapshot_name)
+        except exceptions.Duplicate:
+            self.client.wait_for_image_status(image_id, 'ACTIVE')
+
+        else:
+            self.fail("Should not allow creating an image when another image "
+                      "of the server is still being saved")
+
+    @attr(type='negative')
+    @unittest.skip("Until Bug 1004564 is fixed")
+    def test_create_image_specify_name_over_256_chars(self):
+        # Return an error if snapshot name over 256 characters is passed
+
+        try:
+            snapshot_name = rand_name('a' * 260)
+            self.assertRaises(exceptions.BadRequest, self.client.create_image,
+                              self.server['id'], snapshot_name)
+        except Exception:
+            self.fail("Should return 400 Bad Request if image name is over 256"
+                      " characters")
+
+    @attr(type='negative')
+    def test_delete_image_that_is_not_yet_active(self):
+        # Return an error while trying to delete an image what is creating
+
+        snapshot_name = rand_name('test-snap-')
+        resp, body = self.client.create_image(self.server['id'], snapshot_name)
+        self.assertEqual(202, resp.status)
+        image_id = parse_image_id(resp['location'])
+        self.image_ids.append(image_id)
+
+        # Do not wait, attempt to delete the image, ensure it's successful
+        resp, body = self.client.delete_image(image_id)
+        self.assertEqual('204', resp['status'])
+        self.image_ids.remove(image_id)
+
+        self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
+
+
+class ImagesOneServerTestJSON(base.BaseComputeTestJSON,
+                              ImagesOneServerTestBase):
+
+    def tearDown(self):
+        ImagesOneServerTestBase.tearDown(self)
+
+    @classmethod
+    def setUpClass(cls):
+        super(ImagesOneServerTestJSON, cls).setUpClass()
+        cls.client = cls.images_client
+        cls.servers_client = cls.servers_client
+        cls.server = cls.create_server()
+
+        cls.image_ids = []
+
+        if compute.MULTI_USER:
+            if cls.config.compute.allow_tenant_isolation:
+                creds = cls._get_isolated_creds()
+                username, tenant_name, password = creds
+                cls.alt_manager = clients.Manager(username=username,
+                                                  password=password,
+                                                  tenant_name=tenant_name)
+            else:
+                # Use the alt_XXX credentials in the config file
+                cls.alt_manager = clients.AltManager()
+            cls.alt_client = cls.alt_manager.images_client
+
+
+class ImagesOneServerTestXML(base.BaseComputeTestXML,
+                             ImagesOneServerTestBase):
+
+    def tearDown(self):
+        ImagesOneServerTestBase.tearDown(self)
+
+    @classmethod
+    def setUpClass(cls):
+        super(ImagesOneServerTestXML, cls).setUpClass()
+        cls.client = cls.images_client
+        cls.servers_client = cls.servers_client
+        cls.server = cls.create_server()
+
+        cls.image_ids = []
+
+        if compute.MULTI_USER:
+            if cls.config.compute.allow_tenant_isolation:
+                creds = cls._get_isolated_creds()
+                username, tenant_name, password = creds
+                cls.alt_manager = clients.Manager(username=username,
+                                                  password=password,
+                                                  tenant_name=tenant_name)
+            else:
+                # Use the alt_XXX credentials in the config file
+                cls.alt_manager = clients.AltManager()
+            cls.alt_client = cls.alt_manager.images_client
diff --git a/tempest/tests/compute/servers/test_list_server_filters.py b/tempest/tests/compute/servers/test_list_server_filters.py
index 5eea24f..d943e5d 100644
--- a/tempest/tests/compute/servers/test_list_server_filters.py
+++ b/tempest/tests/compute/servers/test_list_server_filters.py
@@ -208,7 +208,6 @@
                                 ListServerFiltersTest):
     @classmethod
     def setUpClass(cls):
-        raise nose.SkipTest("Until Bug 1039753 is fixed")
         super(ListServerFiltersTestJSON, cls).setUpClass()
         ListServerFiltersTest.setUpClass(cls)
 
@@ -222,7 +221,6 @@
                                ListServerFiltersTest):
     @classmethod
     def setUpClass(cls):
-        raise nose.SkipTest("Until Bug 1039753 is fixed")
         super(ListServerFiltersTestXML, cls).setUpClass()
         ListServerFiltersTest.setUpClass(cls)
 
diff --git a/tempest/tests/compute/servers/test_server_basic_ops.py b/tempest/tests/compute/servers/test_server_basic_ops.py
index 3453d86..2183193 100644
--- a/tempest/tests/compute/servers/test_server_basic_ops.py
+++ b/tempest/tests/compute/servers/test_server_basic_ops.py
@@ -37,7 +37,7 @@
      * Terminate the instance
     """
 
-    def test_001_create_keypair(self):
+    def create_keypair(self):
         kp_name = rand_name('keypair-smoke')
         self.keypair = self.compute_client.keypairs.create(kp_name)
         try:
@@ -46,7 +46,7 @@
         except AttributeError:
             self.fail("Keypair object not successfully created.")
 
-    def test_002_create_security_group(self):
+    def create_security_group(self):
         sg_name = rand_name('secgroup-smoke')
         sg_desc = sg_name + " description"
         self.secgroup = self.compute_client.security_groups.create(sg_name,
@@ -82,7 +82,7 @@
             except Exception:
                 self.fail("Failed to create rule in security group.")
 
-    def test_003_boot_instance(self):
+    def boot_instance(self):
         i_name = rand_name('instance')
         flavor_id = self.config.compute.flavor_ref
         base_image_id = self.config.compute.image_ref
@@ -99,11 +99,11 @@
 
         self.assertEqual(self.instance.status, 'BUILD')
 
-    def test_004_wait_on_active(self):
+    def wait_on_active(self):
         instance_id = self.get_resource('instance').id
         self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
 
-    def test_005_pause_server(self):
+    def pause_server(self):
         instance = self.get_resource('instance')
         instance_id = instance.id
         LOG.debug("Pausing instance %s. Current status: %s",
@@ -111,7 +111,7 @@
         instance.pause()
         self.status_timeout(self.compute_client.servers, instance_id, 'PAUSED')
 
-    def test_006_unpause_server(self):
+    def unpause_server(self):
         instance = self.get_resource('instance')
         instance_id = instance.id
         LOG.debug("Unpausing instance %s. Current status: %s",
@@ -119,7 +119,7 @@
         instance.unpause()
         self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
 
-    def test_007_suspend_server(self):
+    def suspend_server(self):
         instance = self.get_resource('instance')
         instance_id = instance.id
         LOG.debug("Suspending instance %s. Current status: %s",
@@ -128,7 +128,7 @@
         self.status_timeout(self.compute_client.servers,
                             instance_id, 'SUSPENDED')
 
-    def test_008_resume_server(self):
+    def resume_server(self):
         instance = self.get_resource('instance')
         instance_id = instance.id
         LOG.debug("Resuming instance %s. Current status: %s",
@@ -136,7 +136,18 @@
         instance.resume()
         self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
 
-    def test_099_terminate_instance(self):
+    def terminate_instance(self):
         instance = self.get_resource('instance')
         instance.delete()
         self.remove_resource('instance')
+
+    def test_server_basicops(self):
+        self.create_keypair()
+        self.create_security_group()
+        self.boot_instance()
+        self.wait_on_active()
+        self.pause_server()
+        self.unpause_server()
+        self.suspend_server()
+        self.resume_server()
+        self.terminate_instance()
diff --git a/tools/skip_tracker.py b/tools/skip_tracker.py
old mode 100644
new mode 100755
index 9b12eb7..e890e92
--- a/tools/skip_tracker.py
+++ b/tools/skip_tracker.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
 
 # Copyright 2012 OpenStack, LLC