Author: brad
Date: 2006-06-12 04:28:55 +0000 (Mon, 12 Jun 2006)
New Revision: 16147

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16147

Log:
For now, these scripts assume:
 * The microsoft telnet server is enabled and running on the host specified in 
wintest_run.sh.
 * The user specified in wintest_run.sh exists, has admin rights, and can login 
through telnet.

Given this, these scripts:
 1. Log into the windows host though telnet, prepare a directory and a share on 
the windows host.
 2. Run the RAW-QFILEINFO smbtorture test against that share.
 3. Log into the windows host through telnet, remove the share and the 
directory.

Running wintest_run.sh will start the process.

Added:
   branches/SOC/bnh/expect/
   branches/SOC/bnh/expect/common.exp
   branches/SOC/bnh/expect/wintest_remove.exp
   branches/SOC/bnh/expect/wintest_run.sh
   branches/SOC/bnh/expect/wintest_setup.exp


Changeset:
Added: branches/SOC/bnh/expect/common.exp
===================================================================
--- branches/SOC/bnh/expect/common.exp  2006-06-12 02:23:57 UTC (rev 16146)
+++ branches/SOC/bnh/expect/common.exp  2006-06-12 04:28:55 UTC (rev 16147)
@@ -0,0 +1,108 @@
+# A library of commonly used functions written in expect.
+# Copyright Brad Henry <[EMAIL PROTECTED]> 2006
+# Released under the GNU GPL v2 or later.
+
+# This function will create a telnet login shell to $remote_host as $username.
+# If expected dialogue is not recieved, return with a specific error if one
+# is recognized. Otherwise return a generic error indicating the function
+# name.
+proc telnet_login { remote_prompt remote_host username password } {
+
+       set err_str "Unknown error in function telnet_login"
+
+       set cmd "telnet $remote_host\r"
+       send -- $cmd
+       expect  "login: " {
+                       set err_str "OK"
+               } \
+               "Connection refused" {
+                       return "Connection refused"
+               } \
+               "No route to host" {
+                       return "No route to host"
+               }
+       if { $err_str != "OK" } {
+               # Return because we encountered an unrecognized error.
+               return $err_str
+       } else {
+               # Reset err_str
+               set err_str "Unknown error in function telnet_login"
+       }
+
+       set cmd "$username\r"
+       send -- $cmd
+       expect "password: "
+
+       set cmd "$password\r"
+       send -- $cmd
+       expect  $remote_prompt {
+                       set err_str "OK"
+               } \
+               "Login Failed" {
+                       set err_str "Login Failed"
+               }
+       return $err_str
+}
+
+proc create_directory { remote_prompt sharepath } {
+
+       set err_str "Unknown error in function create_directory"
+
+       set cmd "mkdir $sharepath\r"
+       send -- $cmd
+       expect  "already exists" {
+                       return "Directory already exists"
+               } \
+               $remote_prompt {
+                       set err_str "OK"
+               }
+       return $err_str
+}
+
+proc delete_directory { remote_prompt sharepath } {
+
+       set err_str "Unknown error in function delete_directory"
+
+       set cmd "rmdir $sharepath\r"
+       send -- $cmd
+       expect  $remote_prompt {
+                       set err_str "OK"
+               }
+
+# I don't understand why I have to send an extra 'enter' here.
+# There isn't any real error checking in this function either.
+       send -- "\r"
+       expect $remote_prompt
+
+       return $err_str
+}
+
+proc create_share { remote_prompt username sharepath sharename } {
+
+       set err_str "Unknown error in function create_share"
+
+       set cmd "net share $sharename=$sharepath /GRANT:$username,FULL\r"
+       send -- $cmd
+       expect  "was shared successfully." {
+                       set err_str "OK"
+               } \
+               "already been shared." {
+                       return "The name has already been shared"
+               }
+       return $err_str
+}
+
+proc delete_share { remote_prompt sharename } {
+
+       set err_str "Unknown error in function delete_share"
+
+       set cmd "net share $sharename /DELETE\r"
+       send -- $cmd
+       expect  "was deleted successfully." {
+                       set err_str "OK"
+               } \
+               "does not exist." {
+                       return "The share does not exist"
+               }
+       return $err_str
+}

