blob: b91689a329a805639b7751ca4b5acd9af367a1d2 [file] [log] [blame]
Jon Hall05b2b432014-10-08 19:53:25 -04001#!/usr/bin/env python
2'''
3TODO: Document
4'''
5
6
7import time
8import pexpect
9import re
10import traceback
11sys.path.append("../")
12from drivers.common.clidriver import CLI
13
14class 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.us9e2cd0f2014-10-08 20:32:32 -040068
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
Jon Hallde9d9aa2014-10-08 20:36:02 -0400106 def clean_install(self):
107 '''
108 Runs mvn clean install in the root of the ONOS directory.
109 This will clean all ONOS artifacts then compile each module
andrew@onlab.us9e2cd0f2014-10-08 20:32:32 -0400110
Jon Hallde9d9aa2014-10-08 20:36:02 -0400111 Returns: main.TRUE on success
112 On Failure, exits the test
113 '''
114 try:
115 self.handle.sendline("mvn clean install")
116 while 1:
117 i=self.handle.expect([
118 'There\sis\sinsufficient\smemory\sfor\sthe\sJava\s\
119 Runtime\sEnvironment\sto\scontinue',
120 'BUILD\sFAILURE',
121 'BUILD\sSUCCESS',
122 'ONOS\$',
123 pexpect.TIMEOUT],timeout=600)
124 if i == 0:
125 main.log.error(self.name + ":There is insufficient memory \
126 for the Java Runtime Environment to continue.")
127 #return main.FALSE
128 main.cleanup()
129 main.exit()
130 if i == 1:
131 main.log.error(self.name + ": Build failure!")
132 #return main.FALSE
133 main.cleanup()
134 main.exit()
135 elif i == 2:
136 main.log.info(self.name + ": Build success!")
137 elif i == 3:
138 main.log.info(self.name + ": Build complete")
139 self.handle.expect("\$", timeout=60)
140 return main.TRUE
141 elif i == 4:
142 main.log.error(self.name + ": mvn clean install TIMEOUT!")
143 #return main.FALSE
144 main.cleanup()
145 main.exit()
146 else:
147 main.log.error(self.name + ": unexpected response from \
148 mvn clean install")
149 #return main.FALSE
150 main.cleanup()
151 main.exit()
152 except pexpect.EOF:
153 main.log.error(self.name + ": EOF exception found")
154 main.log.error(self.name + ": " + self.handle.before)
155 main.cleanup()
156 main.exit()
157 except:
158 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
159 main.log.error( traceback.print_exc() )
160 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
161 main.cleanup()
162 main.exit()