mirror of
https://github.com/duncs/clusterssh.git
synced 2025-04-21 09:09:06 +00:00
Merge branch 'Azenet-master'
This commit is contained in:
commit
689343eb24
5 changed files with 72 additions and 43 deletions
2
Changes
2
Changes
|
@ -1,5 +1,5 @@
|
|||
4.10 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
||||
- ** new version marker **
|
||||
- Allow 'include' directives when reading SSH configuration files (Github issue #77) (thanks to Azenet)
|
||||
|
||||
4.09 2017-03-11 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
||||
- Add perl-5.24 Travis-CI automated testing config
|
||||
|
|
1
THANKS
1
THANKS
|
@ -46,3 +46,4 @@ Emanuele Tomasi
|
|||
Deny Dias
|
||||
Bill Rushmore
|
||||
Ankit Vadehra
|
||||
Azenet
|
||||
|
|
|
@ -37,30 +37,44 @@ sub new {
|
|||
|
||||
# load in ssh hostname for later use
|
||||
if ( !%ssh_hostname_for || !$ssh_configs_read{ $self->{ssh_config} } ) {
|
||||
$ssh_configs_read{ $self->{ssh_config} } = 1;
|
||||
if ( open( my $ssh_config_fh, '<', $self->{ssh_config} ) ) {
|
||||
while ( my $line = <$ssh_config_fh> ) {
|
||||
chomp $line;
|
||||
next unless ( $line =~ m/^\s*host\s+(.*)/i );
|
||||
$self->read_ssh_file( $self->{ssh_config} );
|
||||
|
||||
# account for multiple declarations of hosts
|
||||
$ssh_hostname_for{$_} = 1 foreach ( split( /\s+/, $1 ) );
|
||||
}
|
||||
close($ssh_config_fh);
|
||||
|
||||
$self->debug( 5, 'Have the following ssh hostnames' );
|
||||
$self->debug( 5, ' "', $_, '"' )
|
||||
foreach ( sort keys %ssh_hostname_for );
|
||||
}
|
||||
else {
|
||||
$self->debug( 3, 'Unable to read ',
|
||||
$self->{ssh_config}, ': ', $!, $/ );
|
||||
}
|
||||
$self->debug( 5, 'Have the following ssh hostnames' );
|
||||
$self->debug( 5, ' "', $_, '"' )
|
||||
foreach ( sort keys %ssh_hostname_for );
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub read_ssh_file($$) {
|
||||
my ($self) = shift;
|
||||
my ($filename) = glob(shift);
|
||||
$self->debug( 3, 'Reading SSH file: ', $filename );
|
||||
|
||||
$ssh_configs_read{$filename} = 1;
|
||||
|
||||
if ( open( my $ssh_config_fh, '<', $filename ) ) {
|
||||
while ( my $line = <$ssh_config_fh> ) {
|
||||
chomp $line;
|
||||
|
||||
if ( $line =~ /^\s*include\s+(.+)/i ) {
|
||||
$self->read_ssh_file($1);
|
||||
next;
|
||||
}
|
||||
|
||||
next unless ( $line =~ m/^\s*host\s+(.*)/i );
|
||||
|
||||
# account for multiple declarations of hosts
|
||||
$ssh_hostname_for{$_} = 1 foreach ( split( /\s+/, $1 ) );
|
||||
}
|
||||
close($ssh_config_fh);
|
||||
}
|
||||
else {
|
||||
$self->debug( 3, 'Unable to read ', $filename, ': ', $!, $/ );
|
||||
}
|
||||
}
|
||||
|
||||
sub get_hostname {
|
||||
my ($self) = @_;
|
||||
return $self->{hostname};
|
||||
|
@ -386,6 +400,11 @@ Given a host string, returns a host object. Parses hosts such as
|
|||
Check the objects hostname to see whether or not it may be configured within
|
||||
the users F< $HOME/.ssh/config > configuration file
|
||||
|
||||
=item read_ssh_file
|
||||
|
||||
Method to ease reading in ssh configuration files. Used for grabbing
|
||||
hostnames for validation when used in clusters
|
||||
|
||||
=over 4
|
||||
|
||||
=item host
|
||||
|
|
55
t/10host.t
55
t/10host.t
|
@ -752,6 +752,7 @@ trap {
|
|||
};
|
||||
is( $trap->leaveby, 'return', 'returned ok' );
|
||||
is( $trap->die, undef, 'returned ok' );
|
||||
is( $trap->stdout, '', 'No unexpected STDOUT' );
|
||||
isa_ok( $host, "App::ClusterSSH::Host" );
|
||||
is( $host, 'ssh_test', 'stringify works' );
|
||||
is( $host->check_ssh_hostname, 0, 'check_ssh_hostname ok for ssh_test', );
|
||||
|
@ -764,37 +765,43 @@ trap {
|
|||
};
|
||||
is( $trap->leaveby, 'return', 'returned ok' );
|
||||
is( $trap->die, undef, 'returned ok' );
|
||||
is( $trap->stdout, '', 'No unexpected STDOUT' );
|
||||
isa_ok( $host, "App::ClusterSSH::Host" );
|
||||
is( $host, 'ssh_test', 'stringify works' );
|
||||
is( $host->check_ssh_hostname, 0, 'check_ssh_hostname ok for ssh_test', );
|
||||
is( $host->get_type, q{}, 'hostname type is correct for ssh_test', );
|
||||
|
||||
for my $hostname (
|
||||
'server1', 'server2',
|
||||
'server3', 'server4',
|
||||
'server-5', 'server5.domain.name',
|
||||
'server-6.domain.name'
|
||||
)
|
||||
{
|
||||
for my $ssh_file (qw/ 10host_ssh_config 10host_ssh_include/) {
|
||||
my @hosts = (
|
||||
'server1', 'server2',
|
||||
'server3', 'server4',
|
||||
'server-5', 'server5.domain.name',
|
||||
'server-6.domain.name'
|
||||
);
|
||||
push @hosts, 'server_ssh_included' if($ssh_file =~ m/include/);
|
||||
for my $hostname (@hosts)
|
||||
{
|
||||
|
||||
$host = undef;
|
||||
is( $host, undef, 'starting afresh for ssh hostname checks' );
|
||||
$host = undef;
|
||||
is( $host, undef, 'starting afresh for ssh hostname checks' );
|
||||
|
||||
trap {
|
||||
$host = App::ClusterSSH::Host->new(
|
||||
hostname => $hostname,
|
||||
ssh_config => $Bin . '/10host_ssh_config',
|
||||
);
|
||||
};
|
||||
is( $trap->leaveby, 'return', 'returned ok' );
|
||||
is( $trap->die, undef, 'returned ok' );
|
||||
isa_ok( $host, "App::ClusterSSH::Host" );
|
||||
is( $host, $hostname, 'stringify works' );
|
||||
is( $host->check_ssh_hostname, 1,
|
||||
'check_ssh_hostname ok for ' . $hostname );
|
||||
is( $host->get_realname, $hostname, 'realname set' );
|
||||
is( $host->get_geometry, q{}, 'geometry set' );
|
||||
is( $host->get_type, 'ssh_alias', 'geometry set' );
|
||||
trap {
|
||||
$host = App::ClusterSSH::Host->new(
|
||||
hostname => $hostname,
|
||||
ssh_config => $Bin . '/'. $ssh_file,
|
||||
);
|
||||
};
|
||||
is( $trap->leaveby, 'return', 'returned ok' );
|
||||
is( $trap->die, undef, 'returned ok' );
|
||||
is( $trap->stdout, '', 'No unexpected STDOUT' );
|
||||
isa_ok( $host, "App::ClusterSSH::Host" );
|
||||
is( $host, $hostname, 'stringify works' );
|
||||
is( $host->check_ssh_hostname, 1,
|
||||
'check_ssh_hostname ok for ' . $hostname );
|
||||
is( $host->get_realname, $hostname, 'realname set' );
|
||||
is( $host->get_geometry, q{}, 'geometry set' );
|
||||
is( $host->get_type, 'ssh_alias', 'geometry set' );
|
||||
}
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
|
2
t/10host_ssh_include
Normal file
2
t/10host_ssh_include
Normal file
|
@ -0,0 +1,2 @@
|
|||
include 10host_ssh_config
|
||||
host server_ssh_included
|
Loading…
Add table
Reference in a new issue