summaryrefslogtreecommitdiff
path: root/source4/selftest/win/wintest_setup.exp
blob: f55732ac008e23ccc5ea709d40a39ff8270ba5a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# An expect script to setup a directory and share for an smbtorture test.
# Copyright Brad Henry <brad@samba.org> 2006
# Released under the GNU GPL version 3 or later.

proc setup_test { remote_prompt sharepath sharename username local_hostname \
			local_ip hosts_file_path backup_hosts_filename } {

	# If creating the directory fails, remove, then
	# re-create the directory.
	set err_str [create_directory $remote_prompt $sharepath]
	if { $err_str != "OK" } {
		if { $err_str != "Directory already exists" } {
			puts stderr "\nUnexpected error occured in setup_test.\n"
			puts stderr "Function create_directory returned $err_str."
		} else {
			puts stdout "\nDirectory $sharepath exists."
		}
		puts stdout "Re-creating directory $sharepath."

		set err_str [delete_directory $remote_prompt $sharepath]
		if { $err_str != "OK" } {
			return $err_str
		}
		set err_str [create_directory $remote_prompt $sharepath]
		if { $err_str != "OK" } {
			return $err_str
		}
	}

	# 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" } {
		if { $err_str != "The name has already been shared" } {
			puts stderr "\nUnexpected error occured in setup_test."
			puts stderr "Function create_share returned $err_str."
		} else {
			puts stdout "\nShare $sharename exists."
		}
		puts stdout "Re-creating share $sharename."

		set err_str [delete_share $remote_prompt $sharename]
		if { $err_str != "OK" } {
			return $err_str
		}
		set err_str [create_share $remote_prompt $username $sharepath \
			$sharename]
		if { $err_str != "OK" } {
			return $err_str
		}
	}

	# Add a hosts file entry on the windows machine for the smbtorture host.
	set err_str [create_hosts_entry $remote_prompt $hosts_file_path \
			$local_hostname $local_ip $backup_hosts_filename]
	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_REMOTE_SHARE_PATH)
set sharename $env(SMBTORTURE_REMOTE_SHARE_NAME)

set local_hostname $env(SMBTORTURE_LOCAL_HOSTNAME)
set local_ip $env(SMBTORTURE_LOCAL_IP)

set backup_hosts_filename $env(REMOTE_BACKUP_HOSTS_FILENAME)
set hosts_file_path $env(REMOTE_HOSTS_FILE_PATH)

set err_val [spawn $env(SHELL)]
if {$err_val == 0} {
	puts stderr "Expect failed while spawning a shell process."
	exit $err_val
}

set err_str [telnet_login $remote_prompt $remote_host $username $password]
if {$err_str != "OK"} {
	puts stderr "\nFunction telnet_login failed during setup."
	puts stderr "Error was: $err_str."
	exit 1
}

set err_str [setup_test $remote_prompt $sharepath $sharename $username \
		$local_hostname $local_ip $hosts_file_path \
		$backup_hosts_filename]
if {$err_str != "OK"} {
	puts stderr "\nFunction setup_test failed during setup."
	puts stderr "Error was: $err_str."
	# Log off from the telnet server.
	send "exit\r\n"
	exit 1
}

# Log off from the telnet server.
send "exit\r\n"
exit 0