timlindberg | ef8d55d | 2013-09-27 12:50:13 -0700 | [diff] [blame] | 1 | import time |
| 2 | import pexpect |
| 3 | import struct, fcntl, os, sys, signal |
| 4 | import sys |
| 5 | import re |
| 6 | import json |
| 7 | sys.path.append("../") |
| 8 | from drivers.common.clidriver import CLI |
| 9 | |
| 10 | |
| 11 | class SDNIPCliDriver(CLI): |
| 12 | |
| 13 | def __init__(self): |
| 14 | super(CLI, self).__init__() |
| 15 | |
| 16 | def connect(self, **connectargs): |
| 17 | for key in connectargs: |
| 18 | vars(self)[key] = connectargs[key] |
| 19 | |
| 20 | self.name = self.options['name'] |
| 21 | self.handle = super(SDNIPCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd) |
| 22 | |
| 23 | if self.handle: |
| 24 | return self.handle |
| 25 | else : |
| 26 | main.log.info("NO HANDLE") |
| 27 | return main.FALSE |
| 28 | |
| 29 | def check_routes(self, brand, ip, user, pw): |
| 30 | self.handle.sendline("") |
| 31 | self.handle.expect("\$") |
| 32 | main.log.info("Connecting to Pronto switch") |
| 33 | child = pexpect.spawn("telnet " + ip) |
| 34 | i = child.expect(["login:", "CLI#",pexpect.TIMEOUT]) |
| 35 | if i == 0: |
| 36 | main.log.info("Username and password required. Passing login info.") |
| 37 | child.sendline(user) |
| 38 | child.expect("Password:") |
| 39 | child.sendline(pw) |
| 40 | child.expect("CLI#") |
| 41 | main.log.info("Logged in, getting flowtable.") |
| 42 | child.sendline("flowtable brief") |
| 43 | for t in range (9): |
| 44 | t2 = 9 - t |
| 45 | main.log.info("\r" + str(t2)) |
| 46 | sys.stdout.write("\033[F") |
| 47 | time.sleep(1) |
| 48 | time.sleep(10) |
| 49 | main.log.info("Scanning flowtable") |
| 50 | child.expect("Flow table show") |
| 51 | count = 0 |
| 52 | while 1: |
| 53 | i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}','CLI#',pexpect.TIMEOUT]) |
| 54 | if i == 0: |
| 55 | count = count + 1 |
| 56 | elif i == 1: |
| 57 | a ="Pronto flows: " + str(count) + "\nDone\n" |
| 58 | main.log.info(a) |
| 59 | break |
| 60 | else: |
| 61 | break |
| 62 | return count |
| 63 | def disconnect(self): |
| 64 | ''' |
| 65 | Called when Test is complete to disconnect the Quagga handle. |
| 66 | ''' |
| 67 | response = '' |
| 68 | try: |
| 69 | self.handle.close() |
| 70 | except: |
| 71 | main.log.error("Connection failed to the host") |
| 72 | response = main.FALSE |
| 73 | return response |