From 0ae8ad5a90e8fdb8ab21dc054d0b032296c944eb Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Fri, 26 Jul 2019 14:12:35 +0200 Subject: [PATCH] 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 --- .../BillingNetworks.yaml | 0 .../Interface => api-rest2}/Calls.yaml | 0 .../Interface => api-rest2}/Contracts.yaml | 0 .../Interface => api-rest2}/Customers.yaml | 0 t/api-rest2/Dockerfile | 52 +++++++++++++++++++ .../NGCP => api-rest2/lib}/TestFramework.pm | 22 ++++---- .../lib}/TestFramework/Client.pm | 2 +- .../lib}/TestFramework/RequestBuilder.pm | 2 +- .../lib}/TestFramework/TestExecutor.pm | 6 +-- t/api-rest2/sources.list.d/builddeps.list | 0 t/api-rest2/sources.list.d/preferences | 0 .../testrunner.pl => api-rest2/testrunner} | 18 ++++--- 12 files changed, 78 insertions(+), 24 deletions(-) rename t/{lib/NGCP/TestFramework/Interface => api-rest2}/BillingNetworks.yaml (100%) rename t/{lib/NGCP/TestFramework/Interface => api-rest2}/Calls.yaml (100%) rename t/{lib/NGCP/TestFramework/Interface => api-rest2}/Contracts.yaml (100%) rename t/{lib/NGCP/TestFramework/Interface => api-rest2}/Customers.yaml (100%) create mode 100644 t/api-rest2/Dockerfile rename t/{lib/NGCP => api-rest2/lib}/TestFramework.pm (92%) rename t/{lib/NGCP => api-rest2/lib}/TestFramework/Client.pm (99%) rename t/{lib/NGCP => api-rest2/lib}/TestFramework/RequestBuilder.pm (98%) rename t/{lib/NGCP => api-rest2/lib}/TestFramework/TestExecutor.pm (98%) create mode 100644 t/api-rest2/sources.list.d/builddeps.list create mode 100644 t/api-rest2/sources.list.d/preferences rename t/{lib/NGCP/testrunner.pl => api-rest2/testrunner} (79%) mode change 100644 => 100755 diff --git a/t/lib/NGCP/TestFramework/Interface/BillingNetworks.yaml b/t/api-rest2/BillingNetworks.yaml similarity index 100% rename from t/lib/NGCP/TestFramework/Interface/BillingNetworks.yaml rename to t/api-rest2/BillingNetworks.yaml diff --git a/t/lib/NGCP/TestFramework/Interface/Calls.yaml b/t/api-rest2/Calls.yaml similarity index 100% rename from t/lib/NGCP/TestFramework/Interface/Calls.yaml rename to t/api-rest2/Calls.yaml diff --git a/t/lib/NGCP/TestFramework/Interface/Contracts.yaml b/t/api-rest2/Contracts.yaml similarity index 100% rename from t/lib/NGCP/TestFramework/Interface/Contracts.yaml rename to t/api-rest2/Contracts.yaml diff --git a/t/lib/NGCP/TestFramework/Interface/Customers.yaml b/t/api-rest2/Customers.yaml similarity index 100% rename from t/lib/NGCP/TestFramework/Interface/Customers.yaml rename to t/api-rest2/Customers.yaml diff --git a/t/api-rest2/Dockerfile b/t/api-rest2/Dockerfile new file mode 100644 index 0000000000..cb38d154c5 --- /dev/null +++ b/t/api-rest2/Dockerfile @@ -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 +################################################################################ diff --git a/t/lib/NGCP/TestFramework.pm b/t/api-rest2/lib/TestFramework.pm similarity index 92% rename from t/lib/NGCP/TestFramework.pm rename to t/api-rest2/lib/TestFramework.pm index 2bf11b171b..ede8d2ec13 100644 --- a/t/lib/NGCP/TestFramework.pm +++ b/t/api-rest2/lib/TestFramework.pm @@ -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)) }; diff --git a/t/lib/NGCP/TestFramework/Client.pm b/t/api-rest2/lib/TestFramework/Client.pm similarity index 99% rename from t/lib/NGCP/TestFramework/Client.pm rename to t/api-rest2/lib/TestFramework/Client.pm index 6430de651d..48894fcd42 100644 --- a/t/lib/NGCP/TestFramework/Client.pm +++ b/t/api-rest2/lib/TestFramework/Client.pm @@ -1,4 +1,4 @@ -package NGCP::TestFramework::Client; +package TestFramework::Client; use strict; use warnings; diff --git a/t/lib/NGCP/TestFramework/RequestBuilder.pm b/t/api-rest2/lib/TestFramework/RequestBuilder.pm similarity index 98% rename from t/lib/NGCP/TestFramework/RequestBuilder.pm rename to t/api-rest2/lib/TestFramework/RequestBuilder.pm index 75c6eacb75..6eaa4ac887 100644 --- a/t/lib/NGCP/TestFramework/RequestBuilder.pm +++ b/t/api-rest2/lib/TestFramework/RequestBuilder.pm @@ -1,4 +1,4 @@ -package NGCP::TestFramework::RequestBuilder; +package TestFramework::RequestBuilder; use strict; use warnings; diff --git a/t/lib/NGCP/TestFramework/TestExecutor.pm b/t/api-rest2/lib/TestFramework/TestExecutor.pm similarity index 98% rename from t/lib/NGCP/TestFramework/TestExecutor.pm rename to t/api-rest2/lib/TestFramework/TestExecutor.pm index 95e025ada9..e531c85076 100644 --- a/t/lib/NGCP/TestFramework/TestExecutor.pm +++ b/t/api-rest2/lib/TestFramework/TestExecutor.pm @@ -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 ) = @_; diff --git a/t/api-rest2/sources.list.d/builddeps.list b/t/api-rest2/sources.list.d/builddeps.list new file mode 100644 index 0000000000..e69de29bb2 diff --git a/t/api-rest2/sources.list.d/preferences b/t/api-rest2/sources.list.d/preferences new file mode 100644 index 0000000000..e69de29bb2 diff --git a/t/lib/NGCP/testrunner.pl b/t/api-rest2/testrunner old mode 100644 new mode 100755 similarity index 79% rename from t/lib/NGCP/testrunner.pl rename to t/api-rest2/testrunner index 19c20c4435..82f1383d9c --- a/t/lib/NGCP/testrunner.pl +++ b/t/api-rest2/testrunner @@ -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 [] []\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();