Merge "Remove executable bit on some files"
diff --git a/run_tests.sh b/run_tests.sh
index d5b2494..366564e 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -166,11 +166,14 @@
 fi
 
 run_tests
+retval=$?
 
 if [ $nova_coverage -eq 1 ]; then
     run_coverage_report
 fi
 
 if [ -z "$noseargs" ]; then
-  run_pep8
+    run_pep8
 fi
+
+exit $retval
diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py
index 5f53080..bbe489c 100644
--- a/tempest/api/compute/servers/test_servers_negative.py
+++ b/tempest/api/compute/servers/test_servers_negative.py
@@ -236,7 +236,11 @@
         # Create a server with a nonexistent security group
 
         security_groups = [{'name': 'does_not_exist'}]
-        self.assertRaises(exceptions.BadRequest,
+        if self.config.network.quantum_available:
+            expected_exception = exceptions.NotFound
+        else:
+            expected_exception = exceptions.BadRequest
+        self.assertRaises(expected_exception,
                           self.create_server,
                           security_groups=security_groups)
 
diff --git a/tempest/api/identity/admin/v3/test_domains.py b/tempest/api/identity/admin/v3/test_domains.py
new file mode 100644
index 0000000..8d019fe
--- /dev/null
+++ b/tempest/api/identity/admin/v3/test_domains.py
@@ -0,0 +1,54 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack Foundation
+# 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.
+
+from tempest.api.identity import base
+from tempest.common.utils.data_utils import rand_name
+from tempest.test import attr
+
+
+class DomainsTestJSON(base.BaseIdentityAdminTest):
+    _interface = 'json'
+
+    def _delete_domain(self, domain_id):
+        # It is necessary to disable the domian before deleting,
+        # or else it would result in unauthorized error
+        _, body = self.v3_client.update_domain(domain_id, enabled=False)
+        resp, _ = self.v3_client.delete_domain(domain_id)
+        self.assertEqual(204, resp.status)
+
+    @attr(type='smoke')
+    def test_list_domains(self):
+        #Test to list domains
+        domain_ids = list()
+        fetched_ids = list()
+        for _ in range(3):
+            _, domain = self.v3_client.create_domain(
+                rand_name('domain-'), description=rand_name('domain-desc-'))
+            # Delete the domian at the end of this method
+            self.addCleanup(self._delete_domain, domain['id'])
+            domain_ids.append(domain['id'])
+        # List and Verify Domains
+        resp, body = self.v3_client.list_domains()
+        self.assertEqual(resp['status'], '200')
+        for d in body:
+            fetched_ids.append(d['id'])
+        missing_doms = [d for d in domain_ids if d not in fetched_ids]
+        self.assertEqual(0, len(missing_doms))
+
+
+class DomainsTestXML(DomainsTestJSON):
+    _interface = 'xml'
diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py
index d7b87d1..b40774e 100644
--- a/tempest/api/object_storage/test_account_services.py
+++ b/tempest/api/object_storage/test_account_services.py
@@ -53,27 +53,25 @@
         self.assertIn('x-account-bytes-used', resp)
 
     @attr(type='smoke')
-    def test_create_account_metadata(self):
+    def test_create_and_delete_account_metadata(self):
+        header = 'test-account-meta'
+        data = 'Meta!'
         # add metadata to account
-        metadata = {'test-account-meta': 'Meta!'}
-        resp, _ = \
-            self.account_client.create_account_metadata(metadata=metadata)
+        resp, _ = self.account_client.create_account_metadata(
+            metadata={header: data})
         self.assertEqual(resp['status'], '204')
 
-        resp, metadata = self.account_client.list_account_metadata()
-        self.assertIn('x-account-meta-test-account-meta', resp)
-        self.assertEqual(resp['x-account-meta-test-account-meta'], 'Meta!')
+        resp, _ = self.account_client.list_account_metadata()
+        self.assertIn('x-account-meta-' + header, resp)
+        self.assertEqual(resp['x-account-meta-' + header], data)
 
-    @attr(type='smoke')
-    def test_delete_account_metadata(self):
         # delete metadata from account
-        metadata = ['test-account-meta']
         resp, _ = \
-            self.account_client.delete_account_metadata(metadata=metadata)
+            self.account_client.delete_account_metadata(metadata=[header])
         self.assertEqual(resp['status'], '204')
 
-        resp, metadata = self.account_client.list_account_metadata()
-        self.assertNotIn('x-account-meta-test-account-meta', resp)
+        resp, _ = self.account_client.list_account_metadata()
+        self.assertNotIn('x-account-meta-' + header, resp)
 
     @attr(type=['negative', 'gate'])
     def test_list_containers_with_non_authorized_user(self):
diff --git a/tempest/api/object_storage/test_object_services.py b/tempest/api/object_storage/test_object_services.py
index f7d2f88..2b8feef 100644
--- a/tempest/api/object_storage/test_object_services.py
+++ b/tempest/api/object_storage/test_object_services.py
@@ -298,7 +298,6 @@
                           self.container_name, object_name,
                           metadata=self.custom_headers)
 
