Merge "Fix race condition in flavor tests"
diff --git a/tempest/api/baremetal/test_nodes.py b/tempest/api/baremetal/test_nodes.py
index b6432ad..1572840 100644
--- a/tempest/api/baremetal/test_nodes.py
+++ b/tempest/api/baremetal/test_nodes.py
@@ -87,3 +87,11 @@
         resp, node = self.client.show_node(node['uuid'])
         self.assertEqual('200', resp['status'])
         self._assertExpected(new_p, node['properties'])
+
+    @test.attr(type='smoke')
+    def test_validate_driver_interface(self):
+        resp, body = self.client.validate_driver_interface(self.node['uuid'])
+        self.assertEqual('200', resp['status'])
+        core_interfaces = ['power', 'deploy']
+        for interface in core_interfaces:
+            self.assertIn(interface, body)
diff --git a/tempest/api/baremetal/test_ports.py b/tempest/api/baremetal/test_ports.py
index c2af29a..4ac7e29 100644
--- a/tempest/api/baremetal/test_ports.py
+++ b/tempest/api/baremetal/test_ports.py
@@ -145,6 +145,19 @@
             self.validate_self_link('ports', port['uuid'],
                                     port['links'][0]['href'])
 
+    def test_list_ports_details_with_address(self):
+        node_id = self.node['uuid']
+        address = data_utils.rand_mac_address()
+        self.create_port(node_id=node_id, address=address)
+        for i in range(0, 5):
+            self.create_port(node_id=node_id,
+                             address=data_utils.rand_mac_address())
+
+        resp, body = self.client.list_ports_detail(address=address)
+        self.assertEqual(200, resp.status)
+        self.assertEqual(1, len(body['ports']))
+        self.assertEqual(address, body['ports'][0]['address'])
+
     @test.attr(type='smoke')
     def test_update_port_replace(self):
         node_id = self.node['uuid']
diff --git a/tempest/api/compute/test_authorization.py b/tempest/api/compute/test_authorization.py
index 375ddf8..fb8ded3 100644
--- a/tempest/api/compute/test_authorization.py
+++ b/tempest/api/compute/test_authorization.py
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import StringIO
+
 from tempest.api.compute import base
 from tempest import clients
 from tempest.common.utils import data_utils
@@ -27,9 +29,10 @@
 
 
 class AuthorizationTestJSON(base.BaseV2ComputeTest):
-
     @classmethod
     def setUpClass(cls):
+        if not CONF.service_available.glance:
+            raise cls.skipException('Glance is not available.')
         # No network resources required for this test
         cls.set_network_resources()
         super(AuthorizationTestJSON, cls).setUpClass()
@@ -38,6 +41,7 @@
             raise cls.skipException(msg)
         cls.client = cls.os.servers_client
         cls.images_client = cls.os.images_client
+        cls.glance_client = cls.os.image_client
         cls.keypairs_client = cls.os.keypairs_client
         cls.security_client = cls.os.security_groups_client
 
@@ -57,9 +61,14 @@
         resp, cls.server = cls.client.get_server(server['id'])
 
         name = data_utils.rand_name('image')
-        resp, body = cls.images_client.create_image(server['id'], name)
-        image_id = data_utils.parse_image_id(resp['location'])
-        cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
+        resp, body = cls.glance_client.create_image(name=name,
+                                                   container_format='bare',
+                                                   disk_format='raw',
+                                                   is_public=False)
+        image_id = body['id']
+        image_file = StringIO.StringIO(('*' * 1024))
+        resp, body = cls.glance_client.update_image(image_id, data=image_file)
+        cls.glance_client.wait_for_image_status(image_id, 'active')
         resp, cls.image = cls.images_client.get_image(image_id)
 
         cls.keypairname = data_utils.rand_name('keypair')
diff --git a/tempest/api/data_processing/base.py b/tempest/api/data_processing/base.py
index 0d6773c..ab0e83a 100644
--- a/tempest/api/data_processing/base.py
+++ b/tempest/api/data_processing/base.py
@@ -29,8 +29,8 @@
         if not CONF.service_available.sahara:
             raise cls.skipException('Sahara support is required')
 
-        os = cls.get_client_manager()
-        cls.client = os.data_processing_client
+        cls.os = cls.get_client_manager()
+        cls.client = cls.os.data_processing_client
 
         cls.flavor_ref = CONF.compute.flavor_ref
 
