Module: check_mk
Branch: master
Commit: b678b6877232855d6e9b2b047e5d51c5246cad2f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b678b687723285…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Jan 25 11:07:29 2019 +0100
mk_jolokia: unit tests and small fixes
Change-Id: I9fce297d03b72796c977ff6783f57c08842a0ee8
---
agents/plugins/mk_jolokia.py | 10 ++++-----
tests/unit/plugins/test_mk_jolokia.py | 38 +++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/agents/plugins/mk_jolokia.py b/agents/plugins/mk_jolokia.py
index 36125ba..ac1e57d 100755
--- a/agents/plugins/mk_jolokia.py
+++ b/agents/plugins/mk_jolokia.py
@@ -206,7 +206,7 @@ class JolokiaInstance(object):
required_keys.add("service_password")
missing_keys = required_keys - set(config.keys())
if missing_keys:
- raise ValueError(err_msg % ("Missing keys " % ",
".join(missing_keys)))
+ raise ValueError(err_msg % ("Missing keys %s" % ",
".join(missing_keys)))
if not instance:
config["instance"] = str(config["port"])
@@ -228,7 +228,7 @@ class JolokiaInstance(object):
self.config = self._sanitize_config(config)
self.name = self.config["instance"]
- self.product = self.config["product"]
+ self.product = self.config.get("product")
self.custom_vars = self.config.get("custom_vars", [])
self.base_url = self._get_base_url()
@@ -353,7 +353,7 @@ def extract_item(key, itemspec):
def fetch_metric(inst, path, title, itemspec, inst_add=None):
- values = fetch_var(inst.config, path, inst.config["service_url"],
inst.config["service_user"],
+ values = fetch_var(inst, path, inst.config["service_url"],
inst.config["service_user"],
inst.config["service_password"])
item_list = make_item_list((), values, itemspec)
@@ -387,7 +387,7 @@ def _get_queries(do_search, inst, itemspec, title, path, mbean):
if not do_search:
return [(mbean + "/" + path, title, itemspec)]
- value = fetch_var(inst.config, mbean, None, None, None, function="search")
+ value = fetch_var(inst, mbean, None, None, None, function="search")
try:
paths = make_item_list((), value, "")[0][1]
except IndexError:
@@ -511,7 +511,7 @@ def prepare_http_opener(inst):
def generate_jolokia_info(inst):
# Determine type of server
- value = fetch_var(inst.config, "", None, None, None)
+ value = fetch_var(inst, "", None, None, None)
server_info = make_item_list((), value, "")
if not server_info:
diff --git a/tests/unit/plugins/test_mk_jolokia.py
b/tests/unit/plugins/test_mk_jolokia.py
new file mode 100644
index 0000000..0dd61ba
--- /dev/null
+++ b/tests/unit/plugins/test_mk_jolokia.py
@@ -0,0 +1,38 @@
+# -*- encoding: utf-8
+# pylint: disable=protected-access
+import os
+import sys
+import copy
+import pytest
+from testlib import cmk_path # pylint: disable=import-error
+
+sys.path.insert(0, os.path.join(cmk_path(), 'agents', 'plugins'))
+
+import mk_jolokia # pylint: disable=import-error,wrong-import-position
+
+
+SANITIZE = mk_jolokia.JolokiaInstance._sanitize_config
+
+
+(a)pytest.mark.parametrize("removed"oved", ["protocol", "server",
"port", "suburi"])
+def test_missing_config_basic(removed):
+ config = copy.deepcopy(mk_jolokia.DEFAULT_CONFIG)
+ config.pop(removed)
+ with pytest.raises(ValueError):
+ SANITIZE(config)
+
+
+def test_config_instance():
+ config = copy.deepcopy(mk_jolokia.DEFAULT_CONFIG)
+ assert SANITIZE(config).get("instance") == "8080"
+ config["instance"] = "some spaces in string"
+ assert SANITIZE(config).get("instance") ==
"some_spaces_in_string"
+
+
+(a)pytest.mark.parametrize("config,base_url"_url", [
+ ({"protocol": "sftp", "server":
"billy.theserver", "port": 42,
+ "suburi": "jolo-site"},
"sftp://billy.theserver:42/jolo-site")
+])
+def test_jolokia_instance_base_url(config, base_url):
+ joloi = mk_jolokia.JolokiaInstance(config)
+ assert joloi._get_base_url() == base_url