TT#28472 thread-safe cert-auth for tests

+ force JSON::PP usage in suite with spawned threads

Change-Id: I3bade7eadda7f0c25ac8636f96a26df451b24136
changes/72/17872/2
Rene Krenn 7 years ago
parent 33852166d5
commit 012686ab02

@ -5,7 +5,7 @@ use threads::shared qw();
#use Sipwise::Base; #causes segfault when creating threads..
use Net::Domain qw(hostfqdn);
use JSON qw();
use JSON -support_by_pp, -no_export;
use Test::More;
use Time::HiRes; #prevent warning from Time::Warp
use Time::Warp qw();
@ -18,7 +18,7 @@ use Text::Wrap;
$Text::Wrap::columns = 58;
#use Sys::CpuAffinity;
use JSON::PP;
#use JSON::PP;
use LWP::Debug;
BEGIN {
@ -27,8 +27,8 @@ BEGIN {
use NGCP::Panel::Utils::DateTime qw();
#use NGCP::Panel::Utils::ProfilePackages qw(); #since it depends on Utils::Subscribers and thus Sipwise::Base, importin it causes segfault when creating threads..
my $is_local_env = 0;
my $disable_parallel_catchup = 1;
my $is_local_env = 1;
my $disable_parallel_catchup = 0;
my $disable_hourly_intervals = 1;
#my $enable_profile_packages = NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES;
#my $enable_profile_packages = 1;

@ -25,7 +25,7 @@ fi
if [ "${SELECT}" = "stable" ] ; then
echo "Test selection: ${SELECT}"
SELECT=$(echo ./t/api-rest/api-{all-links,bannedips,bannedusers,billingfees,billingnetworks,billingprofiles,billingzones,calllists,calls,cert-auth,cfdestinationsets,contracts,customercontacts,customers,faxes,lnp,ncoslevels,pbxdevicemodels,pbxdevices,peeringgroups,peeringrules,peeringinboundrules,peeringservers,preferences,profilepackages,resellers,rewriterules,rewriterulesets,root,soundsets,subscriberregistrations,subscribers,systemcontacts,threads,topuplogs,trustedsources,valid-patch,vouchers,method-override}.t)
SELECT=$(echo ./t/api-rest/api-{all-links,balanceintervals,bannedips,bannedusers,billingfees,billingnetworks,billingprofiles,billingzones,calllists,calls,cert-auth,cfdestinationsets,contracts,customercontacts,customers,faxes,lnp,ncoslevels,pbxdevicemodels,pbxdevices,peeringgroups,peeringrules,peeringinboundrules,peeringservers,preferences,profilepackages,resellers,rewriterules,rewriterulesets,root,soundsets,subscriberregistrations,subscribers,systemcontacts,threads,topuplogs,trustedsources,valid-patch,vouchers,method-override}.t)
elif [ "${SELECT}" = "fast" ] ; then
echo "Test selection: ${SELECT}"
SELECT=$(echo ./t/api-rest/api-{bannedips,bannedusers,billingnetworks,billingzones,calls,cert-auth,cfdestinationsets,ncoslevels,peeringgroups,peeringrules,peeringinboundrules,peeringservers,resellers,rewriterules,root,soundsets,systemcontacts,valid-patch,vouchers,method-override}.t)

@ -3,6 +3,8 @@ package Test::Collection;
#testcollection will keep object of the apiclient
use strict;
use threads qw();
use threads::shared qw();
use Test::More;
use Moose;
use JSON;
@ -20,13 +22,9 @@ use File::Slurp qw/write_file/;
use Storable;
use Carp qw(cluck longmess shortmess);
use IO::Uncompress::Unzip;
use File::Temp qw();
has 'crt_path' => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {'/tmp/apicert.pem';},
);
my $tmpfilename : shared;
has 'data_cache_file' => (
is => 'ro',
@ -267,7 +265,8 @@ sub init_ua {
}
sub init_ssl_cert {
my ($self, $ua) = @_;
unless(-f $self->crt_path) {
lock $tmpfilename;
unless ($tmpfilename) {
my $res = $ua->post(
$self->base_uri . '/api/admincerts/',
Content_Type => 'application/json',
@ -294,13 +293,15 @@ sub init_ssl_cert {
unless($data) {
die "failed to find PEM file in client certificate zip file\n";
}
open my $fh, ">:raw", $self->crt_path or die "failed to open " . $self->crt_path . ": $!\n";
print $fh $data;
close $fh;
(my $tmpfh,$tmpfilename) = File::Temp::tempfile('apicert_XXXX', DIR => '/tmp', SUFFIX => '.pem', UNLINK => 0);
#close $tmpfh;
#open my $fh, ">:raw", $tmpfilename or die "failed to open " . $tmpfilename . ": $!\n";
print $tmpfh $data;
close $tmpfh;
}
$ua->ssl_opts(
SSL_cert_file => $self->crt_path,
SSL_key_file => $self->crt_path,
SSL_cert_file => $tmpfilename,
SSL_key_file => $tmpfilename,
);
}
sub runas {
@ -414,13 +415,13 @@ sub get_item_hal{
#print Dumper $reshal;
if($total_count || ('HASH' eq ref $reshal->{content} && $reshal->{content}->{total_count})){
$self->IS_EMPTY_COLLECTION(0);
$resitem = {
num => 1,
content => $reshal,
res => $res,
req => $req,
location => $location,
total_count => $total_count,
$resitem = {
num => 1,
content => $reshal,
res => $res,
req => $req,
location => $location,
total_count => $total_count,
content_collection => $reshal_collection,
};
$self->DATA_LOADED->{$name} ||= [];
@ -493,18 +494,18 @@ sub get_collection_hal{
$self->IS_EMPTY_COLLECTION(0);
#$self->DATA_LOADED->{$name} ||= [];
$rescollection = {
total_count => $total_count,
total_count => $total_count,
content => $reshal_collection,
res => $res,
req => $req,
res => $res,
req => $req,
collection => [],
};
my $add_item = sub{
my ($number,$location) = @_;
my $resitem = {
num => $number,
content => $reshals[$number],
location => $location,
my $resitem = {
num => $number,
content => $reshals[$number],
location => $location,
};
#while no caching here
#push @{$self->DATA_LOADED->{$name}}, $resitem;
@ -542,10 +543,10 @@ sub encode_content{
if($content){
if( $json_types{$type} && (('HASH' eq ref $content) ||('ARRAY' eq ref $content)) ){
return JSON::to_json($content);
}elsif('multipart/form-data' eq $type
&& 'HASH' eq ref $content
&& $content->{json}
&& (('HASH' eq ref $content->{json}) || ( 'ARRAY' eq ref $content->{json} ) )
}elsif('multipart/form-data' eq $type
&& 'HASH' eq ref $content
&& $content->{json}
&& (('HASH' eq ref $content->{json}) || ( 'ARRAY' eq ref $content->{json} ) )
){
$content->{json} = JSON::to_json($content->{json});
return [

Loading…
Cancel
Save