blob: aed7a5b9e240df7637560f737f80fef43b47a796 [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
Jon Hall2bb3e212017-05-24 17:07:25 -07007
You Wangdb927a52016-02-26 11:03:28 -08008class Controller:
Jon Hall2bb3e212017-05-24 17:07:25 -07009
You Wangdb927a52016-02-26 11:03:28 -080010 def __init__( self, index ):
11 self.default = ''
12 self.index = index
You Wang2d32ef42017-03-03 14:09:44 -080013 self.ip = main.ONOSip[ index - 1 ]
You Wangdb927a52016-02-26 11:03:28 -080014 self.CLI = None
15 self.CLILock = Lock()
16 self.status = 'up'
17
18 def setCLI( self, CLI ):
19 self.CLI = CLI
20
21 def startCLI( self ):
22 return self.CLI.startOnosCli( self.ip )
23
24 def isUp( self ):
25 return self.status == 'up'
26
27 def bringDown( self ):
28 self.status = 'down'
29
30 def bringUp( self ):
31 self.status = 'up'
32
Jon Hall2bb3e212017-05-24 17:07:25 -070033
You Wangdb927a52016-02-26 11:03:28 -080034class Intent:
Jon Hall2bb3e212017-05-24 17:07:25 -070035
You Wangdb927a52016-02-26 11:03:28 -080036 def __init__( self, id ):
37 self.default = ''
38 self.type = 'INTENT'
39 self.id = id
You Wang56577c82016-07-12 10:49:23 -070040 self.expectedState = 'UNKNOWN'
You Wangdb927a52016-02-26 11:03:28 -080041
42 def isHostIntent( self ):
43 return self.type == 'INTENT_HOST'
44
45 def isPointIntent( self ):
46 return self.type == 'INTENT_POINT'
47
You Wang2b687c02016-05-13 17:01:31 -070048 def isFailed( self ):
49 return self.expectedState == 'FAILED'
50
51 def isInstalled( self ):
52 return self.expectedState == 'INSTALLED'
53
Jon Hall2bb3e212017-05-24 17:07:25 -070054
You Wangdb927a52016-02-26 11:03:28 -080055class HostIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070056
You Wangdb927a52016-02-26 11:03:28 -080057 def __init__( self, id, hostA, hostB ):
58 Intent.__init__( self, id )
59 self.type = 'INTENT_HOST'
60 self.hostA = hostA
61 self.hostB = hostB
You Wang2b687c02016-05-13 17:01:31 -070062 self.deviceA = hostA.device
63 self.deviceB = hostB.device
You Wangdb927a52016-02-26 11:03:28 -080064
You Wang56577c82016-07-12 10:49:23 -070065 def setWithdrawn( self ):
66 self.expectedState = 'WITHDRAWN'
You Wang56577c82016-07-12 10:49:23 -070067 if self.hostB in self.hostA.correspondents:
68 self.hostA.correspondents.remove( self.hostB )
69 if self.hostA in self.hostB.correspondents:
70 self.hostB.correspondents.remove( self.hostA )
71
72 def setFailed( self ):
73 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -070074
75 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -070076 if self.expectedState == 'UNKNOWN':
77 self.hostA.correspondents.append( self.hostB )
78 self.hostB.correspondents.append( self.hostA )
You Wang56577c82016-07-12 10:49:23 -070079 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -070080
You Wangdb927a52016-02-26 11:03:28 -080081 def __str__( self ):
82 return "ID: " + self.id
83
Jon Hall2bb3e212017-05-24 17:07:25 -070084
You Wangdb927a52016-02-26 11:03:28 -080085class PointIntent( Intent ):
Jon Hall2bb3e212017-05-24 17:07:25 -070086
You Wangdb927a52016-02-26 11:03:28 -080087 def __init__( self, id, deviceA, deviceB ):
88 Intent.__init__( self, id )
89 self.type = 'INTENT_POINT'
90 self.deviceA = deviceA
91 self.deviceB = deviceB
92
You Wang56577c82016-07-12 10:49:23 -070093 def setWithdrawn( self ):
94 self.expectedState = 'WITHDRAWN'
95 for hostA in self.deviceA.hosts:
96 for hostB in self.deviceB.hosts:
97 if hostB in hostA.correspondents:
98 hostA.correspondents.remove( hostB )
99
100 def setFailed( self ):
101 self.expectedState = 'FAILED'
You Wang56577c82016-07-12 10:49:23 -0700102
103 def setInstalled( self ):
You Wangc848af12016-07-14 09:53:58 -0700104 if self.expectedState == 'UNKNOWN':
105 for hostA in self.deviceA.hosts:
106 for hostB in self.deviceB.hosts:
107 hostA.correspondents.append( hostB )
You Wang56577c82016-07-12 10:49:23 -0700108 self.expectedState = 'INSTALLED'
You Wang56577c82016-07-12 10:49:23 -0700109
You Wangdb927a52016-02-26 11:03:28 -0800110 def __str__( self ):
111 return "ID: " + self.id