Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

enh(broker): cbd with multiargs and robot tests #306

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions centreon-broker/core/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> gl_mainconfigfiles;
Expand All @@ -44,7 +48,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'},
Expand Down Expand Up @@ -155,33 +158,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 <poolsize>] [-c] [-D] [-h] [-v]");
break;
}
}

if (optind < argc)
Expand All @@ -199,14 +204,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] [<configfile>]", 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 <poolsize>] [-c] [-D] [-h] [-v] [<configfile>]",
argv[0]);
log_v2::core()->info(" '-s<poolsize>' 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(
Expand All @@ -217,7 +221,8 @@ int main(int argc, char* argv[]) {
retval = 0;
} else if (gl_mainconfigfiles.empty()) {
log_v2::core()->error(
"USAGE: {} [-c] [-d] [-D] [-h] [-v] [<configfile>]\n\n", argv[0]);
"USAGE: {} [-s <poolsize>] [-c] [-D] [-h] [-v] [<configfile>]\n\n",
argv[0]);
return 1;
} else {
log_v2::core()->info("Centreon Broker {}", CENTREON_BROKER_VERSION);
Expand Down
196 changes: 28 additions & 168 deletions tests/README.md

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions tests/broker/command-line.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
*** 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
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
16 changes: 14 additions & 2 deletions tests/init-sql.sh
Original file line number Diff line number Diff line change
@@ -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
Loading