Added: branches/SOC/bnh/expect/wintest_remove.exp
===================================================================
--- branches/SOC/bnh/expect/wintest_remove.exp  2006-06-12 02:23:57 UTC (rev 
16146)
+++ branches/SOC/bnh/expect/wintest_remove.exp  2006-06-12 04:28:55 UTC (rev 
16147)
@@ -0,0 +1,51 @@
+# An expect script to remove a directory and share which was 
+# previously setup for an smbtorture test.
+# Copyright Brad Henry <[EMAIL PROTECTED]> 2006
+# Released under the GNU GPL v2 or later.
+
+proc remove_test { remote_prompt sharepath sharename } {
+
+       puts stderr "Removing share $sharename."
+
+       set err_str [delete_share $remote_prompt $sharename]
+       if { $err_str != "OK" } {
+               return $err_str
+       }
+
+       puts stderr "Removing directory $sharepath."
+
+       set err_str [delete_directory $remote_prompt $sharepath]
+       if { $err_str != "OK" } {
+               return $err_str
+       }
+       return $err_str
+}
+
+# read parameters
+set remote_host $env(SMBTORTURE_REMOTE_HOST)
+set remote_prompt $env(SMBTORTURE_REMOTE_PROMPT)
+
+set username $env(SMBTORTURE_USERNAME)
+set password $env(SMBTORTURE_PASSWORD)
+
+set timeout $env(SMBTORTURE_EXPECT_TIMEOUT)
+
+set sharepath $env(SMBTORTURE_SHARE_PATH)
+set sharename $env(SMBTORTURE_SHARE_NAME)
+
+spawn $env(SHELL)
+
+set err_str [telnet_login $remote_prompt $remote_host $username $password]
+if {$err_str != "OK"} {
+       puts stderr "\nFunction telnet_login failed.\nError was: $err_str"
+       exit 1
+}
+
+set err_str [remove_test $remote_prompt $sharepath $sharename]
+if {$err_str != "OK"} {
+       puts stderr "\nFunction remove_test failed.\nError was: $err_str"
+       exit 1
+}
+
+send -- "exit\r"
+exit 0

Added: branches/SOC/bnh/expect/wintest_run.sh
===================================================================
--- branches/SOC/bnh/expect/wintest_run.sh      2006-06-12 02:23:57 UTC (rev 
16146)
+++ branches/SOC/bnh/expect/wintest_run.sh      2006-06-12 04:28:55 UTC (rev 
16147)
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# A shell script to connect to a windows host over telnet,
+# setup for a smbtorture test,
+# run the test, 
+# and remove the previously configured directory and share.
+# Copyright Brad Henry <[EMAIL PROTECTED]> 2006
+# Released under the GNU GPL v2 or later.
+
+WINTEST_SETUP_ERROR_LOG="/tmp/wintest_setup.exp.err"
+WINTEST_REMOVE_ERROR_LOG="/tmp/wintest_remove.exp.err"
+
+export SMBTORTURE_REMOTE_HOST=192.168.0.1
+export SMBTORTURE_REMOTE_PROMPT=">"
+
+export SMBTORTURE_USERNAME="tortureuser"
+export SMBTORTURE_PASSWORD="torturepass"
+
+export SMBTORTURE_SHARE_NAME="smbtorture_share"
+export SMBTORTURE_SHARE_PATH="c:\torture_share"
+
+export SMBTORTURE_EXPECT_TIMEOUT=30
+
+# Setup the windows environment.
+# This was the best way I could figure out including library files for the 
moment.
+cat common.exp wintest_setup.exp | expect -f - 2> $WINTEST_SETUP_ERROR_LOG
+err_setup=$?
+
+echo "wintest_setup.exp stderr output:"
+cat $WINTEST_SETUP_ERROR_LOG
+#rm -f $WINTEST_SETUP_ERROR_LOG
+
+if [ $err_setup -ne 0 ] 
+then
+       exit $err_setup
+fi
+
+# Run the smbtorture test.
+/usr/local/samba/bin/smbtorture \
+       -U $SMBTORTURE_USERNAME%$SMBTORTURE_PASSWORD \
+       -d 10 -W SMBTEST \
+       //$SMBTORTURE_REMOTE_HOST/$SMBTORTURE_SHARE_NAME \
+       RAW-QFILEINFO
+err_smbtorture=$?
+
+if [ $err_smbtorture -ne 0 ]
+then
+       exit $err_smbtorture
+fi
+
+# Cleanup the windows environment.
+cat common.exp wintest_remove.exp | expect -f - 2> $WINTEST_REMOVE_ERROR_LOG
+err_remove=$?
+
+echo "wintest_remove.exp stderr output:"
+cat $WINTEST_REMOVE_ERROR_LOG
+#rm -f $WINTEST_REMOVE_ERROR_LOG
+
+if [ $err_remove -ne 0 ]
+then
+       exit $err_remove
+fi
+
+exit 0


