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'}") result = _execute_automation(site, "update-dns-cache") assert isinstance(result, results.UpdateDNSCacheResult) assert result.n_updated > 0 assert result.failed_hosts == ["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 test_log_fixture( request, web, site: Site, fake_sendmail ): # noqa: F811 # pylint: disable=redefined-outer-name core, log = request.param site.set_config("CORE", core, with_restart=True) users = { "hh": { "alias": "Harry Hirsch", "password": "******", "email": "%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(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 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()