def cfg_setup_fixture(request, web, site: Site): hostname = "test-prediction" # Enforce use of the pre-created RRD file from the git. The restart of the core # is needed to make it renew it's internal RRD file cache site.makedirs("var/check_mk/rrd/test-prediction") with open(site.path("var/check_mk/rrd/test-prediction/CPU_load.rrd"), "wb") as f: f.write( Path( repo_path(), "tests", "integration", "cmk", "base", "test-files", "CPU_load.rrd" ).read_bytes() ) site.write_text_file( "var/check_mk/rrd/test-prediction/CPU_load.info", Path( repo_path(), "tests", "integration", "cmk", "base", "test-files", "CPU_load.info" ).read_text(), ) site.restart_core() create_linux_test_host(request, site, "test-prediction") site.write_text_file( "etc/check_mk/conf.d/linux_test_host_%s_cpu_load.mk" % hostname, """ globals().setdefault('custom_checks', []) custom_checks = [ ( {'service_description': u'CPU load', 'has_perfdata': True}, [], ALL_HOSTS, {} ), ] + custom_checks """, ) site.activate_changes_and_wait_for_core_reload() yield # Cleanup site.delete_file("etc/check_mk/conf.d/linux_test_host_%s_cpu_load.mk" % hostname) site.activate_changes_and_wait_for_core_reload() site.delete_dir("var/check_mk/rrd")
def cfg_setup_fixture(request, web, site: Site): # noqa: F811 # pylint: disable=redefined-outer-name hostname = "test-prediction" # Enforce use of the pre-created RRD file from the git. The restart of the core # is needed to make it renew it's internal RRD file cache site.makedirs("var/check_mk/rrd/test-prediction") with open(site.path("var/check_mk/rrd/test-prediction/CPU_load.rrd"), "wb") as f: f.write( open( "%s/tests/integration/cmk/base/test-files/CPU_load.rrd" % repo_path(), "rb").read()) site.write_text_file( "var/check_mk/rrd/test-prediction/CPU_load.info", open("%s/tests/integration/cmk/base/test-files/CPU_load.info" % repo_path()).read(), ) site.restart_core() create_linux_test_host(request, web, site, "test-prediction") site.write_text_file( "etc/check_mk/conf.d/linux_test_host_%s_cpu_load.mk" % hostname, """ globals().setdefault('custom_checks', []) custom_checks = [ ( {'service_description': u'CPU load', 'has_perfdata': True}, [], ALL_HOSTS, {} ), ] + custom_checks """, ) web.activate_changes() yield # Cleanup site.delete_file("etc/check_mk/conf.d/linux_test_host_%s_cpu_load.mk" % hostname) site.delete_dir("var/check_mk/rrd")
def test_cfg_fixture(site: Site, web): print("Applying default config") site.openapi.create_host( "modes-test-host", attributes={ "ipaddress": "127.0.0.1", }, ) site.openapi.create_host( "modes-test-host2", attributes={ "ipaddress": "127.0.0.1", "tag_criticality": "test", }, ) site.openapi.create_host( "modes-test-host3", attributes={ "ipaddress": "127.0.0.1", "tag_criticality": "test", }, ) site.openapi.create_host( "modes-test-host4", attributes={ "ipaddress": "127.0.0.1", "tag_criticality": "offline", }, ) site.write_text_file( "etc/check_mk/conf.d/modes-test-host.mk", "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ALL_HOSTS))\n", ) site.makedirs("var/check_mk/agent_output/") site.write_text_file("var/check_mk/agent_output/modes-test-host", get_standard_linux_agent_output()) site.write_text_file("var/check_mk/agent_output/modes-test-host2", get_standard_linux_agent_output()) site.write_text_file("var/check_mk/agent_output/modes-test-host3", get_standard_linux_agent_output()) web.discover_services( "modes-test-host") # Replace with RestAPI call, see CMK-9249 web.discover_services( "modes-test-host2") # Replace with RestAPI call, see CMK-9249 web.discover_services( "modes-test-host3") # Replace with RestAPI call, see CMK-9249 try: site.activate_changes_and_wait_for_core_reload() yield None finally: # # Cleanup code # print("Cleaning up test config") site.delete_dir("var/check_mk/agent_output") site.delete_file("etc/check_mk/conf.d/modes-test-host.mk") site.openapi.delete_host("modes-test-host") site.openapi.delete_host("modes-test-host2") site.openapi.delete_host("modes-test-host3") site.openapi.delete_host("modes-test-host4") site.activate_changes_and_wait_for_core_reload()
def test_cfg_fixture(web, site: Site): # noqa: F811 # pylint: disable=redefined-outer-name print("Applying default config") web.add_host( "modes-test-host", attributes={ "ipaddress": "127.0.0.1", }, ) web.add_host( "modes-test-host2", attributes={ "ipaddress": "127.0.0.1", "tag_criticality": "test", }, ) web.add_host( "modes-test-host3", attributes={ "ipaddress": "127.0.0.1", "tag_criticality": "test", }, ) web.add_host( "modes-test-host4", attributes={ "ipaddress": "127.0.0.1", "tag_criticality": "offline", }, ) site.write_text_file( "etc/check_mk/conf.d/modes-test-host.mk", "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ALL_HOSTS))\n", ) site.makedirs("var/check_mk/agent_output/") site.write_text_file("var/check_mk/agent_output/modes-test-host", get_standard_linux_agent_output()) site.write_text_file("var/check_mk/agent_output/modes-test-host2", get_standard_linux_agent_output()) site.write_text_file("var/check_mk/agent_output/modes-test-host3", get_standard_linux_agent_output()) web.discover_services("modes-test-host") web.discover_services("modes-test-host2") web.discover_services("modes-test-host3") try: web.activate_changes() yield None finally: # # Cleanup code # print("Cleaning up test config") site.delete_dir("var/check_mk/agent_output") site.delete_file("etc/check_mk/conf.d/modes-test-host.mk") web.delete_host("modes-test-host") web.delete_host("modes-test-host2") web.delete_host("modes-test-host3") web.delete_host("modes-test-host4") web.activate_changes()