You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 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 |
| 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 Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 23 | This file contains intent class for CHOTestMonkey |
| 24 | Author: you@onlab.us |
| 25 | """ |
| 26 | from threading import Lock |
| 27 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 28 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 29 | class Controller: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 30 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 31 | def __init__( self, index ): |
| 32 | self.default = '' |
| 33 | self.index = index |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame^] | 34 | self.ip = main.Cluster.getIps()[ index - 1 ] |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 35 | 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 Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 54 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 55 | class Intent: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 56 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 57 | def __init__( self, id ): |
| 58 | self.default = '' |
| 59 | self.type = 'INTENT' |
| 60 | self.id = id |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 61 | self.expectedState = 'UNKNOWN' |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 62 | |
| 63 | def isHostIntent( self ): |
| 64 | return self.type == 'INTENT_HOST' |
| 65 | |
| 66 | def isPointIntent( self ): |
| 67 | return self.type == 'INTENT_POINT' |
| 68 | |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 69 | def isFailed( self ): |
| 70 | return self.expectedState == 'FAILED' |
| 71 | |
| 72 | def isInstalled( self ): |
| 73 | return self.expectedState == 'INSTALLED' |
| 74 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 75 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 76 | class HostIntent( Intent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 77 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 78 | 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 Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 83 | self.deviceA = hostA.device |
| 84 | self.deviceB = hostB.device |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 85 | |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 86 | def setWithdrawn( self ): |
| 87 | self.expectedState = 'WITHDRAWN' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 88 | 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 95 | |
| 96 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 97 | if self.expectedState == 'UNKNOWN': |
| 98 | self.hostA.correspondents.append( self.hostB ) |
| 99 | self.hostB.correspondents.append( self.hostA ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 100 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 101 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 102 | def __str__( self ): |
| 103 | return "ID: " + self.id |
| 104 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 105 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 106 | class PointIntent( Intent ): |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 107 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 108 | 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 114 | 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 Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 123 | |
| 124 | def setInstalled( self ): |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 125 | if self.expectedState == 'UNKNOWN': |
| 126 | for hostA in self.deviceA.hosts: |
| 127 | for hostB in self.deviceB.hosts: |
| 128 | hostA.correspondents.append( hostB ) |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 129 | self.expectedState = 'INSTALLED' |
You Wang | 56577c8 | 2016-07-12 10:49:23 -0700 | [diff] [blame] | 130 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 131 | def __str__( self ): |
| 132 | return "ID: " + self.id |