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 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 4 | This driver handles the optical switch emulator linc-oe. |
| 5 | |
| 6 | Please follow the coding style demonstrated by existing |
| 7 | functions and document properly. |
| 8 | |
| 9 | If you are a contributor to the driver, please |
| 10 | list your email here for future contact: |
| 11 | |
| 12 | andrew@onlab.us |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 13 | shreya@onlab.us |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 14 | |
| 15 | OCT 20 2014 |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 16 | Modified 2015 by ON.Lab |
| 17 | |
| 18 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 19 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 20 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 21 | """ |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 22 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 23 | import pexpect |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 24 | import sys |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 25 | from drivers.common.cli.emulatordriver import Emulator |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 26 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 27 | |
| 28 | class LincOEDriver( Emulator ): |
| 29 | |
| 30 | """ |
| 31 | LincOEDriver class will handle all emulator functions |
| 32 | """ |
| 33 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 34 | super( LincOEDriver, self ).__init__() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 35 | self.handle = self |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 36 | self.wrapped = sys.modules[ __name__ ] |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 37 | self.flag = 0 |
| 38 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 39 | def connect( self, **connectargs ): |
| 40 | """ |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 41 | Create ssh handle for Linc-OE cli |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 42 | """ |
andrewonlab | a85a776 | 2014-10-22 18:05:52 -0400 | [diff] [blame] | 43 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 44 | for key in connectargs: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 45 | vars( self )[ key ] = connectargs[ key ] |
| 46 | |
| 47 | self.name = self.options[ 'name' ] |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 48 | self.handle = \ |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 49 | super( LincOEDriver, self ).connect( |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 50 | user_name=self.user_name, |
| 51 | ip_address=self.ip_address, |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 52 | port=None, |
| 53 | pwd=self.pwd ) |
| 54 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 55 | self.sshHandle = self.handle |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 56 | |
| 57 | if self.handle: |
| 58 | main.log.info( "Handle successfully created" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 59 | self.home = "~/linc-oe" |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 60 | |
| 61 | self.handle.sendline( "cd " + self.home ) |
| 62 | self.handle.expect( "oe$" ) |
| 63 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 64 | print "handle = ", self.handle.before |
| 65 | |
| 66 | return main.TRUE |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 67 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 68 | main.log.error( self.name + |
| 69 | ": Connection failed to the host " + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 70 | self.user_name + "@" + self.ip_address ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 71 | main.log.error( self.name + |
| 72 | ": Failed to connect to Linc-OE" ) |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 73 | return main.FALSE |
| 74 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 75 | def startConsole( self ): |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 76 | import time |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 77 | main.log.info( |
| 78 | self.name + |
| 79 | ": Starting Linc-OE CLI.. This may take a while" ) |
| 80 | time.sleep( 30 ) |
| 81 | self.handle.sendline( "sudo ./rel/linc/bin/linc console" ) |
| 82 | j = self.handle.expect( [ "linc@", pexpect.EOF, pexpect.TIMEOUT ] ) |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 83 | startResult = self.handle.before |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 84 | if j == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 85 | main.log.info( "Linc-OE CLI started" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 86 | return main.TRUE |
| 87 | else: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 88 | main.log.error( |
| 89 | self.name + |
| 90 | ": Connection failed to the host " + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 91 | self.user_name + |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 92 | "@" + |
kelvin-onlab | 08679eb | 2015-01-21 16:11:48 -0800 | [diff] [blame] | 93 | self.ip_address ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 94 | main.log.error( self.name + |
| 95 | ": Failed to connect to Linc-OE" ) |
shahshreya | e6c7cf4 | 2014-11-26 16:39:01 -0800 | [diff] [blame] | 96 | return main.FALSE |
| 97 | |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 98 | def build( self ): |
| 99 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 100 | Build Linc-OE with the specified settings |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 101 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 102 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 103 | self.handle.sendline( "make rel" ) |
| 104 | i = self.handle.expect( [ |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 105 | "ERROR", |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 106 | self.prompt ] ) |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 107 | |
| 108 | if i == 0: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 109 | self.handle.sendline( "sudo pkill -9 epmd" ) |
| 110 | self.handle.sendline( "make rel" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 111 | self.handle.expect( self.prompt ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 112 | |
andrewonlab | c6d1fa6 | 2014-10-22 16:28:04 -0400 | [diff] [blame] | 113 | handle = self.handle.before |
| 114 | return handle |
| 115 | |
| 116 | else: |
| 117 | return main.TRUE |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 118 | |
| 119 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 120 | main.log.error( self.name + ": EOF exception" ) |
| 121 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 122 | main.cleanup() |
| 123 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 124 | except Exception: |
| 125 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 126 | main.cleanup() |
| 127 | main.exit() |
| 128 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 129 | def setInterfaceUp( self, intfs ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 130 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 131 | Specify interface to bring up. |
| 132 | When Linc-OE is started, tap interfaces should |
| 133 | be created. They must be brought up manually |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 134 | """ |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 135 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 136 | self.handle.sendline( "ifconfig " + str( intfs ) + " up" ) |
| 137 | self.handle.expect( "linc@" ) |
| 138 | |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 139 | handle = self.handle.before |
| 140 | |
| 141 | return handle |
| 142 | |
| 143 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 144 | main.log.error( self.name + ": EOF exception" ) |
| 145 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 146 | main.cleanup() |
| 147 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 148 | except Exception: |
| 149 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 150 | main.cleanup() |
| 151 | main.exit() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 152 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 153 | def startSwitch( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 154 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 155 | Start a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 156 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 157 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 158 | self.handle.sendline( "linc:start_switch(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 159 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 160 | |
| 161 | handle = self.handle.before |
| 162 | |
| 163 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 164 | main.log.error( self.name + ": EOF exception" ) |
| 165 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 166 | main.cleanup() |
| 167 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 168 | except Exception: |
| 169 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 170 | main.cleanup() |
| 171 | main.exit() |
| 172 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 173 | def stopSwitch( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 174 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 175 | Stop a logical switch using switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 176 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 177 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 178 | self.handle.sendline( "linc:stop_switch(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 179 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 180 | |
| 181 | handle = self.handle.before |
| 182 | |
| 183 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 184 | main.log.error( self.name + ": EOF exception" ) |
| 185 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 186 | main.cleanup() |
| 187 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 188 | except Exception: |
| 189 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 190 | main.cleanup() |
| 191 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 192 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 193 | def getDatapathId( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 194 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 195 | Get datapath id of a specific switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 196 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 197 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 198 | self.handle.sendline( "linc_logic:get_datapath_id(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 199 | str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 200 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 201 | |
| 202 | handle = self.handle.before |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 203 | |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 204 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 205 | main.log.error( self.name + ": EOF exception" ) |
| 206 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 207 | main.cleanup() |
| 208 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 209 | except Exception: |
| 210 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 211 | main.cleanup() |
| 212 | main.exit() |
| 213 | |
shahshreya | 9ee36d5 | 2015-04-03 15:38:23 -0700 | [diff] [blame] | 214 | def attachLincOESession( self ): |
| 215 | """ |
| 216 | Since executing opticalTest.py will give you mininet |
| 217 | prompt, you would at some point require to get onto |
| 218 | console of LincOE ((linc@onosTestBench)1>) to execute |
| 219 | commands like bring a optical port up or down on a ROADM |
| 220 | You can attach to console of Linc-OE session by a cmd: |
| 221 | sudo ~/linc-oe/rel/linc/bin/linc attach |
| 222 | """ |
| 223 | try: |
| 224 | self.handle.sendline( "" ) |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 225 | self.handle.expect( self.prompt ) |
shahshreya | 9ee36d5 | 2015-04-03 15:38:23 -0700 | [diff] [blame] | 226 | self.handle.sendline( "sudo ~/linc-oe/rel/linc/bin/linc attach" ) |
| 227 | self.handle.expect( ">" ) |
| 228 | return main.TRUE |
| 229 | except pexpect.EOF: |
| 230 | main.log.error( self.name + ": EOF exception found" ) |
| 231 | main.log.error( self.name + ": " + self.handle.before ) |
| 232 | return main.FALSE |
| 233 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 234 | def listPorts( self, swId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 235 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 236 | List all ports of a switch by switch id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 237 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 238 | try: |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 239 | self.handle.sendline( "linc:ports(" + str( swId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 240 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 241 | |
| 242 | handle = self.handle.before |
| 243 | |
| 244 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 245 | main.log.error( self.name + ": EOF exception" ) |
| 246 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 247 | main.cleanup() |
| 248 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 249 | except Exception: |
| 250 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 251 | main.cleanup() |
| 252 | main.exit() |
| 253 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 254 | def portUp( self, swId, ptId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 255 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 256 | Bring port up using switch id and port id |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 257 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 258 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 259 | self.handle.sendline( "linc:port_up(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 260 | str( swId ) + ", " + str( ptId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 261 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 262 | |
| 263 | handle = self.handle.before |
| 264 | |
| 265 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 266 | main.log.error( self.name + ": EOF exception" ) |
| 267 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 268 | main.cleanup() |
| 269 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 270 | except Exception: |
| 271 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 272 | main.cleanup() |
| 273 | main.exit() |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 274 | |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 275 | def portDown( self, swId, ptId ): |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 276 | """ |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 277 | Bring port down using switch id and port id |
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 | try: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 280 | self.handle.sendline( "linc:port_down(" + |
kelvin-onlab | d3b6489 | 2015-01-20 13:26:24 -0800 | [diff] [blame] | 281 | str( swId ) + ", " + str( ptId ) + ")." ) |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 282 | self.handle.expect( "linc@" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 283 | |
| 284 | handle = self.handle.before |
| 285 | |
| 286 | except pexpect.EOF: |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 287 | main.log.error( self.name + ": EOF exception" ) |
| 288 | main.log.error( self.name + ": " + self.handle.before ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 289 | main.cleanup() |
| 290 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 291 | except Exception: |
| 292 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 52a31e0 | 2014-10-22 12:57:19 -0400 | [diff] [blame] | 293 | main.cleanup() |
| 294 | main.exit() |
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 ) |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 338 | main.cleanup() |
| 339 | main.exit() |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame] | 340 | except Exception: |
| 341 | main.log.exception( self.name + ": Uncaught exception!" ) |
andrewonlab | 0980f42 | 2014-10-21 21:28:39 -0400 | [diff] [blame] | 342 | main.cleanup() |
| 343 | main.exit() |
| 344 | |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 345 | if __name__ != "__main__": |
| 346 | import sys |
kelvin-onlab | edcff05 | 2015-01-16 12:53:55 -0800 | [diff] [blame] | 347 | sys.modules[ __name__ ] = LincOEDriver() |