]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Move integrated tests to 'functional' directory
authorIvan Kolodyazhny <e0ne@e0ne.info>
Thu, 14 Jan 2016 20:20:56 +0000 (22:20 +0200)
committerIvan Kolodyazhny <e0ne@e0ne.info>
Tue, 9 Feb 2016 21:28:27 +0000 (23:28 +0200)
Functional unit tests should not be a part of unit
tests job. This patch adds new tox environment to run
functional tests:
    $ tox -e functional

It also removes logging from functional tests. Some of log calls were
replaced with asserts.

Related Implements: blueprint cinder-integrated-tests

Change-Id: I0ebfef2fe05f502cd5fb08fbc8af09008949e457

13 files changed:
.testr.conf
cinder/tests/functional/__init__.py [moved from cinder/tests/unit/api/extensions/__init__.py with 100% similarity]
cinder/tests/functional/api/__init__.py [moved from cinder/tests/unit/integrated/api/__init__.py with 100% similarity]
cinder/tests/functional/api/client.py [moved from cinder/tests/unit/integrated/api/client.py with 92% similarity]
cinder/tests/functional/api/foxinsocks.py [moved from cinder/tests/unit/api/extensions/foxinsocks.py with 100% similarity]
cinder/tests/functional/functional_helpers.py [moved from cinder/tests/unit/integrated/integrated_helpers.py with 89% similarity]
cinder/tests/functional/test_extensions.py [moved from cinder/tests/unit/api/test_extensions.py with 90% similarity]
cinder/tests/functional/test_login.py [moved from cinder/tests/unit/integrated/test_login.py with 74% similarity]
cinder/tests/functional/test_volumes.py [moved from cinder/tests/unit/integrated/test_volumes.py with 88% similarity]
cinder/tests/functional/test_xml.py [moved from cinder/tests/unit/integrated/test_xml.py with 86% similarity]
cinder/tests/unit/integrated/__init__.py [deleted file]
cinder/tests/unit/integrated/test_extensions.py [deleted file]
tox.ini

index 8e23325b5ba120aa24cba647e4996be4a3d30820..f706ba7f8b7cb7605cbbd714fed2954c9b208313 100644 (file)
@@ -2,7 +2,7 @@
 test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
              OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
              OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
-             ${PYTHON:-python} -m subunit.run discover -t ./ ./cinder/tests $LISTOPT $IDOPTION
+             ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./cinder/tests/unit}  $LISTOPT $IDOPTION
 
 test_id_option=--load-list $IDFILE
 test_list_option=--list
similarity index 92%
rename from cinder/tests/unit/integrated/api/client.py
rename to cinder/tests/functional/api/client.py
index 3010a0bce1f64d748a2f3fb4998b4eda24b97379..8414218141715097fc05001f7a80b575ba2a2609 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-from oslo_log import log as logging
 from oslo_serialization import jsonutils
 from oslo_utils import netutils
 import requests
 from six.moves import urllib
 
-from cinder.i18n import _, _LI
-
-
-LOG = logging.getLogger(__name__)
+from cinder.i18n import _
 
 
 class OpenStackApiException(Exception):
@@ -94,10 +90,6 @@ class TestOpenStackClient(object):
         relative_url = parsed_url.path
         if parsed_url.query:
             relative_url = relative_url + "?" + parsed_url.query
-        LOG.info(_LI("Doing %(method)s on %(relative_url)s"),
-                 {'method': method, 'relative_url': relative_url})
-        if body:
-            LOG.info(_LI("Body: %s") % body)
 
         if port:
             _url = "%s://%s:%d%s" % (scheme, hostname, int(port), relative_url)
@@ -121,8 +113,6 @@ class TestOpenStackClient(object):
                                 headers=headers)
 
         http_status = response.status_code
-        LOG.debug("%(auth_uri)s => code %(http_status)s",
-                  {'auth_uri': auth_uri, 'http_status': http_status})
 
         if http_status == 401:
             raise OpenStackApiAuthenticationException(response=response)
@@ -144,8 +134,6 @@ class TestOpenStackClient(object):
         response = self.request(full_uri, **kwargs)
 
         http_status = response.status_code
-        LOG.debug("%(relative_uri)s => code %(http_status)s",
-                  {'relative_uri': relative_uri, 'http_status': http_status})
 
         if check_response_status:
             if http_status not in check_response_status:
@@ -162,7 +150,6 @@ class TestOpenStackClient(object):
 
     def _decode_json(self, response):
         body = response.text
