[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 02/11] 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> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> --- Changes since RFC: - Place the temp filename in a local variable. - Add error checks. --- Osstest/TestSupport.pm | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index d930e55..0c72faa 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 @@ -314,12 +315,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]: $!"; @@ -585,9 +585,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, $disable_hosts) = @_; + 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($disable_hosts) }]; + + 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.9.3 (Apple Git-50) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |