# TSTssh.def: Tests Remote Connectivity and Operations # $Id: TSTssh.def,v 2.9 2012/05/12 17:06:19 mschenke Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_4/src/scripting/lib/modules/TSTssh.def,v 2.9 2012/05/12 17:06:19 mschenke Exp $ # # Change History # 20120511 KRA Extend the tests. =head1 NAME TSTssh - Tests Remote Connectivity and Associated Operations =head1 DESCRIPTION This test module executes several tests to check remote connectivity and operations: =over 2 =cut use Remote echo tput('bold'),'Processing remote operation test module ...',tput('off') call setRemoteTrace(setDebug()) # Define macros macro chk_env {var ($key,$flg) = @arg if getEnv($key,$flg) {var $val = last import $TTL if $TTL {echo $TTL var $TTL = undef } echo ' ',$key,'=',$val } } macro chk_ident {echo '\012Agent identities:' loop $lin (command('ssh-add -l')) echo ' ',$lin } =item o Tests which commands are available from the PATH. =cut echo '\012Command Availability:' loop $cmd ('rcp','remsh','rsh','scp','ssh','ssh-add','ssh-agent') echo sprintf(" %-12s \001%s",$cmd,nvl(findCommand($cmd),'(Not found)')) =item o Lists related files. =cut var $TTL = '\012Related files:' var $hom = getEnv('HOME') loop $fil ('/etc/hosts.equiv',\ grepDir('/etc/ssh','.','npr'),\ grepDir(getEnv('HOME'),'^\.[rs]hosts$','inp'),\ grepDir(catDir(getEnv('HOME'),'.ssh'),'.','npr')) {next !testFile('f',$fil) if $TTL echo delete($TTL) echo ' ',$fil } =item o Tests if an authentication agent is configured. When possible, it checks if identities have been added. =cut var $TTL = '\012Check if an authentication agent is running' call chk_env('SSH_AGENT_PID') call chk_env('SSH_AUTH_SOCK') if !?$TTL call chk_ident() =item o Lists default remote operation settings defined. =cut var $TTL = '\012Predefined remote operation settings:' loop $key (grepSetting('^REMOTE_.*(SSH|SCP)','n')) {var $set{$key} = getSetting($key) if $TTL echo delete($TTL) echo ' ',$key,'=',$set{$key} } =item o Lists common settings modified by the remote operation initialization. =cut call initRemote() var $TTL = \ '\012Settings modified by the remote operation initialization:' loop $key (grepSetting('^REMOTE_(SSH|SCP)','n')) {var $val = getSetting($key) next compare('eq',$val,$set{$key}) if $TTL echo delete($TTL) echo ' ',$key,'=',$val } =item o Checks if an authentication agent has been started. When possible, it lists agent identities. =cut if $agt {var $TTL = '\012Check if an authentication agent has been started' call chk_env('SSH_AGENT_PID',true) call chk_env('SSH_AUTH_SOCK',true) if !?$TTL call chk_ident() } =item o Tests which drivers are available for the remote connection. =cut echo '\012Driver Availability:' loop $typ ('da','jsch','ssh','rsh') echo sprintf(' %4s %s',$typ,cond($[REM]->can_use($typ),'Available','-')) =item o Tests a remote command execution with different settings. =cut var $sep = repeat('-',${RDA.COLUMNS}) echo echo $sep echo 'Test a remote command' echo $sep if !getSetting('REMOTE_TST_HOSTNAME') call requestSetting('TSTssh') var $hst = getSetting('REMOTE_TST_HOSTNAME') var $rem = getSetting('REMOTE_TST_COMMAND','env') var $usr = getSetting('REMOTE_TST_USER',getSetting('REMOTE_USER')) # Initialize the remote session var $ses = addRemoteSession('TST',$hst,$usr) if needPassword('TST') {call setPassword('host',$hst,$usr,askPassword(\ concat('Enter ',$usr,'@',$hst,' password:'))) if needPassword('TST') {echo 'Connection error connecting to ',$hst call endRemoteSession('TST') return } } echo '\012Check remote command execution with best driver' echo 'Exit code: ',rexec('TST',$rem) var %tbl = (\ DA => {typ => 'da'},\ JSCH => {typ => 'jsch'},\ REMSH => {cmd => 'remsh',\ typ => 'rsh'},\ RSH => {cmd => 'rsh',\ typ => 'rsh'},\ SSH => {cmd => 'ssh',\ opt => '-Cnq -o ConnectTimeout=30',\ typ => 'ssh'},\ SSH0 => {cmd => 'ssh',\ dsc => 'SSH (no timeout)',\ opt => '-Cnq',\ typ => 'ssh'}) loop $typ ('DA','JSCH','SSH','SSH0','RSH','REMSH') {if exists($tbl{$typ,'cmd'}) {var $pre = concat('REMOTE_TST_',uc($tbl{$typ,'typ'})) next !findCommand($tbl{$typ,'cmd'}) call setTempSetting(concat($pre,'_COMMAND'),last) call setTempSetting(concat($pre,'_OPTIONS'),$tbl{$typ,'opt'}) } call setTempSetting('REMOTE_TST_PREFIX',$typ) next $ses->set_type($tbl{$typ,'typ'}) echo '\012Check remote command execution using ',nvl($tbl{$typ,'dsc'},$typ) echo 'Exit code: ',rexec('TST',$rem) } call endRemoteSession('TST') =back =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut