blob: aa080f50715e04abc3d1481a01fa643f8dbb78ce [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
22"""
You Wangdb927a52016-02-26 11:03:28 -080023Start CLI for CHOTestMonkey
24Author: you@onlab.us
25"""
26from multiprocessing.connection import Client
27
28commandMap = {}
29paramNum = {}
30
Jon Hall2bb3e212017-05-24 17:07:25 -070031
You Wangdb927a52016-02-26 11:03:28 -080032def triggerEvent( debugMode, name, scheduleMethod, args ):
33 """
34 This function inserts an event from CLI to CHOTestMonkey
35 """
36 host = "localhost"
37 port = 6000
38 address = ( host, port )
39 conn = Client( address )
40 request = []
41 if debugMode:
42 request.append( 2 )
43 else:
44 request.append( 1 )
45 request.append( name )
46 request.append( scheduleMethod )
47 for arg in args:
48 request.append( arg )
49 conn.send( request )
50 response = conn.recv()
51 return response
52
Jon Hall2bb3e212017-05-24 17:07:25 -070053
You Wangdb927a52016-02-26 11:03:28 -080054def startCLI():
55 debugMode = False
Jon Hall2bb3e212017-05-24 17:07:25 -070056 while True:
You Wangdb927a52016-02-26 11:03:28 -080057 try:
58 if debugMode:
Jon Hall2bb3e212017-05-24 17:07:25 -070059 cmd = raw_input( "CHOTestMonkey-debug>" )
You Wangdb927a52016-02-26 11:03:28 -080060 else:
Jon Hall2bb3e212017-05-24 17:07:25 -070061 cmd = raw_input( "CHOTestMonkey>" )
You Wangdb927a52016-02-26 11:03:28 -080062 except EOFError:
63 print "exit"
64 return
65 except Exception:
66 print "Uncaught exception!"
67 return
68
69 if cmd == 'help':
70 print 'Supported commands:'
71 print 'help'
72 print 'debug'
73 print 'exit'
74 for command in commandMap.keys():
75 print command
76 elif cmd == '':
77 pass
78 elif cmd == 'debug':
79 debugMode = True
80 elif cmd == 'exit':
81 if debugMode:
82 debugMode = False
83 else:
84 return
85 else:
86 cmdList = cmd.split( ' ' )
87 if cmdList[ 0 ] in commandMap.keys():
88 num = paramNum[ cmdList[ 0 ] ]
89 name = commandMap[ cmdList[ 0 ] ]
Jon Hall2bb3e212017-05-24 17:07:25 -070090 """
You Wangdb927a52016-02-26 11:03:28 -080091 if len( cmdList ) < num + 1:
92 print 'not enough arguments'
93 elif len( cmdList ) > num + 1:
94 print 'Too many arguments'
95 else:
Jon Hall2bb3e212017-05-24 17:07:25 -070096 """
You Wang7a27f3a2016-07-05 10:12:27 -070097 result = triggerEvent( debugMode, name, 'RUN_BLOCK', cmdList[ 1: ] )
98 if result == 10:
99 pass
100 elif result == 11:
101 print "Scheduler busy...Try later or use debugging mode by entering \'debug\'"
102 elif result == 20:
103 print "Unknown message to server"
104 elif result == 21:
105 print "Unknown event type to server"
106 elif result == 22:
107 print "Unknown schedule method to server"
108 elif result == 23:
109 print "Not enough argument"
110 else:
111 print "Unknown response from server"
You Wangdb927a52016-02-26 11:03:28 -0800112 else:
113 print 'Unknown command'
114
115if __name__ == '__main__':
116 import xml.etree.ElementTree
117 try:
118 root = xml.etree.ElementTree.parse( '../CHOTestMonkey.params' ).getroot()
119 except Exception:
120 print "Uncaught exception!"
121 for child in root:
122 if child.tag == 'EVENT':
123 for event in child:
124 for item in event:
125 if item.tag == 'CLI':
126 CLI = str( item.text )
127 if item.tag == 'typeString':
128 name = str( item.text )
129 if item.tag == 'CLIParamNum':
130 num = int( item.text )
131 commandMap[ CLI ] = name
132 paramNum[ CLI ] = num
133 startCLI()