7
# The functions in this library used to be responsible for bazillions
8
# of wasted api_starts. Now, they all just use their own library
9
# handle so they are not interrupted when the main tests call init or
10
# destroy. They have to keep track of when the api exists and
11
# restarts, though, since the lib_handle needs to be re-opened in that
14
proc lib_start_api {} {
15
global spawn_id lib_pid test
17
if {! [api_isrunning $lib_pid]} {
19
set lib_pid [api_start]
21
ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
22
$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
25
error "$test: unexpected failure in init"
28
verbose "+++ restarted api ($lib_pid) for lib"
30
verbose "+++ api $lib_pid already running for lib"
39
send "[string trim $command]\n"
41
-re "OK .*$prompt$" { return 1 }
42
-re "ERROR .*$prompt$" { return 0 }
43
"wrong # args" { error "$test: wrong number args"; return 0 }
44
timeout { fail "$test: timeout"; return 0 }
45
eof { fail "$test: eof"; api_exit; lib_start_api; return 0 }
49
proc tcl_cmd {command} {
50
global prompt spawn_id test
52
send "[string trim $command]\n"
54
-re "$prompt$" { return 1}
55
"wrong # args" { error "$test: wrong number args"; return 0 }
56
timeout { error_and_restart "timeout" }
57
eof { api_exit; lib_start_api; return 0 }
61
proc one_line_succeed_test {command} {
66
send "[string trim $command]\n"
68
-re "OK .*$prompt$" { pass "$test"; return 1 }
69
-re "ERROR .*$prompt$" {
70
fail "$test: $expect_out(buffer)"; return 0
72
"wrong # args" { error "$test: wrong number args"; return 0 }
73
timeout { fail "$test: timeout"; return 0 }
74
eof { fail "$test: eof"; api_exit; lib_start_api; return 0 }
78
proc one_line_fail_test {command code} {
83
send "[string trim $command]\n"
85
-re "ERROR .*$code.*$prompt$" { pass "$test"; return 1 }
86
-re "ERROR .*$prompt$" { fail "$test: bad failure"; return 0 }
87
-re "OK .*$prompt$" { fail "$test: bad success"; return 0 }
88
"wrong # args" { error "$test: wrong number args"; return 0 }
89
timeout { fail "$test: timeout"; return 0 }
90
eof { fail "$test: eof"; api_exit; lib_start_api; return 0 }
94
proc one_line_fail_test_nochk {command} {
99
send "[string trim $command]\n"
101
-re "ERROR .*$prompt$" { pass "$test:"; return 1 }
102
-re "OK .*$prompt$" { fail "$test: bad success"; return 0 }
103
"wrong # args" { error "$test: wrong number args"; return 0 }
104
timeout { fail "$test: timeout"; return 0 }
105
eof { fail "$test: eof"; api_exit; lib_start_api; return 0 }
110
global prompt spawn_id test
114
"wrong # args" { error "$test: wrong number args"; return 0 }
115
eof { api_exit; lib_start_api }
119
proc create_principal {name} {
122
set ret [cmd [format {
123
ovsec_kadm_create_principal $lib_handle [simple_principal \
124
"%s"] {OVSEC_KADM_PRINCIPAL} "%s"
130
proc create_policy {name} {
133
set ret [cmd [format {
134
ovsec_kadm_create_policy $lib_handle [simple_policy "%s"] \
141
proc create_principal_pol {name policy} {
144
set ret [cmd [format {
145
ovsec_kadm_create_principal $lib_handle [princ_w_pol "%s" \
146
"%s"] {OVSEC_KADM_PRINCIPAL OVSEC_KADM_POLICY} "%s"
147
} $name $policy $name]]
152
proc delete_principal {name} {
155
set ret [cmd [format {
156
ovsec_kadm_delete_principal $lib_handle "%s"
162
proc delete_policy {name} {
165
set ret [cmd [format {ovsec_kadm_delete_policy $lib_handle "%s"} $name]]
170
proc principal_exists {name} {
171
# puts stdout "Starting principal_exists."
175
set ret [cmd [format {
176
ovsec_kadm_get_principal $lib_handle "%s" principal
179
# puts stdout "Finishing principal_exists."
184
proc policy_exists {name} {
187
# puts stdout "Starting policy_exists."
189
set ret [cmd [format {
190
ovsec_kadm_get_policy $lib_handle "%s" policy
193
# puts stdout "Finishing policy_exists."
198
proc error_and_restart {error} {
209
puts stdout "At $test"
218
# exec $env(SIMPLE_DUMP) > /tmp/dump.before
222
proc end_dump_compare {name} {
228
# set file $TOP/admin/lib/unit-test/diff-files/$name
229
# exec $env(SIMPLE_DUMP) > /tmp/dump.after
230
# exec $env(COMPARE_DUMP) /tmp/dump.before /tmp/dump.after $file
234
proc kinit { princ pass {opts ""} } {
238
eval spawn $KINIT -5 $opts $princ
240
-re {Password for .*: $}
242
timeout {puts "Timeout waiting for prompt" ; close }
245
# this necessary so close(1) in the child will not sleep waiting for
246
# the parent, which is us, to read pending data.
249
"when initializing cache" { error "kinit failed: $expect_out(buffer)" }
257
global errorCode errorInfo
260
if {[info exists errorCode]} {
261
set saveErrorCode $errorCode
263
if {[info exists errorInfo]} {
264
set saveErrorInfo $errorInfo
266
catch "system $KDESTROY -5 2>/dev/null"
267
if {[info exists saveErrorCode]} {
268
set errorCode $saveErrorCode
269
} elseif {[info exists errorCode]} {
272
if {[info exists saveErrorInfo]} {
273
set errorInfo $saveErrorInfo
274
} elseif {[info exists errorInfo]} {
279
proc create_principal_with_keysalts {name keysalts} {
282
spawn $kadmin_local -e "$keysalts"
285
default { error "waiting for kadmin.local prompt"; return 1}
287
send "ank -pw \"$name\" \"$name\"\n"
289
-re "Principal \"$name.*\" created." {}
291
error "expecting principal created message";
294
default { error "waiting for principal created message"; return 1 }
298
default { error "waiting for kadmin.local prompt"; return 1 }