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