You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or 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 Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 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 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 21 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 22 | This file contains intent class for CHOTestMonkey |
| 23 | Author: you@onlab.us |
| 24 | """ |
| 25 | from threading import Lock |
| 26 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 27 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 28 | class Controller: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 29 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 30 | def __init__( self, index ): |
| 31 | self.default = '' |
| 32 | self.index = index |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 33 | self.ip = main.Cluster.getIps()[ index - 1 ] |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 34 | 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 Wang | 7d14d64 | 2019-01-23 15:10:08 -0800 | [diff] [blame] | 49 | main.Cluster.runningNodes[ self.index - 1 ].active = False |
| 50 | main.Cluster.reset() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 51 | |
| 52 | def bringUp( self ): |
| 53 | self.status = 'up' |
You Wang | 7d14d64 | 2019-01-23 15:10:08 -0800 | [diff] [blame] | 54 | main.Cluster.runningNodes[ self.index - 1 ].active = True |
| 55 | main.Cluster.reset() |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 56 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 57 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 58 | class Intent: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 59 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 60 | def __init__( self, id ): |
| 61 | self.default = '' |
| 62 | self.type = 'INTENT' |
| 63 | self.id = id |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 64 | self.expectedState = 'UNKNOWN' |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 65 | |
| 66 | def isHostIntent( self ): |
| 67 | return self.type == 'INTENT_HOST' |
| 68 | |
| 69 | def isPointIntent( self ): |
| 70 | return self.type == 'INTENT_POINT' |
| 71 | |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 72 | def isFailed( self ): |
| 73 | return self.expectedState == 'FAILED' |
| 74 | |
| 75 | def isInstalled( self ): |
| 76 | return self.expectedState == 'INSTALLED' |
| 77 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 78 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 79 | class HostIntent( Intent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 80 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 81 | 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 Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 86 | self.deviceA = hostA.device |
| 87 | self.deviceB = hostB.device |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 88 | |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 89 | def setWithdrawn( self ): |
| 90 | self.expectedState = 'WITHDRAWN' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 91 | 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 98 | |
| 99 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 100 | if self.expectedState == 'UNKNOWN': |
| 101 | self.hostA.correspondents.append( self.hostB ) |
| 102 | self.hostB.correspondents.append( self.hostA ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 103 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 104 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 105 | def __str__( self ): |
| 106 | return "ID: " + self.id |
| 107 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 108 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 109 | class PointIntent( Intent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 110 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 111 | 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 117 | 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 126 | |
| 127 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 128 | if self.expectedState == 'UNKNOWN': |
| 129 | for hostA in self.deviceA.hosts: |
| 130 | for hostB in self.deviceB.hosts: |
| 131 | hostA.correspondents.append( hostB ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 132 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 133 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 134 | def __str__( self ): |
| 135 | return "ID: " + self.id |