Created
September 19, 2014 18:32
-
-
Save weissjeffm/98d560d3862b591f105b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pytest | |
| from utils import db | |
| from utils import providers | |
| from utils import testgen | |
| from utils import conf | |
| import time | |
| from cfme.configure.configuration import candu | |
| pytestmark = [ | |
| pytest.mark.fixtureconf(server_roles="+ems_metrics_coordinator +ems_metrics_collector" | |
| " +ems_metrics_processor"), | |
| pytest.mark.usefixtures('server_roles') | |
| ] | |
| pytest_generate_tests = testgen.infra_providers | |
| @pytest.fixture(scope="module") | |
| def no_providers__enable_candu(): | |
| providers.clear_providers() | |
| # also enable collection for the region | |
| candu.enable_all() | |
| def test_metrics_collection(provider_key, provider_crud): | |
| '''check the db is gathering collection data for the given provider''' | |
| try: | |
| provider_crud.create() | |
| except BaseException: | |
| pytest.skip("Provider setup failed") | |
| try: | |
| metrics_tbl = db.cfmedb['metrics'] | |
| mgmt_systems_tbl = db.cfmedb['ext_management_systems'] | |
| # the id for the provider we're testing | |
| mgmt_system_id = db.cfmedb.session.query(mgmt_systems_tbl).filter( | |
| mgmt_systems_tbl.name == conf.cfme_data['management_systems'][provider_key]['name'] | |
| ).first().id | |
| start_time = time.time() | |
| metric_count = 0 | |
| timeout = 900.0 # 15 min | |
| while time.time() < start_time + timeout: | |
| last_metric_count = metric_count | |
| print "name: %s, id: %s, metrics: %s" % (provider_key, | |
| mgmt_system_id, metric_count) | |
| # count all the metrics for the provider we're testing | |
| metric_count = db.cfmedb.session.query(metrics_tbl).filter( | |
| metrics_tbl.parent_ems_id == mgmt_system_id | |
| ).count() | |
| # collection is working if increasing | |
| if metric_count > last_metric_count and last_metric_count > 0: | |
| return | |
| else: | |
| time.sleep(15) | |
| if time.time() > start_time + timeout: | |
| raise Exception("Timed out waiting for metrics to be collected") | |
| finally: | |
| provider_crud.delete() |
Author
weissjeffm
commented
Sep 19, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment