a bunch of logic changes to allow tests to run standalone

This commit is contained in:
Oliver Gorwits
2021-08-12 10:58:55 +01:00
parent f1224b087c
commit d206b9ccbf
5 changed files with 23 additions and 17 deletions

View File

@@ -709,8 +709,8 @@ sub delete {
{ ip => { '-in' => $devices->as_query } }, { ip => { '-in' => $devices->as_query } },
)->delete; )->delete;
Dancer::Logger::debug sprintf ' [%s] db/device - removed %d %s from %s', Dancer::Logger::debug( sprintf( ' [%s] db/device - removed %d %s from %s',
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger(); $ip, $gone, _plural($gone), $set ) ) if defined Dancer::Logger::logger();
} }
foreach my $set (qw/ foreach my $set (qw/
@@ -729,8 +729,8 @@ sub delete {
], ],
})->delete; })->delete;
Dancer::Logger::debug sprintf ' [%s] db/device - removed %d manual topology %s', Dancer::Logger::debug( sprintf( ' [%s] db/device - removed %d manual topology %s',
$ip, $gone, _plural($gone) if defined Dancer::Logger::logger(); $ip, $gone, _plural($gone) ) ) if defined Dancer::Logger::logger();
$schema->resultset('DevicePort')->search( $schema->resultset('DevicePort')->search(
{ ip => { '-in' => $devices->as_query } }, { ip => { '-in' => $devices->as_query } },

View File

@@ -262,8 +262,8 @@ sub delete {
{ ip => { '-in' => $ports->as_query }}, { ip => { '-in' => $ports->as_query }},
)->delete; )->delete;
Dancer::Logger::debug sprintf ' [%s] db/ports - removed %d port %s from %s', Dancer::Logger::debug( sprintf( ' [%s] db/ports - removed %d port %s from %s',
$ip, $gone, _plural($gone), $set if defined Dancer::Logger::logger(); $ip, $gone, _plural($gone), $set ) ) if defined Dancer::Logger::logger();
} }
$schema->resultset('Node')->search( $schema->resultset('Node')->search(

View File

@@ -2,9 +2,14 @@ package App::Netdisco::JobQueue;
use Dancer qw/:moose :syntax :script/; use Dancer qw/:moose :syntax :script/;
BEGIN {
$ENV{ND_QUEUE_ENGINE} ||=
setting('workers') ? setting('workers')->{queue} : 'PostgreSQL';
}
use Module::Load (); use Module::Load ();
Module::Load::load Module::Load::load
'App::Netdisco::JobQueue::' . setting('workers')->{queue} => ':all'; 'App::Netdisco::JobQueue::' . $ENV{ND_QUEUE_ENGINE} => ':all';
use base 'Exporter'; use base 'Exporter';
our @EXPORT = (); our @EXPORT = ();

View File

@@ -9,7 +9,7 @@ use Try::Tiny;
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
path => setting('api_base').'/object/device/{ip}', path => (setting('api_base') || '').'/object/device/{ip}',
description => 'Returns a row from the device table', description => 'Returns a row from the device table',
parameters => [ parameters => [
ip => { ip => {
@@ -28,7 +28,7 @@ swagger_path {
foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssids powered_ports/) { foreach my $rel (qw/device_ips vlans ports modules port_vlans wireless_ports ssids powered_ports/) {
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
path => setting('api_base')."/object/device/{ip}/$rel", path => (setting('api_base') || '')."/object/device/{ip}/$rel",
description => "Returns $rel rows for a given device", description => "Returns $rel rows for a given device",
parameters => [ parameters => [
ip => { ip => {
@@ -49,7 +49,7 @@ foreach my $rel (qw/nodes active_nodes nodes_with_age active_nodes_with_age vlan
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
description => "Returns $rel rows for a given port", description => "Returns $rel rows for a given port",
path => setting('api_base')."/object/device/{ip}/port/{port}/$rel", path => (setting('api_base') || '')."/object/device/{ip}/port/{port}/$rel",
parameters => [ parameters => [
ip => { ip => {
description => 'Canonical IP of the Device. Use Search methods to find this.', description => 'Canonical IP of the Device. Use Search methods to find this.',
@@ -76,7 +76,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
description => "Returns the related $rel table entry for a given port", description => "Returns the related $rel table entry for a given port",
path => setting('api_base')."/object/device/{ip}/port/{port}/$rel", path => (setting('api_base') || '')."/object/device/{ip}/port/{port}/$rel",
parameters => [ parameters => [
ip => { ip => {
description => 'Canonical IP of the Device. Use Search methods to find this.', description => 'Canonical IP of the Device. Use Search methods to find this.',
@@ -103,7 +103,7 @@ foreach my $rel (qw/power properties ssid wireless agg_master neighbor last_node
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
description => 'Returns a row from the device_port table', description => 'Returns a row from the device_port table',
path => setting('api_base').'/object/device/{ip}/port/{port}', path => (setting('api_base') || '').'/object/device/{ip}/port/{port}',
parameters => [ parameters => [
ip => { ip => {
description => 'Canonical IP of the Device. Use Search methods to find this.', description => 'Canonical IP of the Device. Use Search methods to find this.',
@@ -127,7 +127,7 @@ swagger_path {
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
path => setting('api_base').'/object/device/{ip}/nodes', path => (setting('api_base') || '').'/object/device/{ip}/nodes',
description => "Returns the nodes found on a given Device", description => "Returns the nodes found on a given Device",
parameters => [ parameters => [
ip => { ip => {
@@ -153,7 +153,7 @@ swagger_path {
swagger_path { swagger_path {
tags => ['Objects'], tags => ['Objects'],
path => setting('api_base').'/object/vlan/{vlan}/nodes', path => (setting('api_base') || '').'/object/vlan/{vlan}/nodes',
description => "Returns the nodes found in a given VLAN", description => "Returns the nodes found in a given VLAN",
parameters => [ parameters => [
vlan => { vlan => {

View File

@@ -5,6 +5,7 @@ use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible; use Dancer::Plugin::Auth::Extensible;
use Dancer::Plugin::Swagger; use Dancer::Plugin::Swagger;
use App::Netdisco; # a safe noop but needed for standalone testing
use App::Netdisco::Util::Web 'request_is_api'; use App::Netdisco::Util::Web 'request_is_api';
use MIME::Base64; use MIME::Base64;
@@ -85,7 +86,7 @@ hook 'before' => sub {
swagger_path { swagger_path {
description => 'Obtain an API Key', description => 'Obtain an API Key',
tags => ['General'], tags => ['General'],
path => setting('url_base')->with('/login')->path, path => (setting('url_base') ? setting('url_base')->with('/login')->path : '/login'),
parameters => [], parameters => [],
responses => { default => { examples => { responses => { default => { examples => {
'application/json' => { api_key => 'cc9d5c02d8898e5728b7d7a0339c0785' } } }, 'application/json' => { api_key => 'cc9d5c02d8898e5728b7d7a0339c0785' } } },
@@ -159,14 +160,14 @@ post '/login' => sub {
# ugh, *puke*, but D::P::Swagger has no way to set this with swagger_path # ugh, *puke*, but D::P::Swagger has no way to set this with swagger_path
# must be after the path is declared, above. # must be after the path is declared, above.
Dancer::Plugin::Swagger->instance->doc Dancer::Plugin::Swagger->instance->doc
->{paths}->{ setting('url_base')->with('/login')->path } ->{paths}->{ (setting('url_base') ? setting('url_base')->with('/login')->path : '/login') }
->{post}->{security}->[0]->{BasicAuth} = []; ->{post}->{security}->[0]->{BasicAuth} = [];
# we override the default login_handler, so logout has to be handled as well # we override the default login_handler, so logout has to be handled as well
swagger_path { swagger_path {
description => 'Destroy user API Key and session cookie', description => 'Destroy user API Key and session cookie',
tags => ['General'], tags => ['General'],
path => setting('url_base')->with('/logout')->path, path => (setting('url_base') ? setting('url_base')->with('/logout')->path : '/logout'),
parameters => [], parameters => [],
responses => { default => { examples => { 'application/json' => {} } } }, responses => { default => { examples => { 'application/json' => {} } } },
}, },