blob: 182ecf2dc27f045ddc17345f8c372d2a7caf65bb [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'
You Wang7d14d642019-01-23 15:10:08 -080049 main.Cluster.runningNodes[ self.index - 1 ].active = False
50 main.Cluster.reset()
You Wangdb927a52016-02-26 11:03:28 -080051
52 def bringUp( self ):
53 self.status = 'up'
You Wang7d14d642019-01-23 15:10:08 -080054 main.Cluster.runningNodes[ self.index - 1 ].active = True
55 main.Cluster.reset()
You Wangdb927a52016-02-26 11:03:28 -080056
Jon Hall2bb3e212017-05-24 17:07:25 -070057
You Wangdb927a52016-02-26 11:03:28 -080058class Intent:
Jon Hall2bb3e212017-05-24 17:07:25 -070059
You Wangdb927a52016-02-26 11:03:28 -080060 def __init__( self, id ):
61 self.default = ''
62 self.type = 'INTENT'
63 self.id = id
You Wang56577c82016-07-12 10:49:23 -070064 self.expectedState = 'UNKNOWN'
You Wangdb927a52016-02-26 11:03:28 -080065
66 def isHostIntent( self ):
67 return self.type == 'INTENT_HOST'
68
69 def isPointIntent( self ):
70 return self.type == 'INTENT_POINT'
71
You Wang2b687c02016-05-13 17:01:31 -070072 def isFailed( self ):
73 return self.expectedState == 'FAILED'
74
75 def isInstalled( self ):
76 return self.expectedState == 'INSTALLED'
77
Jon Hall2bb3e212017-05-24 17:07:25 -070078
You Wangdb927a52016-02-26 11:03:28 -080079class HostIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070080
You Wangdb927a52016-02-26 11:03:28 -080081 def __init__( self, id, hostA, hostB ):
82 Intent.__init__( self, id )
83 self.type = 'INTENT_HOST'
84 self.hostA = hostA
85 self.hostB = hostB
You Wang2b687c02016-05-13 17:01:31 -070086 self.deviceA = hostA.device
87 self.deviceB = hostB.device
You Wangdb927a52016-02-26 11:03:28 -080088
You Wang56577c82016-07-12 10:49:23 -070089 def setWithdrawn( self ):
90 self.expectedState = 'WITHDRAWN'
You Wang56577c82016-07-12 10:49:23 -070091 if self.hostB in self.hostA.correspondents:
92 self.hostA.correspondents.remove( self.hostB )
93 if self.hostA in self.hostB.correspondents:
94 self.hostB.correspondents.remove( self.hostA )
95
96 def setFailed( self ):
97 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -070098
99 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -0700100 if self.expectedState == 'UNKNOWN':
101 self.hostA.correspondents.append( self.hostB )
102 self.hostB.correspondents.append( self.hostA )
You Wang56577c82016-07-12 10:49:23 -0700103 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700104
You Wangdb927a52016-02-26 11:03:28 -0800105 def __str__( self ):
106 return "ID: " + self.id
107
Jon Hall2bb3e212017-05-24 17:07:25 -0700108
You Wangdb927a52016-02-26 11:03:28 -0800109class PointIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700110
You Wangdb927a52016-02-26 11:03:28 -0800111 def __init__( self, id, deviceA, deviceB ):
112 Intent.__init__( self, id )
113 self.type = 'INTENT_POINT'
114 self.deviceA = deviceA
115 self.deviceB = deviceB
116
You Wang56577c82016-07-12 10:49:23 -0700117 def setWithdrawn( self ):
118 self.expectedState = 'WITHDRAWN'
119 for hostA in self.deviceA.hosts:
120 for hostB in self.deviceB.hosts:
121 if hostB in hostA.correspondents:
122 hostA.correspondents.remove( hostB )
123
124 def setFailed( self ):
125 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -0700126
127 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -0700128 if self.expectedState == 'UNKNOWN':
129 for hostA in self.deviceA.hosts:
130 for hostB in self.deviceB.hosts:
131 hostA.correspondents.append( hostB )
You Wang56577c82016-07-12 10:49:23 -0700132 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700133
You Wangdb927a52016-02-26 11:03:28 -0800134 def __str__( self ):
135 return "ID: " + self.id