Commit 652d2a10 authored by Moritz Kiemer's avatar Moritz Kiemer
Browse files

migrate tests

Change-Id: I75de5b57a935a5e6d71bf04316d3b6d34edac069
parent 01756438
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
# yapf: disable
# type: ignore
checkname = 'heartbeat_crm'
freeze_time = '2019-04-11 12:38:36'
info = [[u'Stack:', u'corosync'],
[u'Current',
u'DC:',
u'hrssc61i02',
u'(version',
u'1.1.19+20180928.0d2680780-1.8-1.1.19+20180928.0d2680780)',
u'-',
u'partition',
u'with',
u'quorum'],
[u'Last', u'updated:', u'Mon', u'Mar', u'11', u'14:17:33', u'2019'],
[u'Last',
u'change:',
u'Thu',
u'Feb',
u'28',
u'17:40:07',
u'2019',
u'by',
u'hacluster',
u'via',
u'cibadmin',
u'on',
u'hrssc61i01'],
[u'2', u'nodes', u'configured'],
[u'10', u'resources', u'configured'],
[u'Online:', u'[', u'hrssc61i01', u'hrssc61i02', u']'],
[u'Full', u'list', u'of', u'resources:'],
[u'Resource', u'Group:', u'grp_IFG_ASCS22'],
[u'_',
u'rsc_ip_IFG_ASCS22',
u'(ocf::heartbeat:IPaddr2):',
u'Started',
u'hrssc61i01'],
[u'_',
u'rsc_sap_IFG_ASCS22',
u'(ocf::heartbeat:SAPInstance):',
u'Started',
u'hrssc61i01'],
[u'Resource', u'Group:', u'grp_IFG_ERS23'],
[u'_',
u'rsc_ip_IFG_ERS23',
u'(ocf::heartbeat:IPaddr2):',
u'Started',
u'hrssc61i02'],
[u'_',
u'rsc_sap_IFG_ERS23',
u'(ocf::heartbeat:SAPInstance):',
u'Started',
u'hrssc61i02'],
[u'Clone', u'Set:', u'clone_nfs_sapmnt_IFG', u'[nfs_sapmnt_IFG]'],
[u'_', u'Started:', u'[', u'hrssc61i01', u'hrssc61i02', u']'],
[u'Clone', u'Set:', u'clone_nfs_usr_sap_IFG', u'[nfs_usr_sap_IFG]'],
[u'_', u'Started:', u'[', u'hrssc61i01', u'hrssc61i02', u']'],
[u'st-vmware', u'(stonith:fence_vmware_rest):', u'Started', u'hrssc61i02'],
[u'st-vmware2', u'(stonith:fence_vmware_rest):', u'Started', u'hrssc61i01'],
[u'Failed', u'Resource', u'Actions:'],
[u'*',
u'st-vmware_monitor_20000',
u'on',
u'hrssc61i02',
u"'unknown",
u"error'",
u'(1):',
u'call=43,',
u'status=Error,',
u"exitreason='',"],
[u'_',
u"last-rc-change='Mon",
u'Mar',
u'4',
u'09:29:54',
u"2019',",
u'queued=0ms,',
u'exec=11096ms'],
[u'*',
u'st-vmware2_monitor_20000',
u'on',
u'hrssc61i01',
u"'unknown",
u"error'",
u'(1):',
u'call=43,',
u'status=Error,',
u"exitreason='',"],
[u'_',
u"last-rc-change='Mon",
u'Mar',
u'4',
u'09:29:54',
u"2019',",
u'queued=0ms,',
u'exec=11088ms']]
discovery = {'': [(None, {'num_nodes': 2, 'num_resources': 10})],
'resources': [(u'clone_nfs_sapmnt_IFG', {}),
(u'clone_nfs_usr_sap_IFG', {}),
(u'grp_IFG_ASCS22', {}),
(u'grp_IFG_ERS23', {}),
(u'st-vmware', {}),
(u'st-vmware2', {})]}
checks = {'': [(None,
{'max_age': 60, 'num_nodes': 2, 'num_resources': 10},
[(2, 'Ignoring reported data (Status output too old: 31 d)', [])])],
'resources': [(u'clone_nfs_sapmnt_IFG',
{},
[(0,
u"clone_nfs_sapmnt_IFG Clone Started hrssc61i01, hrssc61i02",
[])]),
(u'clone_nfs_usr_sap_IFG',
{},
[(0,
u"clone_nfs_usr_sap_IFG Clone Started hrssc61i01, hrssc61i02",
[])]),
(u'grp_IFG_ASCS22',
{},
[(0,
u'rsc_ip_IFG_ASCS22 (ocf::heartbeat:IPaddr2): Started hrssc61i01',
[]),
(0,
u'rsc_sap_IFG_ASCS22 (ocf::heartbeat:SAPInstance): Started hrssc61i01',
[])
]),
(u'grp_IFG_ERS23',
{},
[(0,
u'rsc_ip_IFG_ERS23 (ocf::heartbeat:IPaddr2): Started hrssc61i02',
[]),
(0,
u'rsc_sap_IFG_ERS23 (ocf::heartbeat:SAPInstance): Started hrssc61i02',
[])]),
(u'st-vmware',
{},
[(0,
u'st-vmware (stonith:fence_vmware_rest): Started hrssc61i02',
[])]),
(u'st-vmware2',
{},
[(0,
u'st-vmware2 (stonith:fence_vmware_rest): Started hrssc61i01',
[])])]}
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
# yapf: disable
# type: ignore
checkname = 'heartbeat_crm'
freeze_time = '2020-09-08 10:36:36'
info = [
['Cluster', 'Summary:'], ['_*', 'Stack:', 'corosync'],
[
'_*', 'Current', 'DC:', 'ha02', '(version',
'2.0.3-5.el8_2.1-4b1f869f0f)', '-', 'partition', 'with', 'quorum'
], ['_*', 'Last', 'updated:', 'Tue', 'Sep', '8', '10:36:12', '2020'],
[
'_*', 'Last', 'change:', 'Mon', 'Sep', '7', '22:33:23', '2020', 'by',
'root', 'via', 'cibadmin', 'on', 'ha01'
], ['_*', '2', 'nodes', 'configured'],
['_*', '3', 'resource', 'instances', 'configured'], ['Node', 'List:'],
['_*', 'Online:', '[', 'ha01', 'ha02', ']'],
['Full', 'List', 'of', 'Resources:'],
['_*', 'vip', '(ocf::heartbeat:IPaddr):', 'Started', 'ha01'],
['_*', 'Clone', 'Set:', 'splunk-clone', '[splunk]:'],
['_', '*', 'Started:', '[', 'ha01', 'ha02', ']']
]
discovery = {
'': [(None, {
'num_nodes': 2,
'num_resources': 3
})],
'resources': []
}
checks = {
'': [
(
None, {
'max_age': 600,
'num_nodes': None,
'num_resources': None
}, [(0, 'DC: ha02', [])]
),
(
None, {
'max_age': 60,
'num_nodes': 2,
'num_resources': 3
}, [
(0, 'DC: ha02', []), (0, 'Nodes: 2', []),
(0, 'Resources: 3', [])
]
)
]
}
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
# yapf: disable
# type: ignore
checkname = 'heartbeat_crm'
freeze_time = '2019-04-11 12:38:36'
info = [[u'Stack:', u'corosync'],
[u'Current',
u'DC:',
u'cluster',
u'(version',
u'1.1.16-12.el7_4.8-94ff4df)',
u'-',
u'partition',
u'with',
u'quorum'],
[u'Last', u'updated:', u'Tue', u'Oct', u'26', u'13:58:47', u'2019'],
[u'Last',
u'change:',
u'Sat',
u'Oct',
u'24',
u'10:54:28',
u'2019',
u'by',
u'root',
u'via',
u'cibadmin',
u'on',
u'cluster'],
[u'2', u'nodes', u'configured'],
[u'6', u'resources', u'configured'],
[u'Online:', u'[', u'cluster1', u'cluster2', u']'],
[u'Full', u'list', u'of', u'resources:'],
[u'Resource', u'Group:', u'mysqldb1'],
[u'_', u'mysqldb1_lvm', u'(ocf::heartbeat:LVM):Started', u'cluster1'],
[u'_', u'mysqldb1_fs', u'(ocf::heartbeat:Filesystem):Started', u'cluster1'],
[u'_', u'mysqldb1_ip', u'(ocf::heartbeat:IPaddr2):Started', u'cluster1'],
[u'_', u'mysqldb1_mysql', u'(service:mysqldb1):Started', u'cluster1'],
[u'cluster1_fence(stonith:fence_ipmilan):', u'Started', u'cluster2'],
[u'cluster2_fence(stonith:fence_ipmilan):', u'Started', u'cluster1'],
[u'Failed', u'Actions:'],
[u'*',
u'mysqldb1_lvm_monitor_10000',
u'on',
u'cluster1',
u"'unknown",
u"error'",
u'(1):',
u'call=158,',
u'status=Timed',
u'Out,',
u"exitreason='none',"],
[u'_',
u"last-rc-change='Fri",
u'Feb',
u'22',
u'22:54:52',
u"2019',",
u'queued=0ms,',
u'exec=0ms']]
discovery = {'': [(None, {'num_nodes': 2, 'num_resources': 6})],
'resources': [(u'cluster1_fence(stonith:fence_ipmilan):', {}),
(u'cluster2_fence(stonith:fence_ipmilan):', {}),
(u'mysqldb1', {})]}
checks = {
'': [
(None,
{'max_age': 60, 'num_nodes': 2, 'num_resources': 6},
[(0, u'DC: cluster', []),
(0, u'Nodes: 2', []),
(0, u'Resources: 6', [])]),
(None,
{'max_age': 60, 'num_nodes': 2, 'num_resources': 6, 'show_failed_actions': True},
[(0, u'DC: cluster', []),
(0, u'Nodes: 2', []),
(0, u'Resources: 6', []),
(1, u"Failed: mysqldb1_lvm_monitor_10000 on cluster1 'unknown error' (1): call=158, "
u"status=Timed Out, exitreason='none', last-rc-change='Fri Feb 22 22:54:52 2019', "
u"queued=0ms, exec=0ms", [])]),
],
'resources': [
(u'cluster1_fence(stonith:fence_ipmilan):',
{},
[(0,
u'cluster1_fence(stonith:fence_ipmilan): Started cluster2',
[]),
(2, u'Resource is in state "cluster2"', [])]),
(u'cluster2_fence(stonith:fence_ipmilan):',
{},
[(0,
u'cluster2_fence(stonith:fence_ipmilan): Started cluster1',
[]),
(2, u'Resource is in state "cluster1"', [])]),
(u'mysqldb1',
{},
[(0,
u'mysqldb1_lvm (ocf::heartbeat:LVM):Started cluster1',
[]),
(2, u'Resource is in state "cluster1"', []),
(0,
u'mysqldb1_fs (ocf::heartbeat:Filesystem):Started cluster1',
[]),
(2, u'Resource is in state "cluster1"', []),
(0,
u'mysqldb1_ip (ocf::heartbeat:IPaddr2):Started cluster1',
[]),
(2, u'Resource is in state "cluster1"', []),
(0,
u'mysqldb1_mysql (service:mysqldb1):Started cluster1',
[]),
(2, u'Resource is in state "cluster1"', [])])
],
}
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
import pytest
from tests.testlib import on_time
from cmk.utils.type_defs import CheckPluginName, SectionName
from cmk.base.plugins.agent_based.agent_based_api.v1 import Result, State
@pytest.fixture(name="section_1", scope="module")
def _get_section_1(fix_register):
return fix_register.agent_sections[SectionName("heartbeat_crm")].parse_function(
[
["Cluster", "Summary:"],
["_*", "Stack:", "corosync"],
[
"_*",
"Current",
"DC:",
"ha02",
"(version",
"2.0.3-5.el8_2.1-4b1f869f0f)",
"-",
"partition",
"with",
"quorum",
],
["_*", "Last", "updated:", "Tue", "Sep", "8", "10:36:12", "2020"],
[
"_*",
"Last",
"change:",
"Mon",
"Sep",
"7",
"22:33:23",
"2020",
"by",
"root",
"via",
"cibadmin",
"on",
"ha01",
],
["_*", "2", "nodes", "configured"],
["_*", "3", "resource", "instances", "configured"],
["Node", "List:"],
["_*", "Online:", "[", "ha01", "ha02", "]"],
["Full", "List", "of", "Resources:"],
["_*", "vip", "(ocf::heartbeat:IPaddr):", "Started", "ha01"],
["_*", "Clone", "Set:", "splunk-clone", "[splunk]:"],
["_", "*", "Started:", "[", "ha01", "ha02", "]"],
]
)
@pytest.fixture(name="section_2", scope="module")
def _get_section_2(fix_register):
return fix_register.agent_sections[SectionName("heartbeat_crm")].parse_function(
[
["Stack:", "corosync"],
[
"Current",
"DC:",
"cluster",
"(version",
"1.1.16-12.el7_4.8-94ff4df)",
"-",
"partition",
"with",
"quorum",
],
["Last", "updated:", "Tue", "Oct", "26", "13:58:47", "2019"],
[
"Last",
"change:",
"Sat",
"Oct",
"24",
"10:54:28",
"2019",
"by",
"root",
"via",
"cibadmin",
"on",
"cluster",
],
["2", "nodes", "configured"],
["6", "resources", "configured"],
["Online:", "[", "cluster1", "cluster2", "]"],
["Full", "list", "of", "resources:"],
["Resource", "Group:", "mysqldb1"],
["_", "mysqldb1_lvm", "(ocf::heartbeat:LVM):Started", "cluster1"],
["_", "mysqldb1_fs", "(ocf::heartbeat:Filesystem):Started", "cluster1"],
["_", "mysqldb1_ip", "(ocf::heartbeat:IPaddr2):Started", "cluster1"],
["_", "mysqldb1_mysql", "(service:mysqldb1):Started", "cluster1"],
["cluster1_fence(stonith:fence_ipmilan):", "Started", "cluster2"],
["cluster2_fence(stonith:fence_ipmilan):", "Started", "cluster1"],
["Failed", "Actions:"],
[
"*",
"mysqldb1_lvm_monitor_10000",
"on",
"cluster1",
"'unknown",
"error'",
"(1):",
"call=158,",
"status=Timed",
"Out,",
"exitreason='none',",
],
[
"_",
"last-rc-change='Fri",
"Feb",
"22",
"22:54:52",
"2019',",
"queued=0ms,",
"exec=0ms",
],
]
)
@pytest.fixture(name="discover_heartbeat_crm")
def _get_discovery_function(fix_register):
return fix_register.check_plugins[CheckPluginName("heartbeat_crm")].discovery_function
@pytest.fixture(name="check_heartbeat_crm")
def _get_check_function(fix_register):
return lambda p, s: fix_register.check_plugins[CheckPluginName("heartbeat_crm")].check_function(
params=p, section=s
)
# enable/fix once migrated
# def test_discover_heartbeat_crm(section_1, discover_heartbeat_crm) -> None:
# assert list(discover_heartbeat_crm(section_1, {})) == [
# Service(parameters={"num_nodes": 2, "num_resources": 3}),
# ]
#
# def test_discovery_section_1(section_1, discover_heartbeat_crm) -> None:
# assert list(discover_heartbeat_crm(section_1, {"naildown_dc": True])) == [
# Service(parameters={"num_nodes": 2, "num_resources": 3}),
# ]
#
def test_check_heartbeat_crm_too_old(section_1, check_heartbeat_crm) -> None:
(result,) = check_heartbeat_crm(
{"max_age": 60, "num_nodes": 2, "num_resources": 3},
section_1,
)
assert result.state is State.CRIT
# Note: going crit is not the same as ignoring data.
assert result.summary.startswith("Ignoring reported data ")
def test_check_heartbeat_crm_ok(section_1, check_heartbeat_crm) -> None:
with on_time("2020-09-08 10:36:36", "UTC"):
assert list(
check_heartbeat_crm(
{"max_age": 60, "num_nodes": 2, "num_resources": 3},
section_1,
)
) == [
Result(state=State.OK, summary="DC: ha02"),
Result(state=State.OK, summary="Nodes: 2"),
Result(state=State.OK, summary="Resources: 3"),
]
def test_check_heartbeat_crm_crit(section_2, check_heartbeat_crm) -> None:
with on_time("2019-08-18 10:36:36", "UTC"):
assert list(
check_heartbeat_crm(
{
"dc": "hasi",
"max_age": 60,
"num_nodes": 1,
"num_resources": 4,
"show_failed_actions": True,
},
section_2,
)
) == [
Result(state=State.CRIT, summary="DC: cluster (Expected hasi)"),
Result(state=State.CRIT, summary="Nodes: 2 (Expected 1)"),
Result(state=State.CRIT, summary="Resources: 6 (Expected 4)"),
Result(
state=State.WARN,
summary=(
"Failed: mysqldb1_lvm_monitor_10000 on cluster1 'unknown error' (1): call=158, "
"status=Timed Out, exitreason='none', "
"last-rc-change='Fri Feb 22 22:54:52 2019', queued=0ms, exec=0ms"
),
),
]
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
import pytest
from cmk.utils.type_defs import CheckPluginName, SectionName
from cmk.base.plugins.agent_based.agent_based_api.v1 import Result, State
@pytest.fixture(name="section_1", scope="module")
def _get_section_1(fix_register):
return fix_register.agent_sections[SectionName("heartbeat_crm")].parse_function(
[
["Stack:", "corosync"],
[
"Current",
"DC:",
"hrssc61i02",
"(version",
"1.1.19+20180928.0d2680780-1.8-1.1.19+20180928.0d2680780)",