Merge "Actually raise BadRequest if create_subnet fails"
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 915e2fa..617c016 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -14,9 +14,6 @@
 uri = http://127.0.0.1:5000/v2.0/
 # URL for where to find the OpenStack V3 Identity API endpoint (Keystone)
 uri_v3 = http://127.0.0.1:5000/v3/
-# Should typically be left as keystone unless you have a non-Keystone
-# authentication API service
-strategy = keystone
 # The identity region
 region = RegionOne
 
diff --git a/requirements.txt b/requirements.txt
index 19d6e0b..df9951d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,7 +3,7 @@
 anyjson
 nose
 httplib2>=0.7.0
-testtools>=0.9.29
+testtools>=0.9.32
 lxml
 boto>=2.2.1
 paramiko
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 0fa5a84..abc5899 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -20,6 +20,7 @@
 from tempest.api import compute
 from tempest import clients
 from tempest.common import log as logging
+from tempest.common.utils.data_utils import parse_image_id
 from tempest.common.utils.data_utils import rand_name
 from tempest import exceptions
 import tempest.test
@@ -73,6 +74,7 @@
         cls.flavor_ref = cls.config.compute.flavor_ref
         cls.flavor_ref_alt = cls.config.compute.flavor_ref_alt
         cls.servers = []
+        cls.images = []
 
         cls.servers_client_v3_auth = os.servers_client_v3_auth
 
@@ -174,7 +176,18 @@
                 pass
 
     @classmethod
+    def clear_images(cls):
+        for image_id in cls.images:
+            try:
+                cls.images_client.delete_image(image_id)
+            except Exception as exc:
+                LOG.info('Exception raised deleting image %s', image_id)
+                LOG.exception(exc)
+                pass
+
+    @classmethod
     def tearDownClass(cls):
+        cls.clear_images()
         cls.clear_servers()
         cls.clear_isolated_creds()
 
@@ -206,6 +219,25 @@
 
         return resp, body
 
+    @classmethod
+    def create_image_from_server(cls, server_id, **kwargs):
+        """Wrapper utility that returns a test server."""
+        name = rand_name(cls.__name__ + "-image")
+        if 'name' in kwargs:
+            name = kwargs.pop('name')
+
+        resp, image = cls.images_client.create_image(
+            server_id, name)
+        image_id = parse_image_id(resp['location'])
+        cls.images.append(image_id)
+
+        if 'wait_until' in kwargs:
+            cls.images_client.wait_for_image_status(image_id,
+                                                    kwargs['wait_until'])
+            resp, image = cls.images_client.get_image(image_id)
+
+        return resp, image
+
     def wait_for(self, condition):
         """Repeatedly calls condition() until a timeout."""
         start_time = int(time.time())
diff --git a/tempest/api/compute/images/test_list_image_filters.py b/tempest/api/compute/images/test_list_image_filters.py
index 9db28ad..5c6b630 100644
--- a/tempest/api/compute/images/test_list_image_filters.py
+++ b/tempest/api/compute/images/test_list_image_filters.py
@@ -16,12 +16,15 @@
 #    under the License.
 
 from tempest.api.compute import base
+from tempest.common import log as logging
 from tempest.common.utils.data_utils import parse_image_id
-from tempest.common.utils.data_utils import rand_name
 from tempest import exceptions
 from tempest.test import attr
 
 
+LOG = logging.getLogger(__name__)
+
+
 class ListImageFiltersTestJSON(base.BaseComputeTest):
     _interface = 'json'
 
@@ -29,6 +32,7 @@
     def setUpClass(cls):
         super(ListImageFiltersTestJSON, cls).setUpClass()
         cls.client = cls.images_client
+        cls.image_ids = []
 
         try:
             resp, cls.server1 = cls.create_server()
@@ -38,9 +42,7 @@
                                                       'ACTIVE')
 
             # Create images to be used in the filter tests
-            image1_name = rand_name('image')
-            resp, body = cls.client.create_image(cls.server1['id'],
-                                                 image1_name)
+            resp, body = cls.create_image_from_server(cls.server1['id'])
             cls.image1_id = parse_image_id(resp['location'])
             cls.client.wait_for_image_resp_code(cls.image1_id, 200)
             cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
@@ -49,35 +51,23 @@
             # Servers have a hidden property for when they are being imaged
             # Performing back-to-back create image calls on a single
             # server will sometimes cause failures
-            image3_name = rand_name('image')
-            resp, body = cls.client.create_image(cls.server2['id'],
-                                                 image3_name)
+            resp, body = cls.create_image_from_server(cls.server2['id'])
             cls.image3_id = parse_image_id(resp['location'])
             cls.client.wait_for_image_resp_code(cls.image3_id, 200)
             cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
             resp, cls.image3 = cls.client.get_image(cls.image3_id)
 
-            image2_name = rand_name('image')
-            resp, body = cls.client.create_image(cls.server1['id'],
-                                                 image2_name)
+            resp, body = cls.create_image_from_server(cls.server1['id'])
             cls.image2_id = parse_image_id(resp['location'])
             cls.client.wait_for_image_resp_code(cls.image2_id, 200)