-        LOG.debug("Decoding JSON: %s" % (body))
         if body:
             return jsonutils.loads(body)
         else:
similarity index 89%
rename from cinder/tests/unit/integrated/integrated_helpers.py
rename to cinder/tests/functional/functional_helpers.py
index 42661bf002dad244493a09ec71f78b6b8424793d..81f199004f333d151ca4dc5820e5cb08c2077f98 100644 (file)
@@ -14,7 +14,7 @@
 #    under the License.
 
 """
-Provides common functionality for integrated unit tests
+Provides common functionality for functional tests
 """
 import os.path
 import random
@@ -24,15 +24,13 @@ import uuid
 import fixtures
 import mock
 from oslo_config import cfg
-from oslo_log import log as logging
 
 from cinder import service
 from cinder import test  # For the flags
-from cinder.tests.unit.integrated.api import client
+from cinder.tests.functional.api import client
 
 
 CONF = cfg.CONF
-LOG = logging.getLogger(__name__)
 
 
 def generate_random_alphanumeric(length):
@@ -56,12 +54,11 @@ def generate_new_element(items, prefix, numeric=False):
             candidate = prefix + generate_random_alphanumeric(8)
         if candidate not in items:
             return candidate
-        LOG.debug("Random collision on %s", candidate)
 
 
-class _IntegratedTestBase(test.TestCase):
+class _FunctionalTestBase(test.TestCase):
     def setUp(self):
-        super(_IntegratedTestBase, self).setUp()
+        super(_FunctionalTestBase, self).setUp()
 
         f = self._get_flags()
         self.flags(**f)
@@ -83,7 +80,7 @@ class _IntegratedTestBase(test.TestCase):
 
     def _start_api_service(self):
         default_conf = os.path.abspath(os.path.join(
-            os.path.dirname(__file__), '..', '..', '..', '..',
+            os.path.dirname(__file__), '..', '..', '..',
             'etc/cinder/api-paste.ini'))
         CONF.api_paste_config = default_conf
         self.osapi = service.WSGIService("osapi_volume")
@@ -91,7 +88,6 @@ class _IntegratedTestBase(test.TestCase):
         # FIXME(ja): this is not the auth url - this is the service url
         # FIXME(ja): this needs fixed in nova as well
         self.auth_url = 'http://%s:%s/v2' % (self.osapi.host, self.osapi.port)
-        LOG.warning(self.auth_url)
 
     def _get_flags(self):
         """An opportunity to setup flags, before the services are started."""
@@ -122,7 +118,6 @@ class _IntegratedTestBase(test.TestCase):
         server = {}
 
         image = self.api.get_images()[0]
-        LOG.debug("Image: %s", image)
 
         if 'imageRef' in image:
             image_href = image['imageRef']
@@ -135,7 +130,6 @@ class _IntegratedTestBase(test.TestCase):
 
         # Set a valid flavorId
         flavor = self.api.get_flavors()[0]
-        LOG.debug("Using flavor: %s", flavor)
         server['flavorRef'] = 'http://fake.server/%s' % flavor['id']
 
         # Set a valid server name
similarity index 90%
rename from cinder/tests/unit/api/test_extensions.py
rename to cinder/tests/functional/test_extensions.py
index c87a2fc127cf21d0e19d49722112c86f8b7b30a0..6772caf331a796ddc11ba4cf788281ff50bdd555 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
-# Copyright 2011 OpenStack Foundation
+# Copyright 2011 Justin Santa Barbara
 # All Rights Reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -14,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+
 import iso8601
 from lxml import etree
 from oslo_config import cfg
@@ -23,23 +23,28 @@ import webob
 from cinder.api import extensions
 from cinder.api.v1 import router
 from cinder.api import xmlutil
-from cinder import test
+from cinder.tests.functional import functional_helpers
 
 
 NS = "{http://docs.openstack.org/common/api/v1.0}"
