Skip to content

Commit

Permalink
feat(test): add tests EBPN about relation parent child
Browse files Browse the repository at this point in the history
  • Loading branch information
sechkem committed Nov 13, 2024
1 parent 663543b commit e3166ef
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 1 deletion.
3 changes: 3 additions & 0 deletions engine/enginerpc/engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ message EngineHost {
UNREACHABLE = 2;
}
State current_state = 6;
string display_name = 7;
repeated string parent_hosts = 8;
repeated string child_hosts = 9;
}

message ContactIdentifier {
Expand Down
12 changes: 11 additions & 1 deletion engine/enginerpc/engine_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,19 @@ grpc::Status engine_impl::GetHost(grpc::ServerContext* context [[maybe_unused]],
host->set_alias(selectedhost->get_alias());
host->set_address(selectedhost->get_address());
host->set_check_period(selectedhost->check_period());
host->set_id(selectedhost->host_id());
host->set_current_state(
static_cast<EngineHost::State>(selectedhost->get_current_state()));
host->set_id(selectedhost->host_id());
host->set_display_name(selectedhost->get_display_name());

if (!selectedhost->parent_hosts.empty())
for (const auto& [key, _] : selectedhost->parent_hosts)
host->add_parent_hosts(key);

if (!selectedhost->child_hosts.empty())
for (const auto& [key, _] : selectedhost->child_hosts)
host->add_child_hosts(key);

return 0;
});

Expand Down
262 changes: 262 additions & 0 deletions tests/broker-engine/parent_child_relation.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
*** Settings ***
Documentation Centreon Engine/Broker verify relation parent child host.
Resource ../resources/import.resource

Suite Setup Ctn Clean Before Suite
Suite Teardown Ctn Clean After Suite
Test Setup Ctn Stop Processes
Test Teardown Ctn Save Logs If Failed


*** Test Cases ***

EBPN0
[Documentation] Verify if child is in queue when parent is down.
[Tags] broker engine MON-151686
Ctn Config Engine ${1} ${5} ${1}
Ctn Config Broker rrd
Ctn Config Broker central
Ctn Config Broker module
Ctn Config BBDO3 1

Ctn Broker Config Log rrd rrd trace
Ctn Broker Config Log central sql debug
Ctn Broker Config Log rrd core error
Ctn Engine Config Set Value 0 log_level_checks debug
Ctn Config Broker Sql Output central unified_sql 10
Ctn Broker Config Flush Log central 0
Ctn Broker Config Flush Log rrd 0

Ctn Clear Retention
Ctn Clear Db resources

# force the check result to 2
Ctn Config Host Command Status ${0} checkh1 2

# host_1 is parent of host_2
Ctn Add Parent To Host 0 host_2 host_1

${start} Get Current Date
Ctn Start Broker
Ctn Start Engine
Ctn Wait For Engine To Be Ready ${start} ${1}

# check if host_2 is child of host_1
Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}

FOR ${index} IN RANGE 30
${output} Query
... SELECT child_id, parent_id FROM hosts_hosts_parents
Log To Console ${output}
Sleep 1s
IF "${output}" == "((2, 1),)" BREAK
END
Should Be Equal As Strings ${output} ((2, 1),) host parent not inserted

# check if host_1 is pending
${result} Ctn Check Host Status host_1 4 1 True
Should Be True ${result} host_1 should be pending

${result} Ctn Check Host Status host_2 4 1 True
Should Be True ${result} host_2 should be pending

