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
This commit is contained in:
parent
ffd8d7d51b
commit
71589dd64f
|
@ -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]
|
[profiler]
|
||||||
connection_string="messaging://"
|
connection_string="messaging://"
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
@ -25,9 +26,19 @@ from osprofiler.tests import test
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
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"
|
SERVICE = "service"
|
||||||
PROJECT = "project"
|
PROJECT = "project"
|
||||||
|
@ -40,15 +51,6 @@ class DriverTestCase(test.TestCase):
|
||||||
trace_sqlalchemy=False,
|
trace_sqlalchemy=False,
|
||||||
hmac_keys="SECRET_KEY")
|
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):
|
def _assert_dict(self, info, **kwargs):
|
||||||
for key in kwargs:
|
for key in kwargs:
|
||||||
self.assertEqual(kwargs[key], info[key])
|
self.assertEqual(kwargs[key], info[key])
|
||||||
|
@ -75,26 +77,35 @@ class DriverTestCase(test.TestCase):
|
||||||
self._assert_dict(raw_stop, **exp_raw)
|
self._assert_dict(raw_stop, **exp_raw)
|
||||||
|
|
||||||
def test_get_report(self):
|
def test_get_report(self):
|
||||||
|
# initialize profiler notifier (the same way as in services)
|
||||||
initializer.init_from_conf(
|
initializer.init_from_conf(
|
||||||
CONF, None, self.PROJECT, self.SERVICE, "host")
|
CONF, {}, self.PROJECT, self.SERVICE, "host")
|
||||||
profiler.init("SECRET_KEY")
|
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)
|
foo.bar(1)
|
||||||
|
|
||||||
|
# instantiate report engine (the same way as in osprofiler CLI)
|
||||||
engine = base.get_driver(CONF.profiler.connection_string,
|
engine = base.get_driver(CONF.profiler.connection_string,
|
||||||
project=self.PROJECT,
|
project=self.PROJECT,
|
||||||
service=self.SERVICE,
|
service=self.SERVICE,
|
||||||
host="host",
|
host="host",
|
||||||
conf=CONF)
|
conf=CONF)
|
||||||
base_id = profiler.get().get_base_id()
|
|
||||||
res = engine.get_report(base_id)
|
|
||||||
|
|
||||||
self.assertEqual("total", res["info"]["name"])
|
# generate the report
|
||||||
self.assertEqual(2, res["stats"]["rpc"]["count"])
|
report = engine.get_report(base_id)
|
||||||
self.assertEqual(1, len(res["children"]))
|
LOG.debug("OSProfiler report: %s", report)
|
||||||
|
|
||||||
cbar = res["children"][0]
|
# verify the report
|
||||||
|
self.assertEqual("total", report["info"]["name"])
|
||||||
|
self.assertEqual(2, report["stats"]["rpc"]["count"])
|
||||||
|
self.assertEqual(1, len(report["children"]))
|
||||||
|
|
||||||
|
cbar = report["children"][0]
|
||||||
self._assert_child_dict(
|
self._assert_child_dict(
|
||||||
cbar, base_id, base_id, "rpc",
|
cbar, base_id, base_id, "rpc",
|
||||||
"osprofiler.tests.functional.test_driver.Foo.bar")
|
"osprofiler.tests.functional.test_driver.Foo.bar")
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
|
@ -20,3 +22,12 @@ from testtools import testcase
|
||||||
class TestCase(testcase.TestCase):
|
class TestCase(testcase.TestCase):
|
||||||
"""Test case base class for all osprofiler unit tests."""
|
"""Test case base class for all osprofiler unit tests."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FunctionalTestCase(TestCase):
|
||||||
|
"""Base for functional tests"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(FunctionalTestCase, self).setUp()
|
||||||
|
|
||||||
|
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -21,6 +21,7 @@ basepython = python2.7
|
||||||
setenv = {[testenv]setenv}
|
setenv = {[testenv]setenv}
|
||||||
OS_TEST_PATH=./osprofiler/tests/functional
|
OS_TEST_PATH=./osprofiler/tests/functional
|
||||||
deps = {[testenv]deps}
|
deps = {[testenv]deps}
|
||||||
|
oslo.messaging
|
||||||
|
|
||||||
[testenv:functional-py35]
|
[testenv:functional-py35]
|
||||||
basepython = python3.5
|
basepython = python3.5
|
||||||
|
|
Loading…
Reference in New Issue