Automating tests for SRBridging

Change-Id: Ia6a215a96b51f44d8ab2ad24aca20d56eba05290
diff --git a/TestON/drivers/common/api/controller/onosrestdriver.py b/TestON/drivers/common/api/controller/onosrestdriver.py
index 403b436..5ab27a7 100755
--- a/TestON/drivers/common/api/controller/onosrestdriver.py
+++ b/TestON/drivers/common/api/controller/onosrestdriver.py
@@ -1598,11 +1598,12 @@
                 port = self.port
             url = "/network/configuration"
             if subjectClass:
-                url += "/" + subjectClass
+                url += "/" + self.checkRegex( subjectClass )
                 if subjectKey:
-                    url += "/" + subjectKey
+                    url += "/" + self.checkRegex( subjectKey )
                     if configKey:
-                        url += "/" + configKey
+                        url += "/" + self.checkRegex( configKey )
+            url = requests.utils.quote( url, safe="%/" )
             response = self.send( url=url, ip = ip, port = port )
             if response:
                 if 200 <= response[ 0 ] <= 299:
@@ -1625,6 +1626,10 @@
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanAndExit()
 
+    def checkRegex( self, inputStr ):
+        res = inputStr.replace('/', '%2f')
+        return res
+
     def setNetCfg( self, cfgJson, ip="DEFAULT", port="DEFAULT",
                    subjectClass=None, subjectKey=None, configKey=None ):
         """
@@ -1647,11 +1652,12 @@
                 port = self.port
             url = "/network/configuration"
             if subjectClass:
-                url += "/" + subjectClass
+                url += "/" + self.checkRegex( subjectClass )
                 if subjectKey:
-                    url += "/" + subjectKey
+                    url += "/" + self.checkRegex( subjectKey )
                     if configKey:
-                        url += "/" + configKey
+                        url += "/" + self.checkRegex( configKey )
+            url = requests.utils.quote( url, safe="%/" )
             response = self.send( method="POST",
                                   url=url, ip = ip, port = port,
                                   data=json.dumps( cfgJson ) )
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino
index b116f3c..51490de 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params.tofino
@@ -1,5 +1,5 @@
 <PARAMS>
-    <testcases>3</testcases>
+    <testcases>9,19,29,39,49,59,69,79</testcases>
 
     <GRAPH>
         <nodeCluster>QA-Pod</nodeCluster>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.2x2.physical b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.2x2.physical
index 9f7e105..e4a823b 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.2x2.physical
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.topo.2x2.physical
@@ -15,6 +15,8 @@
                 <diff_clihost>True</diff_clihost> # if it has different host other than localhost for CLI. True or empty. OC# will be used if True.
                 <karaf_username>karaf</karaf_username>
                 <karaf_password>karaf</karaf_password>
+                <node_username>sdn</node_username>
+                <node_password>rocks</node_password>
                 <karafPrompt_username>karaf</karafPrompt_username>
                 <karafPrompt_password>karaf</karafPrompt_password>
                 <web_user>karaf</web_user>
@@ -22,7 +24,7 @@
                 <rest_port></rest_port>
                 <prompt></prompt>  # TODO: we technically need a few of these, one per component
                 <onos_home></onos_home>  # defines where onos home is on the target cell machine. Defaults to entry in "home" if empty.
-                <nodes> 7 </nodes>  # number of nodes in the cluster
+                <nodes> 3 </nodes>  # number of nodes in the cluster
             </COMPONENTS>
         </ONOScell>
 
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py
index 4e5e5fb..458a4a7 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/SRBridgingTest.py
@@ -34,6 +34,7 @@
         self.switchNames[ '2x2' ] = [ "leaf1", "leaf2", "spine101", "spine102" ]
         main.switchType = "ovs"
 
+
     def runTest( self, main, test_idx, topology, onosNodes, description, vlan = [] ):
         try:
             skipPackage = False
@@ -93,7 +94,12 @@
             else:
                 # Run the test with physical devices
                 run.connectToPhysicalNetwork( main, hostDiscovery=False )  # We don't want to do host discovery in the pod
-
+                if main.cfgName:
+                    returnValue = run.loadNewJson( main )
+                    utilities.assert_equals( expect=main.TRUE,
+                                 actual=returnValue,
+                                 onpass="Successfully changed network config",
+                                 onfail="Failed to changed network config" )
             run.checkFlows( main, minFlowCount=self.topo[ topology ][ 'minFlow-Stratum' if main.useBmv2 else 'minFlow-OvS' ] * self.topo[ topology ][ 'leaves' ], sleep=5 )
             if main.useBmv2:
                 switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', '' )
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE09.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE09.cfg
index 3300a4b..ced0429 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE09.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE09.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -20,3 +21,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE19.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE19.cfg
index 352ba54..7fe7a67 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE19.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE19.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -20,3 +21,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE29.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE29.cfg
index 9f97e82..c09601a 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE29.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE29.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -22,3 +23,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE39.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE39.cfg
index 6948335..ea119ca 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE39.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE39.cfg
@@ -1,3 +1,4 @@
+{
 "ports":{
         "device:leaf1/56":{
             "interfaces":[
@@ -23,3 +24,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE49.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE49.cfg
index 89ceb77..fee5e68 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE49.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE49.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -9,7 +10,7 @@
                 }
             ]
         },
-         "decive:leaf1/56":
+         "device:leaf1/56":
 {           "interfaces":[
                 {
                     "ips":[
@@ -20,3 +21,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE59.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE59.cfg
index 8c462ce..7dfc797 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE59.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE59.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -20,3 +21,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE69.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE69.cfg
index 352ba54..7fe7a67 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE69.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE69.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -20,3 +21,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE79.cfg b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE79.cfg
index b3b04f2..d3a7412 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE79.cfg
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/dependencies/netcfg/CASE79.cfg
@@ -1,5 +1,6 @@
+{
 "ports":{
-        "decive:leaf1/56":{
+        "device:leaf1/56":{
             "interfaces":[
                 {
                     "ips":[
@@ -20,3 +21,4 @@
             ]
         }
     }
+}
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
index bc4bea6..6d1d21f 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
@@ -75,6 +75,7 @@
             main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/"
             main.bmv2Path = "/tools/dev/mininet/"
             main.forJson = "json/"
+            main.forcfg = "netcfg/"
             main.forChart = "chart/"
             main.forConfig = "conf/"
             main.forHost = "host/"
@@ -214,6 +215,28 @@
             main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
 
     @staticmethod
+    def loadNewJson( main, suffix='' ):
+        returnValue = main.TRUE
+        with open( "%s%s.cfg%s" % ( main.configPath + main.forcfg,
+                                     main.cfgName, suffix ) ) as cfg:
+            desiredJSON = json.load ( cfg )
+            for device in desiredJSON ["ports"].keys():
+                deviceCfg = desiredJSON[ "ports" ][ device ]
+                currentJSON = main.Cluster.active( 0 ).REST.getNetCfg( subjectClass = "ports", subjectKey = device )
+
+                currentJSON = json.loads( currentJSON )
+                if currentJSON['interfaces'][0]['ips'] != deviceCfg['interfaces'][0]['ips']:
+                    currentJSON['interfaces'][0]['ips'] == deviceCfg['interfaces'][0]['ips']
+                    data = { 'interfaces': currentJSON['interfaces'] }
+                    A = main.Cluster.active( 0 ).REST.setNetCfg(  data , subjectClass = "ports", subjectKey = device )
+                    returnValue = returnValue and A
+                currentJSON['interfaces'] = deviceCfg['interfaces']
+                data = { 'interfaces': currentJSON['interfaces'] }
+                B = main.Cluster.active( 0 ).REST.setNetCfg( data , subjectClass = "ports", subjectKey = device )
+                returnValue = returnValue and B
+        return returnValue
+
+    @staticmethod
     def loadXconnects( main, suffix='' ):
         with open( "%s%s-xconnects.json%s" % ( main.configPath + main.forJson,
                                      main.cfgName, suffix ) ) as cfg: