Jon Hall | 05b2b43 | 2014-10-08 19:53:25 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | ''' |
| 3 | TODO: Document |
| 4 | ''' |
| 5 | |
| 6 | |
| 7 | import time |
| 8 | import pexpect |
| 9 | import re |
| 10 | import traceback |
| 11 | sys.path.append("../") |
| 12 | from drivers.common.clidriver import CLI |
| 13 | |
| 14 | class OnosDriver(CLI): |
| 15 | |
| 16 | def __init__(self): |
| 17 | super(CLI, self).__init__() |
| 18 | |
| 19 | def connect(self,**connectargs): |
| 20 | ''' |
| 21 | Creates ssh handle for ONOS "bench". |
| 22 | ''' |
| 23 | try: |
| 24 | for key in connectargs: |
| 25 | vars(self)[key] = connectargs[key] |
| 26 | self.home = "~/ONOS" |
| 27 | for key in self.options: |
| 28 | if key == "home": |
| 29 | self.home = self.options['home'] |
| 30 | break |
| 31 | |
| 32 | |
| 33 | self.name = self.options['name'] |
| 34 | self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd, home = self.home) |
| 35 | |
| 36 | if self.handle: |
| 37 | return self.handle |
| 38 | else : |
| 39 | main.log.info("NO ONOS HANDLE") |
| 40 | return main.FALSE |
| 41 | except pexpect.EOF: |
| 42 | main.log.error(self.name + ": EOF exception found") |
| 43 | main.log.error(self.name + ": " + self.handle.before) |
| 44 | main.cleanup() |
| 45 | main.exit() |
| 46 | except: |
| 47 | main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 48 | main.log.error( traceback.print_exc() ) |
| 49 | main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") |
| 50 | main.cleanup() |
| 51 | main.exit() |
| 52 | |
| 53 | def disconnect(self): |
| 54 | ''' |
| 55 | Called when Test is complete to disconnect the ONOS handle. |
| 56 | ''' |
| 57 | response = '' |
| 58 | try: |
| 59 | self.handle.sendline("exit") |
| 60 | self.handle.expect("closed") |
| 61 | except pexpect.EOF: |
| 62 | main.log.error(self.name + ": EOF exception found") |
| 63 | main.log.error(self.name + ": " + self.handle.before) |
| 64 | except: |
| 65 | main.log.error(self.name + ": Connection failed to the host") |
| 66 | response = main.FALSE |
| 67 | return response |