Skip to content

How to write a TestON test

kelvin-onlab edited this page Feb 10, 2015 · 2 revisions

This is just a short Git hub wiki for TestON. Please checkout our official ONOS project wiki for in depth information on ONOS and TestON.

Write a TestON test:

1 . Create the package under tests directory test_name.

2 . Create three files named as test_name.params, test_name.topo and test_name.py under the test test_name.

3 . Define topology in test_name.topo.

Please refer the sample format for topology:

Topology

4 . Define the test parameters and CASE or STEP level parameters in test_name.params file.

Please refer the sample format for params:

Params

5 . Define your test cases in test_name.py

In topo file the component definition is specified as:

  <TOPOLOGY>    
  <COMPONENT>
       <Mininet1>
           <host> 192.168.56.101 </host>
           <user> openflow </user>
       </Mininet1>
     </COMPONENT>
 </TOPOLOGY>

The usage of this component in the test script is as follows: main.Mininet1.checkIP(main.params['CASE1']['destination'])

Here Mininet1 is of Mininet (Corresponding driver in the drivers).

Please refer the sample test script: Test Script

Note: The class name for the test script should be same as the test_name.

Parameterise a TestON test:

1 . CASE level parameters:

<CASE1>
    <destination> h2 </destination>
</CASE1>

This CASE level parameters can be accessed as follows: main.params['CASE1']['destination']

Please refer the CASE level parameters usage example : CASE params

2 . STEP level parameters :

<CASE1>
  <STEP1>
      <host> h2 </host>
  </STEP1>
</CASE1>

This STEP level parameters can be accessed as follows: main.params['CASE1']['STEP1']['host']

Please refer the CASE level parameters usage example : STEP params

3 . TOPOLOGY level parameters :

  <TOPOLOGY>    
    <COMPONENT>
       <Mininet1>
         <host> 192.168.56.101 </host>
          <user> openflow </user>
       </Mininet1>
   </COMPONENT>
 </TOPOLOGY>

This TOPOLOGY level parameters can be accessed as follows: main.topology['localhost']

Read and interpret debug/session logs and report files :

There are three ways to specify the log directory path

1 . Default path will be the /logs/test_name_time/

2 . Providing the command line option --logdir "/path/to/logdirectory"

3 . Parameterise in the test_name.params file as 'logdir' = '/path/to/logdirectory'

After execution of the test, there will be three types of logs :

test_name_time.log – Detailed, verbose log of everything that the script does.

test_name_time.rpt – Summary report of testcase results.

component_name.SESSION – Log of all commands/APIs run on this component with response.

Write a new TestON driver :

Component Drivers – Connects and provides interfaces to various components in the OpenFlow/SDN topology.

The three main methods of a component driver are connect, disconnect and execute. Usually, while writing a custom driver, the user might entirely skip writing these methods and use them from the parent component class or call the equivalent super component method, followed by any logic that is specific to this component.

As a reference to write a custom driver, please refer the link for Mininet driver.

Mininet driver

In this example, the Mininet driver inherits from the abstract Emulator driver which in turn inherits from the CLI driver. The Mininet driver reuses the execute and disconnect API from the CLI driver. The connect API is the only API that is redefined.

class Mininet(Emulator):

    def __init__(self):
        super(Emulator, self).__init__()
        self.handle = self

    def connect(self,user_name, ip_address, pwd,options):
        self.handle = super(Mininet, self).connect(user_name, ip_address, pwd)

Here the connect will call the super (clidriver) connect.

Driver specific methods/functions can be specified using the simple execute command of (clidriver).

def pingall(self):
        '''
           Verifies the reachability of the hosts using pingall command.
        '''
        if self.handle :
            main.log.info("Checking reachabilty to the hosts using pingall")
            response = self.execute(cmd="pingall",prompt="mininet>",timeout=120)
            pattern = 'Results\:\s0\%\sdropped\s\(0\/\d+\slost\)\s*$'
            if utilities.assert_matches(expect=pattern,actual=response,
                         onpass="All hosts are reaching",
                         onfail="Unable to reach all the hosts"):
                return main.TRUE
            else:
                return main.FALSE
        else :
            main.log.error("Connection failed to the host")
  1. Create a driver_name.py file under "/drivers/common/cli/.."

    Note: In this example, the driver is placed under cli->emulator (folder path) hierarchy. If the user wishes to create a driver that is integrated with an API library, then the same can be created under api-emulator(folder path)

  2. Create class name as driver_name.

      Note : Naming convention for the module name is lower case letters.  
        Naming convention for the Class name "StudlyCaps".
        And test's Topology file , component 'type'= 'StudlyCaps'.
    
  3. Create function in driver_name class named as connect with suitable return type. It will facilitate the connection for component or remote host used for driver.

  4. Create more functions /api in driver_name class with suitable defined parameters. It will facilitate the connection for component or remote host used for driver.

More documentation for writing drivers will be added in the future.

Paxterra