Module: check_mk
Branch: master
Commit: 993dfa076fda01935bdd3c758d0d08d7124f5a2d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=993dfa076fda01…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Mar 22 16:51:24 2019 +0100
Make docker_get_short_id work for kubernetes output
CMK-1893
Change-Id: Iac8ec527758cb034fd63de9420fe888f4f6be849
---
checks/docker.include | 2 +-
tests/unit/checks/test_docker_parse_helpers.py | 25 ++++++---------------
.../checks/test_docker_parse_legacy_helpers.py | 26 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/checks/docker.include b/checks/docker.include
index 0c53a16..00cae82 100644
--- a/checks/docker.include
+++ b/checks/docker.include
@@ -44,7 +44,7 @@ def docker_get_version(info):
def docker_get_short_id(string):
- return string.split(":", 1)[-1][:12]
+ return string.rsplit(":", 1)[-1][:12]
def docker_format_labels(obj):
diff --git a/tests/unit/checks/test_docker_parse_helpers.py
b/tests/unit/checks/test_docker_parse_helpers.py
index aa0ebfc..2dd9e6c 100644
--- a/tests/unit/checks/test_docker_parse_helpers.py
+++ b/tests/unit/checks/test_docker_parse_helpers.py
@@ -3,24 +3,13 @@ import os
pytestmark = pytest.mark.checks
-execfile(os.path.join(os.path.dirname(__file__),
'../../../checks/legacy_docker.include'))
+execfile(os.path.join(os.path.dirname(__file__),
'../../../checks/docker.include'))
-(a)pytest.mark.parametrize('indata,outdata'ata', [
- ("123GB (42%)", 123000000000),
- ("0 B", 0),
- ("2B", 2),
- ("23 kB", 23000),
- ("", None),
+(a)pytest.mark.parametrize('indata,expected'ted', [
+
("docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451",
+ "e3456c851a15"),
])
-def test_parse_legacy_docker_get_bytes(indata, outdata):
- parsed = _legacy_docker_get_bytes(indata)
- assert outdata == parsed
-
-
-(a)pytest.mark.parametrize('indata,outdata'ata', [
- ("sha256:8b15606a9e3e430cb7ba739fde2fbb3734a19f8a59a825ffa877f9be49059817",
"8b15606a9e3e"),
-])
-def test_parse_legacy_docker_trunk_id(indata, outdata):
- parsed = _legacy_docker_trunk_id(indata)
- assert outdata == parsed
+def test_parse_short_id(indata, expected):
+ actual = docker_get_short_id(indata)
+ assert actual == expected
diff --git a/tests/unit/checks/test_docker_parse_legacy_helpers.py
b/tests/unit/checks/test_docker_parse_legacy_helpers.py
new file mode 100644
index 0000000..aa0ebfc
--- /dev/null
+++ b/tests/unit/checks/test_docker_parse_legacy_helpers.py
@@ -0,0 +1,26 @@
+import pytest
+import os
+
+pytestmark = pytest.mark.checks
+
+execfile(os.path.join(os.path.dirname(__file__),
'../../../checks/legacy_docker.include'))
+
+
+(a)pytest.mark.parametrize('indata,outdata'ata', [
+ ("123GB (42%)", 123000000000),
+ ("0 B", 0),
+ ("2B", 2),
+ ("23 kB", 23000),
+ ("", None),
+])
+def test_parse_legacy_docker_get_bytes(indata, outdata):
+ parsed = _legacy_docker_get_bytes(indata)
+ assert outdata == parsed
+
+
+(a)pytest.mark.parametrize('indata,outdata'ata', [
+ ("sha256:8b15606a9e3e430cb7ba739fde2fbb3734a19f8a59a825ffa877f9be49059817",
"8b15606a9e3e"),
+])
+def test_parse_legacy_docker_trunk_id(indata, outdata):
+ parsed = _legacy_docker_trunk_id(indata)
+ assert outdata == parsed