diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
commit | 0915b3ef56dfac3113cce55a59a5765dc94976be (patch) | |
tree | a8fea11d50b4f083e1bf0f90025ece7f0824784a /test/icinga-dependencies.cpp | |
parent | Initial commit. (diff) | |
download | icinga2-upstream.tar.xz icinga2-upstream.zip |
Adding upstream version 2.13.6.upstream/2.13.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/icinga-dependencies.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/icinga-dependencies.cpp b/test/icinga-dependencies.cpp new file mode 100644 index 0000000..b31f540 --- /dev/null +++ b/test/icinga-dependencies.cpp @@ -0,0 +1,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() |