TT#62215 Add initial integration for Jenkins daily-build-testrunner

* Separate and isolate new REST API 2 tests into 't/api-rest2'.
* Create initial Dockerfile to run new api-rest2 tests on Jenkins.
* Store test results into '/results' folder to be Docker/Jenkins compatible.
* Simplify the Perl classes naming.
* Make Perl critic happy: Magic variable "$ENV" should be assigned as "local"

Change-Id: I72f62a959ea7dce91b8f7b565bba5969e51f5259
changes/18/32018/4
Alexander Lutay 6 years ago
parent cfc4ed76db
commit 0ae8ad5a90

@ -0,0 +1,52 @@
# DOCKER_NAME=ngcp-panel-tests-rest-api2-buster
FROM docker.mgm.sipwise.com/sipwise-buster:latest
# Important! Update this no-op ENV variable when this Dockerfile
# is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built.
ENV REFRESHED_AT 2019-07-26
# files that get-code generates
COPY t/api-rest/sources.list.d/builddeps.list /etc/apt/sources.list.d/
COPY t/api-rest/sources.list.d/preferences /etc/apt/preferences.d/
RUN apt-get update && \
apt-get install --assume-yes \
libcpanel-json-xs-perl \
libdata-walk-perl \
libdatetime-format-iso8601-perl \
libdatetime-format-strptime-perl \
liblog-log4perl-perl \
libmoose-perl \
liburi-perl \
libwww-perl \
libyaml-libyaml-perl \
&& echo "Done"
RUN echo "cd /code && ./t/api-rest2/testrunner 1.2.3.4" > /root/.bash_history
WORKDIR /code/
################################################################################
# Instructions for usage
# ----------------------
# When you want to build the base image from scratch
# jump to the next section if you don't want to build yourself!:
#
# you need to put the proper NGCP sources at t/api-rest2/sources.list.d/builddeps.list for instance, trunk:
# % echo "deb https://deb.sipwise.com/autobuild/ release-trunk-buster main" > t/api-rest2/sources.list.d/builddeps.list
#
# NOTE: run the following command (from root folder of git repository):
# % docker build --tag="ngcp-panel-tests-rest-api2-buster" -f t/api-rest2/Dockerfile .
# % docker run --rm -i -t -v $(pwd):/code:ro -v $(pwd):/results:rw ngcp-panel-tests-rest-api2-buster:latest bash
#
# Use the existing docker image (run from ngcp-panel base directory):
# % docker pull docker.mgm.sipwise.com/ngcp-panel-tests-rest-api2-buster
# % docker run --rm -i -t -v $(pwd):/code:ro -v $(pwd):/results:rw docker.mgm.sipwise.com/ngcp-panel-tests-rest-api2-buster:latest bash
#
# Inside docker. To run the full REST-API-2 test suite:
# ./t/api-rest2/testrunner $IP_OF_NGCP_SYSTEM # IP_OF_NGCP_SYSTEM can be e.g. IP of a `vagrant up ce-trunk` system (eth1)
# To run only a particular test (e.g. the api-customers.t):
# ./t/api-rest2/testrunner $IP_OF_NGCP_SYSTEM ./t/api-rest2/some_test.yaml
################################################################################

