Merge "ONOS-2399 Added checkLeaderChange() to FUNCintent dependencies. Implemented that function in CASE1000 of FUNCintent"
diff --git a/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py b/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py
index 545aca9..11ca425 100644
--- a/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py
+++ b/TestON/tests/FUNCintent/Dependency/FuncIntentFunction.py
@@ -1122,3 +1122,39 @@
 
     return main.TRUE
 
+def checkLeaderChange( leaders1 , leaders2 ):
+    """
+        Checks for a change in intent partition leadership.
+
+        Takes the output of leaders -c in json string format before and after
+        a potential change as input
+
+        Returns main.TRUE if no mismatches are detected
+        Returns main.FALSE if there is a mismatch or on error loading the input
+    """
+    try:
+        leaders1 = json.loads( leaders1 )
+        leaders2 = json.loads( leaders2 )
+    except ( AttributeError, TypeError):
+        main.log.exception( self.name + ": Object not as expected" )
+        return main.FALSE
+    except Exception:
+        main.log.exception( self.name + ": Uncaught exception!" )
+        main.cleanup()
+        main.exit()
+    main.log.info( "Checking Intent Paritions for Change in Leadership" )
+    mismatch = False
+    for dict1 in leaders1:
+        if "intent" in dict1.get( "topic", [] ):
+            for dict2 in leaders2:
+                if dict1.get( "topic", 0 ) == dict2.get( "topic", 0 ) and \
+                    dict1.get( "leader", 0 ) != dict2.get( "leader", 0 ):
+                    mismatch = True
+                    main.log.error( "{0} changed leader from {1} to {2}".\
+                        format( dict1.get( "topic", "no-topic" ),\
+                            dict1.get( "leader", "no-leader" ),\
+                            dict2.get( "leader", "no-leader" ) ) )
+    if mismatch:
+        return main.FALSE
+    else:
+        return main.TRUE
diff --git a/TestON/tests/FUNCintent/FUNCintent.py b/TestON/tests/FUNCintent/FUNCintent.py
index 1e10db3..2c47b4f 100644
--- a/TestON/tests/FUNCintent/FUNCintent.py
+++ b/TestON/tests/FUNCintent/FUNCintent.py
@@ -347,6 +347,8 @@
         assert main.numSwitch, "Placed the total number of switch topology in \
                                 main.numSwitch"
 
+        intentLeadersOld = main.CLIs[ 0 ].leaderCandidates()
+
         main.case( "Add host intents between 2 host" )
 
         main.step( "IPV4: Add host intents between h1 and h9" )
@@ -446,6 +448,11 @@
                                  onfail="VLAN2: Add inter vlan host" +
                                         " intent failed" )
 
+
+        intentLeadersNew = main.CLIs[ 0 ].leaderCandidates()
+        main.intentFunction.checkLeaderChange( intentLeadersOld,
+                                                intentLeadersNew )
+
     def CASE2000( self, main ):
         """
             Add point intents between 2 hosts:
@@ -638,7 +645,7 @@
                                  actual=stepResult,
                                  onpass="DUALSTACK1: Add point intent" +
                                         " successful",
-                                 onfail="DUALSTACK1: Add point intent failed" ) 
+                                 onfail="DUALSTACK1: Add point intent failed" )
 
         main.step( "VLAN: Add point intents between h5 and h21" )
         stepResult = main.TRUE
@@ -803,7 +810,7 @@
                                  onpass="VLAN: Successfully added single point"
                                         + " to multi point intents",
                                  onfail="VLAN: Failed to add single point" +
-                                        " to multi point intents" ) 
+                                        " to multi point intents" )
 
     def CASE4000( self, main ):
         """