add .travis.yml to test pandora_server

This commit is contained in:
Akihiro Uchida 2016-04-16 22:15:19 +09:00 committed by Akihiro Uchida
parent 50eb15ed50
commit 1d7ea4a7de
2 changed files with 310 additions and 0 deletions

37
.travis.yml Normal file
View File

@ -0,0 +1,37 @@
language: perl
perl:
- "5.18-extras"
- "5.20-extras"
services:
- mysql
sudo: required
before_install:
- sudo apt-get install snmp snmpd traceroute xprobe2 nmap snmp-mibs-downloader
# override install
install:
- pushd pandora_server
- cpanm --quiet --installdeps --notest .
- cpanm --quiet --notest DBD::mysql
- cpanm --quiet --notest Scope::Guard
- popd
before_script:
- mysql -u root -e 'CREATE DATABASE IF NOT EXISTS `pandora`;'
- mysql -u root -e 'GRANT ALL PRIVILEGES ON `pandora`.* TO "pandora" IDENTIFIED BY "pandora";'
- mysql -u root -e 'FLUSH PRIVILEGES;'
- mysql -u root -D pandora < pandora_console/pandoradb.sql
- mysql -u root -D pandora < pandora_console/pandoradb_data.sql
- sudo mkdir -p /var/log/pandora && sudo chown travis:travis /var/log/pandora
# override script
script:
- pushd pandora_server
- prove -lfr
- popd
notifications:
email: false

View File

@ -0,0 +1,273 @@
use strict;
use warnings;
use Test::More;
use Scope::Guard;
use File::Basename;
use Data::Dumper;
use PandoraFMS::Core;
use PandoraFMS::Config;
use PandoraFMS::DB;
no lib '/usr/lib/perl5';
my $conf;
my $dbh;
my $agent;
my $module;
my $module_with_ff;
my $ok = {data => 1};
my $ng = {data => 0};
BEGIN {
diag "startup\n";
$conf = {
quiet => 0, verbosity => 1, daemon => 0, PID => "",
pandora_path => dirname(__FILE__) . "/../conf/pandora_server.conf.new",
};
pandora_load_config($conf);
$dbh = db_connect (
'mysql', $conf->{'dbname'}, $conf->{'dbhost'},
$conf->{'dbport'}, $conf->{'dbuser'}, $conf->{'dbpass'}
);
my $agent_id = pandora_create_agent($conf, $conf->{servername}, "test", "", 10, 0, 1, '', 300, $dbh);
$agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE tagente.id_agente = ?', $agent_id);
}
END {
diag "shutdown\n";
pandora_delete_agent($dbh, $agent->{id_agente}, $conf);
}
sub teardown {
diag "teardown\n";
pandora_delete_module ($dbh, $module->{id_agente_modulo}, $conf);
pandora_delete_module ($dbh, $module_with_ff->{id_agente_modulo}, $conf);
}
sub setup {
diag "setup\n";
my $module_id = pandora_create_module_from_hash(
$conf,
{
id_agente => $agent->{id_agente}, id_tipo_modulo => 2,
nombre => "test", module_interval => 300, id_module_group => 1
},
$dbh
);
$module = get_db_single_row(
$dbh, 'SELECT * FROM tagente_modulo WHERE tagente_modulo.id_agente_modulo = ?', $module_id
);
pandora_process_module(
$conf, $ok, $agent, $module, '', '', time(), $conf->{servername}, $dbh
);
my $module_with_ff_id = pandora_create_module_from_hash(
$conf,
{
id_agente => $agent->{id_agente}, id_tipo_modulo => 2,
nombre => "test with FF", module_interval => 300, id_module_group => 1,
each_ff => 1, min_ff_event_normal => 0, min_ff_event_warning => 0, min_ff_event_critical => 2,
},
$dbh
);
$module_with_ff = get_db_single_row(
$dbh, 'SELECT * FROM tagente_modulo WHERE tagente_modulo.id_agente_modulo = ?', $module_with_ff_id
);
pandora_process_module(
$conf, $ok, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
return Scope::Guard->new(\&teardown);
}
subtest 'OK -> NG, finally status changes' => sub {
my $guard = setup();
my $status;
# OK
pandora_process_module(
$conf, $ok, $agent, $module, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status goes normal');
# NG
pandora_process_module(
$conf, $ng, $agent, $module, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{id_agente_modulo}
);
ok($status->{estado} == 1, 'status goes critical');
};
subtest 'OK -> UN -> NG, finally status changes' => sub {
my $guard = setup();
my $status;
# OK
pandora_process_module(
$conf, $ok, $agent, $module, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status goes normal');
# UNKNOWN
db_do(
$dbh, 'UPDATE tagente_estado SET last_status = 3, estado = 3 WHERE id_agente_modulo = ?', $module->{id_agente_modulo}
);
# NG
pandora_process_module(
$conf, $ng, $agent, $module, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{id_agente_modulo}
);
ok($status->{estado} == 1, 'status goes critical');
};
subtest 'with FF, OK -> NG -> NG -> NG, finally status changes' => sub {
my $guard = setup();
my $status;
# OK
pandora_process_module(
$conf, $ok, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status goes normal');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status keeps normal due to FF');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status keeps normal due to FF');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 1, 'status goes critical, crossing the Rubicon');
};
subtest 'with FF, OK -> UN -> NG -> NG -> NG, status changes finally' => sub {
my $guard = setup();
my $status;
# OK
pandora_process_module(
$conf, $ok, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status goes normal');
# UNKNOWN
db_do(
$dbh, 'UPDATE tagente_estado SET last_status = 3, estado = 3 WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status keeps normal due to FF');
ok($status->{status_changes} == 0, 'status counter equal to 0');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status keeps normal due to FF');
ok($status->{status_changes} == 1, 'status counter equal to 1');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 1, 'status goes critical, crossing the Rubicon');
ok($status->{status_changes} == 2, 'status counter equal to 2');
};
subtest 'with FF, OK -> NG -> UN -> NG -> NG, status changes finally' => sub {
my $guard = setup();
my $status;
# OK
pandora_process_module(
$conf, $ok, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status goes normal');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status keeps normal due to FF');
ok($status->{status_changes} == 0, 'status counter equal to 0');
# UNKNOWN
db_do(
$dbh, 'UPDATE tagente_estado SET last_status = 3, estado = 3 WHERE id_agente_estado = ?', $module_with_ff->{id_agente_modulo}
);
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 0, 'status keeps normal due to FF');
ok($status->{status_changes} == 1, 'status counter equal to 1');
# NG
pandora_process_module(
$conf, $ng, $agent, $module_with_ff, '', '', time(), $conf->{servername}, $dbh
);
$status = get_db_single_row(
$dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module_with_ff->{id_agente_modulo}
);
ok($status->{estado} == 1, 'status goes critical, crossing the Rubicon');
ok($status->{status_changes} == 2, 'status counter equal to 1');
};
done_testing;