1ct_telnet(3)               Erlang Module Definition               ct_telnet(3)
2
3
4

NAME

6       ct_telnet  - Common Test specific layer on top of Telnet client ct_tel‐
7       net_client.erl
8

DESCRIPTION

10       Common  Test  specific  layer  on  top   of   Telnet   client   ct_tel‐
11       net_client.erl.
12
13       Use  this  module to set up Telnet connections, send commands, and per‐
14       form string matching on the result. For information about  how  to  use
15       ct_telnet  and  configure connections, specifically for UNIX hosts, see
16       the unix_telnet manual page.
17
18       Default values defined in ct_telnet:
19
20         * Connection timeout (time to wait for connection) = 10 seconds
21
22         * Command timeout (time to wait for a command to return) = 10 seconds
23
24         * Max number of reconnection attempts = 3
25
26         * Reconnection  interval  (time  to  wait  in  between   reconnection
27           attempts) = 5 seconds
28
29         * Keep  alive  (sends  NOP to the server every 8 sec if connection is
30           idle) = true
31
32         * Polling limit (max number of times  to  poll  to  get  a  remaining
33           string terminated) = 0
34
35         * Polling interval (sleep time between polls) = 1 second
36
37         * The  TCP_NODELAY  option  for the telnet socket is disabled (set to
38           false) per default
39
40       These parameters can be modified by the user with the following config‐
41       uration term:
42
43        {telnet_settings, [{connect_timeout,Millisec},
44                           {command_timeout,Millisec},
45                           {reconnection_attempts,N},
46                           {reconnection_interval,Millisec},
47                           {keep_alive,Bool},
48                           {poll_limit,N},
49                           {poll_interval,Millisec},
50                           {tcp_nodelay,Bool}]}.
51
52       Millisec = integer(), N = integer()
53
54       Enter  the telnet_settings term in a configuration file included in the
55       test and ct_telnet retrieves the information automatically.
56
57       keep_alive can be specified per connection, if necessary. For  details,
58       see unix_telnet.
59

LOGGING

61       The default logging behavior of ct_telnet is to print information about
62       performed operations, commands, and their corresponding results to  the
63       test  case HTML log. The following is not printed to the HTML log: text
64       strings sent from the Telnet server that are not explicitly received by
65       a  ct_telnet function, such as expect/3. However, ct_telnet can be con‐
66       figured  to  use  a  special  purpose  event  handler,  implemented  in
67       ct_conn_log_h,  for  logging  all  Telnet traffic. To use this handler,
68       install a Common Test hook named cth_conn_log. Example (using the  test
69       suite information function):
70
71        suite() ->
72            [{ct_hooks, [{cth_conn_log, [{conn_mod(),hook_options()}]}]}].
73
74       conn_mod()  is the name of the Common Test module implementing the con‐
75       nection protocol, that is, ct_telnet.
76
77       The cth_conn_log hook performs unformatted logging of Telnet data to  a
78       separate  text  file. All Telnet communication is captured and printed,
79       including any data sent from the server. The link to this text file  is
80       located at the top of the test case HTML log.
81
82       By  default,  data  for  all Telnet connections is logged in one common
83       file (named default), which can get messy,  for  example,  if  multiple
84       Telnet  sessions are running in parallel. Therefore a separate log file
85       can be created for each connection. To configure this, use hook  option
86       hosts  and  list the names of the servers/connections to be used in the
87       suite. The connections must be named for  this  to  work  (see  ct_tel‐
88       net:open/1,2,3,4).
89
90       Hook  option  log_type can be used to change the cth_conn_log behavior.
91       The default value of this option is raw, which results in the  behavior
92       described  above. If the value is set to html, all Telnet communication
93       is printed to the test case HTML log instead.
94
95       All cth_conn_log hook options described can also be specified in a con‐
96       figuration file with configuration variable ct_conn_log.
97
98       Example:
99
100        {ct_conn_log, [{ct_telnet,[{log_type,raw},
101                                   {hosts,[key_or_name()]}]}]}
102
103   Note:
104       Hook options specified in a configuration file overwrite any hard-coded
105       hook options in the test suite.
106
107
108       Logging Example:
109
110       The following ct_hooks statement causes printing of Telnet  traffic  to
111       separate  logs for the connections server1 and server2. Traffic for any
112       other connections is logged in the default Telnet log.
113
114        suite() ->
115            [{ct_hooks,
116              [{cth_conn_log, [{ct_telnet,[{hosts,[server1,server2]}]}]}]}].
117
118       As previously explained, this specification can also be provided by  an
119       entry like the following in a configuration file:
120
121        {ct_conn_log, [{ct_telnet,[{hosts,[server1,server2]}]}]}.
122
123       In  this case the ct_hooks statement in the test suite can look as fol‐
124       lows:
125
126        suite() ->
127            [{ct_hooks, [{cth_conn_log, []}]}].
128

