Andrea Speranza | 8b6f46f | 2022-08-23 14:22:15 +0200 | [diff] [blame] | 1 | # Copyright 2021-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | #!/usr/bin/expect -f |
| 15 | # |
| 16 | # This Expect script was generated by autoexpect on Wed Aug 17 22:24:22 2022 |
| 17 | # Expect and autoexpect were both written by Don Libes, NIST. |
| 18 | # |
| 19 | # Note that autoexpect does not guarantee a working script. It |
| 20 | # necessarily has to guess about certain things. Two reasons a script |
| 21 | # might fail are: |
| 22 | # |
| 23 | # 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, |
| 24 | # etc.) and devices discard or ignore keystrokes that arrive "too |
| 25 | # quickly" after prompts. If you find your new script hanging up at |
| 26 | # one spot, try adding a short sleep just before the previous send. |
| 27 | # Setting "force_conservative" to 1 (see below) makes Expect do this |
| 28 | # automatically - pausing briefly before sending each character. This |
| 29 | # pacifies every program I know of. The -c flag makes the script do |
| 30 | # this in the first place. The -C flag allows you to define a |
| 31 | # character to toggle this mode off and on. |
| 32 | |
| 33 | set force_conservative 0 ;# set to 1 to force conservative mode even if |
| 34 | ;# script wasn't run conservatively originally |
| 35 | if {$force_conservative} { |
| 36 | set send_slow {1 .1} |
| 37 | proc send {ignore arg} { |
| 38 | sleep .1 |
| 39 | exp_send -s -- $arg |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | # |
| 44 | # 2) differing output - Some programs produce different output each time |
| 45 | # they run. The "date" command is an obvious example. Another is |
| 46 | # ftp, if it produces throughput statistics at the end of a file |
| 47 | # transfer. If this causes a problem, delete these patterns or replace |
| 48 | # them with wildcards. An alternative is to use the -p flag (for |
| 49 | # "prompt") which makes Expect only look for the last line of output |
| 50 | # (i.e., the prompt). The -P flag allows you to define a character to |
| 51 | # toggle this mode off and on. |
| 52 | # |
| 53 | # Read the man page for more info. |
| 54 | # |
| 55 | # -Don |
| 56 | |
| 57 | set bbfPodName [lindex $argv 0] |
| 58 | |
| 59 | set timeout 5 |
| 60 | spawn ssh -p 50022 voltha@localhost |
| 61 | match_max 100000 |
| 62 | |
| 63 | expect { |
| 64 | {Are you sure you want to continue connecting (yes/no/\[fingerprint\])? } |
| 65 | { send -- "yes\r" |
| 66 | expect "voltha@localhost's password: " |
| 67 | send -- "onf\r" |
| 68 | expect -exact "$bbfPodName:~\$" |
| 69 | send -- "netopeer2-cli\r" |
| 70 | expect -exact "> " |
| 71 | send -- "searchpath /etc/sysrepo/yang\r" |
| 72 | expect -exact "> " |
| 73 | send -- "ext-data /schema-mount.xml\r" |
| 74 | expect -exact "> " |
| 75 | send -- "connect --login voltha\r" |
| 76 | expect -exact "Are you sure you want to continue connecting (yes/no)? " |
| 77 | send -- "yes\r" |
| 78 | expect -exact "Password: " |
| 79 | send -- "onf\r" |
| 80 | expect -exact "> " |
| 81 | send -- "get-data --datastore operational --filter-xpath /bbf-device-aggregation:* --out output.xml" |
| 82 | expect -exact "get-data --datastore operational --filter-xpath /bbf-device-aggregation:* --out output.xml" |
| 83 | send -- "\r" |
| 84 | expect -exact "> " |
| 85 | send -- "" |
| 86 | expect -exact "$bbfPodName:~\$ \[6n" |
| 87 | expect eof ; exp_continue} |
| 88 | |
| 89 | "voltha@localhost's password: " { |
| 90 | send -- "onf\r" |
| 91 | expect -exact "$bbfPodName:~\$" |
| 92 | send -- "netopeer2-cli\r" |
| 93 | expect -exact "> " |
| 94 | send -- "searchpath /etc/sysrepo/yang\r" |
| 95 | expect -exact "> " |
| 96 | send -- "ext-data /schema-mount.xml\r" |
| 97 | expect -exact "> " |
| 98 | send -- "connect --login voltha\r" |
| 99 | expect { |
| 100 | "Are you sure you want to continue connecting (yes/no)? " { |
| 101 | send -- "yes\r" |
| 102 | expect -exact "Password: " |
| 103 | send -- "onf\r" |
| 104 | expect -exact "> " |
| 105 | send -- "get-data --datastore operational --filter-xpath /bbf-device-aggregation:* --out output.xml" |
| 106 | expect -exact "get-data --datastore operational --filter-xpath /bbf-device-aggregation:* --out output.xml" |
| 107 | send -- "\r" |
| 108 | expect -exact "> " |
| 109 | send -- "" |
| 110 | expect -exact "$bbfPodName:~\$ \[6n" |
| 111 | expect eof ; exp_continue} |
| 112 | |
| 113 | "Password: " { |
| 114 | send -- "onf\r" |
| 115 | expect -exact "> " |
| 116 | send -- "get-data --datastore operational --filter-xpath /bbf-device-aggregation:* --out output.xml" |
| 117 | expect -exact "get-data --datastore operational --filter-xpath /bbf-device-aggregation:* --out output.xml" |
| 118 | send -- "\r" |
| 119 | expect -exact "> " |
| 120 | send -- "" |
| 121 | expect -exact "$bbfPodName:~\$ \[6n" |
| 122 | expect eof ; exp_continue} |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | exit 0 |