def test_automation_update_dns_cache(test_cfg, site, web): # noqa: F811 # pylint: disable=redefined-outer-name cache_path = 'var/check_mk/ipaddresses.cache' if site.file_exists(cache_path): site.delete_file(cache_path) try: web.add_host("update-dns-cache-host") web.add_host("localhost") site.write_file(cache_path, "{('bla', 4): '127.0.0.1'}") data = _execute_automation(site, "update-dns-cache") assert isinstance(data, tuple) assert len(data) == 2 assert data[0] > 0 assert data[1] == ["update-dns-cache-host"] assert site.file_exists(cache_path) cache = eval(site.read_file(cache_path)) assert isinstance(cache, dict) assert cache[("localhost", 4)] == "127.0.0.1" assert ("bla", 4) not in cache finally: web.delete_host("localhost") web.delete_host("update-dns-cache-host")
def create_linux_test_host(request, web, site, hostname): def finalizer(): web.delete_host(hostname) web.activate_changes() for path in [ "var/check_mk/agent_output/%s" % hostname, "etc/check_mk/conf.d/linux_test_host_%s.mk" % hostname, "tmp/check_mk/status_data/%s" % hostname, "tmp/check_mk/status_data/%s.gz" % hostname, "var/check_mk/inventory/%s" % hostname, "var/check_mk/inventory/%s.gz" % hostname, ]: if os.path.exists(path): site.delete_file(path) request.addfinalizer(finalizer) web.add_host(hostname, attributes={"ipaddress": "127.0.0.1"}) site.write_file( "etc/check_mk/conf.d/linux_test_host_%s.mk" % hostname, "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ['%s']))\n" % hostname) site.makedirs("var/check_mk/agent_output/") site.write_file("var/check_mk/agent_output/%s" % hostname, get_standard_linux_agent_output())
def test_log(request, web, site, fake_sendmail): core, log = request.param site.set_config("CORE", core, with_restart=True) users = { "hh": { "alias": "Harry Hirsch", "password": "******", "email": u"%s@localhost" % web.site.id, 'contactgroups': ['all'], }, } expected_users = set(["cmkadmin", "automation"] + list(users.keys())) web.add_htpasswd_users(users) all_users = web.get_all_users() assert not expected_users - set(all_users.keys()) site.live.command("[%d] STOP_EXECUTING_HOST_CHECKS" % time.time()) site.live.command("[%d] STOP_EXECUTING_SVC_CHECKS" % time.time()) web.add_host("notify-test", attributes={ "ipaddress": "127.0.0.1", }) web.activate_changes() with WatchLog(site, log, default_timeout=20) as l: yield l site.live.command("[%d] START_EXECUTING_HOST_CHECKS" % time.time()) site.live.command("[%d] START_EXECUTING_SVC_CHECKS" % time.time()) web.delete_host("notify-test") web.delete_htpasswd_users(list(users.keys())) web.activate_changes()
def test_cfg_fixture(web, site): # noqa: F811 # pylint: disable=redefined-outer-name site.ensure_running() 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_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_file("var/check_mk/agent_output/modes-test-host", get_standard_linux_agent_output()) site.write_file("var/check_mk/agent_output/modes-test-host2", get_standard_linux_agent_output()) site.write_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()
def test_cfg_fixture(request, web, site): # noqa: F811 # pylint: disable=redefined-outer-name config = DefaultConfig(core=request.param) site.set_config("CORE", config.core, with_restart=True) print("Applying default config") web.add_host("test-host", attributes={ "ipaddress": "127.0.0.1", "tag_agent": "no-agent", }) web.activate_changes() yield config # # Cleanup code # print("Cleaning up test config") web.delete_host("test-host")
def test_cfg_fixture(web, site): # noqa: F811 # pylint: disable=redefined-outer-name print("Applying default config") web.add_host("modes-test-host", attributes={ "ipaddress": "127.0.0.1", }) site.write_file( "etc/check_mk/conf.d/modes-test-host.mk", "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ['modes-test-host']))\n" ) site.makedirs("var/check_mk/agent_output/") web.activate_changes() yield None # # Cleanup code # print("Cleaning up test config") web.delete_host("modes-test-host")
def create_linux_test_host(request, web, site, hostname): def finalizer(): web.delete_host(hostname) web.activate_changes() site.delete_file("var/check_mk/agent_output/%s" % hostname) site.delete_file("etc/check_mk/conf.d/linux_test_host_%s.mk" % hostname) request.addfinalizer(finalizer) web.add_host(hostname, attributes={"ipaddress": "127.0.0.1"}) site.write_file( "etc/check_mk/conf.d/linux_test_host_%s.mk" % hostname, "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ['%s']))\n" % hostname) site.makedirs("var/check_mk/agent_output/") site.write_file( "var/check_mk/agent_output/%s" % hostname, open("%s/tests/integration/cmk/base/test-files/linux-agent-output" % repo_path()).read())