${content} Create List INITIAL HOST STATE: host_1;
${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 60
Should Be True
... ${result}
... An Initial host state on host_1 should be raised before we can start our external commands.

Ctn Process Host Check Result host_1 0 host_1 UP

FOR ${i} IN RANGE ${4}
Ctn Schedule Forced Host Check host_1 ${VarRoot}/lib/centreon-engine/config0/rw/centengine.cmd
Sleep 1s
END

${content} Create List
... EXTERNAL COMMAND: SCHEDULE_FORCED_HOST_CHECK;host_1;
... HOST ALERT: host_1;DOWN;HARD;

${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 60
Should Be True ${result} Message about SCHEDULE HOST should be down in log.

${result} Ctn Check Host Status host_1 1 1 True
Should Be True ${result} host_1 should be down/hard

${content} Create List
... Check of child host 'host_2' queued.
${result} Ctn Find In Log With Timeout ${engineLog0} ${start} ${content} 60
Should Be True ${result} Check of child host 'host_2' should be queued.

Disconnect From Database
Ctn Stop Engine
Ctn Kindly Stop Broker

EBPN1
[Documentation] verify relation parent child when delete parent.
[Tags] broker engine MON-151686
Ctn Config Engine ${1} ${5} ${1}
Ctn Config Broker rrd
Ctn Config Broker central
Ctn Config Broker module
Ctn Config BBDO3 1

Ctn Broker Config Log rrd rrd error
Ctn Broker Config Log rrd core error
Ctn Broker Config Log module0 core error

Ctn Broker Config Log central sql debug
Ctn Engine Config Set Value 0 log_level_checks error
Ctn Config Broker Sql Output central unified_sql 10
Ctn Broker Config Flush Log central 0
Ctn Broker Config Flush Log rrd 0

Ctn Clear Retention


# host_1 is parent of host_2
Ctn Add Parent To Host 0 host_2 host_1

${start} Get Current Date
Ctn Start Broker
Ctn Start Engine
Ctn Wait For Engine To Be Ready ${start} ${1}

${output} Ctn Get Host Info Grpc ${2}
Log To Console parents:${output}[parentHosts]
Should Contain ${output}[parentHosts] host_1 parentHosts

${output} Ctn Get Host Info Grpc ${1}
Log To Console childs:${output}[childHosts]
Should Contain ${output}[childHosts] host_2 childHosts

Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}

FOR ${index} IN RANGE 30
${output} Query
... SELECT child_id, parent_id FROM hosts_hosts_parents
Log To Console ${output}
Sleep 1s
IF "${output}" == "((2, 1),)" BREAK
END
Should Be Equal As Strings ${output} ((2, 1),) the parent link not inserted

Ctn Engine Config Del Block In Cfg ${0} host host_1 hosts.cfg
Ctn Engine Config Del Block In Cfg ${0} service host_1 services.cfg
Ctn Engine Config Delete Value In Hosts ${0} host_2 parents

${start} Get Current Date
Ctn Reload Engine
Ctn Wait For Engine To Be Ready ${start} ${1}
${content} Create List Reload configuration finished
${result} Ctn Find In Log With Timeout
... ${ENGINE_LOG}/config0/centengine.log
... ${start}
... ${content}
... 60
... verbose=False
Should Be True ${result} Engine is Not Ready after 60s!!


${output} Ctn Get Host Info Grpc ${2}
Log To Console parents:${output}[parentHosts]
Should Be Empty ${output}[parentHosts]

FOR ${index} IN RANGE 30
${output} Query
... SELECT child_id, parent_id FROM hosts_hosts_parents
Log To Console ${output}
Sleep 1s
IF "${output}" == "()" BREAK
END
Should Be Equal As Strings ${output} () the parent link should be deleted

Disconnect From Database
Ctn Stop Engine
Ctn Kindly Stop Broker

EBPN2
[Documentation] verify relation parent child when delete child.
[Tags] broker engine MON-151686
Ctn Config Engine ${1} ${5} ${1}
Ctn Config Broker rrd
Ctn Config Broker central
Ctn Config Broker module
Ctn Config BBDO3 1

Ctn Broker Config Log rrd rrd error
Ctn Broker Config Log rrd core error
Ctn Broker Config Log module0 core error

Ctn Broker Config Log central sql debug
Ctn Engine Config Set Value 0 log_level_checks error
Ctn Config Broker Sql Output central unified_sql 10
Ctn Broker Config Flush Log central 0
Ctn Broker Config Flush Log rrd 0

Ctn Clear Retention

# host_1 is parent of host_2
Ctn Add Parent To Host 0 host_2 host_1

${start} Get Current Date

Ctn Start Broker
Ctn Start Engine
Ctn Wait For Engine To Be Ready ${start} ${1}

${output} Ctn Get Host Info Grpc ${2}
Log To Console parents:${output}[parentHosts]
Should Contain ${output}[parentHosts] host_1 parentHosts

${output} Ctn Get Host Info Grpc ${1}
Log To Console childs:${output}[childHosts]
Should Contain ${output}[childHosts] host_2 childHosts

Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}

FOR ${index} IN RANGE 30
${output} Query
... SELECT child_id, parent_id FROM hosts_hosts_parents
Log To Console ${output}
Sleep 1s
IF "${output}" == "((2, 1),)" BREAK
END
Should Be Equal As Strings ${output} ((2, 1),) the parent link not inserted

Ctn Engine Config Del Block In Cfg ${0} host host_2 hosts.cfg
Ctn Engine Config Del Block In Cfg ${0} service host_2 services.cfg
Ctn Engine Config Delete Value In Hosts ${0} host_2 parents

${start} Get Current Date
Ctn Reload Engine
Ctn Wait For Engine To Be Ready ${start} ${1}
${content} Create List Reload configuration finished
${result} Ctn Find In Log With Timeout
... ${ENGINE_LOG}/config0/centengine.log
... ${start}
... ${content}
... 60
... verbose=False
Should Be True ${result} Engine is Not Ready after 60s!!

${output} Ctn Get Host Info Grpc ${1}
Log To Console childs:${output}[childHosts]
Should Be Empty ${output}[childHosts]

FOR ${index} IN RANGE 30
${output} Query
... SELECT child_id, parent_id FROM hosts_hosts_parents
Log To Console ${output}
Sleep 1s
IF "${output}" == "()" BREAK
END
Should Be Equal As Strings ${output} () the parent link should be deleted

Disconnect From Database
Ctn Stop Engine
Ctn Kindly Stop Broker
Loading

0 comments on commit e3166ef

Please sign in to comment.