Created
September 19, 2014 15:10
-
-
Save weissjeffm/6ede6524ea2424ba6c5c 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() | |
| # blow away all providers when done - collecting metrics for all of them is | |
| # too much | |
| @pytest.yield_fixture | |
| def handle_provider(provider_crud): | |
| try: | |
| provider_crud.create() | |
| yield | |
| finally: | |
| provider_crud.delete() | |
| #@pytest.mark.parametrize("provider", providers.list_all_providers()) | |
| def test_metrics_collection(handle_provider, provider_key): | |
| '''check the db is gathering collection data for the given provider''' | |
| 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment