MT#15033 clean Build.PL server startup

options to start the panel directly or a mysql server
are dropped. this also drops dependencies

Change-Id: I4be60c8495d94b5fc0bcac742602bec3c988e5fb
changes/30/2630/2
Gerhard Jungwirth 10 years ago
parent 03343ad0a1
commit c044e2410a

@ -30,50 +30,23 @@ Build.PL - NGCP-Panel build system including test fixtures
=head1 SYNOPSIS
perl ./Build
./Build test --webdriver='phantomjs --webdriver=4444'
./Build test --webdriver='java -jar selenium-server-standalone.jar'
./Build test --webdriver='chromedriver --url-base=wd/hub --port=4444'
./Build test --webdriver=selenium-rc # from CPAN distro Alien-SeleniumRC
./Build test --webdriver=external --wd-server=127.0.0.1:5555
./Build test --wd-server=127.0.0.1:5555
./Build testcover --webdriver='phantomjs --webdriver=4444'
./Build testcover
./Build test_api
./Build test_api --schema-base-dir=path/to/schema --server=https://1.2.3.4:1443
=head2 Options
--mysqld-port port where the mysqld should be started
--mysql-dump one or more mysql dumps to be imported to our mysqld
--no-junit don't output junit but normal TAP, for manual testing
--run-server panel should be started by build script
--schema-base-dir directory of NGCP::Schema if its not yet installed
--server URI for socket test server
--webdriver Command to be run as Webdriver
--wd-server HOST:PORT of an external webdriver to connect to
--help brief help message
--man full documentation
=head1 OPTIONS
=head2 C<--mysqld-port>
If this option and C<--mysqld-dir> are supplied, a mysqld will be started
at the specified port and be used for the tests. mysqld will be stopped
and the temporary data deleted when this script finishes.
=head2 C<--mysql-dump>
If this option and C<--mysqld-port> are supplied, a mysqld will be started
and be used for the tests. It will import all dumps supplied with this option.
This option can be set multiple times. In this case all specified files will
be dumped into the database.
=head2 C<--run-server>
Does not take an argument. Indicates the ./Build script should start a
server running the panel by itself on the Address given by the --server
argument.
=head2 C<--schema-base-dir>
If the NGCP::Schema is not installed to a known path to perl, this
@ -85,12 +58,6 @@ It will then be included via blib, so we have access to its lib and share.
URI for the HTTP::Server::PSGI socket server run for testing,
default C<http://localhost:5000>
=head2 C<--webdriver>
command to launch a webdriver
external if the webdriver is launched externally
this command is no longer required
=head2 C<--wd-server>
Host:Port of the webdriver to which the tests should connect.

@ -1,48 +1,22 @@
package Local::Module::Build;
use Moose qw(around extends);
use Child qw(child);
use Capture::Tiny;
use TryCatch;
use MooseX::Method::Signatures;
use LWP::UserAgent;
extends 'Module::Build';
our ($plackup, $webdriver, @cover_opt, $mysqld);
method wait_socket($host, $port, $timeout=90) {
require IO::Socket::IP;
my $timer = 0;
while (1) {
my $sock = IO::Socket::IP->new(
PeerHost => $host,
PeerPort => $port,
Type => IO::Socket::IP::SOCK_STREAM(),
);
last if $sock;
sleep 1;
$timer++;
die sprintf('socket %s:%s is not accessible within %d seconds after start', $host, $port, $timeout)
if $timer > $timeout;
};
}
sub shutdown_servers {
for my $proc ($webdriver, $plackup) {
if ($proc) {
$proc->kill('TERM');
}
}
}
sub _test_preconditions {
my ($self) = @_;
require Getopt::Long;
Getopt::Long::Configure('pass_through');
my %opt = (server => 'http://localhost:5000', webdriver => 'external');
Getopt::Long::GetOptions(\%opt, 'webdriver=s', 'server:s', 'help|?', 'man', 'wd-server=s',
'schema-base-dir=s', 'mysqld-port=s', 'mysql-dump=s@', 'no-junit', 'run-server')
or die 'could not process command-line options';
my %opt = (server => 'http://localhost:1443');
Getopt::Long::GetOptions(\%opt,
'server:s',
'help|?', 'man',
'wd-server=s',
'schema-base-dir=s',
'no-junit',
) or die 'could not process command-line options';
require Pod::Usage;
Pod::Usage::pod2usage(-exitval => 1, -input => 'Build.PL') if $opt{help};
@ -61,56 +35,15 @@ sub _test_preconditions {
if ($opt{'schema-base-dir'}) {
require blib;
blib->import($opt{'schema-base-dir'})
blib->import($opt{'schema-base-dir'});
}
$SIG{'INT'} = sub { exit(1) }; # for clean stopping of servers
if ($opt{'mysqld-port'} && $opt{'mysql-dump'}) {
require Test::mysqld;
$mysqld = Test::mysqld->new(
my_cnf => {
'port' => $opt{'mysqld-port'},
},
) or die "couldnt start mysqld";
$ENV{NGCP_PANEL_CUSTOM_DSN} = $mysqld->dsn();
my $dump_files = join(' ', @{ $opt{'mysql-dump'} });
system("cat $dump_files | mysql -uroot --host=127.0.0.1 --port=$opt{'mysqld-port'}");
system(qq/echo "GRANT ALL PRIVILEGES ON *.* TO 'sipwise'\@'localhost' WITH GRANT OPTION;" | mysql -uroot --host=127.0.0.1 --port=$opt{'mysqld-port'}/);
}
unless ($opt{webdriver} eq "external") {
$webdriver = child { exec $opt{webdriver} };
$self->wait_socket(qw(localhost 4444));
}
require URI;
unless ($opt{server} =~ m|^https?://|) {
die "Wrong format of server argument, should start with 'http(s)'.";
}
my $uri = URI->new($opt{server});
if( $opt{'run-server'} ) {
require File::Which;
$ENV{ NGCP_PANEL_CONFIG_LOCAL_SUFFIX } = "testing";
$plackup = child {
my $out_fh = IO::File->new("panel_debug_stdout", "w+");
my $err_fh = IO::File->new("panel_debug_stderr", "w+");
$out_fh->autoflush(1);
$err_fh->autoflush(1);
local $| = 1;
Capture::Tiny::capture {
exec $^X,
'-Ilib',
exists $opt{'schema-base-dir'} ? "-Mblib=$opt{'schema-base-dir'}" : (),
@cover_opt,
scalar File::Which::which('plackup'),
sprintf('--listen=%s:%s', $uri->host, $uri->port),
'ngcp_panel.psgi';
} stdout => $out_fh, stderr => $err_fh;
};
$self->wait_socket($uri->host, $uri->port);
}
$opt{server} =~ s!/$!!;
$ENV{CATALYST_SERVER} = $opt{server};
if ($self->verbose) {
@ -150,7 +83,8 @@ around('ACTION_test', sub {
};
});
method ACTION_testcover {
sub ACTION_testcover {
my ($self) = @_;
{
my @missing;
for my $module (qw(Devel::Cover sigtrap)) {
@ -165,45 +99,47 @@ method ACTION_testcover {
$self->add_to_cleanup('coverage', 'cover_db');
$self->depends_on('code');
$self->do_system(qw(cover -delete));
@cover_opt = (
my @cover_opt = ( # TODO: unused and unsusable currently
'-Msigtrap "handler", sub { exit }, "normal-signals"',
'-MDevel::Cover=+ignore,ngcp_panel.psgi,+ignore,plackup',
);
$self->depends_on('test');
shutdown_servers;
#shutdown_servers;
sleep 5;
$self->do_system(qw(cover));
}
method ACTION_test_servers {
sub ACTION_test_selenium {
my ($self) = @_;
$self->depends_on('code');
$self->_test_preconditions;
print "All servers ready for you!\nPress [Enter] to exit.";
<STDIN>;
$self->test_files('t/selenium/*.t');
$self->generic_test(type => 'default');
}
method ACTION_test_selenium {
sub ACTION_test_api {
my ($self) = @_;
$self->depends_on('code');
$self->_test_preconditions;
$self->test_files('t/selenium/*.t');
$self->_download_certs;
$self->test_files('t/api-rest/*.t');
$self->generic_test(type => 'default');
unlink ($ENV{API_SSL_CLIENT_CERT}, $ENV{API_SSL_CA_CERT}); # created by _download_certs()
}
method ACTION_test_api {
sub ACTION_test_generic {
my ($self) = @_;
$self->depends_on('code');
$self->_test_preconditions;
$self->_download_certs;
$self->test_files('t/api-rest/*.t');
$self->generic_test(type => 'default');
unlink ($ENV{API_SSL_CLIENT_CERT}, $ENV{API_SSL_CA_CERT}); # created by _download_certs()
}
method ACTION_readme {
sub ACTION_readme {
require Pod::Readme;
my $parser = Pod::Readme->new();
$parser->parse_from_file('Build.PL', 'README');
}
END { shutdown_servers }
1;

@ -1,5 +1,3 @@
Source: ngcp-panel-tests-selenium
Build-Depends: libcapture-tiny-perl,
libchild-perl,
libmoosex-method-signatures-perl,
Build-Depends: libmoosex-method-signatures-perl,
libtrycatch-perl,

Loading…
Cancel
Save