Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 1 | """ |
| 2 | These functions are for use with the Network config system |
| 3 | """ |
| 4 | import time |
| 5 | |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 6 | |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 7 | def compareCfg( main, gossipTime=None ): |
| 8 | """ |
| 9 | Compare the network configurations across all nodes in the network |
| 10 | gossipTime is the number of seconds each gossip round take for the netCfg maps |
| 11 | """ |
| 12 | main.step( "Check net config" ) |
| 13 | if gossipTime: |
| 14 | time.sleep( gossipTime * len( main.nodes ) ) |
| 15 | responses = [] |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 16 | result = utilities.retry( f=checkNodeResponses, |
| 17 | retValue=False, |
| 18 | kwargs={'main' : main,'responses' : responses}, |
| 19 | sleep = main.retrysleep, |
| 20 | attempts = main.retrytimes ) |
| 21 | utilities.assert_equals( expect=True, |
| 22 | actual=result, |
| 23 | onpass="Net Cfg is the same on all nodes", |
| 24 | onfail="Check Net Cfg failed. Check above messages." ) |
| 25 | |
| 26 | |
| 27 | def checkNodeResponses ( main, responses ): |
| 28 | numberOfFailedNodes = 0 # Tracks the number of nodes that failed to get net configuration |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 29 | for node in main.nodes: |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 30 | response = node.getNetCfg( ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 31 | responses.append( node.pprint( response ) ) |
| 32 | if response == main.FALSE: |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 33 | numberOfFailedNodes += 1 |
| 34 | |
Jon Hall | bc080f9 | 2017-05-24 16:29:55 -0700 | [diff] [blame] | 35 | compare = [ i == responses[ 0 ] for i in responses ] |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 36 | if numberOfFailedNodes == 0 and all( compare ): |
| 37 | return True |
| 38 | |
| 39 | # Failed, providing feedback on cli |
| 40 | if numberOfFailedNodes > 0: |
| 41 | main.log.warn( numberOfFailedNodes + " node(s) failed to GET Net Config" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 42 | if not all( compare ): |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 43 | main.log.debug( "Net Cfg is different on some nodes. Net Config results:" ) |
Jon Hall | 66e001c | 2015-11-12 09:45:10 -0800 | [diff] [blame] | 44 | for i in responses: |
| 45 | main.log.debug( i ) |
Jeremy Ronquillo | 4a30ffe | 2017-06-07 11:36:35 -0700 | [diff] [blame] | 46 | return False |