+CONF = cfg.CONF
 
 
-CONF = cfg.CONF
+class ExtensionTestCase(functional_helpers._FunctionalTestBase):
+    def _get_flags(self):
+        f = super(ExtensionTestCase, self)._get_flags()
+        f['osapi_volume_extension'] = CONF.osapi_volume_extension[:]
+        f['osapi_volume_extension'].append(
+            'cinder.tests.functional.api.foxinsocks.Foxinsocks')
+        return f
 
 
-class ExtensionTestCase(test.TestCase):
-    def setUp(self):
-        super(ExtensionTestCase, self).setUp()
-        ext_list = CONF.osapi_volume_extension[:]
-        fox = ('cinder.tests.unit.api.extensions.foxinsocks.Foxinsocks')
-        if fox not in ext_list:
-            ext_list.append(fox)
-            self.flags(osapi_volume_extension=ext_list)
+class ExtensionsTest(ExtensionTestCase):
+    def test_get_foxnsocks(self):
+        """Simple check that fox-n-socks works."""
+        response = self.api.api_request('/foxnsocks')
+        foxnsocks = response.text
+        self.assertEqual('Try to say this Mr. Knox, sir...', foxnsocks)
 
 
 class ExtensionControllerTest(ExtensionTestCase):
@@ -183,7 +188,7 @@ class StubExtensionManager(object):
         return controller_extensions
 
 
-class ExtensionControllerIdFormatTest(test.TestCase):
+class ExtensionControllerIdFormatTest(ExtensionTestCase):
 
     def _bounce_id(self, test_id):
 
similarity index 74%
rename from cinder/tests/unit/integrated/test_login.py
rename to cinder/tests/functional/test_login.py
index 2cb62f35868cd76f228e60af554396b6f748dcd5..1b2ab678be15235a6523af23804f0ee26dd8abb1 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-from oslo_log import log as logging
+from cinder.tests.functional import functional_helpers
 
-from cinder.tests.unit.integrated import integrated_helpers
 
-
-LOG = logging.getLogger(__name__)
-
-
-class LoginTest(integrated_helpers._IntegratedTestBase):
+class LoginTest(functional_helpers._FunctionalTestBase):
     def test_login(self):
         """Simple check - we list volumes - so we know we're logged in."""
         volumes = self.api.get_volumes()
-        for volume in volumes:
-            LOG.debug("volume: %s" % volume)
+        self.assertIsNotNone(volumes)
similarity index 88%
rename from cinder/tests/unit/integrated/test_volumes.py
rename to cinder/tests/functional/test_volumes.py
index d9d5482817c243f30961e33761106b26bc5ffed6..e114fc885e18a66db5b4bdee86d27cdac7953489 100644 (file)
 
 import time
 
-from oslo_log import log as logging
 import testtools
 
+from cinder import service
+from cinder.tests.functional.api import client
+from cinder.tests.functional import functional_helpers
 from cinder.tests.unit import fake_driver
-from cinder.tests.unit.integrated.api import client
-from cinder.tests.unit.integrated import integrated_helpers
 
 
-LOG = logging.getLogger(__name__)
-
-
-class VolumesTest(integrated_helpers._IntegratedTestBase):
+class VolumesTest(functional_helpers._FunctionalTestBase):
     def setUp(self):
         super(VolumesTest, self).setUp()
         fake_driver.LoggingVolumeDriver.clear_logs()
 
+    def _start_api_service(self):
+        self.osapi = service.WSGIService("osapi_volume")
+        self.osapi.start()
+        self.auth_url = 'http://%s:%s/v2' % (self.osapi.host, self.osapi.port)
+
     def _get_flags(self):
         f = super(VolumesTest, self)._get_flags()
         f['volume_driver'] = \
@@ -40,14 +42,12 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
     def test_get_volumes_summary(self):
         """Simple check that listing volumes works."""
         volumes = self.api.get_volumes(False)
-        for volume in volumes:
-            LOG.debug("volume: %s", volume)
+        self.assertIsNotNone(volumes)
 
     def test_get_volumes(self):
         """Simple check that listing volumes works."""
         volumes = self.api.get_volumes()
-        for volume in volumes:
-            LOG.debug("volume: %s", volume)
+        self.assertIsNotNone(volumes)
 
     def _poll_while(self, volume_id, continue_states, max_retries=5):
         """Poll (briefly) while the state is in continue_states."""
@@ -57,11 +57,8 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
                 found_volume = self.api.get_volume(volume_id)
             except client.OpenStackApiNotFoundException:
                 found_volume = None
-                LOG.debug("Got 404, proceeding")
                 break
 
-            LOG.debug("Found %s", found_volume)
-
             self.assertEqual(volume_id, found_volume['id'])
 
             if found_volume['status'] not in continue_states:
@@ -79,7 +76,6 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
 
         # Create volume
         created_volume = self.api.post_volume({'volume': {'size': 1}})
-        LOG.debug("created_volume: %s", created_volume)
         self.assertTrue(created_volume['id'])
         created_volume_id = created_volume['id']
 
