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 |
andrew@onlab.us | 9e2cd0f | 2014-10-08 20:32:32 -0400 | [diff] [blame^] | 68 | |
| 69 | def onos_package(self): |
| 70 | ''' |
| 71 | Produce a self-contained tar.gz file that can be deployed |
| 72 | and executed on any platform with Java 7 JRE. |
| 73 | ''' |
| 74 | import os.path |
| 75 | |
| 76 | try: |
| 77 | self.handle.sendline("onos-package") |
| 78 | self.handle.expect("\$") |
| 79 | handle = str(self.handle.before) |
| 80 | main.log.info("onos-package command returned: "+ |
| 81 | handle) |
| 82 | |
| 83 | #Create list out of the handle by partitioning |
| 84 | #spaces. |
| 85 | #NOTE: The last element of the list at the time |
| 86 | # of writing this function is the filepath |
| 87 | #save this filepath for comparison later on |
| 88 | temp_list = handle.split(" ") |
| 89 | file_path = handle[-1:] |
| 90 | |
| 91 | #If last string contains the filepath, return |
| 92 | # as success. |
| 93 | if "/tmp" in file_path: |
| 94 | return main.TRUE |
| 95 | else: |
| 96 | return main.FALSE |
| 97 | |
| 98 | except: |
| 99 | main.log.error(self.name + ": EOF exception found") |
| 100 | main.log.error(self.name + ": " + self.handle.before) |
| 101 | except: |
| 102 | main.log.error("Failed to package ONOS") |
| 103 | main.cleanup() |
| 104 | main.exit() |
| 105 | |
| 106 | |