Added logic to remove the ansi color esacpe sequence from devices(), links(), ports() functions
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 03fc5ca..9c48e32 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -163,7 +163,6 @@
pattern = 'Results\:\s0\%\sdropped\s'
#FIXME:Pending Mininet Pull Request #408
#pattern = 'Results\:\s0\.00\%\sdropped\s'
- print response
#if utilities.assert_matches(expect=pattern,actual=response,onpass="All hosts are reaching",onfail="Unable to reach all the hosts"):
if re.search(pattern,response):
main.log.info(self.name+": All hosts are reachable")
@@ -799,6 +798,62 @@
main.cleanup()
main.exit()
+ def compare_switches(self, topo, switches_json):
+ '''
+ Compare mn and onos switches
+ topo: sts TestONTopology object
+ switches_json: parsed json object from the onos devices api
+
+ This uses the sts TestONTopology object
+
+ '''
+ import json
+ results = main.TRUE
+ output = {"switches":[]}
+ for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
+ #print vars(switch)
+ ports = []
+ for port in switch.ports.values():
+ #print port.hw_addr.toStr(separator = '')
+ ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
+ output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
+ #print output
+
+ #print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))
+
+
+ # created sorted list of dpid's in MN and ONOS for comparison
+ mnDPIDs=[]
+ for switch in output['switches']:
+ mnDPIDs.append(switch['dpid'])
+ mnDPIDs.sort()
+ #print mnDPIDs
+ if switches_json == "":#if rest call fails
+ main.log.error(self.name + ".compare_topo(): Empty JSON object given from ONOS")
+ return main.FALSE
+ onos=switches_json
+ onosDPIDs=[]
+ for switch in onos:
+ onosDPIDs.append(switch['id'].replace(":",'').replace("of",''))
+ #print switch
+ onosDPIDs.sort()
+ #print onosDPIDs
+
+ if mnDPIDs!=onosDPIDs:
+ switch_results = main.FALSE
+ main.log.report( "Switches in MN but not in ONOS:")
+ main.log.report( str([switch for switch in mnDPIDs if switch not in onosDPIDs]))
+ main.log.report( "Switches in ONOS but not in MN:")
+ main.log.report( str([switch for switch in onosDPIDs if switch not in mnDPIDs]))
+ else:#list of dpid's match in onos and mn
+ #main.log.report("DEBUG: The dpid's of the switches in Mininet and ONOS match")
+ switch_results = main.TRUE
+ return switch_results
+
+
+
+
+
def compare_topo(self, topo, onos_json):
'''
compares mn topology with ONOS topology
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 593927b..3318f71 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -426,16 +426,25 @@
else:
if not grep_str:
self.handle.sendline("devices")
- self.handle.expect("devices")
+ self.handle.expect("onos>")
+ self.handle.sendline("")
self.handle.expect("onos>")
else:
self.handle.sendline("devices | grep '"+
str(grep_str)+"'")
- self.handle.expect("devices | grep '"+str(grep_str)+"'")
self.handle.expect("onos>")
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+<<<<<<< HEAD
handle = self.handle.before
print "handle =",handle
return handle
+=======
+
+ handle = self.handle.before
+
+ return handle
+>>>>>>> d1192e144d179c68864828aa6a339764d69d1216
except pexpect.EOF:
main.log.error(self.name + ": EOF exception found")
main.log.error(self.name + ": " + self.handle.before)
@@ -448,7 +457,6 @@
main.cleanup()
main.exit()
-
def links(self, json_format=True, grep_str=""):
'''
Lists all core links
@@ -478,17 +486,25 @@
else:
if not grep_str:
self.handle.sendline("links")
- self.handle.expect("links")
+ self.handle.expect("onos>")
+ self.handle.sendline("")
self.handle.expect("onos>")
else:
self.handle.sendline("links | grep '"+
str(grep_str)+"'")
- self.handle.expect("links | grep '"+str(grep_str)+"'")
+ self.handle.expect("onos>")
+ self.handle.sendline("")
self.handle.expect("onos>")
+<<<<<<< HEAD
handle = self.handle.before
print "handle =",handle
return handle
+=======
+ handle = self.handle.before
+
+ return handle
+>>>>>>> d1192e144d179c68864828aa6a339764d69d1216
except pexpect.EOF:
main.log.error(self.name + ": EOF exception found")
main.log.error(self.name + ": " + self.handle.before)
@@ -531,16 +547,25 @@
else:
if not grep_str:
self.handle.sendline("ports")
- self.handle.expect("ports")
+ self.handle.expect("onos>")
+ self.handle.sendline("")
self.handle.expect("onos>")
else:
self.handle.sendline("ports | grep '"+
str(grep_str)+"'")
- self.handle.expect("ports | grep '"+str(grep_str)+"'")
self.handle.expect("onos>")
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+<<<<<<< HEAD
handle = self.handle.before
print "handle =",handle
return handle
+=======
+
+ handle = self.handle.before
+
+ return handle
+>>>>>>> d1192e144d179c68864828aa6a339764d69d1216
except pexpect.EOF:
main.log.error(self.name + ": EOF exception found")
main.log.error(self.name + ": " + self.handle.before)
@@ -688,6 +713,157 @@
main.cleanup()
main.exit()
+ def add_host_intent(self, host_id_one, host_id_two):
+ '''
+ Required:
+ * host_id_one: ONOS host id for host1
+ * host_id_two: ONOS host id for host2
+ Description:
+ Adds a host-to-host intent (bidrectional) by
+ specifying the two hosts.
+ '''
+ try:
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+
+ self.handle.sendline("add-host-intent "+
+ str(host_id_one) + " " + str(host_id_two))
+ self.handle.expect("onos>")
+
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+
+ handle = self.handle.before
+
+ main.log.info("Intent installed between "+
+ str(host_id_one) + " and " + str(host_id_two))
+
+ 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 add_point_intent(self, ingress_device, port_ingress,
+ egress_device, port_egress):
+ '''
+ Required:
+ * ingress_device: device id of ingress device
+ * egress_device: device id of egress device
+ Description:
+ Adds a point-to-point intent (uni-directional) by
+ specifying device id's
+
+ NOTE: This function may change depending on the
+ options developers provide for point-to-point
+ intent via cli
+ '''
+ try:
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+
+ self.handle.sendline("add-point-intent "+
+ str(ingress_device) + "/" + str(port_ingress) + " " +
+ str(egress_device) + "/" + str(port_egress))
+ i = self.handle.expect([
+ "Error",
+ "onos>"])
+
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+
+ handle = self.handle.before
+
+ if i == 0:
+ main.log.error("Error in adding point-to-point intent")
+ 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)
+ 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 remove_intent(self, intent_id):
+ '''
+ Remove intent for specified intent id
+ '''
+ try:
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+
+ self.handle.sendline("remove-intent "+str(intent_id))
+ i = self.handle.expect([
+ "Error",
+ "onos>"])
+
+ handle = self.handle.before
+
+ if i == 0:
+ main.log.error("Error in removing intent")
+ return handle
+ else:
+ 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 intents(self):
+ '''
+ Description:
+ Obtain intents currently installed
+ '''
+ try:
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+
+ self.handle.sendline("intents")
+ 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()
+
#Wrapper functions ****************
#Wrapper functions use existing driver
#functions and extends their use case.
@@ -695,6 +871,50 @@
#a normal driver function, and parse it
#using a wrapper function
+ def get_all_intents_id(self):
+ '''
+ Description:
+ Obtain all intent id's in a list
+ '''
+ try:
+ #Obtain output of intents function
+ intents_str = self.intents()
+ all_intent_list = []
+ intent_id_list = []
+
+ #Parse the intents output for ID's
+ intents_list = [s.strip() for s in intents_str.splitlines()]
+ for intents in intents_list:
+ if "onos>" in intents:
+ continue
+ elif "intents" in intents:
+ continue
+ else:
+ line_list = intents.split(" ")
+ all_intent_list.append(line_list[0])
+
+ all_intent_list = all_intent_list[1:-2]
+
+ for intents in all_intent_list:
+ if not intents:
+ continue
+ else:
+ intent_id_list.append(intents)
+
+ return intent_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()
+
def get_all_devices_id(self):
'''
Use 'devices' function to obtain list of all devices
@@ -710,7 +930,7 @@
'''
try:
#Call devices and store result string
- devices_str = self.devices()
+ devices_str = self.devices(json_format=False)
id_list = []
if not devices_str: