blob: 0cc46e8b82d078b7b2def40ddddf754e6d2a8e65 [file] [log] [blame]
Jon Hall66e001c2015-11-12 09:45:10 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or 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 These functions are for use with the Network config system
Jon Hall66e001c2015-11-12 09:45:10 -080023"""
24import time
25
Jon Hallbc080f92017-05-24 16:29:55 -070026
Jon Hall66e001c2015-11-12 09:45:10 -080027def compareCfg( main, gossipTime=None ):
28 """
29 Compare the network configurations across all nodes in the network
30 gossipTime is the number of seconds each gossip round take for the netCfg maps
31 """
32 main.step( "Check net config" )
33 if gossipTime:
Devin Lim142b5342017-07-20 15:22:39 -070034 time.sleep( gossipTime * main.Cluster.numCtrls )
Jon Hall66e001c2015-11-12 09:45:10 -080035 responses = []
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070036 result = utilities.retry( f=checkNodeResponses,
37 retValue=False,
38 kwargs={'main' : main,'responses' : responses},
39 sleep = main.retrysleep,
40 attempts = main.retrytimes )
41 utilities.assert_equals( expect=True,
42 actual=result,
43 onpass="Net Cfg is the same on all nodes",
44 onfail="Check Net Cfg failed. Check above messages." )
45
46
47def checkNodeResponses ( main, responses ):
48 numberOfFailedNodes = 0 # Tracks the number of nodes that failed to get net configuration
Devin Lim142b5342017-07-20 15:22:39 -070049 for ctrl in main.Cluster.active():
50 response = ctrl.REST.getNetCfg( )
51 responses.append( ctrl.REST.pprint( response ) )
Jon Hall66e001c2015-11-12 09:45:10 -080052 if response == main.FALSE:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070053 numberOfFailedNodes += 1
54
Jon Hallbc080f92017-05-24 16:29:55 -070055 compare = [ i == responses[ 0 ] for i in responses ]
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070056 if numberOfFailedNodes == 0 and all( compare ):
57 return True
58
59 # Failed, providing feedback on cli
60 if numberOfFailedNodes > 0:
61 main.log.warn( numberOfFailedNodes + " node(s) failed to GET Net Config" )
Jon Hall66e001c2015-11-12 09:45:10 -080062 if not all( compare ):
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070063 main.log.debug( "Net Cfg is different on some nodes. Net Config results:" )
Jon Hall66e001c2015-11-12 09:45:10 -080064 for i in responses:
65 main.log.debug( i )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070066 return False
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -070067
68def checkDeviceAnnotations( main, jsonObj, sw ):
69 id = str( sw.get( 'id' ) )
70 keys = [ 'name', 'owner', 'rackAddress' ]
71 correct = True
72 for k in keys:
73 if str( sw.get( 'annotations', {} ).get( k ) ) != str( jsonObj[ k ] ) :
74 correct = False
75 main.log.debug( "{} is wrong on switch: ".format( k ) + id )
76 if not correct:
77 main.log.error( "Annotations for switch " + id + " are incorrect: {}".format( sw ) )
78 return correct
79
80
81def checkAllDeviceAnnotations( main, json ):
Devin Lim142b5342017-07-20 15:22:39 -070082 devices = main.Cluster.active( 0 ).REST.devices( )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -070083 id = "of:0000000000000001"
84 i = 1
85 result = [ ]
86 try:
87 for sw in json.loads( devices ):
88 if id in sw.get( 'id' ):
89 jsonObj = getattr( main, "s" + str( i ) + "Json" )
90 isDeviceAnnotationCorrect = checkDeviceAnnotations( main, jsonObj, sw )
91 result.append( isDeviceAnnotationCorrect )
92 i += 1
93 id = "of:000000000000000" + str( i )
94 except( TypeError, ValueError ):
95 main.log.error( "Problem loading device" )
96 return False
97 return all( result )