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' |
| 49 | |
| 50 | def bringUp( self ): |
| 51 | self.status = 'up' |
| 52 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 53 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 54 | class Intent: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 55 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 56 | def __init__( self, id ): |
| 57 | self.default = '' |
| 58 | self.type = 'INTENT' |
| 59 | self.id = id |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 60 | self.expectedState = 'UNKNOWN' |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 61 | |
| 62 | def isHostIntent( self ): |
| 63 | return self.type == 'INTENT_HOST' |
| 64 | |
| 65 | def isPointIntent( self ): |
| 66 | return self.type == 'INTENT_POINT' |
| 67 | |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 68 | def isFailed( self ): |
| 69 | return self.expectedState == 'FAILED' |
| 70 | |
| 71 | def isInstalled( self ): |
| 72 | return self.expectedState == 'INSTALLED' |
| 73 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 74 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 75 | class HostIntent( Intent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 76 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 77 | def __init__( self, id, hostA, hostB ): |
| 78 | Intent.__init__( self, id ) |
| 79 | self.type = 'INTENT_HOST' |
| 80 | self.hostA = hostA |
| 81 | self.hostB = hostB |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 82 | self.deviceA = hostA.device |
| 83 | self.deviceB = hostB.device |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 84 | |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 85 | def setWithdrawn( self ): |
| 86 | self.expectedState = 'WITHDRAWN' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 87 | if self.hostB in self.hostA.correspondents: |
| 88 | self.hostA.correspondents.remove( self.hostB ) |
| 89 | if self.hostA in self.hostB.correspondents: |
| 90 | self.hostB.correspondents.remove( self.hostA ) |
| 91 | |
| 92 | def setFailed( self ): |
| 93 | self.expectedState = 'FAILED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 94 | |
| 95 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 96 | if self.expectedState == 'UNKNOWN': |
| 97 | self.hostA.correspondents.append( self.hostB ) |
| 98 | self.hostB.correspondents.append( self.hostA ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 99 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 100 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 101 | def __str__( self ): |
| 102 | return "ID: " + self.id |
| 103 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 104 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 105 | class PointIntent( Intent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 106 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 107 | def __init__( self, id, deviceA, deviceB ): |
| 108 | Intent.__init__( self, id ) |
| 109 | self.type = 'INTENT_POINT' |
| 110 | self.deviceA = deviceA |
| 111 | self.deviceB = deviceB |
| 112 | |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 113 | def setWithdrawn( self ): |
| 114 | self.expectedState = 'WITHDRAWN' |
| 115 | for hostA in self.deviceA.hosts: |
| 116 | for hostB in self.deviceB.hosts: |
| 117 | if hostB in hostA.correspondents: |
| 118 | hostA.correspondents.remove( hostB ) |
| 119 | |
| 120 | def setFailed( self ): |
| 121 | self.expectedState = 'FAILED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 122 | |
| 123 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 124 | if self.expectedState == 'UNKNOWN': |
| 125 | for hostA in self.deviceA.hosts: |
| 126 | for hostB in self.deviceB.hosts: |
| 127 | hostA.correspondents.append( hostB ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 128 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 129 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 130 | def __str__( self ): |
| 131 | return "ID: " + self.id |