Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created September 19, 2014 18:32
Show Gist options
  • Select an option

  • Save weissjeffm/98d560d3862b591f105b to your computer and use it in GitHub Desktop.

Select an option

Save weissjeffm/98d560d3862b591f105b to your computer and use it in GitHub Desktop.
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()
@weissjeffm
Copy link
Author

(cfme)[jweiss@localhost cfme_tests]$ py.test -v cfme/tests/infrastructure/test_utilization.py
py.test -v cfme/tests/infrastructure/test_utilization.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.5 -- py-1.4.24 -- pytest-2.6.2 -- /home/jweiss/.virtualenvs/cfme/bin/python
collecting ... collected 1 items

Appliance's streams: [5.3, downstream]

cfme/tests/infrastructure/test_utilization.py::test_metrics_collection ERROR

==================================== ERRORS ====================================
__________________ ERROR at setup of test_metrics_collection ___________________
file /home/jweiss/workspace/cfme_tests/cfme/tests/infrastructure/test_utilization.py, line 25
  def test_metrics_collection(provider_key, provider_crud):
        fixture 'provider_key' not found
        available fixtures: pytestconfig, db_yamls, uses_infra_providers, random_string, setup_auto_placement_host, intel_chargeback_pg, setup_soap_create_vm, automate_explorer_pg, cloud_availabilityzones_pg, configure_ldap_auth_mode, logger, automate_customization_pg, vm_name, cnf_tasks_pg, setup_pxe_provision, provisioning_setup_data, _smtp_test_session, verify_vm_stopped, datafile, mgmt_sys_api_clients, infra_pxe_pg, soap_client, uses_ssh, has_no_cloud_providers, fixtureconf, cloud_securitygroups_pg, control_simulation_pg, tmpdir, host_provisioning_setup_data, verify_vm_suspended, setup_infrastructure_providers, maximized, go_to_fixture, infra_clusters_pg, server_roles, setup_vm_provisioning_pxe, control_importexport_pg, control_log_pg, verify_vm_running, capfd, uses_pxe, intel_dashboard_pg, configure_aws_iam_auth_mode, cfme_data, register_event, setup_providers, svc_myservices_pg, available_auth_modes, infra_hosts_pg, setup_cloud_providers, recwarn, infra_datastores_pg, logged_in, no_providers__enable_candu, random_uuid_as_string, setup_auto_placement_datastore, bug, cloud_providers_pg, snmp_client, control_explorer_pg, setup_host_provisioning_pxe, intel_reports_pg, optimize_utilization_pg, home_page_logged_in, uses_providers, browser, smtp_test_module, has_no_providers, cloud_flavors_pg, uses_cloud_providers, _markfunc, vm_provisioning_setup_data, has_no_infra_providers, ssh_client, cnf_configuration_pg, smtp_test, infra_providers_pg, db, infra_vms_pg, automate_importexport_pg, uses_event_listener, monkeypatch, cnf_mysettings_pg, configure_appliance_for_event_testing, uses_db, cloud_instances_pg, soft_assert, uses_soap, svc_catalogs_pg, cnf_smartproxies_pg, listener_info, bugs, cnf_about_pg, auto_placement_setup_data, capsys
        use 'py.test --fixtures [testpath]' for help on them.

/home/jweiss/workspace/cfme_tests/cfme/tests/infrastructure/test_utilization.py:25
=========================== 1 error in 69.87 seconds ===========================
(cfme)[jweiss@localhost cfme_tests]$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment