You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2018 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 | import json |
| 22 | class Network(): |
| 23 | |
| 24 | def __str__( self ): |
| 25 | return self.name |
| 26 | |
| 27 | def __repr__( self ): |
| 28 | return "%s:%s" % ( self.name, self.components ) |
| 29 | |
| 30 | def __getattr__( self, name ): |
| 31 | """ |
| 32 | Called when an attribute lookup has not found the attribute |
| 33 | in the usual places (i.e. it is not an instance attribute nor |
| 34 | is it found in the class tree for self). name is the attribute |
| 35 | name. This method should return the (computed) attribute value |
| 36 | or raise an AttributeError exception. |
| 37 | |
| 38 | We will look into each of the network component handles to try |
| 39 | to find the attreibute. |
| 40 | """ |
| 41 | #FIXME: allow to call a specific driver |
| 42 | for component in self.components: |
| 43 | if hasattr( component, name ): |
| 44 | main.log.debug( "%s has attribute '%s'" % ( component.options[ 'name' ], name ) ) |
| 45 | return getattr( component, name ) |
| 46 | raise AttributeError( "Could not find attribute '%s' in any of these components: %s" % ( name, self.components ) ) |
| 47 | |
| 48 | def __init__( self, name="Network" ): |
| 49 | """ |
| 50 | components: network components created for the test |
| 51 | """ |
| 52 | self.name = str( name ) |
| 53 | # Get a list of network components that are created in the test |
| 54 | self.components = [] |
| 55 | for key, value in main.componentDictionary.items(): |
| 56 | if value[ 'type' ] in [ 'MininetCliDriver', 'RemoteMininetDriver', 'NetworkDriver' ] and hasattr( main, key ): |
| 57 | self.components.append( getattr( main, key ) ) |
| 58 | main.log.debug( "%s initialized with components: %s" % ( self.name, self.components ) ) |