-    @testtools.skip('Until Bug #1097137 is resolved.')
     @attr(type='gate')
     def test_get_object_using_temp_url(self):
         # access object using temporary URL within expiration time
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index 014df1e..adbdc83 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -160,3 +160,51 @@
                               (project_id, user_id, role_id), None,
                               self.headers)
         return resp, body
+
+    def create_domain(self, name, **kwargs):
+        """Creates a domain."""
+        description = kwargs.get('description', None)
+        en = kwargs.get('enabled', True)
+        post_body = {
+            'description': description,
+            'enabled': en,
+            'name': name
+        }
+        post_body = json.dumps({'domain': post_body})
+        resp, body = self.post('domains', post_body, self.headers)
+        body = json.loads(body)
+        return resp, body['domain']
+
+    def delete_domain(self, domain_id):
+        """Delete a domain."""
+        resp, body = self.delete('domains/%s' % str(domain_id))
+        return resp, body
+
+    def list_domains(self):
+        """List Domains."""
+        resp, body = self.get('domains')
+        body = json.loads(body)
+        return resp, body['domains']
+
+    def update_domain(self, domain_id, **kwargs):
+        """Updates a domain."""
+        resp, body = self.get_domain(domain_id)
+        description = kwargs.get('description', body['description'])
+        en = kwargs.get('enabled', body['enabled'])
+        name = kwargs.get('name', body['name'])
+        post_body = {
+            'description': description,
+            'enabled': en,
+            'name': name
+        }
+        post_body = json.dumps({'domain': post_body})
+        resp, body = self.patch('domains/%s' % domain_id, post_body,
+                                self.headers)
+        body = json.loads(body)
+        return resp, body['domain']
+
+    def get_domain(self, domain_id):
+        """Get Domain details."""
+        resp, body = self.get('domains/%s' % domain_id)
+        body = json.loads(body)
+        return resp, body['domain']
diff --git a/tempest/services/identity/v3/xml/identity_client.py b/tempest/services/identity/v3/xml/identity_client.py
index 92151dd..708ee28 100644
--- a/tempest/services/identity/v3/xml/identity_client.py
+++ b/tempest/services/identity/v3/xml/identity_client.py
@@ -44,6 +44,14 @@
                 array.append(xml_to_json(child))
         return array
 
+    def _parse_domains(self, node):
+        array = []
+        for child in node.getchildren():
+            tag_list = child.tag.split('}', 1)
+            if tag_list[1] == "domain":
+                array.append(xml_to_json(child))
+        return array
+
     def _parse_array(self, node):
         array = []
         for child in node.getchildren():
@@ -185,3 +193,51 @@
         resp, body = self.put('projects/%s/users/%s/roles/%s' %
                               (project_id, user_id, role_id), '', self.headers)
         return resp, body