diff --git a/tempest/api/data_processing/test_job_binaries.py b/tempest/api/data_processing/test_job_binaries.py
new file mode 100644
index 0000000..689c1fe
--- /dev/null
+++ b/tempest/api/data_processing/test_job_binaries.py
@@ -0,0 +1,148 @@
+# Copyright (c) 2014 Mirantis Inc.
+#
+#    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.data_processing import base as dp_base
+from tempest.common.utils import data_utils
+from tempest import test
+
+
+class JobBinaryTest(dp_base.BaseDataProcessingTest):
+    """Link to the API documentation is http://docs.openstack.org/developer/
+    sahara/restapi/rest_api_v1.1_EDP.html#job-binaries
+    """
+    @classmethod
+    @test.safe_setup
+    def setUpClass(cls):
+        super(JobBinaryTest, cls).setUpClass()
+        cls.swift_job_binary_with_extra = {
+            'url': 'swift://sahara-container.sahara/example.jar',
+            'description': 'Test job binary',
+            'extra': {
+                'user': cls.os.credentials.username,
+                'password': cls.os.credentials.password
+            }
+        }
+        # Create extra cls.swift_job_binary variable to use for comparison to
+        # job binary response body because response body has no 'extra' field.
+        cls.swift_job_binary = cls.swift_job_binary_with_extra.copy()
+        del cls.swift_job_binary['extra']
+
+        name = data_utils.rand_name('sahara-internal-job-binary')
+        cls.job_binary_data = 'Some script may be data'
+        job_binary_internal = cls.create_job_binary_internal(
+            name, cls.job_binary_data)[1]
+        cls.internal_db_job_binary = {
+            'url': 'internal-db://%s' % job_binary_internal['id'],
+            'description': 'Test job binary',
+        }
+
+    def _create_job_binary(self, binary_body, binary_name=None):
+        """Creates Job Binary with optional name specified.
+
+        It creates a link to data (jar, pig files, etc.) and ensures response
+        status, job binary name and response body. Returns id and name of
+        created job binary. Data may not exist when using Swift
+        as data storage. In other cases data must exist in storage.
+        """
+        if not binary_name:
+            # generate random name if it's not specified
+            binary_name = data_utils.rand_name('sahara-job-binary')
+
+        # create job binary
+        resp, body = self.create_job_binary(binary_name, **binary_body)
+
+        # ensure that binary created successfully
+        self.assertEqual(202, resp.status)
+        self.assertEqual(binary_name, body['name'])
+        if 'swift' in binary_body['url']:
+            binary_body = self.swift_job_binary
+        self.assertDictContainsSubset(binary_body, body)
+
+        return body['id'], binary_name
+
+    @test.attr(type='smoke')
+    def test_swift_job_binary_create(self):
+        self._create_job_binary(self.swift_job_binary_with_extra)
+
+    @test.attr(type='smoke')
+    def test_swift_job_binary_list(self):
+        binary_info = self._create_job_binary(self.swift_job_binary_with_extra)
+
+        # check for job binary in list
+        resp, binaries = self.client.list_job_binaries()
+        self.assertEqual(200, resp.status)
+        binaries_info = [(binary['id'], binary['name']) for binary in binaries]
+        self.assertIn(binary_info, binaries_info)
+
+    @test.attr(type='smoke')
+    def test_swift_job_binary_get(self):
+        binary_id, binary_name = self._create_job_binary(
+            self.swift_job_binary_with_extra)
+
+        # check job binary fetch by id
+        resp, binary = self.client.get_job_binary(binary_id)
+        self.assertEqual(200, resp.status)
+        self.assertEqual(binary_name, binary['name'])
+        self.assertDictContainsSubset(self.swift_job_binary, binary)
+
+    @test.attr(type='smoke')
+    def test_swift_job_binary_delete(self):
+        binary_id = self._create_job_binary(
+            self.swift_job_binary_with_extra)[0]
+
+        # delete the job binary by id
+        resp = self.client.delete_job_binary(binary_id)[0]
+        self.assertEqual(204, resp.status)
+
+    @test.attr(type='smoke')
+    def test_internal_db_job_binary_create(self):
+        self._create_job_binary(self.internal_db_job_binary)
+
+    @test.attr(type='smoke')
+    def test_internal_db_job_binary_list(self):
+        binary_info = self._create_job_binary(self.internal_db_job_binary)
+
+        # check for job binary in list
+        resp, binaries = self.client.list_job_binaries()
+        self.assertEqual(200, resp.status)
+        binaries_info = [(binary['id'], binary['name']) for binary in binaries]
+        self.assertIn(binary_info, binaries_info)
+
+    @test.attr(type='smoke')
+    def test_internal_db_job_binary_get(self):
+        binary_id, binary_name = self._create_job_binary(
+            self.internal_db_job_binary)
+
+        # check job binary fetch by id
+        resp, binary = self.client.get_job_binary(binary_id)
+        self.assertEqual(200, resp.status)
+        self.assertEqual(binary_name, binary['name'])
+        self.assertDictContainsSubset(self.internal_db_job_binary, binary)
+
+    @test.attr(type='smoke')
+    def test_internal_db_job_binary_delete(self):
+        binary_id = self._create_job_binary(self.internal_db_job_binary)[0]
+
+        # delete the job binary by id
+        resp = self.client.delete_job_binary(binary_id)[0]
+        self.assertEqual(204, resp.status)
+
+    @test.attr(type='smoke')
+    def test_job_binary_get_data(self):
+        binary_id = self._create_job_binary(self.internal_db_job_binary)[0]
+
+        # get data of job binary by id
+        resp, data = self.client.get_job_binary_data(binary_id)
+        self.assertEqual(200, resp.status)
+        self.assertEqual(data, self.job_binary_data)
diff --git a/tempest/api/identity/admin/v3/test_endpoints.py b/tempest/api/identity/admin/v3/test_endpoints.py
index dd3b576..881f69e 100644
--- a/tempest/api/identity/admin/v3/test_endpoints.py
+++ b/tempest/api/identity/admin/v3/test_endpoints.py
@@ -108,22 +108,22 @@
         s_name = data_utils.rand_name('service-')
         s_type = data_utils.rand_name('type--')
         s_description = data_utils.rand_name('description-')
