mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Tests: Add multi parent dependency test case
This commit is contained in:
parent
9b0365ab43
commit
3a4fb840d4
@ -201,3 +201,13 @@ void Dependency::ValidateStates(const Lazy<Array::Ptr>& lvalue, const Validation
|
|||||||
BOOST_THROW_EXCEPTION(ValidationError(this, { "states" }, "State filter is invalid for service dependency."));
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "states" }, "State filter is invalid for service dependency."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dependency::SetParent(intrusive_ptr<Checkable> parent)
|
||||||
|
{
|
||||||
|
m_Parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dependency::SetChild(intrusive_ptr<Checkable> child)
|
||||||
|
{
|
||||||
|
m_Child = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,10 @@ public:
|
|||||||
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
||||||
|
|
||||||
|
/* Note: Only use them for unit test mocks. Prefer OnConfigLoaded(). */
|
||||||
|
void SetParent(intrusive_ptr<Checkable> parent);
|
||||||
|
void SetChild(intrusive_ptr<Checkable> child);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnConfigLoaded() override;
|
void OnConfigLoaded() override;
|
||||||
void OnAllConfigLoaded() override;
|
void OnAllConfigLoaded() override;
|
||||||
|
@ -25,6 +25,7 @@ set(base_test_SOURCES
|
|||||||
base-value.cpp
|
base-value.cpp
|
||||||
config-ops.cpp
|
config-ops.cpp
|
||||||
icinga-checkresult.cpp
|
icinga-checkresult.cpp
|
||||||
|
icinga-dependencies.cpp
|
||||||
icinga-legacytimeperiod.cpp
|
icinga-legacytimeperiod.cpp
|
||||||
icinga-macros.cpp
|
icinga-macros.cpp
|
||||||
icinga-notification.cpp
|
icinga-notification.cpp
|
||||||
@ -126,6 +127,7 @@ add_boost_test(base
|
|||||||
icinga_checkresult/service_3attempts
|
icinga_checkresult/service_3attempts
|
||||||
icinga_checkresult/host_flapping_notification
|
icinga_checkresult/host_flapping_notification
|
||||||
icinga_checkresult/service_flapping_notification
|
icinga_checkresult/service_flapping_notification
|
||||||
|
icinga_dependencies/multi_parent
|
||||||
icinga_notification/strings
|
icinga_notification/strings
|
||||||
icinga_notification/state_filter
|
icinga_notification/state_filter
|
||||||
icinga_notification/type_filter
|
icinga_notification/type_filter
|
||||||
|
89
test/icinga-dependencies.cpp
Normal file
89
test/icinga-dependencies.cpp
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user