Merge pull request #15 from OPENNETWORKINGLAB/cli_device_role

Add function for onos cli command 'Device-role'
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 419ee06..9875064 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -866,6 +866,7 @@
             2. numpy - "sudo pip install numpy"
 
         '''
+        #FIXME: this does not look for extra ports in ONOS, only checks that ONOS has what is in MN
         import json
         from numpy import uint64
         port_results = main.TRUE
@@ -932,6 +933,7 @@
         This uses the sts TestONTopology object
 
         '''
+        #FIXME: this does not look for extra links in ONOS, only checks that ONOS has what is in MN
         import json
         link_results = main.TRUE
         output = {"switches":[]}
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index eeb379f..4d4a417 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -1348,4 +1348,45 @@
             main.log.info(self.name+" ::::::")
             main.cleanup()
             main.exit()
+
+    def device_role(self, device_id, onos_node, role="master"):
+        '''
+        Calls the device-role cli command.
+        device_id must be the id of a device as seen in the onos devices command
+        onos_node is the ip of one of the onos nodes in the cluster
+        role must be either master, standby, or none
+
+        Returns main.TRUE or main.FALSE based argument varification. 
+            When device-role supports errors this should be extended to 
+            support that output
+        '''
+        #TODO: handle error messages from device-role
+        try:
+            print "beginning device_role... \n\tdevice_id:" + device_id
+            print "\tonos_node: " + onos_node
+            print "\trole: "+ role
+            if role.lower() == "master" or \
+                    role.lower() == "standby" or \
+                    role.lower() == "none":
+                        self.handle.sendline("")
+                        self.handle.expect("onos>")
+                        self.handle.sendline("device-role " + device_id + " " + onos_node +  " " + role)
+                        self.handle.expect("onos>")
+                        return main.TRUE
+            else:
+                return main.FALSE
+
+        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()
+
+
     #***********************************