DATA TYPES

130         connection() = handle() | {target_name(), connection_type()}  |  tar‐
131         get_name():
132
133
134           For target_name(), see module ct.
135
136         connection_type() = telnet | ts1 | ts2:
137
138
139         handle() = handle():
140
141
142           Handle for a specific Telnet connection, see module ct.
143
144         prompt_regexp() = string():
145
146
147           Regular  expression  matching  all  possible prompts for a specific
148           target type. regexp must not have any groups, that is, when  match‐
149           ing,  re:run/3  (in STDLIB) must return a list with one single ele‐
150           ment.
151

EXPORTS

153       close(Connection) -> ok | {error, Reason}
154
155              Types:
156
157                 Connection = connection()
158                 Reason = term()
159
160              Closes the Telnet connection and stops the process managing it.
161
162              A connection can be associated with a target name and/or a  han‐
163              dle. If Connection has no associated target name, it can only be
164              closed with the handle value (see ct_telnet:open/4).
165
166       cmd(Connection, Cmd) -> {ok, Data} | {error, Reason}
167
168              Equivalent to ct_telnet:cmd(Connection, Cmd, []).
169
170       cmd(Connection, Cmd, Opts) -> {ok, Data} | {error, Reason}
171
172              Types:
173
174                 Connection = connection()
175                 Cmd = string()
176                 Opts = [Opt]
177                 Opt = {timeout, timeout()} | {newline, boolean()}
178                 Data = [string()]
179                 Reason = term()
180
181              Sends a command through Telnet and waits for prompt.
182
183              By default, this function adds a new line  to  the  end  of  the
184              specified  command.  If  this  is  not desired, use option {new‐
185              line,false}. This is necessary, for example, when sending Telnet
186              command  sequences prefixed with character Interprete As Command
187              (IAC).
188
189              Option timeout specifies how  long  the  client  must  wait  for
190              prompt.  If  the time expires, the function returns {error,time‐
191              out}. For information about the default value  for  the  command
192              timeout, see the list of default values in the beginning of this
193              module.
194
195       cmdf(Connection, CmdFormat, Args) -> {ok, Data} | {error, Reason}
196
197              Equivalent to ct_telnet:cmdf(Connection, CmdFormat, Args, []).
198
199       cmdf(Connection, CmdFormat, Args, Opts) -> {ok, Data} | {error, Reason}
200
201              Types:
202
203                 Connection = connection()
204                 CmdFormat = string()
205                 Args = list()
206                 Opts = [Opt]
207                 Opt = {timeout, timeout()} | {newline, boolean()}
208                 Data = [string()]
209                 Reason = term()
210
211              Sends a Telnet command and  waits  for  prompt  (uses  a  format
212              string and a list of arguments to build the command).
213
214              For details, see ct_telnet:cmd/3.
215
216       expect(Connection, Patterns) -> term()
217
218              Equivalent to ct_telnet:expect(Connections, Patterns, []).
219
220       expect(Connection,  Patterns,  Opts)  ->  {ok, Match} | {ok, MatchList,
221       HaltReason} | {error, Reason}
222
223              Types:
224
225                 Connection = connection()
226                 Patterns = Pattern | [Pattern]
227                 Pattern = string() | {Tag,  string()}  |  prompt  |  {prompt,
228                 Prompt}
229                 Prompt = string()
230                 Tag = term()
231                 Opts = [Opt]
232                 Opt  =  {idle_timeout,  IdleTimeout} | {total_timeout, Total‐
233                 Timeout} | repeat | {repeat, N} | sequence | {halt,  HaltPat‐
234                 terns}  | ignore_prompt | no_prompt_check | wait_for_prompt |
235                 {wait_for_prompt, Prompt}
236                 IdleTimeout = infinity | integer()
237                 TotalTimeout = infinity | integer()
238                 N = integer()
239                 HaltPatterns = Patterns
240                 MatchList = [Match]
241                 Match = RxMatch | {Tag, RxMatch} | {prompt, Prompt}
242                 RxMatch = [string()]
243                 HaltReason = done | Match
244                 Reason = timeout | {prompt, Prompt}
245
246              Gets data from Telnet and waits for the expected pattern.
247
248              Pattern can be a POSIX regular expression. The function  returns
249              when  a  pattern  is  successfully matched (at least one, in the
250              case of multiple patterns).
251
252              RxMatch is a list of matched strings. It looks as follows [Full‐
253              Match, SubMatch1, SubMatch2, ...], where FullMatch is the string
254              matched by the whole regular expression, and  SubMatchN  is  the
255              string  that  matched subexpression number N. Subexpressions are
256              denoted with '(' ')' in the regular expression.
257
258              If a Tag is speciifed, the  returned  Match  also  includes  the
259              matched Tag. Otherwise, only RxMatch is returned.
260
261              Options:
262
263                idle_timeout:
264                  Indicates that the function must return if the Telnet client
265                  is idle (that is, if no data  is  received)  for  more  than
266                  IdleTimeout milliseconds. Default time-out is 10 seconds.
267
268                total_timeout:
269                  Sets  a  time limit for the complete expect operation. After
270                  TotalTimeout  milliseconds,  {error,timeout}  is   returned.
271                  Default is infinity (that is, no time limit).
272
273                ignore_prompt | no_prompt_check:
274                  >The  function returns when a prompt is received, even if no
275                  pattern has yet been matched, and {error,{prompt,Prompt}} is
276                  returned. However, this behavior can be modified with option
277                  ignore_prompt or option no_prompt_check, which tells  expect
278                  to return only when a match is found or after a time-out.
279
280                ignore_prompt:
281                  ct_telnet ignores any prompt found. This option is useful if
282                  data sent by the  server  can  include  a  pattern  matching
283                  prompt  regexp  (as  returned  by  TargedMod:get_prompt_reg‐
284                  exp/0), but is not to not cause the function to return.
285
286                no_prompt_check:
287                  ct_telnet does not search for a prompt at all. This is  use‐
288                  ful if, for example, Pattern itself matches the prompt.
289
290                wait_for_prompt:
291                  Forces ct_telnet to wait until the prompt string is received
292                  before  returning  (even  if  a  pattern  has  already  been
293                  matched).   This  is  equal  to  calling  expect(Conn,  Pat‐
294                  terns++[{prompt,Prompt}],  [sequence|Opts]).   Notice   that
295                  option  idle_timeout  and total_timeout can abort the opera‐
296                  tion of waiting for prompt.
297
298                repeat | repeat, N:
299                  The pattern(s) must be  matched  multiple  times.  If  N  is
300                  speciified,  the  pattern(s)  are  matched  N times, and the
301                  function returns HaltReason  =  done.  This  option  can  be
302                  interrupted by one or more HaltPatterns. MatchList is always
303                  returned, that is, a list  of  Match  instead  of  only  one
304                  Match. Also HaltReason is returned.
305
306                sequence:
307                  All  patterns  must be matched in a sequence. A match is not
308                  concluded until all patterns are matched. This option can be
309                  interrupted by one or more HaltPatterns. MatchList is always
310                  returned, that is, a list  of  Match  instead  of  only  one
311                  Match. Also HaltReason is returned.
312
313              Example 1:
314
315               expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}],[sequence,{halt,[{nnn,"NNN"}]}])
316
317              First  this  tries  to match "ABC", and then "XYZ", but if "NNN"
318              appears, the function  returns  {error,{nnn,["NNN"]}}.  If  both
319              "ABC"  and  "XYZ"  are  matched,  the function returns {ok,[Abc‐
320              Match,XyzMatch]}.
321
322              Example 2:
323
324               expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}],[{repeat,2},{halt,[{nnn,"NNN"}]}])
325
326              This tries to match "ABC" or "XYZ" twice. If "NNN" appears,  the
327              function returns HaltReason = {nnn,["NNN"]}.
328
329              Options  repeat and sequence can be combined to match a sequence
330              multiple times.
331
332       get_data(Connection) -> {ok, Data} | {error, Reason}
333
334              Types:
335
336                 Connection = connection()
337                 Data = [string()]
338                 Reason = term()
339
340              Gets all data received by the Telnet client since the last  com‐
341              mand  was sent. Only newline-terminated strings are returned. If
342              the last received string has not yet been terminated,  the  con‐
343              nection  can  be  polled  automatically until the string is com‐
344              plete.
345
346              The polling feature is controlled by  the  configuration  values
347              poll_limit  and  poll_interval  and is by default disabled. This
348              means that the function immediately returns all complete strings
349              received and saves a remaining non-terminated string for a later
350              get_data call.
351
352       open(Name) -> {ok, Handle} | {error, Reason}
353
354              Equivalent to ct_telnet:open(Name, telnet).
355
356       open(Name, ConnType) -> {ok, Handle} | {error, Reason}
357
358              Types:
359
360                 Name = target_name()
361                 ConnType = connection_type()
362                 Handle = handle()
363                 Reason = term()
364
365              Opens a Telnet connection to the specified target host.
366
367       open(KeyOrName, ConnType, TargetMod) -> {ok, Handle} | {error, Reason}
368
369              Equivalent to ct_telnet:ct_telnet:open(KeyOrName, ConnType, Tar‐
370              getMod, []).
371
372       open(KeyOrName,  ConnType,  TargetMod, Extra) -> {ok, Handle} | {error,
373       Reason}
374
375              Types:
376
377                 KeyOrName = Key | Name
378                 Key = atom()
379                 Name = target_name()
380                 ConnType = connection_type()
381                 TargetMod = atom()
382                 Extra = term()
383                 Handle = handle()
384                 Reason = term()
385
386              Opens a Telnet connection to the specified target host.
387
388              The target data must exist in a configuration file. The  connec‐
389              tion  can be associated with Name and/or the returned Handle. To
390              allocate a name for the target, use one of the following  alter‐
391              natives:
392
393                * ct:require/2 in a test case
394
395                * A  require  statement  in  the  suite  information  function
396                  (suite/0)
397
398                * A require statement in a test case information function
399
400              If you want the connection to be associated with Handle only (if
401              you,  for example, need to open multiple connections to a host),
402              use Key, the configuration variable name, to specify the target.
403              Notice  that  a connection without an associated target name can
404              only be closed with the Handle value.
405
406              TargetMod is a module that  exports  the  functions  connect(Ip,
407              Port,  KeepAlive,  Extra) and get_prompt_regexp() for the speci‐
408              fied TargetType (for example, unix_telnet).
409
410              For target_name(), see module ct.
411
412              See also ct:require/2.
413
414       send(Connection, Cmd) -> ok | {error, Reason}
415
416              Equivalent to ct_telnet:send(Connection, Cmd, []).
417
418       send(Connection, Cmd, Opts) -> ok | {error, Reason}
419
420              Types:
421
422                 Connection = connection()
423                 Cmd = string()
424                 Opts = [Opt]
425                 Opt = {newline, boolean()}
426                 Reason = term()
427
428              Sends a Telnet command and returns immediately.
429
430              By default, this function adds a newline to the end of the spec‐
431              ified  command.  If  this is not desired, option {newline,false}
432              can be used. This is necessary, for example, when sending Telnet
433              command  sequences prefixed with character Interprete As Command
434              (IAC).
435
436              The resulting output from the command can be read  with  ct_tel‐
437              net:get_data/2 or ct_telnet:expect/2,3.
438
439       sendf(Connection, CmdFormat, Args) -> ok | {error, Reason}
440
441              Equivalent to ct_telnet:sendf(Connection, CmdFormat, Args, []).
442
443       sendf(Connection, CmdFormat, Args, Opts) -> ok | {error, Reason}
444
445              Types:
446
447                 Connection = connection()
448                 CmdFormat = string()
449                 Args = list()
450                 Opts = [Opt]
451                 Opt = {newline, boolean()}
452                 Reason = term()
453
454              Sends  a  Telnet  command and returns immediately (uses a format
455              string and a list of arguments to build the command).
456

SEE ALSO

458       unix_telnet
459
460
461
462Ericsson AB                  common_test 1.15.4.2                 ct_telnet(3)
Impressum