@@ -107,12 +103,9 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
         # Should be gone
         self.assertFalse(found_volume)
 
-        LOG.debug("Logs: %s", fake_driver.LoggingVolumeDriver.all_logs())
-
         create_actions = fake_driver.LoggingVolumeDriver.logs_like(
             'create_volume',
             id=created_volume_id)
-        LOG.debug("Create_Actions: %s", create_actions)
 
         self.assertEqual(1, len(create_actions))
         create_action = create_actions[0]
@@ -144,7 +137,6 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
         created_volume = self.api.post_volume(
             {'volume': {'size': 1,
                         'metadata': metadata}})
-        LOG.debug("created_volume: %s", created_volume)
         self.assertTrue(created_volume['id'])
         created_volume_id = created_volume['id']
 
@@ -161,7 +153,6 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
         created_volume = self.api.post_volume(
             {'volume': {'size': 1,
                         'availability_zone': availability_zone}})
-        LOG.debug("created_volume: %s", created_volume)
         self.assertTrue(created_volume['id'])
         created_volume_id = created_volume['id']
 
similarity index 86%
rename from cinder/tests/unit/integrated/test_xml.py
rename to cinder/tests/functional/test_xml.py
index 3bda0cee863b0a36ceac3cfeca4d3e666eb7fe1a..f2f9786e785ef0fa675354126bd6a302e9a980e9 100644 (file)
 #    under the License.
 
 from lxml import etree
-from oslo_log import log as logging
 
 from cinder.api import common
-from cinder.tests.unit.integrated import integrated_helpers
+from cinder.tests.functional import functional_helpers
 
 
-LOG = logging.getLogger(__name__)
-
-
-class XmlTests(integrated_helpers._IntegratedTestBase):
+class XmlTests(functional_helpers._FunctionalTestBase):
     """Some basic XML sanity checks."""
 
     # FIXME(ja): does cinder need limits?
@@ -44,6 +40,5 @@ class XmlTests(integrated_helpers._IntegratedTestBase):
         response = self.api.api_request('/volumes', headers=headers,
                                         stream=True)
         data = response.raw
-        LOG.warning("data: %s", data)
         root = etree.parse(data).getroot()
         self.assertEqual(common.XML_NS_V2, root.nsmap.get(None))
diff --git a/cinder/tests/unit/integrated/__init__.py b/cinder/tests/unit/integrated/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/cinder/tests/unit/integrated/test_extensions.py b/cinder/tests/unit/integrated/test_extensions.py
deleted file mode 100644 (file)
index e1e6d03..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright 2011 Justin Santa Barbara
-# 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 oslo_config import cfg
-from oslo_log import log as logging
-
-from cinder.tests.unit.integrated import integrated_helpers
-
-
-CONF = cfg.CONF
-
-LOG = logging.getLogger(__name__)
-
-
-class ExtensionsTest(integrated_helpers._IntegratedTestBase):
-    def _get_flags(self):
-        f = super(ExtensionsTest, self)._get_flags()
-        f['osapi_volume_extension'] = CONF.osapi_volume_extension[:]
-        f['osapi_volume_extension'].append(
-            'cinder.tests.unit.api.extensions.foxinsocks.Foxinsocks')
-        return f
-
-    def test_get_foxnsocks(self):
-        """Simple check that fox-n-socks works."""
-        response = self.api.api_request('/foxnsocks')
-        foxnsocks = response.text
-        self.assertEqual('Try to say this Mr. Knox, sir...', foxnsocks)
diff --git a/tox.ini b/tox.ini
index 934f836ddb814cff75e52c513f8509f319b76f6c..105a74ee6c4a046d6dc88c1193fef09d9cf14d73 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -22,7 +22,7 @@ deps = -r{toxinidir}/test-requirements.txt
 # to ncpu, to specify something else use
 # the concurrency=<n> option.
 # call ie: 'tox -epy27 -- --concurrency=4'
-commands = ostestr {posargs}
+commands = python setup.py testr --testr-args='{posargs}'
 
 whitelist_externals = bash
 passenv = *_proxy *_PROXY
@@ -37,6 +37,10 @@ install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstac
 commands =
   ostestr --whitelist_file=tests-py3.txt
 
+[testenv:functional]
+setenv =
+  OS_TEST_PATH = ./cinder/tests/functional
+
 [testenv:py34-constraints]
 install_command = {[testenv:common-constraints]install_command}
 commands = {[testenv:py34]commands}