-        resp, self.service2 =\
+        resp, service2 =\
             self.service_client.create_service(s_name, s_type,
                                                description=s_description)
-        self.service_ids.append(self.service2['id'])
+        self.service_ids.append(service2['id'])
         # Updating endpoint with new values
         region2 = data_utils.rand_name('region')
         url2 = data_utils.rand_name('url')
         interface2 = 'internal'
         resp, endpoint = \
             self.client.update_endpoint(endpoint_for_update['id'],
-                                        service_id=self.service2['id'],
+                                        service_id=service2['id'],
                                         interface=interface2, url=url2,
                                         region=region2, enabled=False)
         self.assertEqual(resp['status'], '200')
         # Asserting if the attributes of endpoint are updated
-        self.assertEqual(self.service2['id'], endpoint['service_id'])
+        self.assertEqual(service2['id'], endpoint['service_id'])
         self.assertEqual(interface2, endpoint['interface'])
         self.assertEqual(url2, endpoint['url'])
         self.assertEqual(region2, endpoint['region'])
diff --git a/tempest/scenario/test_load_balancer_basic.py b/tempest/scenario/test_load_balancer_basic.py
index 03cfef5..826da48 100644
--- a/tempest/scenario/test_load_balancer_basic.py
+++ b/tempest/scenario/test_load_balancer_basic.py
@@ -14,7 +14,6 @@
 #    under the License.
 
 
-import httplib
 import tempfile
 import time
 import urllib2
@@ -150,7 +149,10 @@
                 private_key=private_key)
 
             # Write a backend's responce into a file
-            resp = """HTTP/1.0 200 OK\r\nContent-Length: 8\r\n\r\n%s"""
+            resp = """echo -ne "HTTP/1.1 200 OK\r\nContent-Length: 7\r\n""" \
+                   """Connection: close\r\nContent-Type: text/html; """ \
+                   """charset=UTF-8\r\n\r\n%s"; cat >/dev/null"""
+
             with tempfile.NamedTemporaryFile() as script:
                 script.write(resp % server_name)
                 script.flush()
@@ -158,15 +160,17 @@
                     key.write(private_key)
                     key.flush()
                     commands.copy_file_to_host(script.name,
-                                               "~/script1",
+                                               "/tmp/script1",
                                                ip,
                                                username, key.name)