+
             cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
             resp, cls.image2 = cls.client.get_image(cls.image2_id)
-        except Exception:
-            cls.clear_servers()
-            cls.client.delete_image(cls.image1_id)
-            cls.client.delete_image(cls.image2_id)
-            cls.client.delete_image(cls.image3_id)
+        except Exception as exc:
+            LOG.exception(exc)
+            cls.tearDownClass()
             raise
 
-    @classmethod
-    def tearDownClass(cls):
-        cls.client.delete_image(cls.image1_id)
-        cls.client.delete_image(cls.image2_id)
-        cls.client.delete_image(cls.image3_id)
-        super(ListImageFiltersTestJSON, cls).tearDownClass()
-
     @attr(type=['negative', 'gate'])
     def test_get_image_not_existing(self):
         # Check raises a NotFound
diff --git a/tempest/api/orchestration/stacks/test_stacks.py b/tempest/api/orchestration/stacks/test_stacks.py
index 8847c08..5fed581 100644
--- a/tempest/api/orchestration/stacks/test_stacks.py
+++ b/tempest/api/orchestration/stacks/test_stacks.py
@@ -45,19 +45,19 @@
 
         # count how many stacks to start with
         resp, body = self.client.list_stacks()
-        stack_count = len(body['stacks'])
 
         # create the stack
         stack_identifier = self.create_stack(
             stack_name, self.empty_template)
+        stack_id = stack_identifier.split('/')[1]
 
         # wait for create complete (with no resources it should be instant)
         self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
 
-        # stack count will increment by 1
+        # check for stack in list
         resp, body = self.client.list_stacks()
-        self.assertEqual(stack_count + 1, len(body['stacks']),
-                         'Expected stack count to increment by 1')
+        list_ids = list([stack['id'] for stack in body['stacks']])
+        self.assertIn(stack_id, list_ids)
 
         # fetch the stack
         resp, body = self.client.get_stack(stack_identifier)
@@ -68,7 +68,6 @@
         self.assertEqual('CREATE_COMPLETE', body['stack_status'])
 
         # fetch the stack by id
-        stack_id = stack_identifier.split('/')[1]
         resp, body = self.client.get_stack(stack_id)
         self.assertEqual('CREATE_COMPLETE', body['stack_status'])
 
diff --git a/tempest/clients.py b/tempest/clients.py
index e778dc1..a5c7b4d 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -274,22 +274,15 @@
         self.auth_url = self.config.identity.uri
         self.auth_url_v3 = self.config.identity.uri_v3
 
-        if self.config.identity.strategy == 'keystone':
-            client_args = (self.config, self.username, self.password,
-                           self.auth_url, self.tenant_name)
+        client_args = (self.config, self.username, self.password,
+                       self.auth_url, self.tenant_name)
 
-            if self.auth_url_v3:
-                auth_version = 'v3'
-                client_args_v3_auth = (self.config, self.username,
-                                       self.password, self.auth_url_v3,
-                                       self.tenant_name, auth_version)
-            else:
-                client_args_v3_auth = None
-
+        if self.auth_url_v3:
+            auth_version = 'v3'
+            client_args_v3_auth = (self.config, self.username,
+                                   self.password, self.auth_url_v3,
+                                   self.tenant_name, auth_version)
         else:
-            client_args = (self.config, self.username, self.password,
-                           self.auth_url)
-
             client_args_v3_auth = None
 
         try:
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index baa3c03..531dfc8 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -51,7 +51,6 @@
         self.base_url = None
         self.region = {'compute': self.config.identity.region}
         self.endpoint_url = 'publicURL'
-        self.strategy = self.config.identity.strategy
         self.headers = {'Content-Type': 'application/%s' % self.TYPE,
                         'Accept': 'application/%s' % self.TYPE}
         self.build_interval = config.compute.build_interval
@@ -72,21 +71,14 @@
         Sets the token and base_url used in requests based on the strategy type
         """
 
-        if self.strategy == 'keystone':
-
-            if self.auth_version == 'v3':
-                auth_func = self.identity_auth_v3
-            else:
-                auth_func = self.keystone_auth
-
-            self.token, self.base_url = (
-                auth_func(self.user, self.password, self.auth_url,
-                          self.service, self.tenant_name))
-
+        if self.auth_version == 'v3':
+            auth_func = self.identity_auth_v3
         else:
-            self.token, self.base_url = self.basic_auth(self.user,
-                                                        self.password,
-                                                        self.auth_url)
+            auth_func = self.keystone_auth
+
+        self.token, self.base_url = (
+            auth_func(self.user, self.password, self.auth_url,
+                      self.service, self.tenant_name))
 
     def clear_auth(self):
         """
diff --git a/tempest/config.py b/tempest/config.py
index 85be7a6..7852eba 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -40,10 +40,6 @@
                help="Full URI of the OpenStack Identity API (Keystone), v2"),
     cfg.StrOpt('uri_v3',
                help='Full URI of the OpenStack Identity API (Keystone), v3'),
-    cfg.StrOpt('strategy',
-               default='keystone',
-               help="Which auth method does the environment use? "
-                    "(basic|keystone)"),
     cfg.StrOpt('region',
                default='RegionOne',
                help="The identity region name to use."),
diff --git a/tempest/manager.py b/tempest/manager.py
index 762bc18..4a447f3 100644
--- a/tempest/manager.py
+++ b/tempest/manager.py
@@ -115,11 +115,8 @@
         if 'tokens' not in auth_url:
             auth_url = auth_url.rstrip('/') + '/tokens'
 
-        if self.config.identity.strategy == 'keystone':
-            client_args = (self.config, username, password, auth_url,
-                           tenant_name)
-        else:
-            client_args = (self.config, username, password, auth_url)
+        client_args = (self.config, username, password, auth_url,
+                       tenant_name)
 
         self.servers_client = ServersClient(*client_args)
         self.flavors_client = FlavorsClient(*client_args)
diff --git a/tempest/services/compute/xml/security_groups_client.py b/tempest/services/compute/xml/security_groups_client.py
index 08b381c..5d86790 100644
--- a/tempest/services/compute/xml/security_groups_client.py
+++ b/tempest/services/compute/xml/security_groups_client.py
@@ -97,29 +97,20 @@
         group_id : ID of the Source group
         """
         group_rule = Element("security_group_rule")
-        parent_group = Element("parent_group_id")
-        parent_group.append(Text(content=parent_group_id))
-        ip_protocol = Element("ip_protocol")
-        ip_protocol.append(Text(content=ip_proto))
-        from_port_num = Element("from_port")
-        from_port_num.append(Text(content=str(from_port)))
-        to_port_num = Element("to_port")
-        to_port_num.append(Text(content=str(to_port)))
 
-        cidr = kwargs.get('cidr')
-        if cidr is not None:
-            cidr_num = Element("cidr")
-            cidr_num.append(Text(content=cidr))
+        elements = dict()
+        elements['cidr'] = kwargs.get('cidr')
+        elements['group_id'] = kwargs.get('group_id')
+        elements['parent_group_id'] = parent_group_id
+        elements['ip_protocol'] = ip_proto
+        elements['from_port'] = from_port
+        elements['to_port'] = to_port
 
-        group_id = kwargs.get('group_id')
-        if group_id is not None:
-            group_id_num = Element("group_id")
-            group_id_num.append(Text(content=group_id))
-
-        group_rule.append(parent_group)
-        group_rule.append(ip_protocol)
-        group_rule.append(from_port_num)
-        group_rule.append(to_port_num)
+        for k, v in elements.items():
+            if v is not None:
+                element = Element(k)
+                element.append(Text(content=str(v)))
+                group_rule.append(element)
 
         url = 'os-security-group-rules'
         resp, body = self.post(url, str(Document(group_rule)), self.headers)
diff --git a/tempest/services/object_storage/object_client.py b/tempest/services/object_storage/object_client.py
index 69df472..c894612 100644
--- a/tempest/services/object_storage/object_client.py
+++ b/tempest/services/object_storage/object_client.py
@@ -34,8 +34,11 @@
     def create_object(self, container, object_name, data):
         """Create storage object."""
 
+        headers = dict(self.headers)
+        if not data:
+            headers['content-length'] = '0'
         url = "%s/%s" % (str(container), str(object_name))
-        resp, body = self.put(url, data, self.headers)
+        resp, body = self.put(url, data, headers)
         return resp, body
 
     def update_object(self, container, object_name, data):
@@ -194,6 +197,8 @@
             for key in metadata:
                 headers[str(key)] = metadata[key]
 
+        if not data:
+            headers['content-length'] = '0'
         url = "%s/%s" % (str(container), str(object_name))
         resp, body = self.put(url, data, headers=headers)
         return resp, body
diff --git a/test-requirements.txt b/test-requirements.txt
index 27851da..3912695 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -3,8 +3,6 @@
 pyflakes==0.7.2
 flake8==2.0
 hacking>=0.5.3,<0.6
-#
-#TODO(afazekas): ensure pg_config installed
 psycopg2
 # needed for doc build
 sphinx>=1.1.2
diff --git a/tox.ini b/tox.ini
index 634b7df..caa9403 100644
--- a/tox.ini
+++ b/tox.ini
@@ -59,7 +59,7 @@
 commands =
    python -m tools/tempest_coverage -c start --combine
    nosetests --logging-format '%(asctime)-15s %(message)s' --with-xunit --xunit-file=nosetests-full.xml -sv tempest/api tempest/scenario tempest/thirdparty tempest/cli
-   python -m tools/tempest_coverage -c report --html
+   python -m tools/tempest_coverage -c report --html {posargs}
 
 [testenv:venv]
 commands = {posargs}