@ -1,4 +1,4 @@
package NGCP::TestFramework;
package TestFramework;
use strict;
use warnings;
@ -16,9 +16,9 @@ use URI;
use YAML::XS qw(LoadFile);
use Data::Dumper;
use NGCP::TestFramework::RequestBuilder;
use NGCP::TestFramework::Client;
use NGCP::TestFramework::TestExecutor;
use TestFramework::RequestBuilder;
use TestFramework::Client;
use TestFramework::TestExecutor;
has 'file_path' => (
isa => 'Str',
@ -32,19 +32,19 @@ sub run {
$test_case_name =~ s/.+\/(\w+).yaml/$1/;
chomp $test_case_name;
Log::Log4perl->easy_init( { level => $DEBUG,
file => ">>/var/log/ngcp/test-framework/$test_case_name.log",
file => ">>/results/$test_case_name.log",
category => "TestFramework::Client",
layout => '%d - %F{1} line %L - %M: %m%n' },
{ level => $DEBUG,
file => ">>/var/log/ngcp/test-framework/$test_case_name.log",
file => ">>/results/$test_case_name.log",
category => "TestFramework::RequestBuilder",
layout => '%d - %F{1} line %L - %M: %m%n' },
{ level => $DEBUG,
file => ">>/var/log/ngcp/test-framework/$test_case_name.log",
file => ">>/results/$test_case_name.log",
category => "TestFramework::TestExecutor",
layout => '%d - %F{1} line %L - %M: %m%n' },
{ level => $DEBUG,
file => ">/var/log/ngcp/test-framework/$test_case_name.log",
file => ">/results/$test_case_name.log",
layout => '%d - %F{1} line %L - %M: %m%n' }
);
@ -63,11 +63,11 @@ sub run {
INFO( "Setting up the base URI." );
my $base_uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443');
INFO( "Setting up the RequestBuilder." );
my $request_builder = NGCP::TestFramework::RequestBuilder->new({ base_uri => $base_uri });
my $request_builder = TestFramework::RequestBuilder->new({ base_uri => $base_uri });
INFO( "Setting up the Client." );
my $client = NGCP::TestFramework::Client->new( { uri => $base_uri } );
my $client = TestFramework::Client->new( { uri => $base_uri } );
INFO( "Setting up the Test Executor." );
my $test_executor = NGCP::TestFramework::TestExecutor->new();
my $test_executor = TestFramework::TestExecutor->new();
# initializing time to add to fields which need to be unique
my $retained = { unique_id => int(rand(100000)) };

@ -1,4 +1,4 @@
package NGCP::TestFramework::Client;
package TestFramework::Client;
use strict;
use warnings;

@ -1,4 +1,4 @@
package NGCP::TestFramework::RequestBuilder;
package TestFramework::RequestBuilder;
use strict;
use warnings;

@ -1,4 +1,4 @@
package NGCP::TestFramework::TestExecutor;
package TestFramework::TestExecutor;
use strict;
use warnings;
@ -9,8 +9,8 @@ use Moose;
use Test::More;
use Data::Dumper;
Test::More->builder->output ('/var/log/ngcp/test-framework/result.txt');
Test::More->builder->failure_output ('/var/log/ngcp/test-framework/errors.txt');
Test::More->builder->output ('/results/result.txt');
Test::More->builder->failure_output ('/results/errors.txt');
sub run_tests {
my ( $self, $conditions, $result, $retained, $test_name ) = @_;

@ -1,7 +1,9 @@
use lib '..';
#!/usr/bin/perl
use lib 't/api-rest2/lib';
use strict;
use warnings;
use NGCP::TestFramework;
use TestFramework;
use Test::More;
use threads;
use Thread::Queue;
@ -14,7 +16,7 @@ if ( !$server ){
print "Usage: \$ perl testrunner.pl [<testsystem>] [<testset>]\n";
print "Usage example: \$ perl testrunner.pl 192.168.88.162\n";
print "Usage example: \$ perl testrunner.pl 192.168.88.162 fast\n";
print "Possible test set: all, stable, fast, t/lib/NGCP/TestFramework/Interface/Contracts.yaml\n";
print "Possible test set: all, stable, fast, t/api-rest2/Contracts.yaml\n";
print "Default test set: all\n";
exit(1);
}
@ -29,7 +31,7 @@ elsif ( $selected eq 'fast' ) {
}
elsif ( $selected eq 'all' ) {
print "Test selection: all\n";
map { push @test_files, "TestFramework/Interface/$_" } `ls TestFramework/Interface`;
map { push @test_files, "./$_" } `ls ./t/api-rest2/*.yaml`;
}
else{
print "Test selection: $selected\n";
@ -39,9 +41,9 @@ else{
print "################################################################################\n";
print "Finished main setup, now running tests ...\n";
$ENV{CATALYST_SERVER_SUB}="https://$server:443";
$ENV{CATALYST_SERVER}="https://$server:1443";
$ENV{NGCP_SESSION_ID}=int(rand(1000)).time;
local $ENV{CATALYST_SERVER_SUB}="https://$server:443";
local $ENV{CATALYST_SERVER}="https://$server:1443";
local $ENV{NGCP_SESSION_ID}=int(rand(1000)).time;
my @threads;
my $tests_queue = Thread::Queue->new();
@ -69,7 +71,7 @@ sub worker {
chomp $test_file;
my $start_time = time;
print "Running tests from $test_file\n";
my $test_framework = NGCP::TestFramework->new( {file_path => $test_file} );
my $test_framework = TestFramework->new( {file_path => $test_file} );
my $result = $test_framework->run();
Loading…
Cancel
Save