blob: 8d347c17870463fc1c1ddf7fa77fc5451e052fc3 [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 -080022This file contains classes for CHOTestMonkey that are related to application event
23Author: you@onlab.us
24"""
25from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
26from tests.CHOTestMonkey.dependencies.elements.ONOSElement import HostIntent, PointIntent
27
Jon Hall2bb3e212017-05-24 17:07:25 -070028
You Wangdb927a52016-02-26 11:03:28 -080029class IntentEvent( Event ):
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031 def __init__( self ):
32 Event.__init__( self )
33 # The index of the ONOS CLI that is going to run the command
34 self.CLIIndex = 0
35
You Wang7a27f3a2016-07-05 10:12:27 -070036 def getRandomCorrespondent( self, hostA, connected=True ):
37 import random
38 if connected:
39 candidates = hostA.correspondents
40 else:
41 candidates = [ host for host in main.hosts if host not in hostA.correspondents and host != hostA ]
42 if len( candidates ) == 0:
43 return None
Jon Hall2bb3e212017-05-24 17:07:25 -070044 hostB = random.sample( candidates, 1 )[ 0 ]
You Wang7a27f3a2016-07-05 10:12:27 -070045 return hostB
46
47 def getRandomHostPair( self, connected=True ):
48 import random
49 candidateDict = {}
50 with main.variableLock:
51 for host in main.hosts:
52 correspondent = self.getRandomCorrespondent( host, connected=connected )
Jon Hall2bb3e212017-05-24 17:07:25 -070053 if correspondent is not None:
You Wang7a27f3a2016-07-05 10:12:27 -070054 candidateDict[ host ] = correspondent
55 if candidateDict == {}:
56 return None
Jon Hall2bb3e212017-05-24 17:07:25 -070057 hostA = random.sample( candidateDict.keys(), 1 )[ 0 ]
You Wang7a27f3a2016-07-05 10:12:27 -070058 hostB = candidateDict[ hostA ]
59 return [ hostA, hostB ]
60
61 def getIntentsByType( self, intentType ):
62 intents = []
63 with main.variableLock:
64 for intent in main.intents:
65 if intent.type == intentType:
66 intents.append( intent )
67 return intents
68
69 def getRandomIntentByType( self, intentType ):
70 import random
71 intents = self.getIntentsByType( intentType )
72 if len( intents ) == 0:
73 return None
74 intent = random.sample( intents, 1 )[ 0 ]
75 return intent
76
Jon Hall2bb3e212017-05-24 17:07:25 -070077
You Wangdb927a52016-02-26 11:03:28 -080078class HostIntentEvent( IntentEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070079
You Wangdb927a52016-02-26 11:03:28 -080080 def __init__( self ):
81 IntentEvent.__init__( self )
82 self.hostA = None
83 self.hostB = None
84
85 def startHostIntentEvent( self ):
86 return EventStates().PASS
87
88 def startEvent( self, args ):
89 with self.eventLock:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070090 # main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -080091 if self.typeIndex == EventType().APP_INTENT_HOST_ADD or self.typeIndex == EventType().APP_INTENT_HOST_DEL:
92 if len( args ) < 3:
93 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
94 return EventStates().ABORT
95 elif len( args ) > 3:
96 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
97 return EventStates().ABORT
You Wang59dfeb62016-07-14 09:47:33 -070098 try:
99 if args[ 0 ] == 'random' or args[ 1 ] == 'random':
100 if self.typeIndex == EventType().APP_INTENT_HOST_ADD:
101 hostPairRandom = self.getRandomHostPair( connected=False )
Jon Hall2bb3e212017-05-24 17:07:25 -0700102 if hostPairRandom is None:
You Wang59dfeb62016-07-14 09:47:33 -0700103 main.log.warn( "All host pairs are connected, aborting event" )
104 return EventStates().ABORT
105 self.hostA = hostPairRandom[ 0 ]
106 self.hostB = hostPairRandom[ 1 ]
107 elif self.typeIndex == EventType().APP_INTENT_HOST_DEL:
108 intent = self.getRandomIntentByType( 'INTENT_HOST' )
Jon Hall2bb3e212017-05-24 17:07:25 -0700109 if intent is None:
You Wang59dfeb62016-07-14 09:47:33 -0700110 main.log.warn( "No host intent for deletion, aborting event" )
111 return EventStates().ABORT
112 self.hostA = intent.hostA
113 self.hostB = intent.hostB
114 elif args[ 0 ] == args[ 1 ]:
115 main.log.warn( "%s - invalid argument: %s, %s" % ( self.typeString, args[ 0 ], args[ 1 ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800116 return EventStates().ABORT
You Wang59dfeb62016-07-14 09:47:33 -0700117 else:
118 for host in main.hosts:
119 if host.name == args[ 0 ]:
120 self.hostA = host
121 elif host.name == args[ 1 ]:
122 self.hostB = host
Jon Hall2bb3e212017-05-24 17:07:25 -0700123 if self.hostA is not None and self.hostB is not None:
You Wang59dfeb62016-07-14 09:47:33 -0700124 break
Jon Hall2bb3e212017-05-24 17:07:25 -0700125 if self.hostA is None:
You Wang59dfeb62016-07-14 09:47:33 -0700126 main.log.warn( "Host %s does not exist: " % ( args[ 0 ] ) )
127 return EventStates().ABORT
Jon Hall2bb3e212017-05-24 17:07:25 -0700128 if self.hostB is None:
You Wang59dfeb62016-07-14 09:47:33 -0700129 main.log.warn( "Host %s does not exist: " % ( args[ 1 ] ) )
130 return EventStates().ABORT
131 index = int( args[ 2 ] )
Devin Lim142b5342017-07-20 15:22:39 -0700132 if index < 1 or index > int( main.Cluster.numCtrls ):
You Wang59dfeb62016-07-14 09:47:33 -0700133 main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
You Wangdb927a52016-02-26 11:03:28 -0800134 return EventStates().ABORT
You Wang59dfeb62016-07-14 09:47:33 -0700135 if not main.controllers[ index - 1 ].isUp():
136 main.log.warn( self.typeString + " - invalid argument: onos %s is down" % ( controller.index ) )
137 return EventStates().ABORT
138 self.CLIIndex = index
139 return self.startHostIntentEvent()
140 except Exception:
141 main.log.warn( "Caught exception, aborting event" )
You Wang7a27f3a2016-07-05 10:12:27 -0700142 return EventStates().ABORT
You Wangdb927a52016-02-26 11:03:28 -0800143
Jon Hall2bb3e212017-05-24 17:07:25 -0700144
You Wangdb927a52016-02-26 11:03:28 -0800145class AddHostIntent( HostIntentEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700146
You Wangdb927a52016-02-26 11:03:28 -0800147 """
Jon Hall2bb3e212017-05-24 17:07:25 -0700148 Add a host-to-host intent ( bidirectional )
You Wangdb927a52016-02-26 11:03:28 -0800149 """
150 def __init__( self ):
151 HostIntentEvent.__init__( self )
152 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700153 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800154
155 def startHostIntentEvent( self ):
You Wang7a27f3a2016-07-05 10:12:27 -0700156 try:
Jon Hall2bb3e212017-05-24 17:07:25 -0700157 assert self.hostA is not None and self.hostB is not None
You Wang7a27f3a2016-07-05 10:12:27 -0700158 # Check whether there already exists some intent for the host pair
159 # For now we should avoid installing overlapping intents
160 for intent in main.intents:
161 if not intent.type == 'INTENT_HOST':
162 continue
163 if intent.hostA == self.hostA and intent.hostB == self.hostB or\
Jon Hall2bb3e212017-05-24 17:07:25 -0700164 intent.hostB == self.hostA and intent.hostA == self.hostB:
You Wang7a27f3a2016-07-05 10:12:27 -0700165 main.log.warn( self.typeString + " - find an exiting intent for the host pair, abort installation" )
166 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700167 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.hostA.name, self.hostB.name, self.CLIIndex ) )
You Wang7a27f3a2016-07-05 10:12:27 -0700168 controller = main.controllers[ self.CLIIndex - 1 ]
169 with controller.CLILock:
170 id = controller.CLI.addHostIntent( self.hostA.id, self.hostB.id )
Jon Hall2bb3e212017-05-24 17:07:25 -0700171 if id is None:
You Wang7a27f3a2016-07-05 10:12:27 -0700172 main.log.warn( self.typeString + " - add host intent failed" )
173 return EventStates().FAIL
174 with main.variableLock:
175 newHostIntent = HostIntent( id, self.hostA, self.hostB )
176 if self.hostA.isDown() or self.hostA.isRemoved() or self.hostB.isDown() or self.hostB.isRemoved():
177 newHostIntent.setFailed()
You Wang56577c82016-07-12 10:49:23 -0700178 else:
179 newHostIntent.setInstalled()
You Wang7a27f3a2016-07-05 10:12:27 -0700180 main.intents.append( newHostIntent )
You Wang7a27f3a2016-07-05 10:12:27 -0700181 return EventStates().PASS
182 except Exception:
183 main.log.warn( "Caught exception, aborting event" )
184 return EventStates().ABORT
You Wangdb927a52016-02-26 11:03:28 -0800185
Jon Hall2bb3e212017-05-24 17:07:25 -0700186
You Wangdb927a52016-02-26 11:03:28 -0800187class DelHostIntent( HostIntentEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700188
You Wangdb927a52016-02-26 11:03:28 -0800189 """
Jon Hall2bb3e212017-05-24 17:07:25 -0700190 Delete a host-to-host intent ( bidirectional )
You Wangdb927a52016-02-26 11:03:28 -0800191 """
192 def __init__( self ):
193 HostIntentEvent.__init__( self )
194 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700195 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800196
197 def startHostIntentEvent( self ):
You Wang7a27f3a2016-07-05 10:12:27 -0700198 try:
Jon Hall2bb3e212017-05-24 17:07:25 -0700199 assert self.hostA is not None and self.hostB is not None
You Wang7a27f3a2016-07-05 10:12:27 -0700200 targetIntent = None
201 for intent in main.intents:
202 if not intent.type == 'INTENT_HOST':
203 continue
204 if intent.hostA == self.hostA and intent.hostB == self.hostB or\
Jon Hall2bb3e212017-05-24 17:07:25 -0700205 intent.hostB == self.hostA and intent.hostA == self.hostB:
You Wang7a27f3a2016-07-05 10:12:27 -0700206 targetIntent = intent
207 break
Jon Hall2bb3e212017-05-24 17:07:25 -0700208 if targetIntent is None:
You Wang7a27f3a2016-07-05 10:12:27 -0700209 main.log.warn( self.typeString + " - intent does not exist" )
210 return EventStates().FAIL
You Wang52163202016-07-14 16:37:15 -0700211 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.hostA.name, self.hostB.name, self.CLIIndex ) )
You Wang7a27f3a2016-07-05 10:12:27 -0700212 controller = main.controllers[ self.CLIIndex - 1 ]
213 with controller.CLILock:
214 result = controller.CLI.removeIntent( targetIntent.id, purge=True )
Jon Hall2bb3e212017-05-24 17:07:25 -0700215 if result is None or result == main.FALSE:
You Wang7a27f3a2016-07-05 10:12:27 -0700216 main.log.warn( self.typeString + " - delete host intent failed" )
217 return EventStates().FAIL
218 with main.variableLock:
You Wang56577c82016-07-12 10:49:23 -0700219 targetIntent.setWithdrawn()
You Wang7a27f3a2016-07-05 10:12:27 -0700220 main.intents.remove( targetIntent )
You Wang7a27f3a2016-07-05 10:12:27 -0700221 return EventStates().PASS
222 except Exception:
223 main.log.warn( "Caught exception, aborting event" )
224 return EventStates().ABORT
You Wangdb927a52016-02-26 11:03:28 -0800225
Jon Hall2bb3e212017-05-24 17:07:25 -0700226
You Wangdb927a52016-02-26 11:03:28 -0800227class PointIntentEvent( IntentEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700228
You Wangdb927a52016-02-26 11:03:28 -0800229 def __init__( self ):
230 IntentEvent.__init__( self )
231 self.deviceA = None
232 self.deviceB = None
233
234 def startPointIntentEvent( self ):
235 return EventStates().PASS
236
237 def startEvent( self, args ):
238 with self.eventLock:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700239 # main.log.info( "%s - starting event" % ( self.typeString ) )
You Wangdb927a52016-02-26 11:03:28 -0800240 if self.typeIndex == EventType().APP_INTENT_POINT_ADD or self.typeIndex == EventType().APP_INTENT_POINT_DEL:
241 if len( args ) < 3:
242 main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) )
243 return EventStates().ABORT
You Wang7a27f3a2016-07-05 10:12:27 -0700244 elif len( args ) > 4:
You Wangdb927a52016-02-26 11:03:28 -0800245 main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) )
246 return EventStates().ABORT
You Wang59dfeb62016-07-14 09:47:33 -0700247 try:
248 if args[ 0 ] == 'random' or args[ 1 ] == 'random':
249 if self.typeIndex == EventType().APP_INTENT_POINT_ADD:
250 hostPairRandom = self.getRandomHostPair( connected=False )
Jon Hall2bb3e212017-05-24 17:07:25 -0700251 if hostPairRandom is None:
You Wang59dfeb62016-07-14 09:47:33 -0700252 main.log.warn( "All host pairs are connected, aborting event" )
253 return EventStates().ABORT
254 self.deviceA = hostPairRandom[ 0 ].device
255 self.deviceB = hostPairRandom[ 1 ].device
256 elif self.typeIndex == EventType().APP_INTENT_POINT_DEL:
257 intent = self.getRandomIntentByType( 'INTENT_POINT' )
Jon Hall2bb3e212017-05-24 17:07:25 -0700258 if intent is None:
You Wang59dfeb62016-07-14 09:47:33 -0700259 main.log.warn( "No point intent for deletion, aborting event" )
260 return EventStates().ABORT
261 self.deviceA = intent.deviceA
262 self.deviceB = intent.deviceB
263 elif args[ 0 ] == args[ 1 ]:
264 main.log.warn( "%s - invalid argument: %s" % ( self.typeString, args[ 0 ], args[ 1 ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800265 return EventStates().ABORT
You Wang7a27f3a2016-07-05 10:12:27 -0700266 else:
You Wang59dfeb62016-07-14 09:47:33 -0700267 for device in main.devices:
268 if device.name == args[ 0 ]:
269 self.deviceA = device
270 elif device.name == args[ 1 ]:
271 self.deviceB = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700272 if self.deviceA is not None and self.deviceB is not None:
You Wang59dfeb62016-07-14 09:47:33 -0700273 break
Jon Hall2bb3e212017-05-24 17:07:25 -0700274 if self.deviceA is None:
You Wang59dfeb62016-07-14 09:47:33 -0700275 main.log.warn( "Device %s does not exist: " % ( args[ 0 ] ) )
276 return EventStates().ABORT
Jon Hall2bb3e212017-05-24 17:07:25 -0700277 if self.deviceB is None:
You Wang59dfeb62016-07-14 09:47:33 -0700278 main.log.warn( "Device %s does not exist: " % ( args[ 1 ] ) )
279 return EventStates().ABORT
280 index = int( args[ 2 ] )
Devin Lim142b5342017-07-20 15:22:39 -0700281 if index < 1 or index > int( main.Cluster.numCtrls ):
You Wang59dfeb62016-07-14 09:47:33 -0700282 main.log.warn( "%s - invalid argument: %s" % ( self.typeString, index ) )
283 return EventStates().ABORT
284 if not main.controllers[ index - 1 ].isUp():
285 main.log.warn( self.typeString + " - invalid argument: onos %s is down" % ( controller.index ) )
286 return EventStates().ABORT
287 self.CLIIndex = index
288 if len( args ) == 4 and args[ 3 ] == 'bidirectional':
289 # Install point intents for both directions
290 resultA = self.startPointIntentEvent()
291 [ self.deviceA, self.deviceB ] = [ self.deviceB, self.deviceA ]
292 resultB = self.startPointIntentEvent()
293 if resultA == EventStates().PASS and resultB == EventStates().PASS:
294 return EventStates().PASS
295 else:
296 return EventStates().FAIL
297 else:
298 return self.startPointIntentEvent()
299 except Exception:
300 main.log.warn( "Caught exception, aborting event" )
301 return EventStates().ABORT
You Wangdb927a52016-02-26 11:03:28 -0800302
Jon Hall2bb3e212017-05-24 17:07:25 -0700303
You Wangdb927a52016-02-26 11:03:28 -0800304class AddPointIntent( PointIntentEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700305
You Wangdb927a52016-02-26 11:03:28 -0800306 """
307 Add a point-to-point intent
308 """
309 def __init__( self ):
310 PointIntentEvent.__init__( self )
311 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700312 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800313
314 def startPointIntentEvent( self ):
You Wang7a27f3a2016-07-05 10:12:27 -0700315 try:
Jon Hall2bb3e212017-05-24 17:07:25 -0700316 assert self.deviceA is not None and self.deviceB is not None
You Wang7a27f3a2016-07-05 10:12:27 -0700317 controller = main.controllers[ self.CLIIndex - 1 ]
You Wang59dfeb62016-07-14 09:47:33 -0700318 # TODO: support multiple hosts under one device
You Wang7a27f3a2016-07-05 10:12:27 -0700319 # Check whether there already exists some intent for the device pair
320 # For now we should avoid installing overlapping intents
321 for intent in main.intents:
322 if not intent.type == 'INTENT_POINT':
323 continue
324 if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
325 main.log.warn( self.typeString + " - find an exiting intent for the device pair, abort installation" )
326 return EventStates().ABORT
You Wang52163202016-07-14 16:37:15 -0700327 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.deviceA.name, self.deviceB.name, self.CLIIndex ) )
You Wang7a27f3a2016-07-05 10:12:27 -0700328 controller = main.controllers[ self.CLIIndex - 1 ]
329 with controller.CLILock:
You Wang7a27f3a2016-07-05 10:12:27 -0700330 srcMAC = ""
331 dstMAC = ""
332 if len( self.deviceA.hosts ) > 0:
333 srcMAC = self.deviceA.hosts[ 0 ].mac
334 if len( self.deviceB.hosts ) > 0:
335 dstMAC = self.deviceB.hosts[ 0 ].mac
You Wang59dfeb62016-07-14 09:47:33 -0700336 id = controller.CLI.addPointIntent( self.deviceA.dpid, self.deviceB.dpid, 1, 1, '', srcMAC, dstMAC )
Jon Hall2bb3e212017-05-24 17:07:25 -0700337 if id is None:
You Wang7a27f3a2016-07-05 10:12:27 -0700338 main.log.warn( self.typeString + " - add point intent failed" )
339 return EventStates().FAIL
340 with main.variableLock:
341 newPointIntent = PointIntent( id, self.deviceA, self.deviceB )
342 if self.deviceA.isDown() or self.deviceB.isDown() or self.deviceA.isRemoved() or self.deviceB.isRemoved():
343 newPointIntent.setFailed()
You Wang56577c82016-07-12 10:49:23 -0700344 else:
345 newPointIntent.setInstalled()
You Wang7a27f3a2016-07-05 10:12:27 -0700346 main.intents.append( newPointIntent )
You Wang7a27f3a2016-07-05 10:12:27 -0700347 return EventStates().PASS
348 except Exception:
349 main.log.warn( "Caught exception, aborting event" )
350 return EventStates().ABORT
You Wangdb927a52016-02-26 11:03:28 -0800351
Jon Hall2bb3e212017-05-24 17:07:25 -0700352
You Wangdb927a52016-02-26 11:03:28 -0800353class DelPointIntent( PointIntentEvent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700354
You Wangdb927a52016-02-26 11:03:28 -0800355 """
356 Delete a point-to-point intent
357 """
358 def __init__( self ):
359 PointIntentEvent.__init__( self )
360 self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ]
Jon Hall2bb3e212017-05-24 17:07:25 -0700361 self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] )
You Wangdb927a52016-02-26 11:03:28 -0800362
363 def startPointIntentEvent( self ):
You Wang7a27f3a2016-07-05 10:12:27 -0700364 try:
Jon Hall2bb3e212017-05-24 17:07:25 -0700365 assert self.deviceA is not None and self.deviceB is not None
You Wang7a27f3a2016-07-05 10:12:27 -0700366 targetIntent = None
367 for intent in main.intents:
368 if not intent.type == 'INTENT_POINT':
369 continue
370 if intent.deviceA == self.deviceA and intent.deviceB == self.deviceB:
371 targetIntent = intent
372 break
Jon Hall2bb3e212017-05-24 17:07:25 -0700373 if targetIntent is None:
You Wang7a27f3a2016-07-05 10:12:27 -0700374 main.log.warn( self.typeString + " - intent does not exist" )
375 return EventStates().FAIL
You Wang52163202016-07-14 16:37:15 -0700376 main.log.info( "Event recorded: {} {} {} {} {}".format( self.typeIndex, self.typeString, self.deviceA.name, self.deviceB.name, self.CLIIndex ) )
You Wang7a27f3a2016-07-05 10:12:27 -0700377 controller = main.controllers[ self.CLIIndex - 1 ]
378 with controller.CLILock:
379 result = controller.CLI.removeIntent( targetIntent.id, purge=True )
Jon Hall2bb3e212017-05-24 17:07:25 -0700380 if result is None or result == main.FALSE:
You Wang7a27f3a2016-07-05 10:12:27 -0700381 main.log.warn( self.typeString + " - delete point intent failed" )
382 return EventStates().FAIL
383 with main.variableLock:
You Wang56577c82016-07-12 10:49:23 -0700384 targetIntent.setWithdrawn()
You Wang7a27f3a2016-07-05 10:12:27 -0700385 main.intents.remove( targetIntent )
You Wang7a27f3a2016-07-05 10:12:27 -0700386 return EventStates().PASS
387 except Exception:
388 main.log.warn( "Caught exception, aborting event" )
389 return EventStates().ABORT