First test case for Switch Manager
authorLuis Gomez <luis.gomez@ericsson.com>
Sat, 23 Nov 2013 03:48:18 +0000 (19:48 -0800)
committerLuis Gomez <luis.gomez@ericsson.com>
Sat, 23 Nov 2013 03:48:18 +0000 (19:48 -0800)
Change-Id: I87391a5164525a2068b4d50f9da6ef0c5194c3a3
Signed-off-by: Luis Gomez <luis.gomez@ericsson.com>
test/csit/libraries/Common.py [new file with mode: 0644]
test/csit/libraries/SwitchManager.py [new file with mode: 0644]
test/csit/libraries/Topology.py [new file with mode: 0644]
test/csit/suites/base/005__Switch_Manager.txt [deleted file]
test/csit/suites/base/005__switch_Manager.txt [new file with mode: 0644]
test/csit/suites/base/__init__.txt
test/csit/variables/Variables.py [new file with mode: 0644]

diff --git a/test/csit/libraries/Common.py b/test/csit/libraries/Common.py
new file mode 100644 (file)
index 0000000..000b2b8
--- /dev/null
@@ -0,0 +1,39 @@
+"""
+Library for the robot based system test tool of the OpenDaylight project.
+Authors: Baohua Yang@IBM, Denghui Huang@IBM
+Updated: 2013-11-14
+"""
+import collections
+
+'''
+Common constants and functions for the robot framework.
+'''
+
+def collection_should_contain(collection, *members):
+    """
+    Fail if not every members is in the collection.
+    """
+    if not isinstance(collection, collections.Iterable):
+        return False
+    for m in members:
+        if m not in collection:
+            return False
+    else:
+        return True
+
+def combine_strings(*strings):
+    """
+    Combines the given `strings` together and returns the result.
+    The given strings are not altered by this keyword.
+    """
+    result = ''
+    for s in strings:
+        if isinstance(s,str) or isinstance(s,unicode):
+            result += s
+    if result == '':
+        return None
+    else:
+        return result
+
+if __name__ == '__main__':
+    pass
diff --git a/test/csit/libraries/SwitchManager.py b/test/csit/libraries/SwitchManager.py
new file mode 100644 (file)
index 0000000..c72c636
--- /dev/null
@@ -0,0 +1,48 @@
+"""
+Library for the robot based system test tool of the OpenDaylight project.
+Authors: Baohua Yang@IBM, Denghui Huang@IBM
+Updated: 2013-11-10
+"""
+import robot
+from robot.libraries.BuiltIn import BuiltIn
+
+class SwitchManager(object):
+    def __init__(self):
+        self.builtin = BuiltIn()
+
+    def extract_all_nodes(self, content):
+        """
+        Return all nodes.
+        """
+        if isinstance(content,dict) and content.has_key('nodeProperties'):
+            self.builtin.log("18")
+            return [e.get('node') for e in content['nodeProperties']]
+        else:
+            self.builtin.log("21")
+            return None 
+
+    def extract_all_properties(self, content, property_type):
+        if isinstance(content,dict) and content.has_key(property_type):
+            self.builtin.log("26")
+            list1=[e.get('properties') for e in content[property_type]]
+            self.builtin.log(list1)
+            return [e.get('properties') for e in content[property_type]]
+        else:
+            self.builtin.log("29")
+            return None
+
+    def extract_property_value(self, content, property, property_type):
+        res = self.extract_all_properties(content, property_type)
+        return [e.get(property) for e in res]
+
+    def extract_all_node_properties(self, content):
+        return self.extract_all_properties(content, 'nodeProperties')
+
+    def extract_node_property_values(self, content, property):
+        return self.extract_property_value(content, property, 'nodeProperties')
+
+    def extract_all_nodeconnector_properties(self, content):
+        return self.extract_all_properties(content, 'nodeConnectorProperties')
+
+    def extract_nodeconnector_property_values(self, content, property):
+        return self.extract_property_value(content, property, 'nodeConnectorProperties')
diff --git a/test/csit/libraries/Topology.py b/test/csit/libraries/Topology.py
new file mode 100644 (file)
index 0000000..aa8708a
--- /dev/null
@@ -0,0 +1,42 @@
+"""
+Library for the robot based system test tool of the OpenDaylight project.
+Authors: Baohua Yang@IBM, Denghui Huang@IBM
+Updated: 2013-11-10
+"""
+import string
+import robot
+from robot.libraries.BuiltIn import BuiltIn
+
+class Topology(object):
+    '''
+    Topology class provide topology database and provide many method to get property of topology.
+    '''
+    topo_nodes_db=[[],
+            [{u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}],
+            [{u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},{u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},{u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'}]]
+    def __init__(self):
+        self.builtin = BuiltIn()
+
+    def get_nodes_from_topology(self,topo_level):
+        '''
+        get nodes from topology database by topology tree level
+        '''
+        if isinstance(topo_level, str) or isinstance(topo_level, unicode):
+            if topo_level.isdigit():
+                topo_level=int(topo_level)
+                if topo_level <= 0:
+                    return None
+                return self.topo_nodes_db[topo_level]
+            else:
+                return None
+        elif isinstance(topo_level, int):
+            if topo_level <= 0:
+                return None
+            return self.topo_nodes_db[topo_level]
+        else:
+            return None
+
+if __name__ == '__main__':
+    topology = Topology()
+    print topology.get_nodes_from_topology(2)
+    print topology.get_nodes_from_topology('2')
diff --git a/test/csit/suites/base/005__Switch_Manager.txt b/test/csit/suites/base/005__Switch_Manager.txt
deleted file mode 100755 (executable)
index 5395057..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-*** Settings ***
-Library       Collections
-Library       RequestsLibrary
-
-*** Testcases ***
-Get Nodes
-    ${node1}=  Set Variable  "node":{"type":"OF","id":"00:00:00:00:00:00:00:01"}
-    ${node2}=  Set Variable  "node":{"type":"OF","id":"00:00:00:00:00:00:00:02"}
-    ${node3}=  Set Variable  "node":{"type":"OF","id":"00:00:00:00:00:00:00:03"}
-    ${auth}=    Create List    admin    admin
-    ${headers}=    Create Dictionary    Content-Type   application/json
-    Create Session    controller   http://${CONTROLLER}:8080    headers=${headers}   auth=${auth} 
-    ${resp}=    Get    controller   /controller/nb/v2/switchmanager/default/nodes 
-    Should Be Equal As Strings    ${resp.status_code}    200
-    Log    ${resp.content}
-    Should Contain    ${resp.content}   ${node1}
-    Should Contain    ${resp.content}   ${node2}
-    Should Contain    ${resp.content}   ${node3}
diff --git a/test/csit/suites/base/005__switch_Manager.txt b/test/csit/suites/base/005__switch_Manager.txt
new file mode 100644 (file)
index 0000000..1ffa1f1
--- /dev/null
@@ -0,0 +1,139 @@
+*** Settings ***
+Documentation     Test suite for the switch manager bundle.
+Suite Setup       Create Session    ${ODL_CONTROLLER_SESSION}    http://${CONTROLLER}:8080    auth=${AUTH}    headers=${HEADERS}
+Suite Teardown    Delete All Sessions
+Library           Collections
+Library           RequestsLibrary
+Library           ../../libraries/Common.py
+Library           ../../libraries/SwitchManager.py
+Variables         ../../variables/Variables.py
+Library           ../../libraries/Topology.py
+
+*** Variables ***
+${REST_CONTEXT}    /controller/nb/v2/switchmanager
+
+*** Test Cases ***
+List all nodes
+    [Documentation]    List all nodes and their properties in the network.
+    [Tags]    list_info
+    Log    ${TOPO_TREE_LEVEL}
+    ${topo_nodes}    Get Nodes From Topology    ${TOPO_TREE_LEVEL}
+    ${resp}    Get    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/nodes
+    Should Be Equal As Strings    ${resp.status_code}    200    Response   status code error
+    ${jsondata}=    To JSON    ${resp.content}
+    ${nodes}    Extract All Nodes    ${jsondata}
+    Collection Should Contain    ${nodes}    ${topo_nodes}
+Get a node
+    [Documentation]    Get a node
+    Get node    00:00:00:00:00:00:00:02    OF
+Add property to node
+    [Documentation]    Add a property to node
+    Add property to node    OF    00:00:00:00:00:00:00:02    description     Switch2
+    Node property should exist    OF    00:00:00:00:00:00:00:02    description    Switch2
+Remove property from node
+    [Documentation]    Remove a property from node
+    Remove property from node    OF    00:00:00:00:00:00:00:02    description
+    Node property should not exist    OF    00:00:00:00:00:00:00:02     description    Switch2
+Add property to nodeconnector
+    [Documentation]    Add a property to nodeconnector
+    Add property to nodeconnector    OF    00:00:00:00:00:00:00:02    OF    2    bandwidth    1000
+    Nodeconnector property should exist    OF    00:00:00:00:00:00:00:02    OF    2    bandwidth    ${1000}
+
+Remove property from nodeconnector
+    [Documentation]    Remove a property from nodeconnector
+    Remove property from nodeconnector    OF    00:00:00:00:00:00:00:02    OF    2    bandwidth
+    Nodeconnector property should not exist    OF    00:00:00:00:00:00:00:02    OF    2    bandwidth    ${1000}
+
+*** Keywords ***
+Get node
+    [Arguments]    ${node_id}    ${node_type}
+    [Documentation]    Get a specific node
+    ${resp}    Get    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/nodes
+    Should Be Equal As Strings    ${resp.status_code}    200    Response status code error
+    ${result}    TO JSON    ${resp.content}
+    ${node}    Create Dictionary    id    ${node_id}    type    ${node_type}
+    ${content}    Extract All Nodes    ${result}
+    Log    ${content}
+    List Should Contain Value    ${content}    ${node}
+
+Add property to node
+    [Arguments]    ${node_type}    ${node_id}    ${property}    ${value}
+    [Documentation]    Add property to node
+    ${resp}    Put    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/node/${node_type}/${node_id}/property/${property}/${value}
+    Should Be Equal As Strings    ${resp.status_code}    201    Response status code error
+
+Remove property from node
+    [Arguments]    ${node_type}    ${node_id}    ${property}
+    [Documentation]    Remove property from node
+    ${resp}    Delete    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/node/${node_type}/${node_id}/property/${property}
+    Should Be Equal As Strings    ${resp.status_code}    204    Response status code error
+
+Add property to nodeconnector
+    [Arguments]    ${node_type}    ${node_id}    ${nc_type}    ${nc_id}    ${property}    ${value}
+    [Documentation]    Add property to nodeconnector
+    ${resp}    Put    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/nodeconnector/${node_type}/${node_id}/${nc_type}/${nc_id}/property/${property}/${value}
+    Should Be Equal As Strings    ${resp.status_code}    201    Response status code error
+
+Remove property from nodeconnector
+    [Arguments]    ${node_type}    ${node_id}    ${nc_type}    ${nc_id}    ${property}
+    [Documentation]    Remove property from nodeconnector
+    ${resp}    Delete    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/nodeconnector/${node_type}/${node_id}/${nc_type}/${nc_id}/property/${property}
+    Should Be Equal As Strings    ${resp.status_code}    204    Response status code error
+
+Node property should exist
+    [Arguments]    ${node_type}    ${node_id}    ${property}    ${value}
+    [Documentation]    Property of node should exist
+    ${resp}    Get    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/nodes
+    Should Be Equal As Strings    ${resp.status_code}    200    Response status code error
+    ${result}    TO JSON    ${resp.content}
+    Log    ${result}
+    ${nodes}    Extract All Nodes    ${result}
+    ${property_values}    Extract Node Property Values    ${result}    ${property}
+    ${node}    Create Dictionary    id    ${node_id}    type    ${node_type}
+    ${property_value}    Create Dictionary    value    ${value}
+    Log    ${property_value}
+    List Should Contain Value    ${nodes}    ${node}
+    List Should Contain Value    ${property_values}    ${property_value}
+
+Node property should not exist
+    [Arguments]    ${node_type}    ${node_id}    ${property}    ${value}
+    [Documentation]    Property of node should not exist
+    ${resp}    Get    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/nodes
+    Should Be Equal As Strings    ${resp.status_code}    200    Response status code error
+    ${result}    TO JSON    ${resp.content}
+    Log    ${result}
+    ${nodes}    Extract All Nodes    ${result}
+    ${properties}    Extract Node Property Values    ${result}    ${property}
+    ${node}    Create Dictionary    id    ${node_id}    type    ${node_type}
+    ${property}    Create Dictionary    value    ${value}
+    Log    ${property}
+    List Should Contain Value    ${nodes}    ${node}
+    List Should Not Contain Value    ${properties}    ${property}
+
+Nodeconnector property should exist
+    [Arguments]    ${node_type}    ${node_id}    ${nc_type}    ${nc_id}    ${property}    ${value}
+    [Documentation]    Property of nodeconnector should exist
+    ${resp}    Get    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/node/${node_type}/${node_id}
+    Should Be Equal As Strings    ${resp.status_code}    200    Response status code error
+    ${result}    TO JSON    ${resp.content}
+    Log    ${result}
+    ${property_values}    Extract Nodeconnector Property Values    ${result}    ${property}
+    Log    ${property_values}
+    ${property_value}    Create Dictionary    value    ${value}
+    List Should Contain Value    ${property_values}    ${property_value}
+
+Nodeconnector property should not exist
+    [Arguments]    ${node_type}    ${node_id}    ${nc_type}    ${nc_id}    ${property}    ${value}
+    [Documentation]    Property of nodeconnector should not exist
+    ${resp}    Get    ${ODL_CONTROLLER_SESSION}    ${REST_CONTEXT}/${CONTAINER}/node/${node_type}/${node_id}
+    Should Be Equal As Strings    ${resp.status_code}    200    Response status code error
+    ${result}    TO JSON    ${resp.content}
+    Log    ${result}
+    ${property_values}    Extract Nodeconnector Property Values    ${result}    ${property}
+    Log    ${property_values}
+    ${property_value}    Create Dictionary    value    ${value}
+    List Should not Contain Value    ${property_values}    ${property_value}
+
+List all nodeconnectors of node
+    [Arguments]    ${node_type}    ${node_id}
+    [Documentation]    List all nodeconnectors and properties of node
index b57ceab9a27174820098dcae8fb84cb1e30abcd7..1d6b8bb70169cf4be092af419eea052bcc2b0416 100644 (file)
@@ -1,7 +1,6 @@
 *** Settings ***
 Documentation     Test suite for the OpenDaylight base edition
 Suite Setup       Start Suite
-Suite Teardown    Stop Suite
 Library     SSHLibrary
 
 *** Variables ***
@@ -12,11 +11,8 @@ Start Suite
     Log    Start the test on the base edition
     Open Connection   ${MININET}     prompt=>
     Login With Public Key    ${MININET_USER}   ${USER_HOME}/.ssh/id_rsa   any 
-    Write    sudo mn -c
-    Sleep    2
-    Read
     Write    ${start}
-    Sleep    12
+    Sleep    60
     Read
 Stop Suite
     Log    Stop the test on the base edition
diff --git a/test/csit/variables/Variables.py b/test/csit/variables/Variables.py
new file mode 100644 (file)
index 0000000..100f3bc
--- /dev/null
@@ -0,0 +1,18 @@
+"""
+Library for the robot based system test tool of the OpenDaylight project.
+Authors: Baohua Yang@IBM, Denghui Huang@IBM
+Updated: 2013-11-14
+"""
+import collections
+
+# Global variables
+CONTROLLER = '127.0.0.1'
+PORT = '8080'
+PREFIX = 'http://' + CONTROLLER + ':' + PORT
+CONTAINER = 'default'
+USER = 'admin'
+PWD = 'admin'
+AUTH = [u'admin',u'admin']
+HEADERS={'Content-Type':'application/json'}
+ODL_CONTROLLER_SESSION=None
+TOPO_TREE_LEVEL=2