Module: check_mk
Branch: master
Commit: 78d8c2db65b094dc481650468862b387a1fb936e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=78d8c2db65b094…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Dec 26 00:13:43 2018 +0100
DCD: Use bulk host delete API call
* Using less API calls reduces the API call overhead and improves
execution performance.
* Add test for delete_hosts call on the way
Change-Id: I3cd06fe5e98fd744862fd8e951d86283d000fe85
---
tests/integration/cmk/gui/test_webapi.py | 18 +++++++++++++++---
tests/testlib/__init__.py | 13 +++++++++++++
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/tests/integration/cmk/gui/test_webapi.py
b/tests/integration/cmk/gui/test_webapi.py
index f3d3642..c513722 100644
--- a/tests/integration/cmk/gui/test_webapi.py
+++ b/tests/integration/cmk/gui/test_webapi.py
@@ -82,6 +82,20 @@ def test_delete_host(web):
web.delete_host("test-host-delete")
+def test_delete_hosts(web):
+ try:
+ web.add_host(
+ "test-hosts-delete1", attributes={
+ "ipaddress": "127.0.0.1",
+ })
+ web.add_host(
+ "test-hosts-delete2", attributes={
+ "ipaddress": "127.0.0.1",
+ })
+ finally:
+ web.delete_hosts(["test-hosts-delete1",
"test-hosts-delete2"])
+
+
def test_get_host_effective_attributes(web):
try:
web.add_host(
@@ -246,9 +260,7 @@ def test_write_host_tags(web, site):
assert "lan" in tags_by_host["test-host-lan2"]
finally:
- web.delete_host("test-host-lan2")
- web.delete_host("test-host-lan")
- web.delete_host("test-host-dmz")
+ web.delete_hosts(["test-host-lan2", "test-host-lan",
"test-host-dmz"])
# TODO: Parameterize test for cme / non cme
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 7b9c490..743772b 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -1405,6 +1405,19 @@ class CMKWebSession(WebSession):
hosts = self.get_all_hosts()
assert hostname not in hosts
+ def delete_hosts(self, hostnames):
+ result = self._api_request("webapi.py?action=delete_hosts", {
+ "request": json.dumps({
+ "hostnames": hostnames,
+ }),
+ })
+
+ assert result is None
+
+ hosts = self.get_all_hosts()
+ for hostname in hostnames:
+ assert hostname not in hosts
+
def get_all_groups(self, group_type):
result = self._api_request("webapi.py?action=get_all_%sgroups" %
group_type, {})
return result