From 6814a7f4bebcc34b54c6f15acad487d33508b63f Mon Sep 17 00:00:00 2001 From: Deniza Alzhanova Date: Wed, 29 Jun 2022 08:50:49 -0400 Subject: [PATCH 1/5] enh(broker): cbd with multiargs and robot tests --- centreon-broker/core/src/main.cc | 67 +++++------ tests/README.md | 194 +++++-------------------------- tests/broker/command-line.robot | 28 +++++ tests/resources/Common.py | 133 ++++++++++++--------- 4 files changed, 167 insertions(+), 255 deletions(-) create mode 100644 tests/broker/command-line.robot diff --git a/centreon-broker/core/src/main.cc b/centreon-broker/core/src/main.cc index 6615de76d5e..7fb1e60c82d 100644 --- a/centreon-broker/core/src/main.cc +++ b/centreon-broker/core/src/main.cc @@ -44,7 +44,6 @@ static std::atomic_bool gl_term{false}; static struct option long_options[] = {{"pool_size", required_argument, 0, 's'}, {"check", no_argument, 0, 'c'}, - {"debug", no_argument, 0, 'd'}, {"diagnose", no_argument, 0, 'D'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, @@ -155,33 +154,35 @@ int main(int argc, char* argv[]) { try { // Check the command line. bool check(false); - bool debug(false); bool diagnose(false); bool help(false); bool version(false); - opt = getopt_long(argc, argv, "t:cdDvh", long_options, &option_index); - switch (opt) { - case 't': - n_thread = atoi(optarg); - break; - case 'c': - check = true; - break; - case 'd': - debug = true; - break; - case 'D': - diagnose = true; - break; - case 'h': - help = true; - break; - case 'v': - version = true; - break; - default: - break; + while ((opt = getopt_long(argc, argv, "s:cDvh", long_options, + &option_index)) != -1) { + switch (opt) { + case 's': + if (!absl::SimpleAtoi(optarg, &n_thread)) { + throw msg_fmt("The option -s expects a positive integer"); + } + break; + case 'c': + check = true; + break; + case 'D': + diagnose = true; + break; + case 'h': + help = true; + break; + case 'v': + version = true; + break; + default: + throw msg_fmt( + "Enter allowed options : [-s ] [-c] [-D] [-h] [-v]"); + break; + } } if (optind < argc) @@ -199,14 +200,13 @@ int main(int argc, char* argv[]) { diag.generate(gl_mainconfigfiles); } else if (help) { log_v2::core()->info( - "USAGE: {} [-t] [-c] [-d] [-D] [-h] [-v] []", argv[0]); - - log_v2::core()->info(" -t Set x threads."); - log_v2::core()->info(" -c Check configuration file."); - log_v2::core()->info(" -d Enable debug mode."); - log_v2::core()->info(" -D Generate a diagnostic file."); - log_v2::core()->info(" -h Print this help."); - log_v2::core()->info(" -v Print Centreon Broker version."); + "USAGE: {} [-s ] [-c] [-D] [-h] [-v] []", + argv[0]); + log_v2::core()->info(" '-s' Set poolsize threads."); + log_v2::core()->info(" '-c' Check configuration file."); + log_v2::core()->info(" '-D' Generate a diagnostic file."); + log_v2::core()->info(" '-h' Print this help."); + log_v2::core()->info(" '-v' Print Centreon Broker version."); log_v2::core()->info("Centreon Broker {}", CENTREON_BROKER_VERSION); log_v2::core()->info("Copyright 2009-2021 Centreon"); log_v2::core()->info( @@ -217,7 +217,8 @@ int main(int argc, char* argv[]) { retval = 0; } else if (gl_mainconfigfiles.empty()) { log_v2::core()->error( - "USAGE: {} [-c] [-d] [-D] [-h] [-v] []\n\n", argv[0]); + "USAGE: {} [-s ] [-c] [-D] [-h] [-v] []\n\n", + argv[0]); return 1; } else { log_v2::core()->info("Centreon Broker {}", CENTREON_BROKER_VERSION); diff --git a/tests/README.md b/tests/README.md index ad47a04518f..b9fd2fabd1b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -57,19 +57,9 @@ Here is the list of the currently implemented tests: - [x] **BEBAMIDT2**: A BA of type 'worst' with one service is configured. The BA is in critical state, because of its service. Then we set a downtime on this last one. An inherited downtime is set to the BA. Engine is restarted. Broker is restarted. The two downtimes are still there with no duplicates. The downtime is removed from the service, the inherited downtime is then deleted. ### Broker +- [x] **BLDIS1**: Start broker with core logs 'disabled' - [x] **BFC1**: Start broker with invalid filters but one filter ok - [x] **BFC2**: Start broker with only invalid filters on an output -- [x] **BLDIS1**: Start broker with core logs 'disabled' -- [x] **BSS1**: Start-Stop two instances of broker and no coredump -- [x] **BSS2**: Start/Stop 10 times broker with 300ms interval and no coredump -- [x] **BSS3**: Start-Stop one instance of broker and no coredump -- [x] **BSS4**: Start/Stop 10 times broker with 1sec interval and no coredump -- [x] **BSS5**: Start-Stop with reversed connection on TCP acceptor with only one instance and no deadlock -- [x] **BSSU1**: Start-Stop with unified_sql two instances of broker and no coredump -- [x] **BSSU2**: Start/Stop with unified_sql 10 times broker with 300ms interval and no coredump -- [x] **BSSU3**: Start-Stop with unified_sql one instance of broker and no coredump -- [x] **BSSU4**: Start/Stop with unified_sql 10 times broker with 1sec interval and no coredump -- [x] **BSSU5**: Start-Stop with unified_sql with reversed connection on TCP acceptor with only one instance and no deadlock - [x] **BDB1**: Access denied when database name exists but is not the good one for sql output - [x] **BDB2**: Access denied when database name exists but is not the good one for storage output - [x] **BDB3**: Access denied when database name does not exist for sql output @@ -84,24 +74,13 @@ Here is the list of the currently implemented tests: - [x] **BEDB3**: start broker/engine, then stop MariaDB and then start it again. The gRPC API should give informations about SQL connections. - [x] **BEDB4**: start broker/engine, then stop MariaDB and then start it again. The gRPC API should give informations about SQL connections. - [x] **BDBM1**: start broker/engine and then start MariaDB => connection is established -- [x] **BDBU1**: Access denied when database name exists but is not the good one for unified sql output -- [x] **BDBU3**: Access denied when database name does not exist for unified sql output -- [x] **BDBU5**: cbd does not crash if the unified sql db_host is wrong -- [x] **BDBU7**: Access denied when database user password is wrong for unified sql -- [x] **BDBU10**: Connection should be established when user password is good for unified sql -- [x] **BDBMU1**: start broker/engine with unified sql and then start MariaDB => connection is established -- [x] **BGRPCSS1**: Start-Stop two instances of broker configured with grpc stream and no coredump -- [x] **BGRPCSS2**: Start/Stop 10 times broker configured with grpc stream with 300ms interval and no coredump -- [x] **BGRPCSS3**: Start-Stop one instance of broker configured with grpc stream and no coredump -- [x] **BGRPCSS4**: Start/Stop 10 times broker configured with grpc stream with 1sec interval and no coredump -- [x] **BGRPCSS5**: Start-Stop with reversed connection on grpc acceptor with only one instance and no deadlock -- [x] **BGRPCSSU1**: Start-Stop with unified_sql two instances of broker with grpc stream and no coredump -- [x] **BGRPCSSU2**: Start/Stop with unified_sql 10 times broker configured with grpc stream with 300ms interval and no coredump -- [x] **BGRPCSSU3**: Start-Stop with unified_sql one instance of broker configured with grpc and no coredump -- [x] **BGRPCSSU4**: Start/Stop with unified_sql 10 times broker configured with grpc stream with 1sec interval and no coredump -- [x] **BGRPCSSU5**: Start-Stop with unified_sql with reversed connection on grpc acceptor with only one instance and no deadlock +- [x] **BSS1**: Start-Stop two instances of broker and no coredump +- [x] **BSS2**: Start/Stop 10 times broker with 300ms interval and no coredump +- [x] **BSS3**: Start-Stop one instance of broker and no coredump +- [x] **BSS4**: Start/Stop 10 times broker with 1sec interval and no coredump +- [x] **BSS5**: Start-Stop with reversed connection on TCP acceptor with only one instance and no deadlock - [x] **BCL1**: Starting broker with option '-s foobar' should return an error -- [x] **BCL2**: Starting broker with option '-s 5' should work +- [x] **BCL2**: Starting broker with option '-s5' should work ### Broker/database - [x] **NetworkDbFail1**: network failure test between broker and database (shutting down connection for 100ms) @@ -110,147 +89,43 @@ Here is the list of the currently implemented tests: - [x] **NetworkDbFail4**: network failure test between broker and database (shutting down connection for 30s) - [x] **NetworkDbFail5**: network failure test between broker and database (shutting down connection for 60s) - [x] **NetworkDBFail6**: network failure test between broker and database: we wait for the connection to be established and then we shut down the connection for 60s -- [x] **NetworkDBFailU6**: network failure test between broker and database: we wait for the connection to be established and then we shut down the connection for 60s (with unified_sql) - [x] **NetworkDBFail7**: network failure test between broker and database: we wait for the connection to be established and then we shut down the connection for 60s -- [x] **NetworkDBFailU7**: network failure test between broker and database: we wait for the connection to be established and then we shut down the connection for 60s (with unified_sql) ### Broker/engine -- [x] **BEPBBEE1**: central-module configured with bbdo_version 3.0 but not others. Unable to establish connection. -- [x] **BEPBBEE2**: bbdo_version 3 not compatible with sql/storage -- [x] **BEPBBEE3**: bbdo_version 3 generates new bbdo protobuf service status messages. -- [x] **BEPBBEE4**: bbdo_version 3 generates new bbdo protobuf host status messages. -- [x] **BEPBBEE5**: bbdo_version 3 generates new bbdo protobuf service messages. - [x] **BECC1**: Broker/Engine communication with compression between central and poller -- [x] **EBNHG1**: New host group with several pollers and connections to DB -- [x] **EBNHGU1**: New host group with several pollers and connections to DB with broker configured with unified_sql -- [x] **EBNHGU2**: New host group with several pollers and connections to DB with broker configured with unified_sql -- [x] **EBNHGU3**: New host group with several pollers and connections to DB with broker configured with unified_sql -- [x] **EBNHG4**: New host group with several pollers and connections to DB with broker and rename this hostgroup -- [x] **EBNHGU4**: New host group with several pollers and connections to DB with broker and rename this hostgroup -- [x] **LOGV2EB1**: log-v2 enabled old log disabled check broker sink -- [x] **LOGV2DB1**: log-v2 disabled old log enabled check broker sink -- [x] **LOGV2DB2**: log-v2 disabled old log disabled check broker sink -- [x] **LOGV2EB2**: log-v2 enabled old log enabled check broker sink -- [x] **LOGV2EF1**: log-v2 enabled old log disabled check logfile sink -- [x] **LOGV2DF1**: log-v2 disabled old log enabled check logfile sink -- [x] **LOGV2DF2**: log-v2 disabled old log disabled check logfile sink -- [x] **LOGV2EF2**: log-v2 enabled old log enabled check logfile sink -- [x] **LOGV2BE2**: log-v2 enabled old log enabled check broker sink is equal -- [x] **LOGV2FE2**: log-v2 enabled old log enabled check logfile sink -- [x] **BERES1**: store_in_resources is enabled and store_in_hosts_services is not. Only writes into resources should be done (except hosts/services events that continue to be written in hosts/services tables) -- [x] **BEHS1**: store_in_resources is enabled and store_in_hosts_services is not. Only writes into resources should be done (except hosts/services events that continue to be written in hosts/services tables) - [x] **BRGC1**: Broker good reverse connection - [x] **BRCTS1**: Broker reverse connection too slow - [x] **BRCS1**: Broker reverse connection stopped -- [x] **BRRDDM1**: RRD metrics deletion from metric ids. -- [x] **BRRDDID1**: RRD metrics deletion from index ids. -- [x] **BRRDDMID1**: RRD deletion of non existing metrics and indexes -- [x] **BRRDDMU1**: RRD metric deletion on table metric with unified sql output -- [x] **BRRDDIDU1**: RRD metrics deletion from index ids with unified sql output. -- [x] **BRRDDMIDU1**: RRD deletion of non existing metrics and indexes -- [x] **BRRDRM1**: RRD metric rebuild with gRPC API and unified sql -- [x] **BRRDRMU1**: RRD metric rebuild with gRPC API and unified sql -- [x] **ENRSCHE1**: check next check of reschedule is last_check+interval_check -- [x] **EBNSG1**: New service group with several pollers and connections to DB -- [x] **EBNSGU1**: New service group with several pollers and connections to DB with broker configured with unified_sql -- [x] **EBNSGU2**: New service group with several pollers and connections to DB with broker configured with unified_sql -- [x] **EBNSVC1**: New services with several pollers +- [x] **BEDTMASS1**: New services with several pollers +- [x] **BEEXTCMD2**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo2.0 +- [x] **BEEXTCMD4**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo2.0 +- [x] **BEEXTCMD6**: external command CHANGE_RETRY_SVC_CHECK_INTERVAL on bbdo2.0 +- [x] **BEEXTCMD8**: external command CHANGE_RETRY_HOST_CHECK_INTERVAL on bbdo2.0 +- [x] **BEEXTCMD10**: external command CHANGE_MAX_SVC_CHECK_ATTEMPTS on bbdo2.0 +- [x] **BEEXTCMD12**: external command CHANGE_MAX_HOST_CHECK_ATTEMPTS on bbdo2.0 +- [x] **BEEXTCMD16**: external command CHANGE_HOST_CHECK_TIMEPERIOD on bbdo2.0 +- [x] **BEEXTCMD18**: external command CHANGE_HOST_NOTIFICATION_TIMEPERIOD on bbdo2.0 +- [x] **EBNHG1**: New host group with several pollers and connections to DB +- [x] **EBNHG4**: New host group with several pollers and connections to DB with broker and rename this hostgroup +- [x] **EBSNU1**: New services with notes_url with more than 2000 characters +- [x] **EBSAU2**: New services with action_url with more than 2000 characters +- [x] **EBSN3**: New services with notes with more than 500 characters - [x] **BERD1**: Starting/stopping Broker does not create duplicated events. - [x] **BERD2**: Starting/stopping Engine does not create duplicated events. - [x] **BERDUC1**: Starting/stopping Broker does not create duplicated events in usual cases -- [x] **BERDUCU1**: Starting/stopping Broker does not create duplicated events in usual cases with unified_sql - [x] **BERDUC2**: Starting/stopping Engine does not create duplicated events in usual cases -- [x] **BERDUCU2**: Starting/stopping Engine does not create duplicated events in usual cases with unified_sql -- [x] **BERDUC3U1**: Starting/stopping Broker does not create duplicated events in usual cases with unified_sql and BBDO 3.0 -- [x] **BERDUC3U2**: Starting/stopping Engine does not create duplicated events in usual cases with unified_sql and BBDO 3.0 -- [x] **BEDTMASS1**: New services with several pollers -- [x] **BEDTMASS2**: New services with several pollers +- [x] **ENRSCHE1**: check next check of reschedule is last_check+interval_check +- [x] **EBNSG1**: New service group with several pollers and connections to DB +- [x] **EBNSVC1**: New services with several pollers - [x] **BESS1**: Start-Stop Broker/Engine - Broker started first - Broker stopped first - [x] **BESS2**: Start-Stop Broker/Engine - Broker started first - Engine stopped first - [x] **BESS3**: Start-Stop Broker/Engine - Engine started first - Engine stopped first - [x] **BESS4**: Start-Stop Broker/Engine - Engine started first - Broker stopped first - [x] **BESS5**: Start-Stop Broker/engine - Engine debug level is set to all, it should not hang -- [x] **BESS_GRPC1**: Start-Stop grpc version Broker/Engine - Broker started first - Broker stopped first -- [x] **BESS_GRPC2**: Start-Stop grpc version Broker/Engine - Broker started first - Engine stopped first -- [x] **BESS_GRPC3**: Start-Stop grpc version Broker/Engine - Engine started first - Engine stopped first -- [x] **BESS_GRPC4**: Start-Stop grpc version Broker/Engine - Engine started first - Broker stopped first -- [x] **BESS_GRPC5**: Start-Stop grpc version Broker/engine - Engine debug level is set to all, it should not hang -- [x] **BESS_GRPC_COMPRESS1**: Start-Stop grpc version Broker/Engine - Broker started first - Broker stopped first compression activated -- [x] **BETAG1**: Engine is configured with some tags. When broker receives them, it stores them in the centreon_storage.tags table. Broker is started before. -- [x] **BETAG2**: Engine is configured with some tags. When broker receives them, it stores them in the centreon_storage.tags table. Engine is started before. -- [x] **BEUTAG1**: Engine is configured with some tags. When broker receives them through unified_sql stream, it stores them in the centreon_storage.tags table. Broker is started before. -- [x] **BEUTAG2**: Engine is configured with some tags. A new service is added with a tag. Broker should make the relations. -- [x] **BEUTAG3**: Engine is configured with some tags. When broker receives them, it stores them in the centreon_storage.tags table. Engine is started before. -- [x] **BEUTAG4**: Engine is configured with some tags. Group tags tag9, tag13 are set to services 1 and 3. Category tags tag3 and tag11 are added to services 1, 3, 5 and 6. The centreon_storage.resources and resources_tags tables are well filled. -- [x] **BEUTAG5**: Engine is configured with some tags. Group tags tag2, tag6 are set to hosts 1 and 2. Category tags tag4 and tag8 are added to hosts 2, 3, 4. The resources and resources_tags tables are well filled. -- [x] **BEUTAG6**: Engine is configured with some tags. When broker receives them, it stores them in the centreon_storage.resources_tags table. Engine is started before. -- [x] **BEUTAG7**: some services are configured and deleted with tags on two pollers. -- [x] **BEUTAG8**: Services have tags provided by templates. -- [x] **BEUTAG9**: hosts have tags provided by templates. -- [x] **BEUTAG10**: some services are configured with tags on two pollers. Then tags are removed from some of them and in centreon_storage, we can observe resources_tags table updated. -- [x] **BEUTAG11**: some services are configured with tags on two pollers. Then several tags are removed, and we can observe resources_tags table updated. -- [x] **BEUTAG12**: Engine is configured with some tags. Group tags tag2, tag6 are set to hosts 1 and 2. Category tags tag4 and tag8 are added to hosts 2, 3, 4. The resources and resources_tags tables are well filled. The tag6 and tag8 are removed and resources_tags is also well updated. - [x] **BECT1**: Broker/Engine communication with anonymous TLS between central and poller - [x] **BECT2**: Broker/Engine communication with TLS between central and poller with key/cert - [x] **BECT3**: Broker/Engine communication with anonymous TLS and ca certificate - [x] **BECT4**: Broker/Engine communication with TLS between central and poller with key/cert and hostname forced -- [x] **BECT_GRPC1**: Broker/Engine communication with anonymous TLS between central and poller -- [x] **BECT_GRPC2**: Broker/Engine communication with TLS between central and poller with key/cert -- [x] **BECT_GRPC3**: Broker/Engine communication with anonymous TLS and ca certificate -- [x] **BECT_GRPC4**: Broker/Engine communication with TLS between central and poller with key/cert and hostname forced -- [x] **BEEXTCMD1**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo3.0 -- [x] **BEEXTCMD2**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo2.0 -- [x] **BEEXTCMD3**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo3.0 -- [x] **BEEXTCMD4**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo2.0 -- [x] **BEEXTCMD5**: external command CHANGE_RETRY_SVC_CHECK_INTERVAL on bbdo3.0 -- [x] **BEEXTCMD6**: external command CHANGE_RETRY_SVC_CHECK_INTERVAL on bbdo2.0 -- [x] **BEEXTCMD7**: external command CHANGE_RETRY_HOST_CHECK_INTERVAL on bbdo3.0 -- [x] **BEEXTCMD8**: external command CHANGE_RETRY_HOST_CHECK_INTERVAL on bbdo2.0 -- [x] **BEEXTCMD9**: external command CHANGE_MAX_SVC_CHECK_ATTEMPTS on bbdo3.0 -- [x] **BEEXTCMD10**: external command CHANGE_MAX_SVC_CHECK_ATTEMPTS on bbdo2.0 -- [x] **BEEXTCMD11**: external command CHANGE_MAX_HOST_CHECK_ATTEMPTS on bbdo3.0 -- [x] **BEEXTCMD12**: external command CHANGE_MAX_HOST_CHECK_ATTEMPTS on bbdo2.0 -- [x] **BEEXTCMD13**: external command CHANGE_HOST_CHECK_TIMEPERIOD on bbdo3.0 -- [x] **BEEXTCMD14**: external command CHANGE_HOST_CHECK_TIMEPERIOD on bbdo2.0 -- [x] **BEEXTCMD15**: external command CHANGE_HOST_NOTIFICATION_TIMEPERIOD on bbdo3.0 -- [x] **BEEXTCMD16**: external command CHANGE_HOST_NOTIFICATION_TIMEPERIOD on bbdo2.0 -- [x] **BEEXTCMD17**: external command CHANGE_SVC_CHECK_TIMEPERIOD on bbdo3.0 -- [x] **BEEXTCMD18**: external command CHANGE_SVC_CHECK_TIMEPERIOD on bbdo2.0 -- [x] **BEEXTCMD19**: external command CHANGE_SVC_NOTIFICATION_TIMEPERIOD on bbdo3.0 -- [x] **BEEXTCMD20**: external command CHANGE_SVC_NOTIFICATION_TIMEPERIOD on bbdo2.0 -- [x] **BEEXTCMD21**: external command DISABLE_HOST_AND_CHILD_NOTIFICATIONS and ENABLE_HOST_AND_CHILD_NOTIFICATIONS on bbdo3.0 -- [x] **BEEXTCMD22**: external command DISABLE_HOST_AND_CHILD_NOTIFICATIONS and ENABLE_HOST_AND_CHILD_NOTIFICATIONS on bbdo2.0 -- [x] **BEEXTCMD23**: external command DISABLE_HOST_CHECK and ENABLE_HOST_CHECK on bbdo3.0 -- [x] **BEEXTCMD24**: external command DISABLE_HOST_CHECK and ENABLE_HOST_CHECK on bbdo2.0 -- [x] **BEEXTCMD25**: external command DISABLE_HOST_EVENT_HANDLER and ENABLE_HOST_EVENT_HANDLER on bbdo3.0 -- [x] **BEEXTCMD26**: external command DISABLE_HOST_EVENT_HANDLER and ENABLE_HOST_EVENT_HANDLER on bbdo2.0 -- [x] **BEEXTCMD27**: external command DISABLE_HOST_FLAP_DETECTION and ENABLE_HOST_FLAP_DETECTION on bbdo3.0 -- [x] **BEEXTCMD28**: external command DISABLE_HOST_FLAP_DETECTION and ENABLE_HOST_FLAP_DETECTION on bbdo2.0 -- [x] **BEEXTCMD29**: external command DISABLE_HOST_NOTIFICATIONS and ENABLE_HOST_NOTIFICATIONS on bbdo3.0 -- [x] **BEEXTCMD30**: external command DISABLE_HOST_NOTIFICATIONS and ENABLE_HOST_NOTIFICATIONS on bbdo2.0 -- [x] **BEEXTCMD31**: external command DISABLE_HOST_SVC_CHECKS and ENABLE_HOST_SVC_CHECKS on bbdo3.0 -- [x] **BEEXTCMD32**: external command DISABLE_HOST_SVC_CHECKS and ENABLE_HOST_SVC_CHECKS on bbdo2.0 -- [x] **BEEXTCMD33**: external command DISABLE_HOST_SVC_NOTIFICATIONS and ENABLE_HOST_SVC_NOTIFICATIONS on bbdo3.0 -- [x] **BEEXTCMD34**: external command DISABLE_HOST_SVC_NOTIFICATIONS and ENABLE_HOST_SVC_NOTIFICATIONS on bbdo2.0 -- [x] **BEEXTCMD35**: external command DISABLE_PASSIVE_HOST_CHECKS and ENABLE_PASSIVE_HOST_CHECKS on bbdo3.0 -- [x] **BEEXTCMD36**: external command DISABLE_PASSIVE_HOST_CHECKS and ENABLE_PASSIVE_HOST_CHECKS on bbdo2.0 -- [x] **BEEXTCMD37**: external command DISABLE_PASSIVE_SVC_CHECKS and ENABLE_PASSIVE_SVC_CHECKS on bbdo3.0 -- [x] **BEEXTCMD38**: external command DISABLE_PASSIVE_SVC_CHECKS and ENABLE_PASSIVE_SVC_CHECKS on bbdo2.0 -- [x] **BEEXTCMD39**: external command START_OBSESSING_OVER_HOST and STOP_OBSESSING_OVER_HOST on bbdo3.0 -- [x] **BEEXTCMD40**: external command START_OBSESSING_OVER_HOST and STOP_OBSESSING_OVER_HOST on bbdo2.0 -- [x] **BEEXTCMD41**: external command START_OBSESSING_OVER_SVC and STOP_OBSESSING_OVER_SVC on bbdo3.0 -- [x] **BEEXTCMD42**: external command START_OBSESSING_OVER_SVC and STOP_OBSESSING_OVER_SVC on bbdo2.0 -- [x] **BEEXTCMD_GRPC1**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo3.0 and grpc -- [x] **BEEXTCMD_GRPC2**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo2.0 and grpc -- [x] **BEEXTCMD_GRPC3**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo3.0 and grpc -- [x] **BEEXTCMD_GRPC4**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo2.0 and grpc -- [x] **BEEXTCMD_REVERSE_GRPC1**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo3.0 and reversed gRPC -- [x] **BEEXTCMD_REVERSE_GRPC2**: external command CHANGE_NORMAL_SVC_CHECK_INTERVAL on bbdo2.0 and grpc reversed -- [x] **BEEXTCMD_REVERSE_GRPC3**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo3.0 and grpc reversed -- [x] **BEEXTCMD_REVERSE_GRPC4**: external command CHANGE_NORMAL_HOST_CHECK_INTERVAL on bbdo2.0 and grpc reversed -- [x] **EBSNU1**: New services with notes_url with more than 2000 characters -- [x] **EBSAU2**: New services with action_url with more than 2000 characters -- [x] **EBSN3**: New services with notes with more than 500 characters ### Connector perl - [x] **test use connector perl exist script**: test exist script @@ -263,28 +138,11 @@ Here is the list of the currently implemented tests: - [x] **Test6Hosts**: as 127.0.0.x point to the localhost address we will simulate check on 6 hosts ### Engine -- [x] **EFHC1**: Engine is configured with hosts and we force checks on one 5 times on bbdo2 -- [x] **EFHC2**: Engine is configured with hosts and we force checks on one 5 times on bbdo2 -- [x] **EFHCU1**: Engine is configured with hosts and we force checks on one 5 times on bbdo3. Bbdo3 has no impact on this behavior. resources table is cleared before starting broker. -- [x] **EFHCU2**: Engine is configured with hosts and we force checks on one 5 times on bbdo3. Bbdo3 has no impact on this behavior. - [x] **ESS1**: Start-Stop (0s between start/stop) 5 times one instance of engine and no coredump - [x] **ESS2**: Start-Stop (300ms between start/stop) 5 times one instance of engine and no coredump - [x] **ESS3**: Start-Stop (0s between start/stop) 5 times three instances of engine and no coredump - [x] **ESS4**: Start-Stop (300ms between start/stop) 5 times three instances of engine and no coredump +- [x] **EFHC1**: Engine is configured with hosts and we force checks on one 5 times on bbdo2 +- [x] **EFHC2**: Engine is configured with hosts and we force checks on one 5 times on bbdo2 - [x] **EPC1**: Check with perl connector -### Migration -- [x] **MIGRATION**: Migration bbdo2 => sql/storage => unified_sql => bbdo3 - -### Severities -- [x] **BEUHSEV1**: Four hosts have a severity added. Then we remove the severity from host 1. Then we change severity 10 to severity8 for host 3. -- [x] **BEUHSEV2**: Seven hosts are configured with a severity on two pollers. Then we remove severities from the first and second hosts of the first poller but only the severity from the first host of the second poller. -- [x] **BETUHSEV1**: Hosts have severities provided by templates. -- [x] **BESEV1**: Engine is configured with some severities. When broker receives them, it stores them in the centreon_storage.severities table. Broker is started before. -- [x] **BESEV2**: Engine is configured with some severities. When broker receives them, it stores them in the centreon_storage.severities table. Engine is started before. -- [x] **BEUSEV1**: Engine is configured with some severities. When broker receives them, it stores them in the centreon_storage.severities table. Broker is started before. -- [x] **BEUSEV2**: Engine is configured with some severities. When broker receives them, it stores them in the centreon_storage.severities table. Engine is started before. -- [x] **BEUSEV3**: Four services have a severity added. Then we remove the severity from service 1. Then we change severity 11 to severity7 for service 3. -- [x] **BEUSEV4**: Seven services are configured with a severity on two pollers. Then we remove severities from the first and second services of the first poller but only the severity from the first service of the second poller. Then only severities no more used should be removed from the database. -- [x] **BETUSEV1**: Services have severities provided by templates. - diff --git a/tests/broker/command-line.robot b/tests/broker/command-line.robot new file mode 100644 index 00000000000..b40d8b4a80b --- /dev/null +++ b/tests/broker/command-line.robot @@ -0,0 +1,28 @@ +*** Settings *** +Resource ../resources/resources.robot +Suite Setup Clean Before Suite +Suite Teardown Clean After Suite +Test Setup Stop Processes + +Documentation Centreon Broker only start/stop tests +Library Process +Library OperatingSystem +Library ../resources/Broker.py +Library DateTime + + +*** Test Cases *** +BCL1 + [Documentation] Starting broker with option '-s foobar' should return an error + [Tags] Broker start-stop + Config Broker central + Start Broker With Args -s foobar + ${result}= Wait For Broker + ${expected}= Evaluate "The option -s expects a positive integer" in """${result}""" + Should be True ${expected} msg=expected error 'The option -s expects a positive integer' + +BCL2 + [Documentation] Starting broker with option '-s5' should work + [Tags] Broker start-stop + Config Broker central + ${start}= Get Current Date exclude_millis=True \ No newline at end of file diff --git a/tests/resources/Common.py b/tests/resources/Common.py index 949c34ce684..d791140cf9b 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -138,7 +138,7 @@ def stop_mysql(): getoutput("systemctl stop mysql") else: getoutput( - "kill -9 $(ps aux | grep 'mariadbd --user=root' | grep -v grep | awk '{print $2}')") + "kill -9 $(ps aux | grep 'mariadbd --user=root' | grep -v grep | awk '{print $2}')") def kill_broker(): @@ -223,23 +223,25 @@ def find_line_from(lines, date): start = 0 end = len(lines) - 1 idx = start - while end - start > 1: + while end > start: idx = (start + end) // 2 m = p.match(lines[idx]) while m is None: logger.console("Unable to parse the date ({} <= {} <= {}): <<{}>>".format( start, idx, end, lines[idx])) idx -= 1 - if idx >= 0 : + if idx >= 0: m = p.match(lines[idx]) else: logger.console("We are at the first line and no date found") idx_d = get_date(m.group(1)) - if my_date <= idx_d: + if my_date <= idx_d and end != idx: end = idx - elif my_date > idx_d: + elif my_date > idx_d and start != idx: start = idx + else: + break return idx @@ -269,6 +271,7 @@ def check_reschedule(log: str, date, content: str): logger.console("The file '{}' does not exist".format(log)) return False + def check_reschedule_with_timeout(log: str, date, content: str, timeout: int): limit = time.time() + timeout c = "" @@ -532,6 +535,7 @@ def check_service_severity_with_timeout(host_id: int, service_id: int, severity_ time.sleep(1) return False + def check_host_severity_with_timeout(host_id: int, severity_id, timeout: int): limit = time.time() + timeout while time.time() < limit: @@ -545,7 +549,8 @@ def check_host_severity_with_timeout(host_id: int, severity_id, timeout: int): with connection: with connection.cursor() as cursor: - cursor.execute("select sv.id from resources r left join severities sv ON r.severity_id=sv.severity_id where r.parent_id = 0 and r.id={}".format(host_id)) + cursor.execute( + "select sv.id from resources r left join severities sv ON r.severity_id=sv.severity_id where r.parent_id = 0 and r.id={}".format(host_id)) result = cursor.fetchall() if len(result) > 0: if severity_id == 'None': @@ -556,6 +561,7 @@ def check_host_severity_with_timeout(host_id: int, severity_id, timeout: int): time.sleep(1) return False + def check_resources_tags_with_timeout(parent_id: int, mid: int, typ: str, tag_ids: list, timeout: int): if typ == 'servicegroup': t = 0 @@ -568,41 +574,46 @@ def check_resources_tags_with_timeout(parent_id: int, mid: int, typ: str, tag_id limit = time.time() + timeout while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: - cursor.execute("select t.id from resources r inner join resources_tags rt on r.resource_id=rt.resource_id inner join tags t on rt.tag_id=t.tag_id WHERE r.id={} and r.parent_id={} and t.type={}".format(mid, parent_id, t)) + cursor.execute("select t.id from resources r inner join resources_tags rt on r.resource_id=rt.resource_id inner join tags t on rt.tag_id=t.tag_id WHERE r.id={} and r.parent_id={} and t.type={}".format( + mid, parent_id, t)) result = cursor.fetchall() if len(result) > 0: if len(result) == len(tag_ids): for r in result: if r['id'] not in tag_ids: - logger.console("id {} is not in tag ids".format(r['id'])) + logger.console( + "id {} is not in tag ids".format(r['id'])) break return True else: - logger.console("different sizes: result:{} and tag_ids:{}".format(len(result), len(tag_ids))) + logger.console("different sizes: result:{} and tag_ids:{}".format( + len(result), len(tag_ids))) time.sleep(1) return False + def check_host_tags_with_timeout(host_id: int, tag_id: int, timeout: int): limit = time.time() + timeout while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: - cursor.execute("SELECT t.id FROM resources_tags rt, tags t WHERE rt.tag_id = t.tag_id and resource_id={} and t.id={}".format(host_id, tag_id)) + cursor.execute( + "SELECT t.id FROM resources_tags rt, tags t WHERE rt.tag_id = t.tag_id and resource_id={} and t.id={}".format(host_id, tag_id)) result = cursor.fetchall() if len(result) > 0: if int(result[0]['id']) == tag_id: @@ -610,21 +621,24 @@ def check_host_tags_with_timeout(host_id: int, tag_id: int, timeout: int): time.sleep(1) return False + def check_number_of_resources_monitored_by_poller_is(poller: int, value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: - cursor.execute("select count(*) from hosts h where instance_id={} and enabled=1".format(poller)) + cursor.execute( + "select count(*) from hosts h where instance_id={} and enabled=1".format(poller)) hresult = cursor.fetchall() - cursor.execute("select count(*) from hosts h left join services s on s.host_id=h.host_id where h.instance_id={} and s.enabled=1".format(poller)) + cursor.execute( + "select count(*) from hosts h left join services s on s.host_id=h.host_id where h.instance_id={} and s.enabled=1".format(poller)) sresult = cursor.fetchall() if len(hresult) > 0 and len(sresult) > 0: if int(hresult[0]['count(*)']) + int(sresult[0]['count(*)']) == value: @@ -632,40 +646,45 @@ def check_number_of_resources_monitored_by_poller_is(poller: int, value: int, ti time.sleep(1) return False + def check_number_of_downtimes(expected: int, start, timeout: int): limit = time.time() + timeout d = parser.parse(start).timestamp() while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: - cursor.execute("SELECT count(*) FROM downtimes WHERE start_time >= {} AND deletion_time IS NULL".format(d)) + cursor.execute( + "SELECT count(*) FROM downtimes WHERE start_time >= {} AND deletion_time IS NULL".format(d)) result = cursor.fetchall() if len(result) > 0: - logger.console("{}/{} active downtimes".format(result[0]['count(*)'], expected)) + logger.console( + "{}/{} active downtimes".format(result[0]['count(*)'], expected)) if int(result[0]['count(*)']) == expected: return True time.sleep(1) return False + def check_number_of_relations_between_hostgroup_and_hosts(hostgroup: int, value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: - cursor.execute("SELECT count(*) FROM hosts_hostgroups WHERE hostgroup_id={}".format(hostgroup)) + cursor.execute( + "SELECT count(*) FROM hosts_hostgroups WHERE hostgroup_id={}".format(hostgroup)) result = cursor.fetchall() if len(result) > 0: if int(result[0]['count(*)']) == value: @@ -673,19 +692,21 @@ def check_number_of_relations_between_hostgroup_and_hosts(hostgroup: int, value: time.sleep(1) return False + def check_number_of_relations_between_servicegroup_and_services(servicegroup: int, value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: - cursor.execute("SELECT count(*) FROM services_servicegroups WHERE servicegroup_id={}".format(servicegroup)) + cursor.execute( + "SELECT count(*) FROM services_servicegroups WHERE servicegroup_id={}".format(servicegroup)) result = cursor.fetchall() if len(result) > 0: if int(result[0]['count(*)']) == value: @@ -693,26 +714,29 @@ def check_number_of_relations_between_servicegroup_and_services(servicegroup: in time.sleep(1) return False + def check_host_status(host: str, value: int, t: int, in_resources: bool, timeout: int = TIMEOUT): limit = time.time() + timeout while time.time() < limit: connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', - charset='utf8mb4', - cursorclass=pymysql.cursors.DictCursor) + user='centreon', + password='centreon', + database='centreon_storage', + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: key = '' confirmed = '' if in_resources: - cursor.execute("SELECT status, status_confirmed FROM resources WHERE parent_id=0 AND name='{}'".format(host)) + cursor.execute( + "SELECT status, status_confirmed FROM resources WHERE parent_id=0 AND name='{}'".format(host)) key = 'status' confirmed = 'status_confirmed' else: - cursor.execute("SELECT state, state_type FROM hosts WHERE name='{}'".format(host)) + cursor.execute( + "SELECT state, state_type FROM hosts WHERE name='{}'".format(host)) key = 'state' confirmed = 'state_type' result = cursor.fetchall() @@ -720,6 +744,7 @@ def check_host_status(host: str, value: int, t: int, in_resources: bool, timeout if int(result[0][key]) == value and int(result[0][confirmed]) == t: return True else: - logger.console("Host '{}' has status '{}' with confirmed '{}'".format(host, result[0][key], result[0][confirmed])) + logger.console("Host '{}' has status '{}' with confirmed '{}'".format( + host, result[0][key], result[0][confirmed])) time.sleep(1) return False From 771e90c3852c0522166ab641a1c8d51b98ec2a1a Mon Sep 17 00:00:00 2001 From: Deniza Alzhanova Date: Wed, 29 Jun 2022 09:18:23 -0400 Subject: [PATCH 2/5] fix(robot): correct tests --- tests/broker/command-line.robot | 46 ++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/broker/command-line.robot b/tests/broker/command-line.robot index b40d8b4a80b..0d7ae58a6c7 100644 --- a/tests/broker/command-line.robot +++ b/tests/broker/command-line.robot @@ -25,4 +25,48 @@ BCL2 [Documentation] Starting broker with option '-s5' should work [Tags] Broker start-stop Config Broker central - ${start}= Get Current Date exclude_millis=True \ No newline at end of file + ${start}= Get Current Date exclude_millis=True + Sleep 1s + Start Broker With Args -s5 /etc/centreon-broker/central-broker.json + ${table}= Create List Starting the TCP thread pool of 5 threads + ${logger_res}= Find in log with timeout ${centralLog} ${start} ${table} 30 + Should be True ${logger_res} msg=Didn't found 5 threads in /var/log/centreon-broker/central-broker +-master.log + Stop Broker With Args + +BCL3 + [Documentation] Starting broker with options '-D' should work and activate diagnose mode + [Tags] Broker start-stop + Config Broker central + ${start}= Get Current Date exclude_millis=True + Sleep 1s + Start Broker With Args -D /etc/centreon-broker/central-broker.json + ${result}= Wait For Broker + ${expected}= Evaluate "diagnostic:" in """${result}""" + Should be True ${expected} msg=diagnostic mode didn't launch + +BCL4 + [Documentation] Starting broker with options '-s2' and '-D' should work. + [Tags] Broker start-stop + Config Broker central + Start Broker With Args -s2 -D /etc/centreon-broker/central-broker.json + ${result}= Wait For Broker + ${expected}= Evaluate "diagnostic:" in """${result}""" + Should be True ${expected} msg=diagnostic mode didn't launch + +*** Keywords *** +Start Broker With Args + [Arguments] @{options} + log to console @{options} + Start Process /usr/sbin/cbd @{options} alias=b1 stdout=/tmp/output.txt + +Wait For broker + Wait For Process b1 + ${result}= Get File /tmp/output.txt + Remove File /tmp/output.txt + [Return] ${result} + +Stop Broker With Args + Send Signal To Process SIGTERM b1 + ${result}= Wait For Process b1 timeout=60s on_timeout=kill + Should Be Equal As Integers ${result.rc} 0 From 69906f07e721b7572b8b6aa6c02f2cdc0ba1e148 Mon Sep 17 00:00:00 2001 From: Deniza Alzhanova Date: Wed, 29 Jun 2022 10:39:14 -0400 Subject: [PATCH 3/5] fix(robot): robot tests and ninja compilation works --- centreon-broker/core/src/main.cc | 4 ++++ tests/README.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/centreon-broker/core/src/main.cc b/centreon-broker/core/src/main.cc index 7fb1e60c82d..359c724bd5e 100644 --- a/centreon-broker/core/src/main.cc +++ b/centreon-broker/core/src/main.cc @@ -35,7 +35,11 @@ #include "com/centreon/broker/log_v2.hh" #include "com/centreon/broker/misc/diagnostic.hh" +#include "absl/strings/numbers.h" +#include "com/centreon/exceptions/msg_fmt.hh" + using namespace com::centreon::broker; +using namespace com::centreon::exceptions; // Main config file. static std::vector gl_mainconfigfiles; diff --git a/tests/README.md b/tests/README.md index b9fd2fabd1b..17a028094c1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -81,6 +81,8 @@ Here is the list of the currently implemented tests: - [x] **BSS5**: Start-Stop with reversed connection on TCP acceptor with only one instance and no deadlock - [x] **BCL1**: Starting broker with option '-s foobar' should return an error - [x] **BCL2**: Starting broker with option '-s5' should work +- [x] **BCL3**: Starting broker with options '-D' should work and activate diagnose mode +- [x] **BCL4**: Starting broker with options '-s2' and '-D' should work. ### Broker/database - [x] **NetworkDbFail1**: network failure test between broker and database (shutting down connection for 100ms) From ba596a9b71b50d17807e73d992db947352692854 Mon Sep 17 00:00:00 2001 From: denliA <91119589+denliA@users.noreply.github.com> Date: Tue, 21 Jun 2022 10:02:45 +0200 Subject: [PATCH 4/5] fix(robot): database credentials in db_variables.robot --- tests/broker/command-line.robot | 95 +++-- tests/init-sql.sh | 16 +- tests/resources/Broker.py | 557 ++++++++++++++++------------- tests/resources/Common.py | 238 ++++++------ tests/resources/db_conf.py | 44 ++- tests/resources/db_variables.robot | 9 + tests/resources/resources.robot | 19 +- 7 files changed, 558 insertions(+), 420 deletions(-) create mode 100644 tests/resources/db_variables.robot diff --git a/tests/broker/command-line.robot b/tests/broker/command-line.robot index 0d7ae58a6c7..93aa9ae5d80 100644 --- a/tests/broker/command-line.robot +++ b/tests/broker/command-line.robot @@ -5,68 +5,67 @@ Suite Teardown Clean After Suite Test Setup Stop Processes Documentation Centreon Broker only start/stop tests -Library Process -Library OperatingSystem -Library ../resources/Broker.py -Library DateTime +Library Process +Library OperatingSystem +Library ../resources/Broker.py +Library DateTime *** Test Cases *** BCL1 - [Documentation] Starting broker with option '-s foobar' should return an error - [Tags] Broker start-stop - Config Broker central - Start Broker With Args -s foobar - ${result}= Wait For Broker - ${expected}= Evaluate "The option -s expects a positive integer" in """${result}""" - Should be True ${expected} msg=expected error 'The option -s expects a positive integer' + [Documentation] Starting broker with option '-s foobar' should return an error + [Tags] Broker start-stop + Config Broker central + Start Broker With Args -s foobar + ${result}= Wait For Broker + ${expected}= Evaluate "The option -s expects a positive integer" in """${result}""" + Should be True ${expected} msg=expected error 'The option -s expects a positive integer' BCL2 - [Documentation] Starting broker with option '-s5' should work - [Tags] Broker start-stop - Config Broker central - ${start}= Get Current Date exclude_millis=True - Sleep 1s - Start Broker With Args -s5 /etc/centreon-broker/central-broker.json - ${table}= Create List Starting the TCP thread pool of 5 threads - ${logger_res}= Find in log with timeout ${centralLog} ${start} ${table} 30 - Should be True ${logger_res} msg=Didn't found 5 threads in /var/log/centreon-broker/central-broker --master.log - Stop Broker With Args + [Documentation] Starting broker with option '-s5' should work + [Tags] Broker start-stop + Config Broker central + ${start}= Get Current Date exclude_millis=True + Sleep 1s + Start Broker With Args -s5 /etc/centreon-broker/central-broker.json + ${table}= Create List Starting the TCP thread pool of 5 threads + ${logger_res}= Find in log with timeout ${centralLog} ${start} ${table} 30 + Should be True ${logger_res} msg=Didn't found 5 threads in /var/log/centreon-broker/central-broker-master.log + Stop Broker With Args BCL3 - [Documentation] Starting broker with options '-D' should work and activate diagnose mode - [Tags] Broker start-stop - Config Broker central - ${start}= Get Current Date exclude_millis=True - Sleep 1s - Start Broker With Args -D /etc/centreon-broker/central-broker.json - ${result}= Wait For Broker - ${expected}= Evaluate "diagnostic:" in """${result}""" - Should be True ${expected} msg=diagnostic mode didn't launch + [Documentation] Starting broker with options '-D' should work and activate diagnose mode + [Tags] Broker start-stop + Config Broker central + ${start}= Get Current Date exclude_millis=True + Sleep 1s + Start Broker With Args -D /etc/centreon-broker/central-broker.json + ${result}= Wait For Broker + ${expected}= Evaluate "diagnostic:" in """${result}""" + Should be True ${expected} msg=diagnostic mode didn't launch BCL4 - [Documentation] Starting broker with options '-s2' and '-D' should work. - [Tags] Broker start-stop - Config Broker central - Start Broker With Args -s2 -D /etc/centreon-broker/central-broker.json - ${result}= Wait For Broker - ${expected}= Evaluate "diagnostic:" in """${result}""" - Should be True ${expected} msg=diagnostic mode didn't launch + [Documentation] Starting broker with options '-s2' and '-D' should work. + [Tags] Broker start-stop + Config Broker central + Start Broker With Args -s2 -D /etc/centreon-broker/central-broker.json + ${result}= Wait For Broker + ${expected}= Evaluate "diagnostic:" in """${result}""" + Should be True ${expected} msg=diagnostic mode didn't launch *** Keywords *** Start Broker With Args - [Arguments] @{options} - log to console @{options} - Start Process /usr/sbin/cbd @{options} alias=b1 stdout=/tmp/output.txt + [Arguments] @{options} + log to console @{options} + Start Process /usr/sbin/cbd @{options} alias=b1 stdout=/tmp/output.txt Wait For broker - Wait For Process b1 - ${result}= Get File /tmp/output.txt - Remove File /tmp/output.txt - [Return] ${result} + Wait For Process b1 + ${result}= Get File /tmp/output.txt + Remove File /tmp/output.txt + [Return] ${result} Stop Broker With Args - Send Signal To Process SIGTERM b1 - ${result}= Wait For Process b1 timeout=60s on_timeout=kill - Should Be Equal As Integers ${result.rc} 0 + Send Signal To Process SIGTERM b1 + ${result}= Wait For Process b1 timeout=60s on_timeout=kill + Should Be Equal As Integers ${result.rc} 0 diff --git a/tests/init-sql.sh b/tests/init-sql.sh index 514503abd03..f22037423d8 100755 --- a/tests/init-sql.sh +++ b/tests/init-sql.sh @@ -1,4 +1,16 @@ #!/bin/bash -mysql -u root -pcentreon -e "drop database centreon" -mysql -u root -pcentreon < resources/centreon.sql +DBUserRoot=$(awk '($1=="${DBUserRoot}") {print $2}' resources/db_variables.robot) +DBPassRoot=$(awk '($1=="${DBPassRoot}") {print $2}' resources/db_variables.robot) + +if [ -z $DBUserRoot ] ; then + DBUserRoot="root" +fi + +if [ -z $DBPassRoot ] ; then + DBPassRoot="centreon" +fi + +mysql --user="$DBUserRoot" --password="$DBPassRoot" -e "drop database centreon" +mysql --user="$DBUserRoot" --password="$DBPassRoot" < ../resources/centreon.sql +mysql --user="$DBUserRoot" --password="$DBPassRoot" < ../resources/centreon_storage.sql diff --git a/tests/resources/Broker.py b/tests/resources/Broker.py index c6b5e81e2cd..eefe85ae5dc 100755 --- a/tests/resources/Broker.py +++ b/tests/resources/Broker.py @@ -3,7 +3,9 @@ import pymysql.cursors import time import shutil -import socket, sys, time +import socket +import sys +import time from datetime import datetime from subprocess import getoutput import subprocess as subp @@ -17,15 +19,18 @@ from google.protobuf import empty_pb2 from robot.libraries.BuiltIn import BuiltIn -db_name = BuiltIn().get_variable_value("${DBName}") -db_host = BuiltIn().get_variable_value("${DBHost}") -db_user = BuiltIn().get_variable_value("${DBUser}") -db_pass = BuiltIn().get_variable_value("${DBPass}") -db_port = BuiltIn().get_variable_value("${DBPort}") TIMEOUT = 30 +BuiltIn().import_resource('db_variables.robot') +DB_NAME_STORAGE = BuiltIn().get_variable_value("${DBName}") +DB_NAME_CONF = BuiltIn().get_variable_value("${DBNameConf}") +DB_USER = BuiltIn().get_variable_value("${DBUser}") +DB_PASS = BuiltIn().get_variable_value("${DBPass}") +DB_HOST = BuiltIn().get_variable_value("${DBHost}") +DB_PORT = BuiltIn().get_variable_value("${DBPort}") + config = { -"central": """{{ + "central": """{{ "centreonBroker": {{ "broker_id": {0}, "broker_name": "{1}", @@ -74,11 +79,11 @@ "db_type": "mysql", "retry_interval": "5", "buffering_timeout": "0", - "db_host": "localhost", - "db_port": "3306", - "db_user": "centreon", - "db_password": "centreon", - "db_name": "centreon_storage", + "db_host": "{2}", + "db_port": "{3}", + "db_user": "{4}", + "db_password": "{5}", + "db_name": "{6}", "queries_per_transaction": "1000", "connections_count": "3", "read_timeout": "1", @@ -88,7 +93,7 @@ "name": "centreon-broker-master-rrd", "port": "5670", "buffering_timeout": "0", - "host": "localhost", + "host": "127.0.0.1", "retry_interval": "5", "protocol": "bbdo", "tls": "no", @@ -104,11 +109,11 @@ "buffering_timeout": "0", "length": "15552000", "db_type": "mysql", - "db_host": "localhost", - "db_port": "3306", - "db_user": "centreon", - "db_password": "centreon", - "db_name": "centreon_storage", + "db_host": "{2}", + "db_port": "{3}", + "db_user": "{4}", + "db_password": "{5}", + "db_name": "{6}", "queries_per_transaction": "1000", "read_timeout": "1", "check_replication": "no", @@ -131,7 +136,7 @@ }} }}""", -"module": """{{ + "module": """{{ "centreonBroker": {{ "broker_id": {}, "broker_name": "{}", @@ -164,7 +169,7 @@ {{ "name": "central-module-master-output", "port": "5669", - "host": "localhost", + "host": "127.0.0.1", "protocol": "bbdo", "tls": "no", "negotiation": "yes", @@ -188,7 +193,7 @@ }} }}""", -"rrd": """{{ + "rrd": """{{ "centreonBroker": {{ "broker_id": {0}, "broker_name": "{1}", @@ -258,7 +263,7 @@ }} }}""", -"central_map": """{{ + "central_map": """{{ "centreonBroker": {{ "broker_id": {0}, "broker_name": "{1}", @@ -284,7 +289,8 @@ "tcp": "error", "tls": "error", "lua": "error", - "bam": "error" + "bam": "error", + "grpc": "error" }} }}, "input": [ @@ -307,11 +313,11 @@ "db_type": "mysql", "retry_interval": "5", "buffering_timeout": "0", - "db_host": "localhost", - "db_port": "3306", - "db_user": "centreon", - "db_password": "centreon", - "db_name": "centreon_storage", + "db_host": "{2}", + "db_port": "{3}", + "db_user": "{4}", + "db_password": "{5}", + "db_name": "{6}", "queries_per_transaction": "1000", "connections_count": "3", "read_timeout": "1", @@ -349,11 +355,11 @@ "buffering_timeout": "0", "length": "15552000", "db_type": "mysql", - "db_host": "localhost", - "db_port": "3306", - "db_user": "centreon", - "db_password": "centreon", - "db_name": "centreon_storage", + "db_host": "{2}", + "db_port": "{3}", + "db_user": "{4}", + "db_password": "{5}", + "db_name": "{6}", "queries_per_transaction": "1000", "read_timeout": "1", "check_replication": "no", @@ -377,9 +383,26 @@ }}""", } + +def _apply_conf(name, callback): + if name == 'central': + filename = "central-broker.json" + elif name.startswith('module'): + filename = "central-{}.json".format(name) + else: + filename = "central-rrd.json" + + f = open("/etc/centreon-broker/{}".format(filename), "r") + buf = f.read() + f.close() + conf = json.loads(buf) + callback(conf) + f = open("/etc/centreon-broker/{}".format(filename), "w") + f.write(json.dumps(conf, indent=2)) + f.close() + + def config_broker(name, poller_inst: int = 1): - if not exists("/var/lib/centreon-broker/"): - makedirs("/var/lib/centreon-broker/") if name == 'central': broker_id = 1 broker_name = "central-broker-master" @@ -398,15 +421,18 @@ def config_broker(name, poller_inst: int = 1): if not exists("/var/lib/centreon/status/"): makedirs("/var/lib/centreon/status/") if not exists("/var/lib/centreon/metrics/tmpl_15552000_300_0.rrd"): - getoutput("rrdcreate /var/lib/centreon/metrics/tmpl_15552000_300_0.rrd DS:value:ABSOLUTE:3000:U:U RRA:AVERAGE:0.5:1:864000") + getoutput( + "rrdcreate /var/lib/centreon/metrics/tmpl_15552000_300_0.rrd DS:value:ABSOLUTE:3000:U:U RRA:AVERAGE:0.5:1:864000") broker_id = 2 broker_name = "central-rrd-master" filename = "central-rrd.json" if name == 'module': for i in range(poller_inst): - broker_name = "/etc/centreon-broker/central-module{}.json".format(i) - buf = config[name].format(broker_id, "central-module-master{}".format(i)) + broker_name = "/etc/centreon-broker/central-module{}.json".format( + i) + buf = config[name].format( + broker_id, "central-module-master{}".format(i)) conf = json.loads(buf) conf["centreonBroker"]["poller_id"] = i + 1 @@ -415,9 +441,36 @@ def config_broker(name, poller_inst: int = 1): f.close() else: f = open("/etc/centreon-broker/{}".format(filename), "w") - f.write(config[name].format(broker_id, broker_name)) + f.write(config[name].format(broker_id, broker_name, DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME_STORAGE)) f.close() + +def change_broker_tcp_output_to_grpc(name: str): + def output_to_grpc(conf): + output_dict = conf["centreonBroker"]["output"] + for i, v in enumerate(output_dict): + if v["type"] == "ipv4": + v["type"] = "grpc" + _apply_conf(name, output_to_grpc) + + +def change_broker_tcp_input_to_grpc(name: str): + def input_to_grpc(conf): + input_dict = conf["centreonBroker"]["input"] + for i, v in enumerate(input_dict): + if v["type"] == "ipv4": + v["type"] = "grpc" + _apply_conf(name, input_to_grpc) + + +def change_broker_compression_output(config_name: str, compression_value: str): + def compression_modifier(conf): + output_dict = conf["centreonBroker"]["output"] + for i, v in enumerate(output_dict): + v["compression"] = compression_value + _apply_conf(config_name, compression_modifier) + + def config_broker_sql_output(name, output): if name == 'central': filename = "central-broker.json" @@ -436,66 +489,67 @@ def config_broker_sql_output(name, output): output_dict.pop(i) if output == 'unified_sql': output_dict.append({ - "name" : "central-broker-unified-sql", - "db_type" : "mysql", - "db_host" : "localhost", - "db_port" : "3306", - "db_user" : "centreon", - "db_password" : "centreon", - "db_name" : "centreon_storage", - "interval" : "60", - "length" : "15552000", - "queries_per_transaction" : "20000", - "connections_count" : "4", - "read_timeout" : "60", - "buffering_timeout" : "0", - "retry_interval" : "60", - "check_replication" : "no", - "type" : "unified_sql", - "store_in_data_bin" : "yes", - "insert_in_index_data" : "1" + "name": "central-broker-unified-sql", + "db_type": "mysql", + "db_host": DB_HOST, + "db_port": DB_PORT, + "db_user": DB_USER, + "db_password": DB_PASS, + "db_name": DB_NAME_STORAGE, + "interval": "60", + "length": "15552000", + "queries_per_transaction": "20000", + "connections_count": "4", + "read_timeout": "60", + "buffering_timeout": "0", + "retry_interval": "60", + "check_replication": "no", + "type": "unified_sql", + "store_in_data_bin": "yes", + "insert_in_index_data": "1" }) elif output == 'sql/perfdata': output_dict.append({ - "name": "central-broker-master-sql", - "db_type": "mysql", - "retry_interval": "5", - "buffering_timeout": "0", - "db_host": "localhost", - "db_port": "3306", - "db_user": "centreon", - "db_password": "centreon", - "db_name": "centreon_storage", - "queries_per_transaction": "1000", - "connections_count": "3", - "read_timeout": "1", - "type": "sql" + "name": "central-broker-master-sql", + "db_type": "mysql", + "retry_interval": "5", + "buffering_timeout": "0", + "db_host": DB_HOST, + "db_port": DB_PORT, + "db_user": DB_USER, + "db_password": DB_PASS, + "db_name": DB_NAME_STORAGE, + "queries_per_transaction": "1000", + "connections_count": "3", + "read_timeout": "1", + "type": "sql" }) output_dict.append({ - "name": "central-broker-master-perfdata", - "interval": "60", - "retry_interval": "5", - "buffering_timeout": "0", - "length": "15552000", - "db_type": "mysql", - "db_host": "localhost", - "db_port": "3306", - "db_user": "centreon", - "db_password": "centreon", - "db_name": "centreon_storage", - "queries_per_transaction": "1000", - "read_timeout": "1", - "check_replication": "no", - "store_in_data_bin": "yes", - "connections_count": "3", - "insert_in_index_data": "1", - "type": "storage" + "name": "central-broker-master-perfdata", + "interval": "60", + "retry_interval": "5", + "buffering_timeout": "0", + "length": "15552000", + "db_type": "mysql", + "db_host": DB_HOST, + "db_port": DB_PORT, + "db_user": DB_USER, + "db_password": DB_PASS, + "db_name": DB_NAME_STORAGE, + "queries_per_transaction": "1000", + "read_timeout": "1", + "check_replication": "no", + "store_in_data_bin": "yes", + "connections_count": "3", + "insert_in_index_data": "1", + "type": "storage" }) f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() -def broker_config_clear_outputs_except(name, ex : list): + +def broker_config_clear_outputs_except(name, ex: list): if name == 'central': filename = "central-broker.json" elif name.startswith('module'): @@ -567,14 +621,15 @@ def broker_config_add_lua_output(name, output, luafile): conf = json.loads(buf) output_dict = conf["centreonBroker"]["output"] output_dict.append({ - "name": output, - "path": luafile, - "type": "lua" + "name": output, + "path": luafile, + "type": "lua" }) f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_output_set(name, output, key, value): if name == 'central': filename = "central-broker.json" @@ -586,12 +641,14 @@ def broker_config_output_set(name, output, key, value): buf = f.read() f.close() conf = json.loads(buf) - output_dict = [elem for i, elem in enumerate(conf["centreonBroker"]["output"]) if elem["name"] == output][0] + output_dict = [elem for i, elem in enumerate( + conf["centreonBroker"]["output"]) if elem["name"] == output][0] output_dict[key] = value f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_output_set_json(name, output, key, value): if name == 'central': filename = "central-broker.json" @@ -603,13 +660,15 @@ def broker_config_output_set_json(name, output, key, value): buf = f.read() f.close() conf = json.loads(buf) - output_dict = [elem for i, elem in enumerate(conf["centreonBroker"]["output"]) if elem["name"] == output][0] + output_dict = [elem for i, elem in enumerate( + conf["centreonBroker"]["output"]) if elem["name"] == output][0] j = json.loads(value) output_dict[key] = j f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_output_remove(name, output, key): if name == 'central': filename = "central-broker.json" @@ -621,13 +680,15 @@ def broker_config_output_remove(name, output, key): buf = f.read() f.close() conf = json.loads(buf) - output_dict = [elem for i, elem in enumerate(conf["centreonBroker"]["output"]) if elem["name"] == output][0] + output_dict = [elem for i, elem in enumerate( + conf["centreonBroker"]["output"]) if elem["name"] == output][0] if key in output_dict: - output_dict.pop(key) + output_dict.pop(key) f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_input_set(name, inp, key, value): if name == 'central': filename = "central-broker.json" @@ -639,12 +700,14 @@ def broker_config_input_set(name, inp, key, value): buf = f.read() f.close() conf = json.loads(buf) - input_dict = [elem for i, elem in enumerate(conf["centreonBroker"]["input"]) if elem["name"] == inp][0] + input_dict = [elem for i, elem in enumerate( + conf["centreonBroker"]["input"]) if elem["name"] == inp][0] input_dict[key] = value f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_input_remove(name, inp, key): if name == 'central': filename = "central-broker.json" @@ -656,13 +719,15 @@ def broker_config_input_remove(name, inp, key): buf = f.read() f.close() conf = json.loads(buf) - input_dict = [elem for i, elem in enumerate(conf["centreonBroker"]["input"]) if elem["name"] == inp][0] + input_dict = [elem for i, elem in enumerate( + conf["centreonBroker"]["input"]) if elem["name"] == inp][0] if key in input_dict: - input_dict.pop(key) + input_dict.pop(key) f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_log(name, key, value): if name == 'central': filename = "central-broker.json" @@ -680,6 +745,7 @@ def broker_config_log(name, key, value): f.write(json.dumps(conf, indent=2)) f.close() + def broker_config_flush_log(name, value): if name == 'central': filename = "central-broker.json" @@ -697,63 +763,65 @@ def broker_config_flush_log(name, value): f.write(json.dumps(conf, indent=2)) f.close() + def check_broker_stats_exist(name, key1, key2, timeout=TIMEOUT): - limit = time.time() + timeout - while time.time() < limit: - if name == 'central': - filename = "central-broker-master-stats.json" - elif name == 'module': - filename = "central-module-master-stats.json" - else: - filename = "central-rrd-master-stats.json" - retry = True - while retry: - retry = False - f = open("/var/lib/centreon-broker/{}".format(filename), "r") - buf = f.read() - f.close() - - try: - conf = json.loads(buf) - except: + limit = time.time() + timeout + while time.time() < limit: + if name == 'central': + filename = "central-broker-master-stats.json" + elif name == 'module': + filename = "central-module-master-stats.json" + else: + filename = "central-rrd-master-stats.json" retry = True - if key1 in conf: - if key2 in conf[key1]: - return True - time.sleep(1) - return False + while retry: + retry = False + f = open("/var/lib/centreon-broker/{}".format(filename), "r") + buf = f.read() + f.close() + + try: + conf = json.loads(buf) + except: + retry = True + if key1 in conf: + if key2 in conf[key1]: + return True + time.sleep(1) + return False + def get_broker_stats_size(name, key, timeout=TIMEOUT): - limit = time.time() + timeout - retval = 0 - while time.time() < limit: - if name == 'central': - filename = "central-broker-master-stats.json" - elif name == 'module': - filename = "central-module-master-stats.json" - else: - filename = "central-rrd-master-stats.json" - retry = True - while retry: - retry = False - f = open("/var/lib/centreon-broker/{}".format(filename), "r") - buf = f.read() - f.close() - try: - conf = json.loads(buf) - except: + limit = time.time() + timeout + retval = 0 + while time.time() < limit: + if name == 'central': + filename = "central-broker-master-stats.json" + elif name == 'module': + filename = "central-module-master-stats.json" + else: + filename = "central-rrd-master-stats.json" retry = True - - if key in conf: - value = len(conf[key]) - else: - value = 0 - if value > retval: - retval = value - elif retval != 0: - return retval - time.sleep(5) - return retval + while retry: + retry = False + f = open("/var/lib/centreon-broker/{}".format(filename), "r") + buf = f.read() + f.close() + try: + conf = json.loads(buf) + except: + retry = True + + if key in conf: + value = len(conf[key]) + else: + value = 0 + if value > retval: + retval = value + elif retval != 0: + return retval + time.sleep(5) + return retval ## @@ -763,12 +831,12 @@ def get_broker_stats_size(name, key, timeout=TIMEOUT): # # @return a list of index ids. # -def get_not_existing_indexes(count:int): +def get_not_existing_indexes(count: int): # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -801,15 +869,16 @@ def get_not_existing_indexes(count:int): # # @return a list of index ids. # -def get_indexes_to_delete(count:int): - files = [os.path.basename(x) for x in glob.glob("/var/lib/centreon/metrics/[0-9]*.rrd")] +def get_indexes_to_delete(count: int): + files = [os.path.basename(x) for x in glob.glob( + "/var/lib/centreon/metrics/[0-9]*.rrd")] ids = [int(f.split(".")[0]) for f in files] # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -840,15 +909,16 @@ def get_indexes_to_delete(count:int): # # @return a list of metric ids. # -def get_not_existing_metrics(count:int): - files = [os.path.basename(x) for x in glob.glob("/var/lib/centreon/metrics/[0-9]*.rrd")] +def get_not_existing_metrics(count: int): + files = [os.path.basename(x) for x in glob.glob( + "/var/lib/centreon/metrics/[0-9]*.rrd")] ids = [int(f.split(".")[0]) for f in files] # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -877,15 +947,16 @@ def get_not_existing_metrics(count:int): # # @return a list of metric ids. # -def get_metrics_to_delete(count:int): - files = [os.path.basename(x) for x in glob.glob("/var/lib/centreon/metrics/[0-9]*.rrd")] +def get_metrics_to_delete(count: int): + files = [os.path.basename(x) for x in glob.glob( + "/var/lib/centreon/metrics/[0-9]*.rrd")] ids = [int(f.split(".")[0]) for f in files] # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -906,15 +977,17 @@ def get_metrics_to_delete(count:int): # @param count:int The number of metrics to create. # -def create_metrics(count:int): - files = [os.path.basename(x) for x in glob.glob("/var/lib/centreon/metrics/[0-9]*.rrd")] + +def create_metrics(count: int): + files = [os.path.basename(x) for x in glob.glob( + "/var/lib/centreon/metrics/[0-9]*.rrd")] ids = [int(f.split(".")[0]) for f in files] # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -925,7 +998,7 @@ def create_metrics(count:int): cursor.execute(sql) result = cursor.fetchall() ids_db = [r['metric_id'] for r in result] - if list(set(ids) & set(ids_db)) == [] : + if list(set(ids) & set(ids_db)) == []: sql = "DELETE FROM metrics" cursor.execute(sql) connection.commit() @@ -933,21 +1006,24 @@ def create_metrics(count:int): cursor.execute(sql) result = cursor.fetchall() ids_index = [r['id'] for r in result] - if ids_index == [] : + if ids_index == []: sql = "INSERT INTO index_data (host_id, service_id) VALUES ('1', '1')" cursor.execute(sql) ids_index = cursor.lastrowid - for c in range(count) : - sql = "INSERT INTO metrics (index_id,metric_name,unit_name,warn,warn_low,warn_threshold_mode,crit,crit_low,crit_threshold_mode,min,max,current_value,data_source_type) VALUES ('{}','metric_{}','unit_{}','10','1','0','1','1','0','0','100','25','0')".format(ids_index[0],c,c) + for c in range(count): + sql = "INSERT INTO metrics (index_id,metric_name,unit_name,warn,warn_low,warn_threshold_mode,crit,crit_low,crit_threshold_mode,min,max,current_value,data_source_type) VALUES ('{}','metric_{}','unit_{}','10','1','0','1','1','0','0','100','25','0')".format( + ids_index[0], c, c) cursor.execute(sql) ids_metric = cursor.lastrowid connection.commit() - shutil.copy("/var/lib/centreon/metrics/tmpl_15552000_300_0.rrd", "/var/lib/centreon/metrics/{}.rrd".format(ids_metric)) + shutil.copy("/var/lib/centreon/metrics/tmpl_15552000_300_0.rrd", + "/var/lib/centreon/metrics/{}.rrd".format(ids_metric)) logger.console("create metric file {}".format(ids_metric)) def run_reverse_bam(duration, interval): - subp.Popen("broker/map_client.py {:f}".format(interval), shell=True, stdout=subp.PIPE, stdin=subp.PIPE) + subp.Popen("broker/map_client.py {:f}".format(interval), + shell=True, stdout=subp.PIPE, stdin=subp.PIPE) time.sleep(duration) getoutput("kill -9 $(ps aux | grep map_client.py | awk '{print $2}')") @@ -959,14 +1035,15 @@ def run_reverse_bam(duration, interval): # # @return a list of indexes def get_indexes_to_rebuild(count: int): - files = [os.path.basename(x) for x in glob.glob("/var/lib/centreon/metrics/[0-9]*.rrd")] + files = [os.path.basename(x) for x in glob.glob( + "/var/lib/centreon/metrics/[0-9]*.rrd")] ids = [int(f.split(".")[0]) for f in files] # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) retval = [] @@ -978,15 +1055,18 @@ def get_indexes_to_rebuild(count: int): result = cursor.fetchall() for r in result: if int(r['metric_id']) in ids: - logger.console("building data for metric {}".format(r['metric_id'])) + logger.console( + "building data for metric {}".format(r['metric_id'])) start = int(time.time()) - 24 * 60 * 60 * 30 # We go back to 30 days with steps of 5 mn value1 = int(r['metric_id']) value2 = 0 value = value1 - cursor.execute("DELETE FROM data_bin WHERE id_metric={} AND ctime >= {}".format(r['metric_id'], start)) + cursor.execute("DELETE FROM data_bin WHERE id_metric={} AND ctime >= {}".format( + r['metric_id'], start)) for i in range(0, 24 * 60 * 60 * 30, 60 * 5): - cursor.execute("INSERT INTO data_bin (id_metric, ctime, value, status) VALUES ({},{},{},'0')".format(r['metric_id'], start + i, value)) + cursor.execute("INSERT INTO data_bin (id_metric, ctime, value, status) VALUES ({},{},{},'0')".format( + r['metric_id'], start + i, value)) if value == value1: value = value2 else: @@ -1010,16 +1090,17 @@ def get_indexes_to_rebuild(count: int): # @return a list of metric ids. def get_metrics_matching_indexes(indexes): # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: # Read a single record - sql = "SELECT `metric_id` FROM `metrics` WHERE `index_id` IN ({})".format(','.join(map(str, indexes))) + sql = "SELECT `metric_id` FROM `metrics` WHERE `index_id` IN ({})".format( + ','.join(map(str, indexes))) cursor.execute(sql) result = cursor.fetchall() retval = [int(r['metric_id']) for r in result] @@ -1029,25 +1110,23 @@ def get_metrics_matching_indexes(indexes): ## # @brief send a gRPC command to remove graphs (by indexes or by metrics) # +# @param port the gRPC port to use to send the command # @param indexes a list of indexes # @param metrics a list of metrics # -#def remove_graphs(indexes, metrics, timeout=10): -# # Connect to the database -# connection = pymysql.connect(host='localhost', -# user='centreon', -# password='centreon', -# database='centreon_storage', -# charset='utf8mb4', -# cursorclass=pymysql.cursors.DictCursor) -# with connection: -# with connection.cursor() as cursor: -# # Read a single record -# sql = "UPDATE metrics SET to_delete='1' WHERE index_id IN ({})".format(','.join(map(str, indexes))) -# cursor.execute(sql) -# result = cursor.fetchall() -# retval = [int(r['metric_id']) for r in result] -# return retval +def remove_graphs(port, indexes, metrics, timeout=10): + limit = time.time() + timeout + while time.time() < limit: + time.sleep(1) + with grpc.insecure_channel("127.0.0.1:{}".format(port)) as channel: + stub = broker_pb2_grpc.BrokerStub(channel) + trm = broker_pb2.ToRemove() + trm.index_ids.extend(indexes) + trm.metric_ids.extend(metrics) + try: + stub.RemoveGraphs(trm) + except: + logger.console("gRPC server not ready") ## @@ -1090,7 +1169,8 @@ def compare_rrd_average_value(metric, value: float): res = float(lst[1].replace(',', '.')) return abs(res - float(value)) < 2 else: - logger.console("It was impossible to get the average value from the file /var/lib/centreon/metrics/{}.rrd from the last 30 days".format(metric)) + logger.console( + "It was impossible to get the average value from the file /var/lib/centreon/metrics/{}.rrd from the last 30 days".format(metric)) return True @@ -1167,34 +1247,33 @@ def add_bam_config_to_broker(name): "cache": "yes", "check_replication": "no", "command_file": "/var/lib/centreon-engine/config0/rw/centengine.cmd", - "db_host": "127.0.0.1", - "db_name": "centreon", - "db_password": "centreon", - "db_port": "3306", + "db_host": DB_HOST, + "db_name": DB_NAME_CONF, + "db_password": DB_PASS, + "db_port": DB_PORT, "db_type": "mysql", - "db_user": "centreon", + "db_user": DB_USER, "queries_per_transaction": "0", - "storage_db_name": "centreon_storage", + "storage_db_name": DB_NAME_STORAGE, "type": "bam" - }) + }) output_dict.append({ - "name": "centreon-bam-reporting", - "filters": { - "category": [ - "bam" - ] - }, - "check_replication": "no", - "db_host": "127.0.0.1", - "db_name": "centreon_storage", - "db_password": "centreon", - "db_port": "3306", - "db_type": "mysql", - "db_user": "centreon", - "queries_per_transaction": "0", - "type": "bam_bi" + "name": "centreon-bam-reporting", + "filters": { + "category": [ + "bam" + ] + }, + "check_replication": "no", + "db_host": DB_HOST, + "db_name": DB_NAME_STORAGE, + "db_password": DB_PASS, + "db_port": DB_PORT, + "db_type": "mysql", + "db_user": DB_USER, + "queries_per_transaction": "0", + "type": "bam_bi" }) f = open("/etc/centreon-broker/{}".format(filename), "w") f.write(json.dumps(conf, indent=2)) f.close() - diff --git a/tests/resources/Common.py b/tests/resources/Common.py index d791140cf9b..4809e3b8afa 100644 --- a/tests/resources/Common.py +++ b/tests/resources/Common.py @@ -6,13 +6,23 @@ from dateutil import parser from datetime import datetime import pymysql.cursors +from robot.libraries.BuiltIn import BuiltIn + TIMEOUT = 30 +BuiltIn().import_resource('db_variables.robot') +DB_NAME_STORAGE = BuiltIn().get_variable_value("${DBName}") +DB_NAME_CONF = BuiltIn().get_variable_value("${DBNameConf}") +DB_USER = BuiltIn().get_variable_value("${DBUser}") +DB_PASS = BuiltIn().get_variable_value("${DBPass}") +DB_HOST = BuiltIn().get_variable_value("${DBHost}") +DB_PORT = BuiltIn().get_variable_value("${DBPort}") + def check_connection(port: int, pid1: int, pid2: int): limit = time.time() + TIMEOUT - r = re.compile(r"^ESTAB.*127\.0\.0\.1:{}\s".format(port)) + r = re.compile(r"^ESTAB.*127\.0\.0\.1\]*:{}\s".format(port)) while time.time() < limit: out = getoutput("ss -plant") lst = out.split('\n') @@ -20,7 +30,7 @@ def check_connection(port: int, pid1: int, pid2: int): if len(estab_port) >= 2: ok = [False, False] p = re.compile( - r"127\.0\.0\.1:(\d+)\s+127\.0\.0\.1:(\d+)\s+.*,pid=(\d+)") + r"127\.0\.0\.1\]*:(\d+)\s+.*127\.0\.0\.1\]*:(\d+)\s+.*,pid=(\d+)") for l in estab_port: m = p.search(l) if m is not None: @@ -126,15 +136,19 @@ def create_certificate(host: str, cert: str): create_key_and_certificate(host, "", cert) +def run_env(): + return getoutput("echo $RUN_ENV | awk '{print $1}'") + + def start_mysql(): - if not getoutput("echo $RUN_ENV | awk '{print $1}'"): + if not run_env(): getoutput("systemctl start mysql") else: getoutput("mariadbd --user=root > /dev/null 2>&1 &") def stop_mysql(): - if not getoutput("echo $RUN_ENV | awk '{print $1}'"): + if not run_env(): getoutput("systemctl stop mysql") else: getoutput( @@ -183,7 +197,8 @@ def check_engine_logs_are_duplicated(log: str, date): idx = find_line_from(lines, date) count_true = 0 count_false = 0 - logs = [] + logs_old = [] + logs_new = [] old_log = re.compile(r"\[[^\]]*\] \[[^\]]*\] ([^\[].*)") new_log = re.compile( r"\[[^\]]*\] \[[^\]]*\] \[[^\]]*\] \[[^\]]*\] (.*)") @@ -191,25 +206,27 @@ def check_engine_logs_are_duplicated(log: str, date): mo = old_log.match(l) mn = new_log.match(l) if mo is not None: - if mo.group(1) in logs: - logs.remove(mo.group(1)) + if mo.group(1) in logs_new: + logs_new.remove(mo.group(1)) else: - logs.append(mo.group(1)) + logs_old.append(mo.group(1)) else: mn = new_log.match(l) if mn is not None: - if mn.group(1) in logs: - logs.remove(mn.group(1)) + if mn.group(1) in logs_old: + logs_old.remove(mn.group(1)) else: - logs.append(mn.group(1)) - if len(logs) <= 1: + logs_new.append(mn.group(1)) + if len(logs_old) <= 1: # It is possible to miss one log because of the initial split of the # file. return True else: - logger.console("Logs not duplicated") - for l in logs: + logger.console( + "{} old logs are not duplicated".format(len(logs_old))) + for l in logs_old: logger.console(l) + # We don't care about new logs not duplicated, in a future, we won't have any old logs except IOError: logger.console("The file '{}' does not exist".format(log)) return False @@ -223,7 +240,7 @@ def find_line_from(lines, date): start = 0 end = len(lines) - 1 idx = start - while end > start: + while end - start > 1: idx = (start + end) // 2 m = p.match(lines[idx]) while m is None: @@ -236,12 +253,10 @@ def find_line_from(lines, date): logger.console("We are at the first line and no date found") idx_d = get_date(m.group(1)) - if my_date <= idx_d and end != idx: + if my_date <= idx_d: end = idx - elif my_date > idx_d and start != idx: + elif my_date > idx_d: start = idx - else: - break return idx @@ -314,11 +329,11 @@ def set_command_status(cmd, status): def check_service_status_with_timeout(hostname: str, service_desc: str, status: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, autocommit=True, - database='centreon_storage', + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -336,10 +351,10 @@ def check_service_status_with_timeout(hostname: str, service_desc: str, status: def check_severity_with_timeout(name: str, level, icon_id, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -358,10 +373,10 @@ def check_severity_with_timeout(name: str, level, icon_id, timeout: int): def check_tag_with_timeout(name: str, typ, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -380,10 +395,10 @@ def check_tag_with_timeout(name: str, typ, timeout: int): def check_severities_count(value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -401,10 +416,10 @@ def check_severities_count(value: int, timeout: int): def check_tags_count(value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -422,10 +437,10 @@ def check_tags_count(value: int, timeout: int): def check_ba_status_with_timeout(ba_name: str, status: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection: @@ -442,10 +457,10 @@ def check_ba_status_with_timeout(ba_name: str, status: int, timeout: int): def check_service_downtime_with_timeout(hostname: str, service_desc: str, enabled, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -462,10 +477,10 @@ def check_service_downtime_with_timeout(hostname: str, service_desc: str, enable def delete_service_downtime(hst: str, svc: str): now = int(time.time()) - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -482,10 +497,10 @@ def delete_service_downtime(hst: str, svc: str): def number_of_downtimes_is(nb: int): - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -498,10 +513,10 @@ def number_of_downtimes_is(nb: int): def clear_db(table: str): - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -514,10 +529,10 @@ def clear_db(table: str): def check_service_severity_with_timeout(host_id: int, service_id: int, severity_id, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -539,10 +554,10 @@ def check_service_severity_with_timeout(host_id: int, service_id: int, severity_ def check_host_severity_with_timeout(host_id: int, severity_id, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', autocommit=True, cursorclass=pymysql.cursors.DictCursor) @@ -562,7 +577,7 @@ def check_host_severity_with_timeout(host_id: int, severity_id, timeout: int): return False -def check_resources_tags_with_timeout(parent_id: int, mid: int, typ: str, tag_ids: list, timeout: int): +def check_resources_tags_with_timeout(parent_id: int, mid: int, typ: str, tag_ids: list, timeout: int, enabled: bool = True): if typ == 'servicegroup': t = 0 elif typ == 'hostgroup': @@ -573,29 +588,45 @@ def check_resources_tags_with_timeout(parent_id: int, mid: int, typ: str, tag_id t = 3 limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: + logger.console("select t.id from resources r inner join resources_tags rt on r.resource_id=rt.resource_id inner join tags t on rt.tag_id=t.tag_id WHERE r.id={} and r.parent_id={} and t.type={}".format( + mid, parent_id, t)) cursor.execute("select t.id from resources r inner join resources_tags rt on r.resource_id=rt.resource_id inner join tags t on rt.tag_id=t.tag_id WHERE r.id={} and r.parent_id={} and t.type={}".format( mid, parent_id, t)) result = cursor.fetchall() - if len(result) > 0: + logger.console(result) + if not enabled: + if len(result) == 0: + return True + else: + for r in result: + if r['id'] in tag_ids: + logger.console( + "id {} is in tag ids".format(r['id'])) + break + return True + elif enabled and len(result) > 0: if len(result) == len(tag_ids): for r in result: if r['id'] not in tag_ids: logger.console( "id {} is not in tag ids".format(r['id'])) break - return True + return True else: logger.console("different sizes: result:{} and tag_ids:{}".format( len(result), len(tag_ids))) + else: + logger.console("result") + logger.console(result) time.sleep(1) return False @@ -603,10 +634,10 @@ def check_resources_tags_with_timeout(parent_id: int, mid: int, typ: str, tag_id def check_host_tags_with_timeout(host_id: int, tag_id: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -625,23 +656,20 @@ def check_host_tags_with_timeout(host_id: int, tag_id: int, timeout: int): def check_number_of_resources_monitored_by_poller_is(poller: int, value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection: with connection.cursor() as cursor: cursor.execute( - "select count(*) from hosts h where instance_id={} and enabled=1".format(poller)) - hresult = cursor.fetchall() - cursor.execute( - "select count(*) from hosts h left join services s on s.host_id=h.host_id where h.instance_id={} and s.enabled=1".format(poller)) - sresult = cursor.fetchall() - if len(hresult) > 0 and len(sresult) > 0: - if int(hresult[0]['count(*)']) + int(sresult[0]['count(*)']) == value: + "SELECT count(*) FROM resources WHERE poller_id={} AND enabled=1".format(poller)) + result = cursor.fetchall() + if len(result) > 0: + if int(result[0]['count(*)']) == value: return True time.sleep(1) return False @@ -651,10 +679,10 @@ def check_number_of_downtimes(expected: int, start, timeout: int): limit = time.time() + timeout d = parser.parse(start).timestamp() while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection: @@ -674,10 +702,10 @@ def check_number_of_downtimes(expected: int, start, timeout: int): def check_number_of_relations_between_hostgroup_and_hosts(hostgroup: int, value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -696,10 +724,10 @@ def check_number_of_relations_between_hostgroup_and_hosts(hostgroup: int, value: def check_number_of_relations_between_servicegroup_and_services(servicegroup: int, value: int, timeout: int): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -718,10 +746,10 @@ def check_number_of_relations_between_servicegroup_and_services(servicegroup: in def check_host_status(host: str, value: int, t: int, in_resources: bool, timeout: int = TIMEOUT): limit = time.time() + timeout while time.time() < limit: - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon_storage', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_STORAGE, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) diff --git a/tests/resources/db_conf.py b/tests/resources/db_conf.py index 742764d19ed..041aec19924 100755 --- a/tests/resources/db_conf.py +++ b/tests/resources/db_conf.py @@ -1,11 +1,21 @@ #!/usr/bin/python3 from robot.api import logger -import sys import pymysql.cursors +from robot.libraries.BuiltIn import BuiltIn + CONF_DIR = "/etc/centreon-engine" ENGINE_HOME = "/var/lib/centreon-engine" +BuiltIn().import_resource('db_variables.robot') +DB_NAME_STORAGE = BuiltIn().get_variable_value("${DBName}") +DB_NAME_CONF = BuiltIn().get_variable_value("${DBNameConf}") +DB_USER = BuiltIn().get_variable_value("${DBUser}") +DB_PASS = BuiltIn().get_variable_value("${DBPass}") +DB_HOST = BuiltIn().get_variable_value("${DBHost}") +DB_PORT = BuiltIn().get_variable_value("${DBPort}") + + class DbConf: def __init__(self, engine): self.last_service_id = 0 @@ -26,10 +36,10 @@ def __init__(self, engine): def clear_db(self): # Connect to the database - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -56,10 +66,10 @@ def clear_db(self): connection.commit() def init_bam(self): - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -73,10 +83,10 @@ def init_bam(self): self.engine.centengine_conf_add_bam() def create_conf_db(self): - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) @@ -161,10 +171,10 @@ def create_conf_db(self): connection.commit() def create_ba_with_services(self, name:str, typ:str, svc:[(str,str)]): - connection = pymysql.connect(host='localhost', - user='centreon', - password='centreon', - database='centreon', + connection = pymysql.connect(host=DB_HOST, + user=DB_USER, + password=DB_PASS, + database=DB_NAME_CONF, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) diff --git a/tests/resources/db_variables.robot b/tests/resources/db_variables.robot new file mode 100644 index 00000000000..6aa17e4f969 --- /dev/null +++ b/tests/resources/db_variables.robot @@ -0,0 +1,9 @@ +*** Variables *** +${DBName} centreon_storage +${DBNameConf} centreon +${DBHost} localhost +${DBUser} centreon +${DBPass} Fa@V@?L9@4Wfh70u +${DBPort} 3306 +${DBUserRoot} root +${DBPassRoot} Af58MwnP@zJ*@6!5 \ No newline at end of file diff --git a/tests/resources/resources.robot b/tests/resources/resources.robot index 514dd532e37..736b1e3e69b 100644 --- a/tests/resources/resources.robot +++ b/tests/resources/resources.robot @@ -1,4 +1,5 @@ *** Settings *** +Resource ./db_variables.robot Library Process Library OperatingSystem Library Common.py @@ -9,6 +10,10 @@ Clean Before Suite Clear Engine Logs Clear Broker Logs +Clean Grpc Before Suite + set grpc port 0 + Clean Before Suite + Clean After Suite # Remove Files ${ENGINE_LOG}${/}centengine.log ${ENGINE_LOG}${/}centengine.debug # Remove Files ${BROKER_LOG}${/}central-broker-master.log ${BROKER_LOG}${/}central-rrd-master.log ${BROKER_LOG}${/}central-module-master.log @@ -26,6 +31,9 @@ Clear Broker Logs Start Broker Start Process /usr/sbin/cbd /etc/centreon-broker/central-broker.json alias=b1 Start Process /usr/sbin/cbd /etc/centreon-broker/central-rrd.json alias=b2 +# ${log_pid1}= Get Process Id b1 +# ${log_pid2}= Get Process Id b2 +# Log To Console \npidcentral=${log_pid1} pidrrd=${log_pid2}\n Reload Broker Send Signal To Process SIGHUP b1 @@ -60,6 +68,8 @@ Start Engine Create Directory ${log} Create Directory ${lib} Start Process /usr/sbin/centengine ${conf} alias=${alias} +# ${log_pid1}= Get Process Id ${alias} +# Log To Console \npidengine${idx}=${log_pid1}\n END Start Custom Engine @@ -120,12 +130,3 @@ ${rrdLog} ${BROKER_LOG}/central-rrd-master.log ${logEngine0} ${ENGINE_LOG}/config0/centengine.log ${logEngine1} ${ENGINE_LOG}/config1/centengine.log ${logEngine2} ${ENGINE_LOG}/config2/centengine.log -${dbgEngine0} ${ENGINE_LOG}/config0/centengine.debug -${dbgEngine1} ${ENGINE_LOG}/config1/centengine.debug -${dbgEngine2} ${ENGINE_LOG}/config2/centengine.debug - -${DBName} centreon_storage -${DBHost} localhost -${DBUser} centreon -${DBPass} centreon -${DBPort} 3306 From 6d4c4581dce3cad87a301b03814a8bf677855d79 Mon Sep 17 00:00:00 2001 From: Deniza Alzhanova Date: Thu, 30 Jun 2022 05:02:28 -0400 Subject: [PATCH 5/5] fix(robot): correct resources.robot with dbgEngine0 --- tests/resources/resources.robot | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/resources/resources.robot b/tests/resources/resources.robot index 736b1e3e69b..4aa30b14cca 100644 --- a/tests/resources/resources.robot +++ b/tests/resources/resources.robot @@ -130,3 +130,6 @@ ${rrdLog} ${BROKER_LOG}/central-rrd-master.log ${logEngine0} ${ENGINE_LOG}/config0/centengine.log ${logEngine1} ${ENGINE_LOG}/config1/centengine.log ${logEngine2} ${ENGINE_LOG}/config2/centengine.log +${dbgEngine0} ${ENGINE_LOG}/config0/centengine.debug +${dbgEngine1} ${ENGINE_LOG}/config1/centengine.debug +${dbgEngine2} ${ENGINE_LOG}/config2/centengine.debug \ No newline at end of file