blob: 89852429ef91dee77e89d2fcda5553182cb610d9 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022Start CLI for CHOTestMonkey
23Author: you@onlab.us
24"""
25from multiprocessing.connection import Client
26
27commandMap = {}
28paramNum = {}
29
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031def triggerEvent( debugMode, name, scheduleMethod, args ):
32 """
33 This function inserts an event from CLI to CHOTestMonkey
34 """
35 host = "localhost"
36 port = 6000
37 address = ( host, port )
38 conn = Client( address )
39 request = []
40 if debugMode:
41 request.append( 2 )
42 else:
43 request.append( 1 )
44 request.append( name )
45 request.append( scheduleMethod )
46 for arg in args:
47 request.append( arg )
48 conn.send( request )
49 response = conn.recv()
50 return response
51
Jon Hall2bb3e212017-05-24 17:07:25 -070052
You Wangdb927a52016-02-26 11:03:28 -080053def startCLI():
54 debugMode = False
Jon Hall2bb3e212017-05-24 17:07:25 -070055 while True:
You Wangdb927a52016-02-26 11:03:28 -080056 try:
57 if debugMode:
Jon Hall2bb3e212017-05-24 17:07:25 -070058 cmd = raw_input( "CHOTestMonkey-debug>" )
You Wangdb927a52016-02-26 11:03:28 -080059 else:
Jon Hall2bb3e212017-05-24 17:07:25 -070060 cmd = raw_input( "CHOTestMonkey>" )
You Wangdb927a52016-02-26 11:03:28 -080061 except EOFError:
62 print "exit"
63 return
64 except Exception:
65 print "Uncaught exception!"
66 return
67
68 if cmd == 'help':
69 print 'Supported commands:'
70 print 'help'
71 print 'debug'
72 print 'exit'
73 for command in commandMap.keys():
74 print command
75 elif cmd == '':
76 pass
77 elif cmd == 'debug':
78 debugMode = True
79 elif cmd == 'exit':
80 if debugMode:
81 debugMode = False
82 else:
83 return
84 else:
85 cmdList = cmd.split( ' ' )
86 if cmdList[ 0 ] in commandMap.keys():
87 num = paramNum[ cmdList[ 0 ] ]
88 name = commandMap[ cmdList[ 0 ] ]
Jon Hall2bb3e212017-05-24 17:07:25 -070089 """
You Wangdb927a52016-02-26 11:03:28 -080090 if len( cmdList ) < num + 1:
91 print 'not enough arguments'
92 elif len( cmdList ) > num + 1:
93 print 'Too many arguments'
94 else:
Jon Hall2bb3e212017-05-24 17:07:25 -070095 """
You Wang7a27f3a2016-07-05 10:12:27 -070096 result = triggerEvent( debugMode, name, 'RUN_BLOCK', cmdList[ 1: ] )
97 if result == 10:
98 pass
99 elif result == 11:
100 print "Scheduler busy...Try later or use debugging mode by entering \'debug\'"
101 elif result == 20:
102 print "Unknown message to server"
103 elif result == 21:
104 print "Unknown event type to server"
105 elif result == 22:
106 print "Unknown schedule method to server"
107 elif result == 23:
108 print "Not enough argument"
109 else:
110 print "Unknown response from server"
You Wangdb927a52016-02-26 11:03:28 -0800111 else:
112 print 'Unknown command'
113
114if __name__ == '__main__':
115 import xml.etree.ElementTree
116 try:
You Wang9fc5ce42019-01-23 15:10:08 -0800117 root = xml.etree.ElementTree.parse( '../CHOTestMonkey.params.trellis' ).getroot()
You Wangdb927a52016-02-26 11:03:28 -0800118 except Exception:
119 print "Uncaught exception!"
120 for child in root:
121 if child.tag == 'EVENT':
122 for event in child:
123 for item in event:
124 if item.tag == 'CLI':
125 CLI = str( item.text )
126 if item.tag == 'typeString':
127 name = str( item.text )
128 if item.tag == 'CLIParamNum':
129 num = int( item.text )
130 commandMap[ CLI ] = name
131 paramNum[ CLI ] = num
132 startCLI()