Add specific visualization for labels depending on their source
[check_mk.git] / tests / unit / cmk_base / test_unit_automations.py
blob39f08145c12cedb3b31199063f2d8047c97eed84
1 import cmk
2 import cmk_base.automations
3 import cmk_base.automations.check_mk as automations
4 import cmk_base.config as config
7 def test_registered_automations(site):
8 needed_automations = [
9 'active-check',
10 'analyse-host',
11 'analyse-service',
12 'delete-hosts',
13 'diag-host',
14 'get-agent-output',
15 'get-autochecks',
16 'get-check-information',
17 'get-check-manpage',
18 'get-configuration',
19 'get-labels-of',
20 'get-real-time-checks',
21 'get-service-configurations',
22 'inventory',
23 'notification-analyse',
24 'notification-get-bulks',
25 'notification-replay',
26 'reload',
27 'rename-hosts',
28 'restart',
29 'scan-parents',
30 'set-autochecks',
31 'try-inventory',
32 'update-dns-cache',
35 if cmk.is_enterprise_edition():
36 needed_automations += [
37 'bake-agents',
38 'get-package-info',
39 'get-package',
40 'create-package',
41 'edit-package',
42 'install-package',
43 'remove-package',
44 'release-package',
45 'remove-unpackaged-file',
48 registered_automations = cmk_base.automations.automations._automations.keys()
50 assert sorted(needed_automations) == sorted(registered_automations)
53 def test_static_check_rules_of_host(monkeypatch):
54 as_automation = automations.AutomationAnalyseServices()
55 assert as_automation.static_check_rules_of("checkgroup_ding", "test-host") == []
57 monkeypatch.setattr(config, "all_hosts", ["test-host"])
58 monkeypatch.setattr(config, "host_paths", {"test-host": "/"})
59 monkeypatch.setattr(
60 config, "static_checks", {
61 "checkgroup_ding": [
62 (("ding-check", "item"), [], config.ALL_HOSTS, {}),
63 (("ding-check", "item2"), [], config.ALL_HOSTS, {
64 "disabled": True
65 }),
66 (("dong-check", "item2", {
67 "param1": 1
68 }), [], config.ALL_HOSTS, {}),
71 config.get_config_cache().initialize()
73 assert as_automation.static_check_rules_of("checkgroup_ding", "test-host") == [
74 ('ding-check', 'item'),
75 ('dong-check', 'item2', {
76 'param1': 1
77 }),
81 def test_get_labels_of_host(monkeypatch):
82 automation = automations.AutomationGetLabelsOf()
84 monkeypatch.setattr(config, "all_hosts", ["test-host"])
85 monkeypatch.setattr(config, "host_paths", {"test-host": "/"})
86 monkeypatch.setattr(config, "host_labels", {
87 "test-host": {
88 "explicit": "ding",
91 config.get_config_cache().initialize()
93 assert automation.execute(["host", "test-host"]) == {
94 "labels": {
95 "explicit": "ding"
97 "label_sources": {
98 "explicit": "explicit"
103 def test_get_labels_of_service(monkeypatch):
104 automation = automations.AutomationGetLabelsOf()
106 monkeypatch.setattr(config, "all_hosts", ["test-host"])
107 monkeypatch.setattr(config, "host_paths", {"test-host": "/"})
109 ruleset = [
111 "label1": "val1"
112 }, [], config.ALL_HOSTS, ["CPU load$"], {}),
114 "label2": "val2"
115 }, [], config.ALL_HOSTS, ["CPU load$"], {}),
117 monkeypatch.setattr(config, "service_label_rules", ruleset)
119 config.get_config_cache().initialize()
121 assert automation.execute(["service", "test-host", "CPU load"]) == {
122 "labels": {
123 "label1": "val1",
124 "label2": "val2"
126 "label_sources": {
127 "label1": "ruleset",
128 "label2": "ruleset"
133 def test_analyse_host(monkeypatch):
134 automation = automations.AutomationAnalyseHost()
136 monkeypatch.setattr(config, "all_hosts", ["test-host"])
137 monkeypatch.setattr(config, "host_paths", {"test-host": "/"})
138 monkeypatch.setattr(config, "host_labels", {
139 "test-host": {
140 "explicit": "ding",
143 config.get_config_cache().initialize()
145 assert automation.execute(["test-host"]) == {
146 "labels": {
147 "explicit": "ding"
149 "label_sources": {
150 "explicit": "explicit"