Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mon 21110 rewording in tests #1118

Merged
merged 15 commits into from
Feb 29, 2024
Merged
39 changes: 20 additions & 19 deletions broker/unified_sql/inc/com/centreon/broker/unified_sql/stream.hh
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/*
** Copyright 2019-2022 Centreon
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** For more information : [email protected]
*/
/**
* Copyright 2019-2024 Centreon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*/

#ifndef CCB_UNIFIED_SQL_STREAM_HH
#define CCB_UNIFIED_SQL_STREAM_HH
#include <absl/container/flat_hash_map.h>
Expand Down Expand Up @@ -324,8 +325,8 @@ class stream : public io::stream {
database::mysql_stmt _flapping_status_insupdate;
database::mysql_stmt _host_check_update;
database::mysql_stmt _pb_host_check_update;
database::mysql_stmt _host_dependency_insupdate;
database::mysql_stmt _pb_host_dependency_insupdate;
database::mysql_stmt _host_exe_dependency_insupdate;
database::mysql_stmt _host_notif_dependency_insupdate;
database::mysql_stmt _host_group_insupdate;
database::mysql_stmt _pb_host_group_insupdate;
database::mysql_stmt _host_group_member_delete;
Expand Down
16 changes: 16 additions & 0 deletions broker/unified_sql/src/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,22 @@ void stream::_init_statements() {
"last_check=?," // 9: last_check
"output=? " // 10: output
"WHERE id=? AND parent_id=?"); // 11, 12: service_id and host_id
const std::string host_exe_dep_query(
"INSERT INTO hosts_hosts_dependencies (dependent_host_id, host_id, "
"dependency_period, execution_failure_options, inherits_parent) "
"VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE "
"dependency_period=VALUES(dependency_period), "
"execution_failure_options=VALUES(execution_failure_options), "
"inherits_parent=VALUES(inherits_parent)");
_host_exe_dependency_insupdate = _mysql.prepare_query(host_exe_dep_query);
const std::string host_notif_dep_query(
"INSERT INTO hosts_hosts_dependencies (dependent_host_id, host_id, "
"dependency_period, notification_failure_options, inherits_parent) "
"VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE "
"dependency_period=VALUES(dependency_period), "
"notification_failure_options=VALUES(notification_failure_options), "
"inherits_parent=VALUES(inherits_parent)");
_host_notif_dependency_insupdate = _mysql.prepare_query(host_notif_dep_query);
if (_store_in_hosts_services) {
if (_bulk_prepared_statement) {
auto hu = std::make_unique<database::mysql_bulk_stmt>(hscr_query);
Expand Down
85 changes: 47 additions & 38 deletions broker/unified_sql/src/stream_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1212,19 +1212,29 @@ void stream::_process_host_dependency(const std::shared_ptr<io::data>& d) {
hd.execution_failure_options,
hd.notification_failure_options);

// Prepare queries.
if (!_host_dependency_insupdate.prepared()) {
query_preparator::event_unique unique;
unique.insert("host_id");
unique.insert("dependent_host_id");
query_preparator qp(neb::host_dependency::static_type(), unique);
_host_dependency_insupdate = qp.prepare_insert_or_update(_mysql);
}

// Process object.
_host_dependency_insupdate << hd;
_mysql.run_statement(_host_dependency_insupdate,
database::mysql_error::store_host_dependency, conn);
if (!hd.execution_failure_options.empty()) {
_host_exe_dependency_insupdate.bind_value_as_i32(0, hd.dependent_host_id);
_host_exe_dependency_insupdate.bind_value_as_i32(1, hd.host_id);
_host_exe_dependency_insupdate.bind_value_as_str(2, hd.dependency_period);
_host_exe_dependency_insupdate.bind_value_as_str(
3, hd.execution_failure_options);
_host_exe_dependency_insupdate.bind_value_as_tiny(4, hd.inherits_parent);
_mysql.run_statement(_host_exe_dependency_insupdate,
database::mysql_error::store_host_dependency, conn);
} else if (!hd.notification_failure_options.empty()) {
_host_notif_dependency_insupdate.bind_value_as_i32(0,
hd.dependent_host_id);
_host_notif_dependency_insupdate.bind_value_as_i32(1, hd.host_id);
_host_notif_dependency_insupdate.bind_value_as_str(2,
hd.dependency_period);
_host_notif_dependency_insupdate.bind_value_as_str(
3, hd.notification_failure_options);
_host_notif_dependency_insupdate.bind_value_as_tiny(4,
hd.inherits_parent);
_mysql.run_statement(_host_notif_dependency_insupdate,
database::mysql_error::store_host_dependency, conn);
}
_add_action(conn, actions::host_dependencies);
}
// Delete.
Expand Down Expand Up @@ -1269,33 +1279,32 @@ void stream::_process_pb_host_dependency(const std::shared_ptr<io::data>& d) {
hd.dependent_host_id(), hd.host_id(), hd.execution_failure_options(),
hd.notification_failure_options());

// Prepare queries.
if (!_pb_host_dependency_insupdate.prepared()) {
query_preparator::event_pb_unique unique{
{6, "host_id", io::protobuf_base::invalid_on_zero, 0},
{3, "dependent_host_id", io::protobuf_base::invalid_on_zero, 0}};
query_preparator qp(neb::pb_host_dependency::static_type(), unique);
_pb_host_dependency_insupdate = qp.prepare_insert_or_update_table(
_mysql, "hosts_hosts_dependencies ", /*space is mandatory to avoid
conflict with _process_host_dependency*/
{{3, "dependent_host_id", io::protobuf_base::invalid_on_zero, 0},
{6, "host_id", io::protobuf_base::invalid_on_zero, 0},
{2, "dependency_period", 0,
get_hosts_hosts_dependencies_col_size(
hosts_hosts_dependencies_dependency_period)},
{5, "execution_failure_options", 0,
get_hosts_hosts_dependencies_col_size(
hosts_hosts_dependencies_execution_failure_options)},
{7, "inherits_parent", 0, 0},
{8, "notification_failure_options", 0,
get_hosts_hosts_dependencies_col_size(
hosts_hosts_dependencies_notification_failure_options)}});
}

// Process object.
_pb_host_dependency_insupdate << hd_protobuf;
_mysql.run_statement(_pb_host_dependency_insupdate,
database::mysql_error::store_host_dependency, conn);
if (!hd.execution_failure_options().empty()) {
_host_exe_dependency_insupdate.bind_value_as_i32(0,
hd.dependent_host_id());
_host_exe_dependency_insupdate.bind_value_as_i32(1, hd.host_id());
_host_exe_dependency_insupdate.bind_value_as_str(2,
hd.dependency_period());
_host_exe_dependency_insupdate.bind_value_as_str(
3, hd.execution_failure_options());
_host_exe_dependency_insupdate.bind_value_as_tiny(4,
hd.inherits_parent());
_mysql.run_statement(_host_exe_dependency_insupdate,
database::mysql_error::store_host_dependency, conn);
} else if (!hd.notification_failure_options().empty()) {
_host_notif_dependency_insupdate.bind_value_as_i32(
0, hd.dependent_host_id());
_host_notif_dependency_insupdate.bind_value_as_i32(1, hd.host_id());
_host_notif_dependency_insupdate.bind_value_as_str(
2, hd.dependency_period());
_host_notif_dependency_insupdate.bind_value_as_str(
3, hd.notification_failure_options());
_host_notif_dependency_insupdate.bind_value_as_tiny(4,
hd.inherits_parent());
_mysql.run_statement(_host_notif_dependency_insupdate,
database::mysql_error::store_host_dependency, conn);
}
_add_action(conn, actions::host_dependencies);
}
// Delete.
Expand Down
8 changes: 4 additions & 4 deletions tests/bam/boolean_rules.robot
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ BABOOCOMPL_RESTART
FOR ${i} IN RANGE ${15} ${21} ${2}
Remove Files /tmp/ba${id_ba__sid[0]}_*.dot
${result} Check Ba Status With Timeout boolean-ba 2 30
Dump Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_1.dot
Broker Get Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_1.dot
Should Be True ${result} Step${i}: The 'boolean-ba' BA is not CRITICAL as expected
${start} Get Current Date

Expand All @@ -404,7 +404,7 @@ BABOOCOMPL_RESTART
${result} Find In Log With Timeout ${centralLog} ${start} ${content} 60
Should Be True ${result} It seems that no cache has been restored into BAM.

Dump Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_2.dot
Broker Get Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_2.dot

Wait Until Created /tmp/ba${id_ba__sid[0]}_2.dot
${result} Compare Dot Files /tmp/ba${id_ba__sid[0]}_1.dot /tmp/ba${id_ba__sid[0]}_2.dot
Expand Down Expand Up @@ -488,7 +488,7 @@ BABOOCOMPL_RELOAD
FOR ${i} IN RANGE ${15} ${21} ${2}
Remove Files /tmp/ba${id_ba__sid[0]}_*.dot
${result} Check Ba Status With Timeout boolean-ba 2 30
Dump Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_1.dot
Broker Get Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_1.dot
Should Be True ${result} Step${i}: The 'boolean-ba' BA is not CRITICAL as expected
${start} Get Current Date

Expand All @@ -498,7 +498,7 @@ BABOOCOMPL_RELOAD
${result} Find In Log With Timeout ${centralLog} ${start} ${content} 60
Should Be True ${result} It seems that no cache has been restored into BAM.

Dump Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_2.dot
Broker Get Ba 51001 ${id_ba__sid[0]} /tmp/ba${id_ba__sid[0]}_2.dot

Wait Until Created /tmp/ba${id_ba__sid[0]}_2.dot
${result} Compare Dot Files /tmp/ba${id_ba__sid[0]}_1.dot /tmp/ba${id_ba__sid[0]}_2.dot
Expand Down
4 changes: 2 additions & 2 deletions tests/broker-engine/bbdo-protobuf.robot
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ BEPBCVS
[Teardown] Stop Engine Broker And Save Logs True

BEPB_HOST_DEPENDENCY
[Documentation] bbdo_version 3 communication of host dependencies.
[Documentation] BBDO 3 communication of host dependencies.
[Tags] broker engine protobuf bbdo
Config Engine ${1}
Config Engine Add Cfg File 0 dependencies.cfg
Expand All @@ -191,7 +191,7 @@ BEPB_HOST_DEPENDENCY
Start Broker True
Start Engine

${result} Common.Check Host Dependencies 2 1 24x7 1 ou ${EMPTY} 30
${result} Common.Check Host Dependencies 2 1 24x7 1 ou dp 30
Should Be True ${result} No notification dependency from 2 to 1 with timeperiod 24x7 on 'ou'

Config Engine ${1}
Expand Down
12 changes: 6 additions & 6 deletions tests/broker/log.robot
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ BLEC1
Broker Config Log central sql debug
${start} Get Current Date
Start Broker
${result} Get Broker Log Level 51001 central core
${result} Get Broker Log Level 51001 core
Should Be Equal ${result} trace
Set Broker Log Level 51001 central core debug
${result} Get Broker Log Level 51001 central core
Set Broker Log Level 51001 core debug
${result} Get Broker Log Level 51001 core
Should Be Equal ${result} debug

BLEC2
Expand All @@ -51,9 +51,9 @@ BLEC2
Broker Config Log central sql debug
${start} Get Current Date
Start Broker
${result} Get Broker Log Level 51001 central core
${result} Get Broker Log Level 51001 core
Should Be Equal ${result} trace
${result} Set Broker Log Level 51001 central core foo
${result} Set Broker Log Level 51001 core foo
Should Be Equal ${result} Enum LogLevelEnum has no value defined for name 'FOO'

BLEC3
Expand All @@ -65,5 +65,5 @@ BLEC3
Broker Config Log central sql debug
${start} Get Current Date
Start Broker
${result} Set Broker Log Level 51001 central foo trace
${result} Set Broker Log Level 51001 foo trace
Should Be Equal ${result} The 'foo' logger does not exist
Loading
Loading