ONOS-2483 Added checkMasters and checkBalanceMasters functions
Added master information printout and error message for failure case
Change-Id: I76c2873c7fda7d15d2586b3b2cfe2c5506374ff8
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index f991b09..e8e5d64 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -677,6 +677,70 @@
main.cleanup()
main.exit()
+ def checkMasters( self,jsonFormat=True ):
+ """
+ Returns the output of the masters command.
+ Optional argument:
+ * jsonFormat - boolean indicating if you want output in json
+ """
+ try:
+ cmdStr = "onos:masters"
+ if jsonFormat:
+ cmdStr += " -j"
+ output = self.sendline( cmdStr )
+ return output
+ except TypeError:
+ main.log.exception( self.name + ": Object not as expected" )
+ return None
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
+ def checkBalanceMasters( self,jsonFormat=True ):
+ """
+ Uses the master command to check that the devices' leadership
+ is evenly divided
+
+ Dependencies: checkMasters() and summary()
+
+ Returns main.True if the devices are balanced
+ Returns main.False if the devices are unbalanced
+ Exits on Exception
+ Returns None on TypeError
+ """
+ try:
+ totalDevices = json.loads( self.summary() )[ "devices" ]
+ totalOwnedDevices = 0
+ masters = json.loads( self.checkMasters() )
+ first = masters[ 0 ][ "size" ]
+ for master in masters:
+ totalOwnedDevices += master[ "size" ]
+ if master[ "size" ] > first + 1 or master[ "size" ] < first - 1:
+ main.log.error( "Mastership not balanced" )
+ main.log.info( "\n" + self.checkMasters( False ) )
+ return main.FALSE
+ main.log.info( "Mastership balanced between " \
+ + str( len(masters) ) + " masters" )
+ return main.TRUE
+ except TypeError:
+ main.log.exception( self.name + ": Object not as expected" )
+ return None
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
def links( self, jsonFormat=True ):
"""
Lists all core links