How to use delete_host method in autotest

Best Python code snippet using autotest_python

test_webapi.py

Source:test_webapi.py Github

copy

Full Screen

...17 web.add_host("test-host", attributes={18 "ipaddress": "127.0.0.1",19 })20 finally:21 web.delete_host("test-host")22def test_add_host_folder_create(web):23 web.add_host("test-host", attributes={24 "ipaddress": "127.0.0.1",25 },26 create_folders=True,27 folder="asd/eee",28 )29 web.delete_host("test-host")30def test_add_host_no_folder_create(web):31 with pytest.raises(APIError) as e:32 web.add_host("test-host", attributes={33 "ipaddress": "127.0.0.1",34 },35 create_folders=False,36 folder="eins/zwei",37 expect_error=True,38 )39 assert "Folder not existing" in "%s" % e40def test_get_all_hosts_basic(web):41 try:42 web.add_host("test-host-list", attributes={43 "ipaddress": "127.0.0.1",44 })45 hosts = web.get_all_hosts()46 assert "test-host-list" in hosts47 finally:48 web.delete_host("test-host-list")49def test_delete_host(web):50 try:51 web.add_host("test-host-delete", attributes={52 "ipaddress": "127.0.0.1",53 })54 finally:55 web.delete_host("test-host-delete")56def test_get_host_effective_attributes(web):57 try:58 web.add_host("test-host", attributes={59 "ipaddress": "127.0.0.1",60 })61 host = web.get_host("test-host", effective_attributes=False)62 assert "tag_networking" not in host["attributes"]63 host = web.get_host("test-host", effective_attributes=True)64 assert "tag_networking" in host["attributes"]65 assert host["attributes"]["tag_networking"] == "lan"66 finally:67 web.delete_host("test-host")68def test_get_all_hosts_effective_attributes(web):69 try:70 web.add_host("test-host", attributes={71 "ipaddress": "127.0.0.1",72 })73 hosts = web.get_all_hosts(effective_attributes=False)74 host = hosts["test-host"]75 assert "tag_networking" not in host["attributes"]76 hosts = web.get_all_hosts(effective_attributes=True)77 host = hosts["test-host"]78 assert "tag_networking" in host["attributes"]79 assert host["attributes"]["tag_networking"] == "lan"80 finally:81 web.delete_host("test-host")82def test_write_host_tags(web, site):83 try:84 web.add_host("test-host-dmz", attributes={85 "ipaddress": "127.0.0.1",86 "tag_networking": "dmz",87 })88 web.add_host("test-host-lan", attributes={89 "ipaddress": "127.0.0.1",90 "tag_networking": "lan",91 })92 web.add_host("test-host-lan2", attributes={93 "ipaddress": "127.0.0.1",94 })95 hosts = web.get_all_hosts(effective_attributes=True)96 assert hosts["test-host-dmz"]["attributes"]["tag_networking"] == "dmz"97 assert hosts["test-host-lan"]["attributes"]["tag_networking"] == "lan"98 assert hosts["test-host-lan2"]["attributes"]["tag_networking"] == "lan"99 cfg = {100 "FOLDER_PATH": "/",101 "all_hosts": [],102 "ipaddresses": {},103 "host_attributes": {},104 }105 exec(site.read_file("etc/check_mk/conf.d/wato/hosts.mk"), cfg, cfg)106 tags_by_host = {}107 for entry in cfg["all_hosts"]:108 hostname, tag_txt = entry.split("|", 1)109 tags_by_host[hostname] = tag_txt.split("|")110 assert "dmz" in tags_by_host["test-host-dmz"]111 assert "lan" not in tags_by_host["test-host-dmz"]112 assert "dmz" not in tags_by_host["test-host-lan"]113 assert "lan" in tags_by_host["test-host-lan"]114 assert "dmz" not in tags_by_host["test-host-lan2"]115 assert "lan" in tags_by_host["test-host-lan2"]116 finally:117 web.delete_host("test-host-lan2")118 web.delete_host("test-host-lan")119 web.delete_host("test-host-dmz")120@pytest.mark.parametrize(("group_type"), [ "contact", "host", "service" ])121def test_add_group(web, group_type):122 group_id = "%s_testgroup_id" % group_type123 group_alias = "%s_testgroup_alias" % group_type124 try:125 web.add_group(group_type, group_id, {"alias": group_alias})126 all_groups = web.get_all_groups(group_type)127 assert group_id in all_groups128 assert group_alias == all_groups[group_id]["alias"]129 finally:130 web.delete_group(group_type, group_id)131@pytest.mark.parametrize(("group_type"), [ "contact", "host", "service" ])132def test_edit_group(web, group_type):133 group_id = "%s_testgroup_id" % group_type134 group_alias = "%s_testgroup_alias" % group_type135 group_alias2 = "%s_testgroup_otheralias" % group_type136 try:137 web.add_group(group_type, group_id, {"alias": group_alias})138 web.edit_group(group_type, group_id, {"alias": group_alias2})139 all_groups = web.get_all_groups(group_type)140 assert group_id in all_groups141 assert group_alias2 in all_groups[group_id]["alias"]142 finally:143 web.delete_group(group_type, group_id)144@pytest.mark.parametrize(("group_type"), [ "contact", "host", "service" ])145def test_edit_group_missing(web, group_type):146 group_id = "%s_testgroup_id" % group_type147 group_alias = "%s_testgroup_alias" % group_type148 group_alias2 = "%s_testgroup_otheralias" % group_type149 try:150 web.add_group(group_type, group_id, {"alias": group_alias})151 try:152 #web.edit_group(group_type, group_id, {"alias": group_alias2}, expect_error = True)153 web.edit_group(group_type, "%s_missing" % group_id, {"alias": group_alias2}, expect_error = True)154 except APIError, e:155 assert str(e) != str(None)156 return157 assert False158 finally:159 web.delete_group(group_type, group_id)160def test_edit_cg_group_with_nagvis_maps(web, site):161 dummy_map_filepath1 = "%s/etc/nagvis/maps/blabla.cfg" % site.root162 dummy_map_filepath2 = "%s/etc/nagvis/maps/bloblo.cfg" % site.root163 try:164 file(dummy_map_filepath1, "w")165 file(dummy_map_filepath2, "w")166 web.add_group("contact", "nagvis_test", {"alias": "nagvis_test_alias", "nagvis_maps": ["blabla"]})167 web.edit_group("contact", "nagvis_test", {"alias": "nagvis_test_alias", "nagvis_maps": ["bloblo"]})168 all_groups = web.get_all_groups("contact")169 assert "nagvis_test" in all_groups170 assert "bloblo" in all_groups["nagvis_test"]["nagvis_maps"]171 finally:172 web.delete_group("contact", "nagvis_test")173 os.unlink(dummy_map_filepath1)174 os.unlink(dummy_map_filepath2)175@pytest.mark.parametrize(("group_type"), [ "contact", "host", "service" ])176def test_delete_group(web, group_type):177 group_id = "%s_testgroup_id" % group_type178 group_alias = "%s_testgroup_alias" % group_type179 try:180 web.add_group(group_type, group_id, {"alias": group_alias})181 finally:182 web.delete_group(group_type, group_id)183def test_get_all_users(web):184 users = {"klaus": {"alias": "mr. klaus", "pager": "99221199", "password": "1234"},185 "monroe": {"alias": "mr. monroe"}}186 expected_users = set(["cmkadmin", "automation"] + users.keys())187 try:188 response = web.add_htpasswd_users(users)189 all_users = web.get_all_users()190 assert not expected_users - set(all_users.keys())191 finally:192 web.delete_htpasswd_users(users.keys())193def test_add_htpasswd_users(web):194 users = {"klaus": {"alias": "mr. klaus", "pager": "99221199", "password": "1234"},195 "monroe": {"alias": "mr. monroe"}}196 try:197 web.add_htpasswd_users(users)198 finally:199 web.delete_htpasswd_users(users.keys())200def test_edit_htpasswd_users(web):201 users = {"klaus": {"alias": "mr. klaus", "pager": "99221199", "password": "1234"},202 "monroe": {"alias": "mr. monroe"}}203 try:204 web.add_htpasswd_users(users)205 web.edit_htpasswd_users({"monroe": {"set_attributes": {"alias": "ms. monroe"}},206 "klaus": {"unset_attributes": ["pager"]}})207 all_users = web.get_all_users()208 assert not "pager" in all_users["klaus"]209 assert all_users["monroe"]["alias"] == "ms. monroe"210 finally:211 web.delete_htpasswd_users(users.keys())212 pass213def test_discover_servics(web):214 try:215 web.add_host("test-host-discovery", attributes={216 "ipaddress": "127.0.0.1",217 })218 web.discover_services("test-host-discovery")219 finally:220 web.delete_host("test-host-discovery")221def test_activate_changes(web, site):222 try:223 web.add_host("test-host-activate", attributes={224 "ipaddress": "127.0.0.1",225 })226 web.activate_changes()227 result = site.live.query("GET hosts\nColumns: name\nFilter: name = test-host-activate\n")228 assert result == [["test-host-activate"]]229 finally:230 web.delete_host("test-host-activate")231 web.activate_changes()232def test_get_graph(web, site):233 try:234 # No graph yet...235 with pytest.raises(APIError) as e:236 data = web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True)237 assert "Cannot calculate graph recipes" in "%s" % e238 # Now add the host239 web.add_host("test-host-get-graph", attributes={240 "ipaddress": "127.0.0.1",241 })242 web.discover_services("test-host-get-graph")243 web.activate_changes()244 # Issue a reschedule245 site.live.command("SCHEDULE_FORCED_SERVICE_CHECK;test-host-get-graph;Check_MK;%d" % int(time.time()))246 # Wait for RRD file creation247 # Isn't this a bug that the graph is not instantly available?248 timeout = 10249 print "Checking for graph..."250 while timeout and not site.file_exists("var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"):251 try:252 data = web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True)253 except Exception:254 pass255 timeout -= 1256 time.sleep(1)257 print "Checking for graph..."258 assert site.file_exists("var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"), \259 "RRD %s is still missing" % "var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"260 _test_get_graph_api(web)261 _test_get_graph_image(web)262 _test_get_graph_notification_image(web)263 finally:264 web.delete_host("test-host-get-graph")265 web.activate_changes()266def _test_get_graph_api(web):267 # Now we get a graph268 data = web.get_regular_graph("test-host-get-graph", "Check_MK", 0)269 assert len(data["curves"]) == 4270 assert data["curves"][0]["title"] == "CPU time in user space"271 assert data["curves"][1]["title"] == "CPU time in operating system"272 assert data["curves"][2]["title"] == "Time spent waiting for Check_MK agent"273 assert data["curves"][3]["title"] == "Total execution time"274def _test_get_graph_image(web):275 result = web.post("graph_image.py", data={276 "request": json.dumps({277 "specification": ["template", {278 "service_description" : "Check_MK",...