+
             # Start netcat
-            start_server = """sudo nc -ll -p %(port)s -e cat """ \
-                           """~/%(script)s &"""
+            start_server = """sudo nc -ll -p %(port)s -e sh """ \
+                           """/tmp/%(script)s &"""
             cmd = start_server % {'port': self.port1,
                                   'script': 'script1'}
             ssh_client.exec_command(cmd)
+
             if len(self.server_ips) == 1:
                 with tempfile.NamedTemporaryFile() as script:
                     script.write(resp % 'server2')
@@ -175,7 +179,7 @@
                         key.write(private_key)
                         key.flush()
                         commands.copy_file_to_host(script.name,
-                                                   "~/script2", ip,
+                                                   "/tmp/script2", ip,
                                                    username, key.name)
                 cmd = start_server % {'port': self.port2,
                                       'script': 'script2'}
@@ -281,19 +285,14 @@
     def _send_requests(self, vip_ip, expected, num_req=10):
         count = 0
         while count < num_req:
-            try:
-                resp = []
-                for i in range(len(self.members)):
-                    resp.append(
-                        urllib2.urlopen(
-                            "http://{0}/".format(vip_ip)).read())
-                count += 1
-                self.assertEqual(expected,
-                                 set(resp))
-            # NOTE: There always is a slim chance of getting this exception
-            #       due to special aspects of haproxy internal behavior.
-            except httplib.BadStatusLine:
-                pass
+            resp = []
+            for i in range(len(self.members)):
+                resp.append(
+                    urllib2.urlopen(
+                        "http://{0}/".format(vip_ip)).read())
+            count += 1
+            self.assertEqual(expected,
+                             set(resp))
 
     @test.attr(type='smoke')
     @test.services('compute', 'network')
diff --git a/tempest/services/baremetal/base.py b/tempest/services/baremetal/base.py
index 321b08b..f98ecff 100644
--- a/tempest/services/baremetal/base.py
+++ b/tempest/services/baremetal/base.py
@@ -122,7 +122,7 @@
 
         return resp, self.deserialize(body)
 
-    def _show_request(self, resource, uuid, permanent=False):
+    def _show_request(self, resource, uuid, permanent=False, **kwargs):
         """
         Gets a specific object of the specified type.
 
@@ -130,7 +130,10 @@
         :return: Serialized object as a dictionary.
 
         """
-        uri = self._get_uri(resource, uuid=uuid, permanent=permanent)
+        if 'uri' in kwargs:
+            uri = kwargs['uri']
+        else:
+            uri = self._get_uri(resource, uuid=uuid, permanent=permanent)
         resp, body = self.get(uri)
 
         return resp, self.deserialize(body)
diff --git a/tempest/services/baremetal/v1/base_v1.py b/tempest/services/baremetal/v1/base_v1.py
index 52479b5..61342eb 100644
--- a/tempest/services/baremetal/v1/base_v1.py
+++ b/tempest/services/baremetal/v1/base_v1.py
@@ -47,9 +47,9 @@
         return self._list_request('/nodes/%s/states' % uuid)
 
     @base.handle_errors
-    def list_ports_detail(self):
+    def list_ports_detail(self, **kwargs):
         """Details list all existing ports."""
-        return self._list_request('/ports/detail')
+        return self._list_request('/ports/detail', **kwargs)
 
     @base.handle_errors
     def list_drivers(self):
@@ -239,3 +239,19 @@
         target = {'target': state}
         return self._put_request('nodes/%s/states/power' % node_uuid,
                                  target)
+
+    @base.handle_errors
+    def validate_driver_interface(self, node_uuid):
+        """
+        Get all driver interfaces of a specific node.
+
+        :param uuid: Unique identifier of the node in UUID format.
+
+        """
+
+        uri = '{pref}/{res}/{uuid}/{postf}'.format(pref=self.uri_prefix,
+                                                   res='nodes',
+                                                   uuid=node_uuid,
+                                                   postf='validate')
+
+        return self._show_request('nodes', node_uuid, uri=uri)
diff --git a/tox.ini b/tox.ini
index 73546ec..7f69fad 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = pep8
+envlist = pep8,py27
 minversion = 1.6
 skipsdist = True