You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 21 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 22 | Start CLI for CHOTestMonkey |
| 23 | Author: you@onlab.us |
| 24 | """ |
| 25 | from multiprocessing.connection import Client |
| 26 | |
| 27 | commandMap = {} |
| 28 | paramNum = {} |
| 29 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 30 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 31 | def 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 52 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 53 | def startCLI(): |
| 54 | debugMode = False |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 55 | while True: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 56 | try: |
| 57 | if debugMode: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 58 | cmd = raw_input( "CHOTestMonkey-debug>" ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 59 | else: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 60 | cmd = raw_input( "CHOTestMonkey>" ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 61 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 89 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 90 | if len( cmdList ) < num + 1: |
| 91 | print 'not enough arguments' |
| 92 | elif len( cmdList ) > num + 1: |
| 93 | print 'Too many arguments' |
| 94 | else: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 95 | """ |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 96 | 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 Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 111 | else: |
| 112 | print 'Unknown command' |
| 113 | |
| 114 | if __name__ == '__main__': |
| 115 | import xml.etree.ElementTree |
| 116 | try: |
| 117 | root = xml.etree.ElementTree.parse( '../CHOTestMonkey.params' ).getroot() |
| 118 | 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() |