blob: b31f540b167f050b20aa912f16fa117c77efa24e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */
#include "icinga/host.hpp"
#include "icinga/dependency.hpp"
#include <BoostTestTargetConfig.h>
#include <iostream>
using namespace icinga;
BOOST_AUTO_TEST_SUITE(icinga_dependencies)
BOOST_AUTO_TEST_CASE(multi_parent)
{
/* One child host, two parent hosts. Simulate multi-parent dependencies. */
std::cout << "Testing reachability for multi parent dependencies." << std::endl;
/*
* Our mock requires:
* - SetParent/SetChild functions for the dependency
* - Parent objects need a CheckResult object
* - Dependencies need a StateFilter
*/
Host::Ptr parentHost1 = new Host();
parentHost1->SetActive(true);
parentHost1->SetMaxCheckAttempts(1);
parentHost1->Activate();
parentHost1->SetAuthority(true);
parentHost1->SetStateRaw(ServiceCritical);
parentHost1->SetStateType(StateTypeHard);
parentHost1->SetLastCheckResult(new CheckResult());
Host::Ptr parentHost2 = new Host();
parentHost2->SetActive(true);
parentHost2->SetMaxCheckAttempts(1);
parentHost2->Activate();
parentHost2->SetAuthority(true);
parentHost2->SetStateRaw(ServiceOK);
parentHost2->SetStateType(StateTypeHard);
parentHost2->SetLastCheckResult(new CheckResult());
Host::Ptr childHost = new Host();
childHost->SetActive(true);
childHost->SetMaxCheckAttempts(1);
childHost->Activate();
childHost->SetAuthority(true);
childHost->SetStateRaw(ServiceOK);
childHost->SetStateType(StateTypeHard);
/* Build the dependency tree. */
Dependency::Ptr dep1 = new Dependency();
dep1->SetParent(parentHost1);
dep1->SetChild(childHost);
dep1->SetStateFilter(StateFilterUp);
// Reverse dependencies
childHost->AddDependency(dep1);
parentHost1->AddReverseDependency(dep1);
Dependency::Ptr dep2 = new Dependency();
dep2->SetParent(parentHost2);
dep2->SetChild(childHost);
dep2->SetStateFilter(StateFilterUp);
// Reverse dependencies
childHost->AddDependency(dep2);
parentHost2->AddReverseDependency(dep2);
/* Test the reachability from this point.
* parentHost1 is DOWN, parentHost2 is UP.
* Expected result: childHost is reachable.
*/
parentHost1->SetStateRaw(ServiceCritical); // parent Host 1 DOWN
parentHost2->SetStateRaw(ServiceOK); // parent Host 2 UP
BOOST_CHECK(childHost->IsReachable() == true);
/* parentHost1 is DOWN, parentHost2 is DOWN.
* Expected result: childHost is unreachable.
*/
parentHost1->SetStateRaw(ServiceCritical); // parent Host 1 DOWN
parentHost2->SetStateRaw(ServiceCritical); // parent Host 2 DOWN
BOOST_CHECK(childHost->IsReachable() == false);
}
BOOST_AUTO_TEST_SUITE_END()
|