Skip to content

Commit 0aa87ef

Browse files
author
Digimer
committed
* Added a check that throws an error if the striker.conf points to the same database target more than once.
* Fixed a bug in 'AN::Remote->remote_call()' where the same ssh filehandle is cached when two nodes have the same IP but different ports (as is the case in most remote connections via port forwards). Signed-off-by: Digimer <[email protected]>
1 parent 0068df5 commit 0aa87ef

File tree

10 files changed

+119
-49
lines changed

10 files changed

+119
-49
lines changed

AN/Tools/Alert.pod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,10 @@ The 'AN::Tools::Get' module's 'ram_used_by_program()' method was called without
982982

983983
The 'AN::Tools::ScanCore' module's 'check_ram_usage()' method was called without a program name to check.
984984

985+
=head2 C<193>
986+
987+
The 'AN::Tools::DB' module's 'connect_to_databases()' method tried to connect to the same database twice.
988+
985989

986990
=head2 C<999>
987991

AN/Tools/DB.pm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ sub connect_to_databases
191191
name1 => "sys::host_uuid", value1 => $an->data->{sys}{host_uuid},
192192
}, file => $THIS_FILE, line => __LINE__});
193193

194+
my $seen_connections = [];
194195
my $connections = 0;
195196
my $failed_connections = [];
196197
my $successful_connections = [];
@@ -207,6 +208,24 @@ sub connect_to_databases
207208
my $postgres_password = $an->data->{scancore}{db}{$id}{postgres_password} ? $an->data->{scancore}{db}{$id}{postgres_password} : "";
208209
my $initialize = $an->data->{scancore}{db}{$id}{initialize} ? $an->data->{scancore}{db}{$id}{initialize} : 0;
209210

211+
# Make sure the user didn't specify the same target twice.
212+
my $target_host = "$host:$port";
213+
my $duplicate = 0;
214+
foreach my $existing_host (sort {$a cmp $b} @{$seen_connections})
215+
{
216+
if ($existing_host eq $target_host)
217+
{
218+
# User is connecting to the same target twice.
219+
$an->Alert->error({title_key => "error_title_0005", message_key => "error_message_0193", message_variables => { target => $target_host}, code => 193, file => $THIS_FILE, line => __LINE__});
220+
$duplicate = 1;
221+
}
222+
}
223+
if (not $duplicate)
224+
{
225+
push @{$seen_connections}, $target_host;
226+
}
227+
next if $duplicate;
228+
210229
# Log what we're doing.
211230
$an->Log->entry({log_level => 3, title_key => "an_alert_title_0001", message_key => "tools_log_0007", message_variables => {
212231
id => $id,

AN/Tools/Get.pm

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,6 +4511,14 @@ sub target_details
45114511
my $target = $parameter->{target} ? $parameter->{target} : $an->hostname;
45124512
my $port = $parameter->{port} ? $parameter->{port} : 22;
45134513
my $password = $parameter->{password} ? $parameter->{password} : "";
4514+
$an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => {
4515+
name1 => "target", value1 => $target,
4516+
name2 => "port", value2 => $port,
4517+
}, file => $THIS_FILE, line => __LINE__});
4518+
$an->Log->entry({log_level => 4, message_key => "an_variables_0001", message_variables => {
4519+
name1 => "password", value1 => $password,
4520+
}, file => $THIS_FILE, line => __LINE__});
4521+
45144522
my $return = {
45154523
anvil_name => "",
45164524
network => {
@@ -4535,9 +4543,10 @@ sub target_details
45354543
{
45364544
### Remote calls
45374545
# UUID
4538-
$an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => {
4546+
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
45394547
name1 => "uuid_shell_call", value1 => $uuid_shell_call,
45404548
name2 => "target", value2 => $target,
4549+
name3 => "port", value3 => $port,
45414550
}, file => $THIS_FILE, line => __LINE__});
45424551
(my $error, my $ssh_fh, $uuid_return) = $an->Remote->remote_call({
45434552
target => $target,
@@ -4548,9 +4557,10 @@ sub target_details
45484557
});
45494558

45504559
# IP info
4551-
$an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => {
4560+
$an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => {
45524561
name1 => "ip_shell_call", value1 => $ip_shell_call,
45534562
name2 => "target", value2 => $target,
4563+
name3 => "port", value3 => $port,
45544564
}, file => $THIS_FILE, line => __LINE__});
45554565
($error, $ssh_fh, $ip_return) = $an->Remote->remote_call({
45564566
target => $target,
@@ -4581,12 +4591,16 @@ sub target_details
45814591
{
45824592
chomp;
45834593
my $line = $_;
4594+
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
4595+
name1 => "line", value1 => $line,
4596+
}, file => $THIS_FILE, line => __LINE__});
4597+
45844598
push @{$uuid_return}, $line;
45854599
}
45864600
close $file_handle;
45874601

45884602
# IP Info
4589-
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
4603+
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
45904604
name1 => "ip_shell_call", value1 => $ip_shell_call,
45914605
}, file => $THIS_FILE, line => __LINE__});
45924606
open ($file_handle, "$ip_shell_call 2>&1 |") or $an->Alert->error({title_key => "error_title_0020", message_key => "error_message_0022", message_variables => { shell_call => $ip_shell_call, error => $! }, code => 30, file => $THIS_FILE, line => __LINE__});

AN/Tools/InstallManifest.pm

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11894,12 +11894,14 @@ sub map_network_on_node
1189411894
my $an = $self->parent;
1189511895
$an->Log->entry({log_level => 2, title_key => "tools_log_0001", title_variables => { function => "map_network_on_node" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__});
1189611896

11897-
my $remap = $parameter->{remap} ? $parameter->{remap} : "";
11898-
my $say_node = $parameter->{say_node} ? $parameter->{say_node} : "";
11899-
my $node = $parameter->{node} ? $parameter->{node} : "";
11900-
my $target = $parameter->{target} ? $parameter->{target} : "";
11901-
my $port = $parameter->{port} ? $parameter->{port} : "";
11902-
my $password = $parameter->{password} ? $parameter->{password} : "";
11897+
### TODO: Why are we not using $an->Remote->remote_call() ?
11898+
my $remap = $parameter->{remap} ? $parameter->{remap} : "";
11899+
my $say_node = $parameter->{say_node} ? $parameter->{say_node} : "";
11900+
my $node = $parameter->{node} ? $parameter->{node} : "";
11901+
my $target = $parameter->{target} ? $parameter->{target} : "";
11902+
my $port = $parameter->{port} ? $parameter->{port} : 22;
11903+
my $ssh_fh_key = $target.":".$port;
11904+
my $password = $parameter->{password} ? $parameter->{password} : "";
1190311905
$an->Log->entry({log_level => 2, message_key => "an_variables_0005", message_variables => {
1190411906
name1 => "remap", value1 => $remap,
1190511907
name2 => "say_node", value2 => $say_node,
@@ -11979,10 +11981,10 @@ fi";
1197911981
}
1198011982
}
1198111983
$an->Log->entry({log_level => 2, message_key => "an_variables_0004", message_variables => {
11982-
name1 => "proceed", value1 => $proceed,
11983-
name2 => "return_code", value2 => $return_code,
11984-
name3 => "ssh_fh", value3 => $ssh_fh,
11985-
name4 => "node::${target}::ssh_fh", value4 => $an->data->{target}{$target}{ssh_fh},
11984+
name1 => "proceed", value1 => $proceed,
11985+
name2 => "return_code", value2 => $return_code,
11986+
name3 => "ssh_fh", value3 => $ssh_fh,
11987+
name4 => "node::${ssh_fh_key}::ssh_fh", value4 => $an->data->{target}{$ssh_fh_key}{ssh_fh},
1198611988
}, file => $THIS_FILE, line => __LINE__});
1198711989

1198811990
my $nics_seen = 0;
@@ -11993,20 +11995,20 @@ fi";
1199311995
print $an->String->get({key => "message_0378"});
1199411996
}
1199511997
}
11996-
elsif ($an->data->{target}{$target}{ssh_fh} !~ /^Net::SSH2/)
11998+
elsif ($an->data->{target}{$ssh_fh_key}{ssh_fh} !~ /^Net::SSH2/)
1199711999
{
1199812000
# Invalid or broken SSH handle.
1199912001
$an->Log->entry({log_level => 1, message_key => "log_0186", message_variables => {
1200012002
node => $node,
12001-
ssh_fh => $an->data->{target}{$target}{ssh_fh},
12003+
ssh_fh => $an->data->{target}{$ssh_fh_key}{ssh_fh},
1200212004
}, file => $THIS_FILE, line => __LINE__});
1200312005
$return_code = 8;
1200412006
}
1200512007
else
1200612008
{
1200712009
### WARNING: Don't use 'remote_call()'! We need input from the user, so we need to call the
1200812010
### target directly
12009-
my $ssh_fh = $an->data->{target}{$target}{ssh_fh};
12011+
my $ssh_fh = $an->data->{target}{$ssh_fh_key}{ssh_fh};
1201012012
my $close = 0;
1201112013

1201212014
### Build the shell call

AN/Tools/Remote.pm

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -354,26 +354,29 @@ sub remote_call
354354
my $parameter = shift;
355355
my $an = $self->parent;
356356

357-
# Get the target
358-
my $target = $parameter->{target};
357+
# Get the target and port so that we can create the ssh_fh key
358+
my $target = $parameter->{target};
359+
my $port = $parameter->{port} ? $parameter->{port} : 22;
360+
my $ssh_fh_key = $target.":".$port;
359361

360362
# This will store the SSH file handle for the given target after the initial connection.
361-
$an->data->{target}{$target}{ssh_fh} = defined $an->data->{target}{$target}{ssh_fh} ? $an->data->{target}{$target}{ssh_fh} : "";
363+
$an->data->{target}{$ssh_fh_key}{ssh_fh} = defined $an->data->{target}{$ssh_fh_key}{ssh_fh} ? $an->data->{target}{$ssh_fh_key}{ssh_fh} : "";
362364

363365
# Now pick up the rest of the variables.
364-
my $port = $parameter->{port} ? $parameter->{port} : 22;
365366
my $user = $parameter->{user} ? $parameter->{user} : "root";
366367
my $password = $parameter->{password} ? $parameter->{password} : $an->data->{sys}{root_password};
367-
my $ssh_fh = $parameter->{ssh_fh} ? $parameter->{ssh_fh} : $an->data->{target}{$target}{ssh_fh};
368+
my $ssh_fh = $parameter->{ssh_fh} ? $parameter->{ssh_fh} : $an->data->{target}{$ssh_fh_key}{ssh_fh};
368369
my $close = defined $parameter->{'close'} ? $parameter->{'close'} : 0;
369370
my $shell_call = $parameter->{shell_call};
370-
$an->Log->entry({log_level => 3, message_key => "an_variables_0006", message_variables => {
371-
name1 => "time", value1 => time,
371+
my $start_time = time;
372+
$an->Log->entry({log_level => 3, message_key => "an_variables_0007", message_variables => {
373+
name1 => "start_time", value1 => $start_time,
372374
name2 => "target", value2 => $target,
373375
name3 => "port", value3 => $port,
374376
name4 => "user", value4 => $user,
375-
name5 => "ssh_fh", value5 => $ssh_fh,
376-
name6 => "close", value6 => $close,
377+
name5 => "ssh_fh_key", value5 => $ssh_fh_key,
378+
name6 => "ssh_fh", value6 => $ssh_fh,
379+
name7 => "close", value7 => $close,
377380
}, file => $THIS_FILE, line => __LINE__});
378381
# Shell calls can expose passwords, which is why it is down here.
379382
$an->Log->entry({log_level => 4, message_key => "an_variables_0002", message_variables => {
@@ -431,13 +434,13 @@ sub remote_call
431434
if (not $an->Validate->is_ipv4({ip => $target}))
432435
{
433436
my $new_target = $an->Get->ip_from_hostname({host_name => $target});
434-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
437+
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
435438
name1 => "new_target", value1 => $new_target,
436439
}, file => $THIS_FILE, line => __LINE__});
437440
if ($new_target)
438441
{
439442
$target = $new_target;
440-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
443+
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
441444
name1 => "target", value1 => $target,
442445
}, file => $THIS_FILE, line => __LINE__});
443446
}
@@ -541,29 +544,30 @@ sub remote_call
541544
if ($ssh_fh->auth_publickey($user, $public_key, $private_key))
542545
{
543546
# We're in! Record the file handle for this target.
544-
$an->data->{target}{$target}{ssh_fh} = $ssh_fh;
547+
$an->data->{target}{$ssh_fh_key}{ssh_fh} = $ssh_fh;
545548
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
546-
name1 => "target::${target}::ssh_fh", value1 => $an->data->{target}{$target}{ssh_fh},
549+
name1 => "target::${ssh_fh_key}::ssh_fh", value1 => $an->data->{target}{$ssh_fh_key}{ssh_fh},
547550
}, file => $THIS_FILE, line => __LINE__});
548551