Property changes on: branches/SOC/bnh/expect/wintest_run.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/SOC/bnh/expect/wintest_setup.exp
===================================================================
--- branches/SOC/bnh/expect/wintest_setup.exp   2006-06-12 02:23:57 UTC (rev 
16146)
+++ branches/SOC/bnh/expect/wintest_setup.exp   2006-06-12 04:28:55 UTC (rev 
16147)
@@ -0,0 +1,74 @@
+# An expect script to setup a directory and share for an smbtorture test.
+# Copyright Brad Henry <[EMAIL PROTECTED]> 2006
+# Released under the GNU GPL v2 or later.
+
+proc setup_test { remote_prompt sharepath sharename username } {
+
+       puts stderr "Creating directory $sharepath."
+
+       # if creating the directory fails, remove, then
+       # re-create the directory.
+       set err_str [create_directory $remote_prompt $sharepath]
+       if { $err_str != "OK" } {
+               puts stderr "Directory $sharepath exists."
+               puts stderr "Deleting directory $sharepath."
+               set err_str [delete_directory $remote_prompt $sharepath]
+               if { $err_str != "OK" } {
+                       return $err_str
+               }
+               puts stderr "Creating directory $sharepath."
+               set err_str [create_directory $remote_prompt $sharepath]
+               if { $err_str != "OK" } {
+                       return $err_str
+               }
+       }
+
+       puts stderr "Creating share $sharename."
+
+       # if creating the share fails, remove, then
+       # re-create the share.
+       set err_str [create_share $remote_prompt $username $sharepath 
$sharename]
+       if { $err_str != "OK" } {
+               puts stderr "Share $sharename exists."
+               puts stderr "Removing share $sharename."
+               set err_str [delete_share $remote_prompt $sharename]
+               if { $err_str != "OK" } {
+                       return $err_str
+               }
+               puts stderr "Creating share $sharename."
+               set err_str [create_share $remote_prompt $username $sharepath 
$sharename]
+               if { $err_str != "OK" } {
+                       return $err_str
+               }
+       }
+       return $err_str
+}
+
+# read parameters
+set remote_host $env(SMBTORTURE_REMOTE_HOST)
+set remote_prompt $env(SMBTORTURE_REMOTE_PROMPT)
+
+set username $env(SMBTORTURE_USERNAME)
+set password $env(SMBTORTURE_PASSWORD)
+
+set timeout $env(SMBTORTURE_EXPECT_TIMEOUT)
+
+set sharepath $env(SMBTORTURE_SHARE_PATH)
+set sharename $env(SMBTORTURE_SHARE_NAME)
+
+spawn $env(SHELL)
+
+set err_str [telnet_login $remote_prompt $remote_host $username $password]
+if {$err_str != "OK"} {
+       puts stderr "\nFunction telnet_login failed.\nError was: $err_str"
+       exit 1
+}
+
+set err_str [setup_test $remote_prompt $sharepath $sharename $username]
+if {$err_str != "OK"} {
+       puts stderr "\nFunction setup_test failed.\nError was: $err_str"
+       exit 1
+}
+
+send -- "exit\r"
+exit 0

Reply via email to