blob: e18e0b343476bdbe9457cfe12598a4f0f74100e9 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
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
11 (at your option) any later version.
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"""
21
22"""
You Wangdb927a52016-02-26 11:03:28 -080023This file contains intent class for CHOTestMonkey
24Author: you@onlab.us
25"""
26from threading import Lock
27
Jon Hall2bb3e212017-05-24 17:07:25 -070028
You Wangdb927a52016-02-26 11:03:28 -080029class Controller:
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031 def __init__( self, index ):
32 self.default = ''
33 self.index = index
Devin Lim142b5342017-07-20 15:22:39 -070034 self.ip = main.Cluster.getIps()[ index - 1 ]
You Wangdb927a52016-02-26 11:03:28 -080035 self.CLI = None
36 self.CLILock = Lock()
37 self.status = 'up'
38
39 def setCLI( self, CLI ):
40 self.CLI = CLI
41
42 def startCLI( self ):
43 return self.CLI.startOnosCli( self.ip )
44
45 def isUp( self ):
46 return self.status == 'up'
47
48 def bringDown( self ):
49 self.status = 'down'
50
51 def bringUp( self ):
52 self.status = 'up'
53
Jon Hall2bb3e212017-05-24 17:07:25 -070054
You Wangdb927a52016-02-26 11:03:28 -080055class Intent:
Jon Hall2bb3e212017-05-24 17:07:25 -070056
You Wangdb927a52016-02-26 11:03:28 -080057 def __init__( self, id ):
58 self.default = ''
59 self.type = 'INTENT'
60 self.id = id
You Wang56577c82016-07-12 10:49:23 -070061 self.expectedState = 'UNKNOWN'
You Wangdb927a52016-02-26 11:03:28 -080062
63 def isHostIntent( self ):
64 return self.type == 'INTENT_HOST'
65
66 def isPointIntent( self ):
67 return self.type == 'INTENT_POINT'
68
You Wang2b687c02016-05-13 17:01:31 -070069 def isFailed( self ):
70 return self.expectedState == 'FAILED'
71
72 def isInstalled( self ):
73 return self.expectedState == 'INSTALLED'
74
Jon Hall2bb3e212017-05-24 17:07:25 -070075
You Wangdb927a52016-02-26 11:03:28 -080076class HostIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070077
You Wangdb927a52016-02-26 11:03:28 -080078 def __init__( self, id, hostA, hostB ):
79 Intent.__init__( self, id )
80 self.type = 'INTENT_HOST'
81 self.hostA = hostA
82 self.hostB = hostB
You Wang2b687c02016-05-13 17:01:31 -070083 self.deviceA = hostA.device
84 self.deviceB = hostB.device
You Wangdb927a52016-02-26 11:03:28 -080085
You Wang56577c82016-07-12 10:49:23 -070086 def setWithdrawn( self ):
87 self.expectedState = 'WITHDRAWN'
You Wang56577c82016-07-12 10:49:23 -070088 if self.hostB in self.hostA.correspondents:
89 self.hostA.correspondents.remove( self.hostB )
90 if self.hostA in self.hostB.correspondents:
91 self.hostB.correspondents.remove( self.hostA )
92
93 def setFailed( self ):
94 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -070095
96 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -070097 if self.expectedState == 'UNKNOWN':
98 self.hostA.correspondents.append( self.hostB )
99 self.hostB.correspondents.append( self.hostA )
You Wang56577c82016-07-12 10:49:23 -0700100 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700101
You Wangdb927a52016-02-26 11:03:28 -0800102 def __str__( self ):
103 return "ID: " + self.id
104
Jon Hall2bb3e212017-05-24 17:07:25 -0700105
You Wangdb927a52016-02-26 11:03:28 -0800106class PointIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -0700107
You Wangdb927a52016-02-26 11:03:28 -0800108 def __init__( self, id, deviceA, deviceB ):
109 Intent.__init__( self, id )
110 self.type = 'INTENT_POINT'
111 self.deviceA = deviceA
112 self.deviceB = deviceB
113
You Wang56577c82016-07-12 10:49:23 -0700114 def setWithdrawn( self ):
115 self.expectedState = 'WITHDRAWN'
116 for hostA in self.deviceA.hosts:
117 for hostB in self.deviceB.hosts:
118 if hostB in hostA.correspondents:
119 hostA.correspondents.remove( hostB )
120
121 def setFailed( self ):
122 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -0700123
124 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -0700125 if self.expectedState == 'UNKNOWN':
126 for hostA in self.deviceA.hosts:
127 for hostB in self.deviceB.hosts:
128 hostA.correspondents.append( hostB )
You Wang56577c82016-07-12 10:49:23 -0700129 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700130
You Wangdb927a52016-02-26 11:03:28 -0800131 def __str__( self ):
132 return "ID: " + self.id