549-
$an->Log->entry({log_level => 3, message_key => "notice_message_0014", message_variables => { target => $target }, file => $THIS_FILE, line => __LINE__});
552+
$an->Log->entry({log_level => 2, message_key => "notice_message_0014", message_variables => { target => $ssh_fh_key }, file => $THIS_FILE, line => __LINE__});
550553
}
551554
else
552555
{
553556
# This is for the user
554-
$error = $an->String->get({key => "error_message_0032", variables => { target => $target }});
557+
$error = $an->String->get({key => "error_message_0032", variables => { target => $ssh_fh_key }});
555558
# This is for our logs
556-
$an->Log->entry({log_level => 1, message_key => "error_message_0032", message_variables => { target => $target }, file => $THIS_FILE, line => __LINE__});
559+
$an->Log->entry({log_level => 1, message_key => "error_message_0032", message_variables => { target => $ssh_fh_key }, file => $THIS_FILE, line => __LINE__});
557560
}
558561
}
559562
else
560563
{
561564
# We're in! Record the file handle for this target.
562-
$an->data->{target}{$target}{ssh_fh} = $ssh_fh;
565+
$an->data->{target}{$ssh_fh_key}{ssh_fh} = $ssh_fh;
563566
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
564-
name1 => "target::${target}::ssh_fh", value1 => $an->data->{target}{$target}{ssh_fh},
567+
name1 => "target::${ssh_fh_key}::ssh_fh", value1 => $an->data->{target}{$ssh_fh_key}{ssh_fh},
565568
}, file => $THIS_FILE, line => __LINE__});
566-
$an->Log->entry({log_level => 3, message_key => "notice_message_0004", message_variables => { target => $target }, file => $THIS_FILE, line => __LINE__});
569+
570+
$an->Log->entry({log_level => 2, message_key => "notice_message_0004", message_variables => { target => $ssh_fh_key }, file => $THIS_FILE, line => __LINE__});
567571
}
568572
}
569573
}
@@ -682,14 +686,14 @@ sub remote_call
682686
# Close the connection if requested.
683687
if ($close)
684688
{
685-
$an->Log->entry({log_level => 2, message_key => "notice_message_0005", message_variables => { target => $target }, file => $THIS_FILE, line => __LINE__});
689+
$an->Log->entry({log_level => 2, message_key => "notice_message_0005", message_variables => { target => $ssh_fh_key }, file => $THIS_FILE, line => __LINE__});
686690
$ssh_fh->disconnect() if $ssh_fh;
687691

688692
# For good measure, blank both variables.
689-
$an->data->{target}{$target}{ssh_fh} = "";
693+
$an->data->{target}{$ssh_fh_key}{ssh_fh} = "";
690694
$ssh_fh = "";
691695
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
692-
name1 => "target::${target}::ssh_fh", value1 => $an->data->{target}{$target}{ssh_fh},
696+
name1 => "target::${ssh_fh_key}::ssh_fh", value1 => $an->data->{target}{$ssh_fh_key}{ssh_fh},
693697
}, file => $THIS_FILE, line => __LINE__});
694698
}
695699