+
+    def create_domain(self, name, **kwargs):
+        """Creates a domain."""
+        description = kwargs.get('description', None)
+        en = kwargs.get('enabled', True)
+        post_body = Element("domain",
+                            xmlns=XMLNS,
+                            name=name,
+                            description=description,
+                            enabled=str(en).lower())
+        resp, body = self.post('domains', str(Document(post_body)),
+                               self.headers)
+        body = self._parse_body(etree.fromstring(body))
+        return resp, body
+
+    def list_domains(self):
+        """Get the list of domains."""
+        resp, body = self.get("domains", self.headers)
+        body = self._parse_domains(etree.fromstring(body))
+        return resp, body
+
+    def delete_domain(self, domain_id):
+        """Delete a domain."""
+        resp, body = self.delete('domains/%s' % domain_id, self.headers)
+        return resp, body
+
+    def update_domain(self, domain_id, **kwargs):
+        """Updates a domain."""
+        resp, body = self.get_domain(domain_id)
+        description = kwargs.get('description', body['description'])
+        en = kwargs.get('enabled', body['enabled'])
+        name = kwargs.get('name', body['name'])
+        post_body = Element("domain",
+                            xmlns=XMLNS,
+                            name=name,
+                            description=description,
+                            enabled=str(en).lower())
+        resp, body = self.patch('domains/%s' % domain_id,
+                                str(Document(post_body)),
+                                self.headers)
+        body = self._parse_body(etree.fromstring(body))
+        return resp, body
+
+    def get_domain(self, domain_id):
+        """Get Domain details."""
+        resp, body = self.get('domains/%s' % domain_id, self.headers)
+        body = self._parse_body(etree.fromstring(body))
+        return resp, body
diff --git a/tempest/thirdparty/boto/test_s3_ec2_images.py b/tempest/thirdparty/boto/test_s3_ec2_images.py
index 2c0d8ae..0f836d0 100644
--- a/tempest/thirdparty/boto/test_s3_ec2_images.py
+++ b/tempest/thirdparty/boto/test_s3_ec2_images.py
@@ -72,21 +72,22 @@
         retrieved_image = self.images_client.get_image(image["image_id"])
         self.assertTrue(retrieved_image.name == image["name"])
         self.assertTrue(retrieved_image.id == image["image_id"])
-        if retrieved_image.state != "available":
+        state = retrieved_image.state
+        if state != "available":
             def _state():
                 retr = self.images_client.get_image(image["image_id"])
                 return retr.state
             state = state_wait(_state, "available")
         self.assertEqual("available", state)
         self.images_client.deregister_image(image["image_id"])
-        #TODO(afazekas): double deregister ?
+        self.assertNotIn(image["image_id"], str(
+            self.images_client.get_all_images()))
         self.cancelResourceCleanUp(image["cleanUp"])
 
-    @testtools.skip("Skipped until the Bug #1074904 is resolved")
     def test_register_get_deregister_aki_image(self):
         # Register and deregister aki image
         image = {"name": rand_name("aki-name-"),
-                 "location": self.bucket_name + "/" + self.ari_manifest,
+                 "location": self.bucket_name + "/" + self.aki_manifest,
                  "type": "aki"}
         image["image_id"] = self.images_client.register_image(
             name=image["name"],
@@ -102,9 +103,8 @@
         if retrieved_image.state != "available":
             self.assertImageStateWait(retrieved_image, "available")
         self.images_client.deregister_image(image["image_id"])
-        #TODO(afazekas): verify deregister in  a better way
-        retrieved_image = self.images_client.get_image(image["image_id"])
-        self.assertIn(retrieved_image.state, self.valid_image_state)
+        self.assertNotIn(image["image_id"], str(
+            self.images_client.get_all_images()))
         self.cancelResourceCleanUp(image["cleanUp"])
 
     @testtools.skip("Skipped until the Bug #1074908 and #1074904 is resolved")
diff --git a/tools/skip_tracker.py b/tools/skip_tracker.py
index a4cf394..c7b0033 100755
--- a/tools/skip_tracker.py
+++ b/tools/skip_tracker.py
@@ -28,7 +28,7 @@
 from launchpadlib import launchpad
 
 BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
-TESTDIR = os.path.join(BASEDIR, 'tempest', 'tests')
+TESTDIR = os.path.join(BASEDIR, 'tempest')
 LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')