[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 1/5] osstest: add routine to execute ssh with password
This is needed when bootstrapping FreeBSD, since the installer has ssh enabled with the root password set to 'root' by default. Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx> Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> --- Changes since RFC: - Place the temp filename in a local variable. - Add error checks. --- Osstest/TestSupport.pm | 43 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index fea54d5..1a6aec5 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -60,6 +60,7 @@ BEGIN { target_install_packages target_install_packages_norec target_jobdir target_extract_jobdistpath_subdir target_extract_jobdistpath target_guest_lv_name + target_cmd_root_with_password poll_loop tcpconnect await_tcp contents_make_cpio file_simple_write_contents @@ -313,12 +314,11 @@ END #---------- running commands eg on targets ---------- sub cmd { - my ($timeout,$stdout,@cmd) = @_; + my ($timeout,$child_sub,@cmd) = @_; my $child= fork; die $! unless defined $child; if (!$child) { - if (defined $stdout) { - open STDOUT, '>&', $stdout - or die "STDOUT $stdout $cmd[0] $!"; + if (defined $child_sub) { + $child_sub->(); } exec @cmd; die "$cmd[0]: $!"; @@ -573,9 +573,42 @@ sub tcmd { # $tcmd will be put between '' but not escaped sub target_cmd ($$;$) { tcmd(undef,'osstest',@_); } sub target_cmd_root ($$;$) { tcmd(undef,'root',@_); } +sub target_cmd_root_with_password { + my ($ho,$tcmd,$timeout,$password) = @_; + my $temp_name = "tmp/t.ssh-password-helper.$flight.$job"; + + open(my $temp_fh, '>', $temp_name) + or die "Cannot open $temp_name: $!"; + print $temp_fh "#!/bin/sh\n\necho \"$password\"\n" + or die "Cannot write to $temp_name: $!"; + chmod 0755, $temp_name + or die "Cannot chmod $temp_name: $!"; + close $temp_fh + or die "Cannot close $temp_name: $!"; + + my $child_sub = sub { + $ENV{DISPLAY} = ":0"; + $ENV{SSH_ASKPASS} = "tmp/t.ssh-password-helper.$flight.$job"; + setsid or die "Can't start a new session: $!"; + }; + + my $ssh_opts = [qw(-o BatchMode=no + -o PasswordAuthentication=yes + -o ChallengeResponseAuthentication=yes), + @{ sshopts() }]; + + tcmdex($timeout,$child_sub, + 'ssh', $ssh_opts, + sshuho("root",$ho), $tcmd); + + unlink $temp_fh; +} + sub tcmdout { my $stdout= IO::File::new_tmpfile(); - tcmd($stdout,@_); + my $stdout_sub = sub { open STDOUT, '>&', $stdout + or die "STDOUT $stdout $!"; }; + tcmd($stdout_sub,@_); $stdout->seek(0,0) or die "$stdout $!"; my $r; { local ($/) = undef; -- 1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |