Address comments from code review
- Removed all grep_str's from onosclidriver
- fix some sendline issues
- refactor HA tests a bit
- fix typos
diff --git a/TestON/drivers/common/cli/emulator/lincoedriver.py b/TestON/drivers/common/cli/emulator/lincoedriver.py
index 4d2cc01..6f7ce3a 100644
--- a/TestON/drivers/common/cli/emulator/lincoedriver.py
+++ b/TestON/drivers/common/cli/emulator/lincoedriver.py
@@ -293,8 +293,8 @@
'''
try:
#Send CTRL+C twice to exit CLI
- self.handle.sendline("\x03")
- self.handle.sendline("\x03")
+ self.handle.send("\x03")
+ self.handle.send("\x03")
self.handle.expect("\$")
except pexpect.EOF:
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index e2570ac..2f31b7d 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -672,7 +672,7 @@
returns: main.FASLE on an error, else main.TRUE
'''
dpid = kwargs.get('dpid', '')
- command = "addswitch " + sw + " " + str(dpid)
+ command = "addswitch " + str( sw ) + " " + str( dpid )
try:
response = self.execute(cmd=command,prompt="mininet>",timeout=10)
if re.search("already exists!", response):
@@ -700,7 +700,7 @@
switchname = name of the switch as a string
returns: main.FASLE on an error, else main.TRUE
'''
- command = "delswitch " + sw
+ command = "delswitch " + str( sw )
try:
response = self.execute(cmd=command,prompt="mininet>",timeout=10)
if re.search("no switch named", response):
@@ -730,7 +730,7 @@
node2 = the string node name of the second endpoint of the link
returns: main.FASLE on an error, else main.TRUE
'''
- command = "addlink " + node1 + " " + node2
+ command = "addlink " + str( node1 ) + " " + str( node2 )
try:
response = self.execute(cmd=command,prompt="mininet>",timeout=10)
if re.search("doesnt exist!", response):
@@ -759,7 +759,7 @@
node2 = the string node name of the second endpoint of the link
returns: main.FASLE on an error, else main.TRUE
'''
- command = "dellink " + node1 + " " + node2
+ command = "dellink " + str( node1 ) + " " + str( node2 )
try:
response = self.execute(cmd=command,prompt="mininet>",timeout=10)
if re.search("no node named", response):
@@ -791,7 +791,7 @@
returns: main.FASLE on an error, else main.TRUE
'''
switch = kwargs.get('switch', '')
- command = "addhost " + hostname + " " + switch
+ command = "addhost " + str( hostname ) + " " + str( switch )
try:
response = self.execute(cmd=command,prompt="mininet>",timeout=10)
if re.search("already exists!", response):
@@ -822,7 +822,7 @@
hostname = the string hostname
returns: main.FASLE on an error, else main.TRUE
'''
- command = "delhost " + hostname
+ command = "delhost " + str( hostname )
try:
response = self.execute(cmd=command,prompt="mininet>",timeout=10)
if re.search("no host named", response):
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index dd54d45..4916ba5 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -90,7 +90,7 @@
self.handle.expect("Confirm")
self.handle.sendline("yes")
self.handle.expect("\$")
- self.handle.sendline("\n")
+ self.handle.sendline("")
self.handle.expect("\$")
self.handle.sendline("exit")
self.handle.expect("closed")
@@ -194,13 +194,7 @@
else:
#If failed, send ctrl+c to process and try again
main.log.info("Starting CLI failed. Retrying...")
- self.handle.sendline("\x03")
- i = self.handle.expect(["onos>",pexpect.TIMEOUT],
- timeout=30)
- #Send ctrl+d to exit the onos> prompt that was
- #not successful
- self.handle.sendline("\x04")
- self.handle.expect("\$")
+ self.handle.send("\x03")
self.handle.sendline("onos -w "+str(ONOS_ip))
i = self.handle.expect(["onos>",pexpect.TIMEOUT],
timeout=30)
@@ -467,27 +461,21 @@
main.log.info(self.name+" ::::::")
main.cleanup()
main.exit()
-
- def devices(self, json_format=True, grep_str=""):
+
+ def devices(self, json_format=True):
'''
Lists all infrastructure devices or switches
Optional argument:
- * grep_str - pass in a string to grep
+ * json_format - boolean indicating if you want output in json
'''
try:
self.handle.sendline("")
self.handle.expect("onos>")
-
+
if json_format:
- if not grep_str:
- self.handle.sendline("devices -j")
- self.handle.expect("devices -j")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("devices -j | grep '"+
- str(grep_str)+"'")
- self.handle.expect("devices -j | grep '"+str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("devices -j")
+ self.handle.expect("devices -j")
+ self.handle.expect("onos>")
handle = self.handle.before
'''
handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
@@ -503,13 +491,8 @@
#print "repr(handle1) = ", repr(handle1)
return handle1
else:
- if not grep_str:
- self.handle.sendline("devices")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("devices | grep '"+
- str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("devices")
+ self.handle.expect("onos>")
handle = self.handle.before
#print "handle =",handle
return handle
@@ -525,34 +508,28 @@
main.cleanup()
main.exit()
- def links(self, json_format=True, grep_str=""):
+ def links(self, json_format=True):
'''
Lists all core links
Optional argument:
- * grep_str - pass in a string to grep
+ * json_format - boolean indicating if you want output in json
'''
try:
self.handle.sendline("")
self.handle.expect("onos>")
-
+
if json_format:
- if not grep_str:
- self.handle.sendline("links -j")
- self.handle.expect("links -j")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("links -j | grep '"+
- str(grep_str)+"'")
- self.handle.expect("links -j | grep '"+str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("links -j")
+ self.handle.expect("links -j")
+ self.handle.expect("onos>")
handle = self.handle.before
'''
handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
To make that escape sequence visible, use repr() function. The repr(handle) output when printed shows the ANSI escape sequences.
In json.loads(somestring), this somestring variable is actually repr(somestring) and json.loads would fail with the escape sequence.
- So we take off that escape sequence using
+ So we take off that escape sequence using
ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
- handle1 = ansi_escape.sub('', handle)
+ handle1 = ansi_escape.sub('', handle)
'''
#print "repr(handle) =", repr(handle)
ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
@@ -560,13 +537,8 @@
#print "repr(handle1) = ", repr(handle1)
return handle1
else:
- if not grep_str:
- self.handle.sendline("links")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("links | grep '"+
- str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("links")
+ self.handle.expect("onos>")
handle = self.handle.before
#print "handle =",handle
return handle
@@ -583,34 +555,28 @@
main.exit()
- def ports(self, json_format=True, grep_str=""):
+ def ports(self, json_format=True):
'''
Lists all ports
Optional argument:
- * grep_str - pass in a string to grep
+ * json_format - boolean indicating if you want output in json
'''
try:
self.handle.sendline("")
self.handle.expect("onos>")
-
+
if json_format:
- if not grep_str:
- self.handle.sendline("ports -j")
- self.handle.expect("ports -j")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("ports -j | grep '"+
- str(grep_str)+"'")
- self.handle.expect("ports -j | grep '"+str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("ports -j")
+ self.handle.expect("ports -j")
+ self.handle.expect("onos>")
handle = self.handle.before
'''
handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
To make that escape sequence visible, use repr() function. The repr(handle) output when printed shows the ANSI escape sequences.
In json.loads(somestring), this somestring variable is actually repr(somestring) and json.loads would fail with the escape sequence.
- So we take off that escape sequence using the following commads:
+ So we take off that escape sequence using the following commads:
ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
- handle1 = ansi_escape.sub('', handle)
+ handle1 = ansi_escape.sub('', handle)
'''
#print "repr(handle) =", repr(handle)
ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
@@ -619,20 +585,13 @@
return handle1
else:
- if not grep_str:
- self.handle.sendline("ports")
- self.handle.expect("onos>")
- self.handle.sendline("")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("ports | grep '"+
- str(grep_str)+"'")
- self.handle.expect("onos>")
- self.handle.sendline("")
- self.handle.expect("onos>")
+ self.handle.sendline("ports")
+ self.handle.expect("onos>")
+ self.handle.sendline("")
+ self.handle.expect("onos>")
handle = self.handle.before
#print "handle =",handle
- return handle
+ return handle
except pexpect.EOF:
main.log.error(self.name + ": EOF exception found")
main.log.error(self.name + ": " + self.handle.before)
@@ -646,11 +605,11 @@
main.exit()
- def roles(self, json_format=True, grep_str=""):
+ def roles(self, json_format=True):
'''
Lists all devices and the controllers with roles assigned to them
Optional argument:
- * grep_str - pass in a string to grep
+ * json_format - boolean indicating if you want output in json
'''
try:
self.handle.sendline("")
@@ -686,7 +645,7 @@
self.handle.expect("onos>")
handle = self.handle.before
#print "handle =",handle
- return handle
+ return handle
except pexpect.EOF:
main.log.error(self.name + ": EOF exception found")
main.log.error(self.name + ": " + self.handle.before)
@@ -774,35 +733,29 @@
main.log.info(self.name+" ::::::")
main.cleanup()
main.exit()
-
- def hosts(self, json_format=True, grep_str=""):
+
+ def hosts(self, json_format=True):
'''
- Lists all discovered hosts
+ Lists all discovered hosts
Optional argument:
- * grep_str - pass in a string to grep
+ * json_format - boolean indicating if you want output in json
'''
try:
self.handle.sendline("")
self.handle.expect("onos>")
-
+
if json_format:
- if not grep_str:
- self.handle.sendline("hosts -j")
- self.handle.expect("hosts -j")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("hosts -j | grep '"+
- str(grep_str)+"'")
- self.handle.expect("hosts -j | grep '"+str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("hosts -j")
+ self.handle.expect("hosts -j")
+ self.handle.expect("onos>")
handle = self.handle.before
'''
handle variable here contains some ANSI escape color code sequences at the end which are invisible in the print command output
To make that escape sequence visible, use repr() function. The repr(handle) output when printed shows the ANSI escape sequences.
In json.loads(somestring), this somestring variable is actually repr(somestring) and json.loads would fail with the escape sequence.
- So we take off that escape sequence using
+ So we take off that escape sequence using
ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
- handle1 = ansi_escape.sub('', handle)
+ handle1 = ansi_escape.sub('', handle)
'''
#print "repr(handle) =", repr(handle)
ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
@@ -810,13 +763,8 @@
#print "repr(handle1) = ", repr(handle1)
return handle1
else:
- if not grep_str:
- self.handle.sendline("hosts")
- self.handle.expect("onos>")
- else:
- self.handle.sendline("hosts | grep '"+
- str(grep_str)+"'")
- self.handle.expect("onos>")
+ self.handle.sendline("hosts")
+ self.handle.expect("onos>")
handle = self.handle.before
#print "handle =",handle
return handle
@@ -925,7 +873,7 @@
self.handle.expect("onos>")
handle = self.handle.before
- print "handle =", handle
+ #print "handle =", handle
main.log.info("Intent installed between "+
str(host_id_one) + " and " + str(host_id_two))
@@ -1168,7 +1116,7 @@
main.cleanup()
main.exit()
- def intents(self, json_format = False):
+ def intents(self, json_format = True):
'''
Optional:
* json_format: enable output formatting in json
@@ -1206,7 +1154,7 @@
main.cleanup()
main.exit()
- def flows(self, json_format = False):
+ def flows(self, json_format = True):
'''
Optional:
* json_format: enable output formatting in json
@@ -1649,6 +1597,8 @@
def clusters(self, json_format=True):
'''
Lists all clusters
+ Optional argument:
+ * json_format - boolean indicating if you want output in json
'''
try:
self.handle.sendline("")
@@ -1676,7 +1626,7 @@
#print "repr(handle1) = ", repr(handle1)
return handle1
else:
- self.handle.sendline("links")
+ self.handle.sendline("clusters")
self.handle.expect("onos>")
handle = self.handle.before
#print "handle =",handle
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index f733d35..1f52be1 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -82,7 +82,7 @@
'''
response = ''
try:
- self.handle.sendline("\n")
+ self.handle.sendline("")
self.handle.expect("\$")
self.handle.sendline("exit")
self.handle.expect("closed")
@@ -164,7 +164,7 @@
self.handle.sendline("cd "+ self.home)
self.handle.expect("\$")
- self.handle.sendline("\n")
+ self.handle.sendline("")
self.handle.expect("\$")
self.handle.sendline("mvn clean install")
self.handle.expect("mvn clean install")
@@ -195,7 +195,7 @@
for line in self.handle.before.splitlines():
if "Total time:" in line:
main.log.info(line)
- self.handle.sendline("\n")
+ self.handle.sendline("")
self.handle.expect("\$", timeout=60)
return main.TRUE
elif i == 4:
@@ -392,11 +392,11 @@
self.handle.sendline("export TERM=xterm-256color")
self.handle.expect("xterm-256color")
self.handle.expect("\$")
- self.handle.sendline("\n")
+ self.handle.sendline("")
self.handle.expect("\$")
self.handle.sendline("cd " + self.home + "; git log -1 --pretty=fuller --decorate=short | grep -A 6 \"commit\" --color=never")
#NOTE: for some reason there are backspaces inserted in this phrase when run from Jenkins on some tests
- #self.handle.expect("--color=never")
+ self.handle.expect("never")
self.handle.expect("\$")
response=(self.name +": \n"+ str(self.handle.before + self.handle.after))
self.handle.sendline("cd " + self.home)
@@ -790,7 +790,6 @@
self.handle.sendline("")
self.handle.expect("\$")
self.handle.sendline( "onos-uninstall "+str(node_ip) )
- self.handle.expect( "onos-uninstall "+str(node_ip) )
self.handle.expect("\$")
main.log.info("ONOS "+node_ip+" was uninstalled")
diff --git a/TestON/drivers/common/clidriver.py b/TestON/drivers/common/clidriver.py
index e54c663..7bf7667 100644
--- a/TestON/drivers/common/clidriver.py
+++ b/TestON/drivers/common/clidriver.py
@@ -76,7 +76,7 @@
elif i==6:
main.log.info("Password not required logged in")
- self.handle.sendline("\n")
+ self.handle.sendline("")
self.handle.expect('>|#|\$')
return self.handle