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
new file mode 100644
index 0000000..9f21f9c
--- /dev/null
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -0,0 +1,188 @@
+#!/usr/bin/env python
+
+'''
+This driver enters the onos> prompt to issue commands.
+
+Please follow the coding style demonstrated by existing
+functions and document properly.
+
+If you are a contributor to the driver, please
+list your email here for future contact:
+
+jhall@onlab.us
+andrew@onlab.us
+
+OCT 13 2014
+
+'''
+
+import sys
+import time
+import pexpect
+import re
+import traceback
+import os.path
+import pydoc
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class OnosCliDriver(CLI):
+
+ def __init__(self):
+ '''
+ Initialize client
+ '''
+ super(CLI, self).__init__()
+
+ def connect(self,**connectargs):
+ '''
+ Creates ssh handle for ONOS cli.
+ '''
+ try:
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+ self.home = "~/ONOS"
+ for key in self.options:
+ if key == "home":
+ self.home = self.options['home']
+ break
+
+
+ self.name = self.options['name']
+ self.handle = super(OnosCliDriver,self).connect(
+ user_name = self.user_name,
+ ip_address = self.ip_address,
+ port = self.port,
+ pwd = self.pwd,
+ home = self.home)
+
+ self.handle.sendline("cd "+ self.home)
+ self.handle.expect("\$")
+ if self.handle:
+ return self.handle
+ else :
+ main.log.info("NO ONOS HANDLE")
+ 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(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.cleanup()
+ main.exit()
+
+ def disconnect(self):
+ '''
+ Called when Test is complete to disconnect the ONOS handle.
+ '''
+ response = ''
+ try:
+ self.handle.sendline("exit")
+ self.handle.expect("closed")
+ except pexpect.EOF:
+ main.log.error(self.name + ": EOF exception found")
+ main.log.error(self.name + ": " + self.handle.before)
+ except:
+ main.log.error(self.name + ": Connection failed to the host")
+ response = main.FALSE
+ return response
+
+ def set_cell(self, cellname):
+ '''
+ Calls 'cell <name>' to set the environment variables on ONOSbench
+
+ Before issuing any cli commands, set the environment variable first.
+ '''
+ try:
+ if not cellname:
+ main.log.error("Must define cellname")
+ main.cleanup()
+ main.exit()
+ else:
+ self.handle.sendline("cell "+str(cellname))
+ #Expect the cellname in the ONOS_CELL variable.
+ #Note that this variable name is subject to change
+ # and that this driver will have to change accordingly
+ self.handle.expect("ONOS_CELL="+str(cellname))
+ handle_before = self.handle.before
+ handle_after = self.handle.after
+ #Get the rest of the handle
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ handle_more = self.handle.before
+
+ main.log.info("Cell call returned: "+handle_before+
+ handle_after + handle_more)
+
+ 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 start_onos_cli(self):
+ try:
+ self.handle.sendline("")
+ self.handle.expect("\$")
+
+ #Wait for onos start (-w) and enter onos cli
+ self.handle.sendline("onos -w")
+ self.handle.expect("onos>")
+
+ 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()
+
+ #IMPORTANT NOTE:
+ #For all cli commands, naming convention should match
+ #the cli command replacing ':' with '_'.
+ #Ex) onos:topology > onos_topology
+ # onos:links > onos_links
+ # feature:list > feature_list
+
+ def onos_topology(self):
+ try:
+ self.handle.sendline("")
+ self.handle.expect("onos>")
+ self.handle.sendline("onos:topology")
+ self.handle.expect("onos>")
+
+ handle = self.handle.before
+
+ main.log.info("onos:topology returned: " +
+ str(handle))
+
+ 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()
+
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.params b/TestON/tests/ONOSNextTest/ONOSNextTest.params
index d2c7e51..01c432e 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.params
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.params
@@ -1,6 +1,6 @@
<PARAMS>
- <testcases>1,4,3</testcases>
+ <testcases>1,5</testcases>
#Environment variables
<ENV>
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.py b/TestON/tests/ONOSNextTest/ONOSNextTest.py
index e4b7a48..dd91efb 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.py
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.py
@@ -144,3 +144,21 @@
onpass="Pingall Test successful",
onfail="Pingall Test NOT successful")
+ def CASE5(self, main):
+ '''
+ Test the ONOS-cli functionality
+ '''
+ cell_name = main.params['ENV']['cellName']
+ ONOS1_ip = main.params['CTRL']['ip1']
+
+ main.case("Testing the ONOS-cli")
+
+ main.step("Set cell for ONOS-cli environment")
+ main.ONOScli.set_cell(cell_name)
+
+ main.step("Start ONOS-cli")
+ main.ONOScli.start_onos_cli()
+
+ main.step("issue command: onos:topology")
+ main.ONOScli.onos_topology()
+
diff --git a/TestON/tests/ONOSNextTest/ONOSNextTest.topo b/TestON/tests/ONOSNextTest/ONOSNextTest.topo
index 0f7388e..de31bc9 100755
--- a/TestON/tests/ONOSNextTest/ONOSNextTest.topo
+++ b/TestON/tests/ONOSNextTest/ONOSNextTest.topo
@@ -10,12 +10,21 @@
<COMPONENTS> </COMPONENTS>
</ONOSbench>
+ <ONOScli>
+ <host>10.128.20.10</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosCliDriver</type>
+ <connect_order>2</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli>
+
<ONOS1>
<host>10.128.20.11</host>
<user>sdn</user>
<password>sdn</password>
<type>OnosDriver</type>
- <connect_order>2</connect_order>
+ <connect_order>3</connect_order>
<COMPONENTS> </COMPONENTS>
</ONOS1>
@@ -24,7 +33,7 @@
<user>admin</user>
<password>onos_test</password>
<type>MininetCliDriver</type>
- <connect_order>3</connect_order>
+ <connect_order>4</connect_order>
<COMPONENTS>
#Specify the Option for mininet
<arg1> --topo tree,2,3</arg1>