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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
.TH ct_telnet 3 "common_test 1.3.2" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
ct_telnet \- Common Test specific layer on top of telnet client ct_telnet_client\&.erl\&.
.SH DESCRIPTION
.LP
Common Test specific layer on top of telnet client ct_telnet_client\&.erl
.LP
Use this module to set up telnet connections, send commands and perform string matching on the result\&. (See the \fIunix_telnet\fR manual page for information about how ct_telnet may be used specifically with unix hosts\&.)
.LP
The rx driver used by ct_telnet for handling regular expressions is currently only ported to Unix and Linux and will not work on Windows!
.LP
The following default values are defined in ct_telnet:
.nf
Connection timeout = 10 sec (time to wait for connection)
Command timeout = 10 sec (time to wait for a command to return)
Max no of reconnection attempts = 3
Reconnection interval = 5 sek (time to wait in between reconnection attempts)
.fi
.LP
These parameters can be altered by the user with the following configuration term:
.nf
{telnet_settings, [{connect_timeout,Millisec},
{command_timeout,Millisec},
{reconnection_attempts,N},
{reconnection_interval,Millisec}]}\&.
.fi
.LP
\fIMillisec = integer(), N = integer()\fR
.LP
Enter the \fItelnet_settings\fR term in a configuration file included in the test and ct_telnet will retrieve the information automatically\&.
.SH DATA TYPES
.RS 2
.TP 4
.B
\fIconnection() = handle() | {target_name() (see module ct), connection_type()} | target_name() (see module ct)\fR:
.TP 4
.B
\fIconnection_type() = telnet | ts1 | ts2\fR:
.TP 4
.B
\fIhandle() = handle() (see module ct_gen_conn)\fR:
.RS 4
.LP
Handle for a specific telnet connection\&.
.LP
.RE
.TP 4
.B
\fIprompt_regexp() = string()\fR:
.RS 4
.LP
A regular expression which matches all possible prompts for a specific type of target\&. The regexp must not have any groups i\&.e\&. when matching, rx:match shall return a list with one single element\&.
.LP
.RE
.RE
.SH EXPORTS
.LP
.B
close(Connection) -> ok | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
.RE
.RS
.LP
Close the telnet connection and stop the process managing it\&.
.RE
.LP
.B
cmd(Connection, Cmd) -> {ok, Data} | {error, Reason}
.br
.RS
.LP
Equivalent to cmd(Connection, Cmd, DefaultTimeout)\&.
.RE
.LP
.B
cmd(Connection, Cmd, Timeout) -> {ok, Data} | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
Cmd = string()
.br
Timeout = integer()
.br
Data = [string()]
.br
.RE
.RS
.LP
Send a command via telnet and wait for prompt\&.
.RE
.LP
.B
cmdf(Connection, CmdFormat, Args) -> {ok, Data} | {error, Reason}
.br
.RS
.LP
Equivalent to cmdf(Connection, CmdFormat, Args, DefaultTimeout)\&.
.RE
.LP
.B
cmdf(Connection, CmdFormat, Args, Timeout) -> {ok, Data} | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
CmdFormat = string()
.br
Args = list()
.br
Timeout = integer()
.br
Data = [string()]
.br
.RE
.RS
.LP
Send a telnet command and wait for prompt (uses a format string and list of arguments to build the command)\&. -----------------------------------------------------------------
.RE
.LP
.B
cont_log() -> term()
.br
.RS
.RE
.LP
.B
end_log() -> term()
.br
.RS
.RE
.LP
.B
expect(Connection, Patterns) -> term()
.br
.RS
.LP
Equivalent to expect(Connections, Patterns, [])\&.
.RE
.LP
.B
expect(Connection, Patterns, Opts) -> {ok, Match} | {ok, MatchList, HaltReason} | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
Patterns = Pattern | [Pattern]
.br
Pattern = string() | {Tag, string()} | prompt | {prompt, Prompt}
.br
Prompt = string()
.br
Tag = term()
.br
Opts = [Opt]
.br
Opt = {timeout, Timeout} | repeat | {repeat, N} | sequence | {halt, HaltPatterns} | ignore_prompt
.br
Timeout = integer()
.br
N = integer()
.br
HaltPatterns = Patterns
.br
MatchList = [Match]
.br
Match = RxMatch | {Tag, RxMatch} | {prompt, Prompt}
.br
RxMatch = [string()]
.br
HaltReason = done | Match
.br
Reason = timeout | {prompt, Prompt}
.br
.RE
.RS
.LP
Get data from telnet and wait for the expected pattern\&.
.LP
\fIPattern\fR can be a POSIX regular expression\&. If more than one pattern is given, the function returns when the first match is found\&.
.LP
\fIRxMatch\fR is a list of matched strings\&. It looks like this: \fI[FullMatch, SubMatch1, SubMatch2, \&.\&.\&.]\fR where \fIFullMatch\fR is the string matched by the whole regular expression and \fISubMatchN\fR is the string that matched subexpression no \fIN\fR\&. Subexpressions are denoted with \&'(\&' \&')\&' in the regular expression
.LP
If a \fITag\fR is given, the returned \fIMatch\fR will also include the matched \fITag\fR\&. Else, only \fIRxMatch\fR is returned\&.
.LP
The function will always return when a prompt is found, unless the \fIignore_prompt\fR options is used\&.
.LP
The \fItimeout\fR option indicates that the function shall return if the telnet client is idle (i\&.e\&. if no data is received) for more than \fITimeout\fR milliseconds\&. Default timeout is 10 seconds\&.
.LP
The \fIrepeat\fR option indicates that the pattern(s) shall be matched multiple times\&. If \fIN\fR is given, the pattern(s) will be matched \fIN\fR times, and the function will return with \fIHaltReason = done\fR\&.
.LP
The \fIsequence\fR option indicates that all patterns shall be matched in a sequence\&. A match will not be concluded untill all patterns are matched\&.
.LP
Both \fIrepeat\fR and \fIsequence\fR can be interrupted by one or more \fIHaltPatterns\fR\&. When \fIsequence\fR or \fIrepeat\fR is used, there will always be a \fIMatchList\fR returned, i\&.e\&. a list of \fIMatch\fR instead of only one \fIMatch\fR\&. There will also be a \fIHaltReason\fR returned\&.
.LP
\fIExamples:\fR
.br
\fIexpect(Connection, [{abc, "ABC"}, {xyz, "XYZ"}], [sequence, {halt, [{nnn, "NNN"}]}])\&.\fR
.br
will try to match "ABC" first and then "XYZ", but if "NNN" appears the function will return \fI{error, {nnn, ["NNN"]}}\fR\&. If both "ABC" and "XYZ" are matched, the function will return \fI{ok, [AbcMatch, XyzMatch]}\fR\&.
.LP
\fIexpect(Connection, [{abc, "ABC"}, {xyz, "XYZ"}], [{repeat, 2}, {halt, [{nnn, "NNN"}]}])\&.\fR
.br
will try to match "ABC" or "XYZ" twice\&. If "NNN" appears the function will return with \fIHaltReason = {nnn, ["NNN"]}\fR\&.
.LP
The \fIrepeat\fR and \fIsequence\fR options can be combined in order to match a sequence multiple times\&.
.RE
.LP
.B
get_data(Connection) -> {ok, Data} | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
Data = [string()]
.br
.RE
.RS
.LP
Get all data which has been received by the telnet client since last command was sent\&.
.RE
.LP
.B
open(Name) -> {ok, Handle} | {error, Reason}
.br
.RS
.LP
Equivalent to open(Name, telnet)\&.
.RE
.LP
.B
open(Name, ConnType) -> {ok, Handle} | {error, Reason}
.br
.RS
.TP
Types
Name = target_name()
.br
ConnType = connection_type() (see module ct_telnet)
.br
Handle = handle() (see module ct_telnet)
.br
.RE
.RS
.LP
Open a telnet connection to a node\&.
.RE
.LP
.B
open(Name, ConnType, TargetMod) -> {ok, Handle} | {error, Reason}
.br
.RS
.LP
Equivalent to open(Name, ConnType, TargetMod, [])\&.
.RE
.LP
.B
open(Name, ConnType, TargetMod, Extra) -> {ok, Handle} | {error, Reason}
.br
.RS
.TP
Types
Name = target_name() (see module ct)
.br
ConnType = connection_type()
.br
TargetMod = atom()
.br
Extra = term()
.br
Handle = handle()
.br
.RE
.RS
.LP
Open a telnet connection to the specified target\&.
.LP
The target must exist in a config file, and \fIName\fR is the name allocated to the target - either with \fIct:require/2\fR or with a \fIrequire\fR statement in the test suite default data or the test case info function\&.
.LP
\fITargetMod\fR is a module which exports the functions \fIconnect(Ip, Port, Extra)\fR and \fIget_prompt_regexp()\fR for the given \fITargetType\fR\&.
.RE
.LP
.B
send(Connection, Cmd) -> ok | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
Cmd = string()
.br
.RE
.RS
.LP
Send a telnet command and return immediately\&.
.LP
The resulting output from the command can be read with \fIget_data/1\fR or \fIexpect/2/3\fR\&.
.RE
.LP
.B
sendf(Connection, CmdFormat, Args) -> ok | {error, Reason}
.br
.RS
.TP
Types
Connection = connection() (see module ct_telnet)
.br
CmdFormat = string()
.br
Args = list()
.br
.RE
.RS
.LP
Send a telnet command and return immediately (uses a format string and a list of arguments to build the command)\&.
.RE
.SH SEE ALSO
.LP
unix_telnet
|