Full Screen

Full Screen

nagios.py

Source:nagios.py Github

copy

Full Screen

...79 elif robot.args.delete_application:80 robot.create_branch()81 robot.delete_application()82 if robot.args.delete_host:83 robot.delete_host()84 robot.commit_branch()85 robot.deploy_branch()86 # Create new host.87 elif robot.args.create_host:88 robot.create_branch()89 robot.create_host()90 robot.commit_branch()91 robot.deploy_branch()92 # Remove host.93 elif robot.args.delete_host:94 robot.create_branch()95 robot.delete_host()96 robot.commit_branch()97 robot.deploy_branch()98 elif robot.args.create_service:99 pass100 elif robot.args.delete_service:101 pass102 else:103 pass104 robot.logger.debug("==== END DEBUG ====")105if __name__ == "__main__":...

Full Screen

Full Screen

delete_test.py

Source:delete_test.py Github

copy

Full Screen

1# !/usr/bin/env python2# -*- coding: utf-8 -*-3"""4@author: mango5@contact: w4n9@sina.com6@create: 16/3/297删除测试8"""9__author__ = "mango"10__version__ = "0.1"11from prettytable import PrettyTable12from multiprocessing import Manager, Pool13from multiprocessing.pool import ApplyResult14import pyfdfs_lib15import requests16import time17class DeleteTest(object):18 def __init__(self, delete_host, domain, limit):19 self.start_time = time.time()20 self.delete_host = delete_host21 self.domain = domain22 self.limit = limit23 self.delete_num = 024 self.success = 025 self.fail = 026 def delete_file(self):27 delete_client = pyfdfs_lib.PyFdfsLib(self.delete_host)28 while 1:29 delete_list_stat, delete_list_info = delete_client.fdfs_list_file(self.domain, self.limit)30 if delete_list_stat:31 if isinstance(delete_list_info, list):32 self.delete_num += len(delete_list_info)33 for i in delete_list_info:34 delete_stat, delete_info = delete_client.fdfs_delete_file(self.domain, i)35 if delete_stat:36 self.success += 137 else:38 self.fail += 139 else:40 break41 use_time = time.time() - self.start_time42 print "delete_count:%s, success:%s, fail:%s, use_time:%s" % (self.delete_num, self.success, self.fail, use_time)43if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful