Merging branch

Merge branch 'ONOS-Next' of https://github.com/OPENNETWORKINGLAB/ONLabTest into ONOS-Next
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 01e5838..44d796a 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -278,6 +278,38 @@
             main.cleanup()
             main.exit()
 
+    def nodes(self):
+        '''
+        List the nodes currently visible
+        Issues command: 'nodes'
+        Returns: entire handle of list of nodes
+        '''
+        try:
+            self.handle.sendline("")
+            self.handle.expect("onos>")
+
+            self.handle.sendline("nodes")
+            self.handle.expect("onos>")
+
+            self.handle.sendline("")
+            self.handle.expect("onos>")
+
+            handle = self.handle.before
+
+            return handle
+
+        except pexpect.EOF:
+            main.log.error(self.name + ": EOF exception found")
+            main.log.error(self.name + ":    " + self.handle.before)
+            main.cleanup()
+            main.exit()
+        except:
+            main.log.info(self.name+" ::::::")
+            main.log.error( traceback.print_exc())
+            main.log.info(self.name+" ::::::")
+            main.cleanup()
+            main.exit()
+
     def topology(self):
         '''
         Shows the current state of the topology
@@ -389,6 +421,53 @@
             handle += self.handle.after
 
             return handle
+        
+        except pexpect.EOF:
+            main.log.error(self.name + ": EOF exception found")
+            main.log.error(self.name + ":    " + self.handle.before)
+            main.cleanup()
+            main.exit()
+        except:
+            main.log.info(self.name+" ::::::")
+            main.log.error( traceback.print_exc())
+            main.log.info(self.name+" ::::::")
+            main.cleanup()
+            main.exit()
+
+    def device_role(self, device_id, node_id, role):
+        '''
+        Set device role for specified device and node with role
+        Required: 
+            * device_id : may be obtained by function get_all_devices_id
+            * node_id : may be obtained by function get_all_nodes_id
+            * role: specify one of the following roles:
+                - master
+                - standby
+                - none
+        '''
+        try:
+            self.handle.sendline("")
+            self.handle.expect("onos>")
+
+            self.handle.sendline("device-role "+
+                    str(device_id) + " " +
+                    str(node_id) + " " +
+                    str(role))
+            i = self.handle.expect([
+                "Error",
+                "onos>"])
+            
+            self.handle.sendline("")
+            self.handle.expect("onos>")
+    
+            handle = self.handle.before
+
+            if i == 0:
+                main.log.error("device-role command returned error")
+                return handle
+            else:
+                return main.TRUE 
+
         except pexpect.EOF:
             main.log.error(self.name + ": EOF exception found")
             main.log.error(self.name + ":    " + self.handle.before)
@@ -423,7 +502,7 @@
 
             if i == 0:
                 main.log.error("Error in getting paths")
-                return handle
+                return (handle, "Error")
             else:
                 path = handle.split(";")[0]
                 cost = handle.split(";")[1]
@@ -496,5 +575,43 @@
             main.cleanup()
             main.exit()
 
+    def get_all_nodes_id(self):
+        '''
+        Uses 'nodes' function to obtain list of all nodes
+        and parse the result of nodes to obtain just the
+        node id's. 
+        Returns:
+            list of node id's
+        '''
+        try:
+            nodes_str = self.nodes()
+            id_list = []
+
+            if not nodes_str:
+                main.log.info("There are no nodes to get id from")
+                return id_list
+
+            #Sample nodes_str output
+            #id=local, address=127.0.0.1:9876, state=ACTIVE *
+
+            #Split the string into list by comma
+            nodes_list = nodes_str.split(",")
+            temp_list = [node for node in nodes_list if "id=" in node]
+            for arg in temp_list:
+                id_list.append(arg.split("id=")[1])
+
+            return id_list
+        
+        except pexpect.EOF:
+            main.log.error(self.name + ": EOF exception found")
+            main.log.error(self.name + ":    " + self.handle.before)
+            main.cleanup()
+            main.exit()
+        except:
+            main.log.info(self.name+" ::::::")
+            main.log.error( traceback.print_exc())
+            main.log.info(self.name+" ::::::")
+            main.cleanup()
+            main.exit()
 
     #***********************************
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.py b/TestON/tests/ONOSNextTest/ONOSNextTest.py
index cbf8afe..4f716d9 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.py
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.py
@@ -174,7 +174,7 @@
         main.ONOScli.start_onos_cli(ONOS1_ip)
 
         main.step("issue command: onos:topology")
-        topology_obj = main.ONOScli.onos_topology()
+        topology_obj = main.ONOScli.topology()
 
         main.step("issue various feature:install <str> commands")
         main.ONOScli.feature_install("onos-app-fwd")
@@ -206,7 +206,25 @@
         (path, cost) = main.ONOScli.paths(devices_id_list[0], devices_id_list[6])
         main.log.info("Path: "+str(path))
         main.log.info("Cost: "+str(cost))
-    
+
+        main.step("Get nodes currently visible")
+        nodes_str = main.ONOScli.nodes()
+        main.log.info(nodes_str)
+
+        main.step("Get all nodes id's")
+        node_id_list = main.ONOScli.get_all_nodes_id()
+        main.log.info(node_id_list)
+
+        main.step("Set device "+str(devices_id_list[0])+" to role: standby")
+        device_role_result = main.ONOScli.device_role(
+                devices_id_list[0], node_id_list[0], "standby")
+        if device_role_result == main.TRUE:
+            main.log.report("Device role successfully set")
+
+        main.step("Check devices / role again")
+        dev_result = main.ONOScli.devices()
+        main.log.info(dev_result)
+
 ######
 #jhall@onlab.us
 #andrew@onlab.us