AN/Tools/ScanCore.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ sub insert_or_update_nodes
20422042
my $node_sn = $parameter->{node_sn} ? $parameter->{node_sn} : "NULL";
20432043
my $node_ifn = $parameter->{node_ifn} ? $parameter->{node_ifn} : "NULL";
20442044
my $node_password = $parameter->{node_password} ? $parameter->{node_password} : "NULL";
2045-
$an->Log->entry({log_level => 3, message_key => "an_variables_0009", message_variables => {
2045+
$an->Log->entry({log_level => 2, message_key => "an_variables_0009", message_variables => {
20462046
name1 => "node_uuid", value1 => $node_uuid,
20472047
name2 => "node_anvil_uuid", value2 => $node_anvil_uuid,
20482048
name3 => "node_host_uuid", value3 => $node_host_uuid,
@@ -2285,7 +2285,7 @@ AND
22852285
AND
22862286
node_cache_name = ".$an->data->{sys}{use_db_fh}->quote($node_cache_name)."
22872287
;";
2288-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
2288+
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
22892289
name1 => "query", value1 => $query,
22902290
}, file => $THIS_FILE, line => __LINE__});
22912291

@@ -2298,7 +2298,7 @@ AND
22982298
foreach my $row (@{$results})
22992299
{
23002300
$node_cache_uuid = $row->[0];
2301-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
2301+
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
23022302
name1 => "node_cache_uuid", value1 => $node_cache_uuid,
23032303
}, file => $THIS_FILE, line => __LINE__});
23042304
}
@@ -2330,7 +2330,7 @@ INSERT INTO
23302330
);
23312331
";
23322332
$query =~ s/'NULL'/NULL/g;
2333-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
2333+
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
23342334
name1 => "query", value1 => $query,
23352335
}, file => $THIS_FILE, line => __LINE__});
23362336
$an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__});
@@ -2351,7 +2351,7 @@ FROM
23512351
WHERE
23522352
node_cache_uuid = ".$an->data->{sys}{use_db_fh}->quote($node_cache_uuid)."
23532353
;";
2354-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
2354+
$an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => {
23552355
name1 => "query", value1 => $query,
23562356
}, file => $THIS_FILE, line => __LINE__});
23572357

@@ -2403,7 +2403,7 @@ WHERE
24032403
node_cache_uuid = ".$an->data->{sys}{use_db_fh}->quote($node_cache_uuid)."
24042404
";
24052405
$query =~ s/'NULL'/NULL/g;
2406-
$an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => {
2406+
$an->Log->entry({log_level => 4, message_key => "an_variables_0001", message_variables => {
24072407
name1 => "query", value1 => $query,
24082408
}, file => $THIS_FILE, line => __LINE__});
24092409
$an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__});

AN/Tools/Striker.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7264,7 +7264,7 @@ sub _gather_node_details
72647264
my $target = $an->data->{sys}{anvil}{$node_key}{use_ip};
72657265
my $port = $an->data->{sys}{anvil}{$node_key}{use_port};
72667266
my $password = $an->data->{sys}{anvil}{$node_key}{password};
7267-
$an->Log->entry({log_level => 2, message_key => "an_variables_0007", message_variables => {
7267+
$an->Log->entry({log_level => 3, message_key => "an_variables_0007", message_variables => {
72687268
name1 => "node_uuid", value1 => $node_uuid,
72697269
name2 => "node_key", value2 => $node_key,
72707270
name3 => "anvil_uuid", value3 => $anvil_uuid,

AN/tools.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ Failed to send an alert because this host is not yet in the database. This can h
940940
<key name="error_message_0190"><![CDATA[A request to shut down: [#!variable!node_name!#] appears to have failed.<br />In some cases, this can be caused by something holding open the shared storage, resulting in the node getting fenced.<br />Please go back to the main page, wait a few minutes and see if the node comes back online.<br />Once things stabilize, please try shutting down the system again.]]></key>
941941
<key name="error_message_0191"><![CDATA[The 'AN::Tools::Get' module's 'ram_used_by_program()' method was called without a program name to check.]]></key>
942942
<key name="error_message_0192"><![CDATA[The 'AN::Tools::ScanCore' module's 'check_ram_usage()' method was called without a program name to check.]]></key>
943+
<key name="error_message_0193"><![CDATA[The 'AN::Tools::DB' module's 'connect_to_databases()' method tried to connect to the same database twice: [#!variable!target!#].]]></key>
943944

944945
<!-- Cleared warning/error messages -->
945946
<key name="cleared_message_0001">Connection to the database: [#!variable!name!#] on host: [#!variable!host!#:#!variable!port!#] has been re-established.</key>

0 commit comments

Comments
 (0)