blob: e9dff2957d63e33c1eb8ba9694959dfed5919b16 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2This file contains intent class for CHOTestMonkey
3Author: you@onlab.us
4"""
5from threading import Lock
6
7class Controller:
8 def __init__( self, index ):
9 self.default = ''
10 self.index = index
11 self.ip = main.onosIPs[ index - 1 ]
12 self.CLI = None
13 self.CLILock = Lock()
14 self.status = 'up'
15
16 def setCLI( self, CLI ):
17 self.CLI = CLI
18
19 def startCLI( self ):
20 return self.CLI.startOnosCli( self.ip )
21
22 def isUp( self ):
23 return self.status == 'up'
24
25 def bringDown( self ):
26 self.status = 'down'
27
28 def bringUp( self ):
29 self.status = 'up'
30
31class Intent:
32 def __init__( self, id ):
33 self.default = ''
34 self.type = 'INTENT'
35 self.id = id
You Wang56577c82016-07-12 10:49:23 -070036 self.expectedState = 'UNKNOWN'
You Wangdb927a52016-02-26 11:03:28 -080037
38 def isHostIntent( self ):
39 return self.type == 'INTENT_HOST'
40
41 def isPointIntent( self ):
42 return self.type == 'INTENT_POINT'
43
You Wang2b687c02016-05-13 17:01:31 -070044 def isFailed( self ):
45 return self.expectedState == 'FAILED'
46
47 def isInstalled( self ):
48 return self.expectedState == 'INSTALLED'
49
You Wangdb927a52016-02-26 11:03:28 -080050class HostIntent( Intent ):
51 def __init__( self, id, hostA, hostB ):
52 Intent.__init__( self, id )
53 self.type = 'INTENT_HOST'
54 self.hostA = hostA
55 self.hostB = hostB
You Wang2b687c02016-05-13 17:01:31 -070056 self.deviceA = hostA.device
57 self.deviceB = hostB.device
You Wangdb927a52016-02-26 11:03:28 -080058
You Wang56577c82016-07-12 10:49:23 -070059 def setWithdrawn( self ):
60 self.expectedState = 'WITHDRAWN'
You Wang56577c82016-07-12 10:49:23 -070061 if self.hostB in self.hostA.correspondents:
62 self.hostA.correspondents.remove( self.hostB )
63 if self.hostA in self.hostB.correspondents:
64 self.hostB.correspondents.remove( self.hostA )
65
66 def setFailed( self ):
67 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -070068
69 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -070070 if self.expectedState == 'UNKNOWN':
71 self.hostA.correspondents.append( self.hostB )
72 self.hostB.correspondents.append( self.hostA )
You Wang56577c82016-07-12 10:49:23 -070073 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -070074
You Wangdb927a52016-02-26 11:03:28 -080075 def __str__( self ):
76 return "ID: " + self.id
77
78class PointIntent( Intent ):
79 def __init__( self, id, deviceA, deviceB ):
80 Intent.__init__( self, id )
81 self.type = 'INTENT_POINT'
82 self.deviceA = deviceA
83 self.deviceB = deviceB
84
You Wang56577c82016-07-12 10:49:23 -070085 def setWithdrawn( self ):
86 self.expectedState = 'WITHDRAWN'
87 for hostA in self.deviceA.hosts:
88 for hostB in self.deviceB.hosts:
89 if hostB in hostA.correspondents:
90 hostA.correspondents.remove( hostB )
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 for hostA in self.deviceA.hosts:
98 for hostB in self.deviceB.hosts:
99 hostA.correspondents.append( hostB )
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