blob: 688324c335df8499c8ebf23b8e2b2b3cb30cfb35 [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 intent class for CHOTestMonkey
23Author: you@onlab.us
24"""
25from threading import Lock
26
Jon Hall2bb3e212017-05-24 17:07:25 -070027
You Wangdb927a52016-02-26 11:03:28 -080028class Controller:
Jon Hall2bb3e212017-05-24 17:07:25 -070029
You Wangdb927a52016-02-26 11:03:28 -080030 def __init__( self, index ):
31 self.default = ''
32 self.index = index
Devin Lim142b5342017-07-20 15:22:39 -070033 self.ip = main.Cluster.getIps()[ index - 1 ]
You Wangdb927a52016-02-26 11:03:28 -080034 self.CLI = None
35 self.CLILock = Lock()
36 self.status = 'up'
37
38 def setCLI( self, CLI ):
39 self.CLI = CLI
40
41 def startCLI( self ):
42 return self.CLI.startOnosCli( self.ip )
43
44 def isUp( self ):
45 return self.status == 'up'
46
47 def bringDown( self ):
48 self.status = 'down'
49
50 def bringUp( self ):
51 self.status = 'up'
52
Jon Hall2bb3e212017-05-24 17:07:25 -070053
You Wangdb927a52016-02-26 11:03:28 -080054class Intent:
Jon Hall2bb3e212017-05-24 17:07:25 -070055
You Wangdb927a52016-02-26 11:03:28 -080056 def __init__( self, id ):
57 self.default = ''
58 self.type = 'INTENT'
59 self.id = id
You Wang56577c82016-07-12 10:49:23 -070060 self.expectedState = 'UNKNOWN'
You Wangdb927a52016-02-26 11:03:28 -080061
62 def isHostIntent( self ):
63 return self.type == 'INTENT_HOST'
64
65 def isPointIntent( self ):
66 return self.type == 'INTENT_POINT'
67
You Wang2b687c02016-05-13 17:01:31 -070068 def isFailed( self ):
69 return self.expectedState == 'FAILED'
70
71 def isInstalled( self ):
72 return self.expectedState == 'INSTALLED'
73
Jon Hall2bb3e212017-05-24 17:07:25 -070074
You Wangdb927a52016-02-26 11:03:28 -080075class HostIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070076
You Wangdb927a52016-02-26 11:03:28 -080077 def __init__( self, id, hostA, hostB ):
78 Intent.__init__( self, id )
79 self.type = 'INTENT_HOST'
80 self.hostA = hostA
81 self.hostB = hostB
You Wang2b687c02016-05-13 17:01:31 -070082 self.deviceA = hostA.device
83 self.deviceB = hostB.device
You Wangdb927a52016-02-26 11:03:28 -080084
You Wang56577c82016-07-12 10:49:23 -070085 def setWithdrawn( self ):
86 self.expectedState = 'WITHDRAWN'
You Wang56577c82016-07-12 10:49:23 -070087 if self.hostB in self.hostA.correspondents:
88 self.hostA.correspondents.remove( self.hostB )
89 if self.hostA in self.hostB.correspondents:
90 self.hostB.correspondents.remove( self.hostA )
91
92 def setFailed( self ):
93 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -070094
95 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -070096 if self.expectedState == 'UNKNOWN':
97 self.hostA.correspondents.append( self.hostB )
98 self.hostB.correspondents.append( self.hostA )
You Wang56577c82016-07-12 10:49:23 -070099 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700100
You Wangdb927a52016-02-26 11:03:28 -0800101 def __str__( self ):
102 return "ID: " + self.id
103
Jon Hall2bb3e212017-05-24 17:07:25 -0700104
You Wangdb927a52016-02-26 11:03:28 -0800105class PointIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700106
You Wangdb927a52016-02-26 11:03:28 -0800107 def __init__( self, id, deviceA, deviceB ):
108 Intent.__init__( self, id )
109 self.type = 'INTENT_POINT'
110 self.deviceA = deviceA
111 self.deviceB = deviceB
112
You Wang56577c82016-07-12 10:49:23 -0700113 def setWithdrawn( self ):
114 self.expectedState = 'WITHDRAWN'
115 for hostA in self.deviceA.hosts:
116 for hostB in self.deviceB.hosts:
117 if hostB in hostA.correspondents:
118 hostA.correspondents.remove( hostB )
119
120 def setFailed( self ):
121 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -0700122
123 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -0700124 if self.expectedState == 'UNKNOWN':
125 for hostA in self.deviceA.hosts:
126 for hostB in self.deviceB.hosts:
127 hostA.correspondents.append( hostB )
You Wang56577c82016-07-12 10:49:23 -0700128 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700129
You Wangdb927a52016-02-26 11:03:28 -0800130 def __str__( self ):
131 return "ID: " + self.id