andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 3 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 4 | Copyright 2014 Open Networking Foundation (ONF) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 9 | |
| 10 | TestON is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 13 | (at your option) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 14 | |
| 15 | TestON is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | |
| 24 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 25 | This driver handles the optical switch emulator linc-oe. |
| 26 | |
| 27 | Please follow the coding style demonstrated by existing |
| 28 | functions and document properly. |
| 29 | |
| 30 | If you are a contributor to the driver, please |
| 31 | list your email here for future contact: |
| 32 | |
| 33 | andrew@onlab.us |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 34 | shreya@onlab.us |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 35 | |
| 36 | OCT 20 2014 |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 37 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 38 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 39 | import pexpect |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 40 | import sys |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 41 | from drivers.common.cli.emulatordriver import Emulator |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 42 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 43 | |
| 44 | class LincOEDriver( Emulator ): |
| 45 | |
| 46 | """ |
| 47 | LincOEDriver class will handle all emulator functions |
| 48 | """ |
| 49 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 50 | super( LincOEDriver, self ).__init__() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 51 | self.handle = self |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 52 | self.wrapped = sys.modules[ __name__ ] |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 53 | self.flag = 0 |
| 54 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 55 | def connect( self, **connectargs ): |
| 56 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 57 | Create ssh handle for Linc-OE cli |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 58 | """ |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 59 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 60 | for key in connectargs: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 61 | vars( self )[ key ] = connectargs[ key ] |
| 62 | |
| 63 | self.name = self.options[ 'name' ] |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 64 | self.handle = \ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 65 | super( LincOEDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 66 | user_name=self.user_name, |
| 67 | ip_address=self.ip_address, |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 68 | port=None, |
| 69 | pwd=self.pwd ) |
| 70 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 71 | self.sshHandle = self.handle |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 72 | |
| 73 | if self.handle: |
| 74 | main.log.info( "Handle successfully created" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 75 | self.home = "~/linc-oe" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 76 | |
| 77 | self.handle.sendline( "cd " + self.home ) |
| 78 | self.handle.expect( "oe$" ) |
| 79 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 80 | print "handle = ", self.handle.before |
| 81 | |
| 82 | return main.TRUE |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 83 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 84 | main.log.error( self.name + |
| 85 | ": Connection failed to the host " + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 86 | self.user_name + "@" + self.ip_address ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 87 | main.log.error( self.name + |
| 88 | ": Failed to connect to Linc-OE" ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 89 | return main.FALSE |
| 90 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 91 | def startConsole( self ): |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 92 | import time |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 93 | main.log.info( |
| 94 | self.name + |
| 95 | ": Starting Linc-OE CLI.. This may take a while" ) |
| 96 | time.sleep( 30 ) |
| 97 | self.handle.sendline( "sudo ./rel/linc/bin/linc console" ) |
| 98 | j = self.handle.expect( [ "linc@", pexpect.EOF, pexpect.TIMEOUT ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 99 | startResult = self.handle.before |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 100 | if j == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 101 | main.log.info( "Linc-OE CLI started" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 102 | return main.TRUE |
| 103 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 104 | main.log.error( |
| 105 | self.name + |
| 106 | ": Connection failed to the host " + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 107 | self.user_name + |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 108 | "@" + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 109 | self.ip_address ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 110 | main.log.error( self.name + |
| 111 | ": Failed to connect to Linc-OE" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 112 | return main.FALSE |
| 113 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 114 | def build( self ): |
| 115 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 116 | Build Linc-OE with the specified settings |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 117 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 118 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 119 | self.handle.sendline( "make rel" ) |
| 120 | i = self.handle.expect( [ |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 121 | "ERROR", |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 122 | self.prompt ] ) |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 123 | |
| 124 | if i == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 125 | self.handle.sendline( "sudo pkill -9 epmd" ) |
| 126 | self.handle.sendline( "make rel" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 127 | self.handle.expect( self.prompt ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 128 | |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 129 | handle = self.handle.before |
| 130 | return handle |
| 131 | |
| 132 | else: |
| 133 | return main.TRUE |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 134 | |
| 135 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 136 | main.log.error( self.name + ": EOF exception" ) |
| 137 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 138 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 139 | except Exception: |
| 140 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 141 | main.cleanAndExit() |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 142 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 143 | def setInterfaceUp( self, intfs ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 144 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 145 | Specify interface to bring up. |
| 146 | When Linc-OE is started, tap interfaces should |
| 147 | be created. They must be brought up manually |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 148 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 149 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 150 | self.handle.sendline( "ifconfig " + str( intfs ) + " up" ) |
| 151 | self.handle.expect( "linc@" ) |
| 152 | |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 153 | handle = self.handle.before |
| 154 | |
| 155 | return handle |
| 156 | |
| 157 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 158 | main.log.error( self.name + ": EOF exception" ) |
| 159 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 160 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 161 | except Exception: |
| 162 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 163 | main.cleanAndExit() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 164 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 165 | def startSwitch( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 166 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 167 | Start a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 168 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 169 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 170 | self.handle.sendline( "linc:start_switch(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 171 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 172 | |
| 173 | handle = self.handle.before |
| 174 | |
| 175 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 176 | main.log.error( self.name + ": EOF exception" ) |
| 177 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 178 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 179 | except Exception: |
| 180 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 181 | main.cleanAndExit() |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 182 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 183 | def stopSwitch( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 184 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 185 | Stop a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 186 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 187 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 188 | self.handle.sendline( "linc:stop_switch(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 189 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 190 | |
| 191 | handle = self.handle.before |
| 192 | |
| 193 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 194 | main.log.error( self.name + ": EOF exception" ) |
| 195 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 196 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 197 | except Exception: |
| 198 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 199 | main.cleanAndExit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 200 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 201 | def getDatapathId( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 202 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 203 | Get datapath id of a specific switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 204 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 205 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 206 | self.handle.sendline( "linc_logic:get_datapath_id(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 207 | str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 208 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 209 | |
| 210 | handle = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 211 | |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 212 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 213 | main.log.error( self.name + ": EOF exception" ) |
| 214 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 215 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 216 | except Exception: |
| 217 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 218 | main.cleanAndExit() |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 219 | |
shahshreya | 9ee36d5 | 2015-04-03 15:38:23 -0700 | [diff] [blame] | 220 | def attachLincOESession( self ): |
| 221 | """ |
| 222 | Since executing opticalTest.py will give you mininet |
| 223 | prompt, you would at some point require to get onto |
Jeremy Ronquillo | 4d5f1d0 | 2017-10-13 20:23:57 +0000 | [diff] [blame] | 224 | console of LincOE ((linc@onosTestBench)1>) to execute |
shahshreya | 9ee36d5 | 2015-04-03 15:38:23 -0700 | [diff] [blame] | 225 | commands like bring a optical port up or down on a ROADM |
| 226 | You can attach to console of Linc-OE session by a cmd: |
| 227 | sudo ~/linc-oe/rel/linc/bin/linc attach |
| 228 | """ |
| 229 | try: |
| 230 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 231 | self.handle.expect( self.prompt ) |
shahshreya | 9ee36d5 | 2015-04-03 15:38:23 -0700 | [diff] [blame] | 232 | self.handle.sendline( "sudo ~/linc-oe/rel/linc/bin/linc attach" ) |
| 233 | self.handle.expect( ">" ) |
| 234 | return main.TRUE |
| 235 | except pexpect.EOF: |
| 236 | main.log.error( self.name + ": EOF exception found" ) |
| 237 | main.log.error( self.name + ": " + self.handle.before ) |
| 238 | return main.FALSE |
| 239 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 240 | def listPorts( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 241 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 242 | List all ports of a switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 243 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 244 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 245 | self.handle.sendline( "linc:ports(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 246 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 247 | |
| 248 | handle = self.handle.before |
| 249 | |
| 250 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 251 | main.log.error( self.name + ": EOF exception" ) |
| 252 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 253 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 254 | except Exception: |
| 255 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 256 | main.cleanAndExit() |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 257 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 258 | def portUp( self, swId, ptId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 259 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 260 | Bring port up using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 261 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 262 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 263 | self.handle.sendline( "linc:port_up(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 264 | str( swId ) + ", " + str( ptId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 265 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 266 | |
| 267 | handle = self.handle.before |
| 268 | |
| 269 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 270 | main.log.error( self.name + ": EOF exception" ) |
| 271 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 272 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 273 | except Exception: |
| 274 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 275 | main.cleanAndExit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 276 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 277 | def portDown( self, swId, ptId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 278 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 279 | Bring port down using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 280 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 281 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 282 | self.handle.sendline( "linc:port_down(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 283 | str( swId ) + ", " + str( ptId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 284 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 285 | |
| 286 | handle = self.handle.before |
| 287 | |
| 288 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 289 | main.log.error( self.name + ": EOF exception" ) |
| 290 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 291 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 292 | except Exception: |
| 293 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 294 | main.cleanAndExit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 295 | |
| 296 | def stopLincOEConsole( self ): |
| 297 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 298 | This function is only used for packet optical testing |
| 299 | Send disconnect prompt to Linc-OE CLI |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 300 | ( CTRL+C ) and kill the linc process |
| 301 | """ |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 302 | try: |
| 303 | cmd = "pgrep -f linc" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 304 | self.handle.sendline( "pgrep -f linc" ) |
| 305 | self.handle.expect( "linc" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 306 | print "stophandle = ", self.handle.before |
| 307 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 308 | main.log.error( self.name + ": EOF exception" ) |
| 309 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 310 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 311 | def disconnect( self ): |
| 312 | """ |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 313 | Send disconnect prompt to Linc-OE CLI |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 314 | ( CTRL+C ) and kill the linc process |
| 315 | """ |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 316 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 317 | # Send CTRL+C twice to exit CLI |
| 318 | self.handle.send( "\x03" ) |
| 319 | self.handle.send( "\x03" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 320 | self.handle.expect( self.prompt ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 321 | handle1 = self.handle.before |
| 322 | cmd = "pgrep -f linc" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 323 | self.handle.sendline( cmd ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 324 | self.handle.expect( self.prompt ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 325 | handle2 = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 326 | main.log.info( "pid's = " + handle2 ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 327 | cmd = "sudo kill -9 `pgrep -f linc`" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 328 | self.handle.sendline( cmd ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 329 | self.handle.expect( self.prompt ) |
shahshreya | 5a03484 | 2015-02-05 11:08:46 -0800 | [diff] [blame] | 330 | # Close the ssh connection |
| 331 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 332 | self.handle.expect( self.prompt ) |
shahshreya | 5a03484 | 2015-02-05 11:08:46 -0800 | [diff] [blame] | 333 | self.handle.sendline( "exit" ) |
| 334 | self.handle.expect( "closed" ) |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 335 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 336 | main.log.error( self.name + ": EOF exception" ) |
| 337 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 338 | main.cleanAndExit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 339 | except Exception: |
| 340 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 341 | main.cleanAndExit() |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 342 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 343 | if __name__ != "__main__": |
| 344 | import sys |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 345 | sys.modules[ __name__ ] = LincOEDriver() |