Add Zuul job for functional testing

The job prepares VM with RabbitMQ installed, then it executes tests
located under osprofiler/tests/functional.

To run the job manually use `tox -e functional` or
`tox -e functional-py35`.

Change-Id: I1f2b99737d1f17bb09662dc24c4858a1a7a1ad44
changes/08/515108/8
Ilya Shakhat 5 years ago
parent ffd8d7d51b
commit 71589dd64f
  1. 10
      .zuul.yaml
  2. 1
      bindep.txt
  3. 2
      osprofiler/tests/functional/config.cfg
  4. 47
      osprofiler/tests/functional/test_driver.py
  5. 11
      osprofiler/tests/test.py
  6. 1
      tox.ini

@ -0,0 +1,10 @@
- project:
name: openstack/osprofiler
check:
jobs:
- openstack-tox-functional
- openstack-tox-functional-py35
gate:
jobs:
- openstack-tox-functional
- openstack-tox-functional-py35

@ -0,0 +1 @@
rabbitmq-server [test]

@ -1,3 +1,5 @@
[DEFAULT]
transport_url=rabbit://localhost:5672/
[profiler]
connection_string="messaging://"

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
from oslo_config import cfg
@ -25,9 +26,19 @@ from osprofiler.tests import test
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
class DriverTestCase(test.TestCase):
@profiler.trace_cls("rpc", hide_args=True)
class Foo(object):
def bar(self, x):
return self.baz(x, x)
def baz(self, x, y):
return x * y
class DriverTestCase(test.FunctionalTestCase):
SERVICE = "service"
PROJECT = "project"
@ -40,15 +51,6 @@ class DriverTestCase(test.TestCase):
trace_sqlalchemy=False,
hmac_keys="SECRET_KEY")
@profiler.trace_cls("rpc", hide_args=True)
class Foo(object):
def bar(self, x):
return self.baz(x, x)
def baz(self, x, y):
return x * y
def _assert_dict(self, info, **kwargs):
for key in kwargs:
self.assertEqual(kwargs[key], info[key])
@ -75,26 +77,35 @@ class DriverTestCase(test.TestCase):
self._assert_dict(raw_stop, **exp_raw)
def test_get_report(self):
# initialize profiler notifier (the same way as in services)
initializer.init_from_conf(
CONF, None, self.PROJECT, self.SERVICE, "host")
CONF, {}, self.PROJECT, self.SERVICE, "host")
profiler.init("SECRET_KEY")
foo = DriverTestCase.Foo()
# grab base_id
base_id = profiler.get().get_base_id()
# execute profiled code
foo = Foo()
foo.bar(1)
# instantiate report engine (the same way as in osprofiler CLI)
engine = base.get_driver(CONF.profiler.connection_string,
project=self.PROJECT,
service=self.SERVICE,
host="host",
conf=CONF)
base_id = profiler.get().get_base_id()
res = engine.get_report(base_id)
self.assertEqual("total", res["info"]["name"])
self.assertEqual(2, res["stats"]["rpc"]["count"])
self.assertEqual(1, len(res["children"]))
# generate the report
report = engine.get_report(base_id)
LOG.debug("OSProfiler report: %s", report)
# verify the report
self.assertEqual("total", report["info"]["name"])
self.assertEqual(2, report["stats"]["rpc"]["count"])
self.assertEqual(1, len(report["children"]))
cbar = res["children"][0]
cbar = report["children"][0]
self._assert_child_dict(
cbar, base_id, base_id, "rpc",
"osprofiler.tests.functional.test_driver.Foo.bar")

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import sys
from testtools import testcase
@ -20,3 +22,12 @@ from testtools import testcase
class TestCase(testcase.TestCase):
"""Test case base class for all osprofiler unit tests."""
pass
class FunctionalTestCase(TestCase):
"""Base for functional tests"""
def setUp(self):
super(FunctionalTestCase, self).setUp()
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

@ -21,6 +21,7 @@ basepython = python2.7
setenv = {[testenv]setenv}
OS_TEST_PATH=./osprofiler/tests/functional
deps = {[testenv]deps}
oslo.messaging
[testenv:functional-py35]
basepython = python3.5

Loading…
Cancel
Save