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