from urllib import urlencode
+
import robot
from robot.libraries.BuiltIn import BuiltIn
"""
session = self._cache.switch(alias)
- #data = json.dumps(self._utf8_urlencode(data))
+ #data = self._utf8_urlencode(data)
data = json.dumps(data)
resp = session.put(self._get_url(session, uri),
session.last_resp = resp
return resp
+ def put_xml(self, alias, uri, data=None, headers=None):
+ """ Send a PUT_xml request on the session object found using the
+ given `alias`
+
+ `alias` that will be used to identify the Session object in the cache
+
+ `uri` to send the PUT_xml request to
+
+ `headers` a dictionary of headers to use with the request
+
+ """
+
+ session = self._cache.switch(alias)
+ data = self._utf8_urlencode(data)
+ #data = json.dumps(data)
+
+ resp = session.put(self._get_url(session, uri),
+ data=data, headers=headers,
+ cookies=self.cookies, timeout=self.timeout)
+
+ self.builtin.log("PUT response: %s DEBUG" % resp.content)
+
+ # store the last response object
+ session.last_resp = resp
+ return resp
+
def delete(self, alias, uri, data=(), headers=None):
""" Send a DELETE request on the session object found using the
given `alias`
session.last_resp = resp
return resp
+
def head(self, alias, uri, headers=None):
""" Send a HEAD request on the session object found using the
given `alias`
--- /dev/null
+*** Settings ***
+Documentation Test suite for RESTCONF inventory
+Suite Setup Create Session session http://${CONTROLLER}:8080 auth=${AUTH} headers=${HEADERS_XML}
+Suite Teardown Delete All Sessions
+Library Collections
+Library ../../libraries/RequestsLibrary.py
+Library ../../libraries/Common.py
+Variables ../../variables/Variables.py
+
+*** Variables ***
+${REST_CONTEXT} /restconf/datastore/opendaylight-inventory:nodes
+
+*** Test Cases ***
+Get list of nodes
+ [Documentation] Get the inventory
+ ${resp} Get session ${REST_CONTEXT}
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} openflow:1
+ Should Contain ${resp.content} openflow:2
+ Should Contain ${resp.content} openflow:3
+
+Get nodeconnector for a node
+ [Documentation] Get the inventory for a node
+ ${resp} Get session ${REST_CONTEXT}/node/openflow:2
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} openflow:2:1
+ Should Contain ${resp.content} openflow:2:2
+ Should Contain ${resp.content} openflow:2:3
+
+
+
--- /dev/null
+*** Settings ***
+Documentation Test suite for pushing/verify/remove a flow through RESTCONF
+Suite Setup Create Session session http://${CONTROLLER}:8080 auth=${AUTH} headers=${HEADERS_XML}
+Suite Teardown Delete All Sessions
+Library Collections
+Library ../../libraries/RequestsLibrary.py
+Library ../../libraries/Common.py
+Variables ../../variables/Variables.py
+
+*** Variables ***
+
+${REST_CON} /restconf/config/opendaylight-inventory:nodes
+${REST_OPR} /restconf/operational/opendaylight-inventory:nodes
+${BODY} <flow xmlns="urn:opendaylight:flow:inventory"><priority>2</priority><flow-name>Foo</flow-name><match><ethernet-match><ethernet-type><type>2048</type></ethernet-type></ethernet-match><ipv4-destination>10.0.10.2/24</ipv4-destination></match><id>139</id><table_id>2</table_id><instructions><instruction><order>0</order><apply-actions><action><order>0</order><dec-nw-ttl/></action></apply-actions></instruction></instructions></flow>
+
+*** Test Cases ***
+Add a flow
+ [Documentation] Push a flow through REST-API
+ [Tags] Push
+ ${resp} Putxml session ${REST_CON}/node/openflow:1/table/2/flow/139 data=${BODY}
+ Should Be Equal As Strings ${resp.status_code} 200
+
+Verify after adding flow config
+ [Documentation] Verify the flow
+ [Tags] Get
+ ${resp} Get session ${REST_CON}/node/openflow:1/table/2
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} 10.0.10.2/24
+ Should Contain ${resp.content} 2048
+
+Verify after adding flow operational
+ [Documentation] Verify the flow
+ [Tags] Get
+ ${resp} Get session ${REST_OPR}/node/openflow:1/table/2
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} "flow-node-inventory:id": 2
+
+Remove a flow
+ [Documentation] Remove a flow
+ [Tags] remove
+ ${resp} Delete session ${REST_CON}/node/openflow:1/table/2/flow/139
+ Should Be Equal As Strings ${resp.status_code} 200
+
+Verify after deleting flow config
+ [Documentation] Verify the flow
+ [Tags] Get
+ ${resp} Get session ${REST_CON}/node/openflow:1/table/2
+ Should Be Equal As Strings ${resp.status_code} 404
+ Should Contain ${resp.content} No data exists
+ Should Not Contain ${resp.content} 10.0.10.2/24
+ Should Not Contain ${resp.content} 2048
+
+
--- /dev/null
+*** Settings ***
+Documentation Restat Mininet with OF10 simulation
+Library SSHLibrary
+
+*** Variables ***
+${start}= sudo mn --controller=remote,ip=${CONTROLLER} --topo tree,2
+
+*** Test Cases ***
+Stop Mininet
+ Log Stop Mininet
+ Read
+ Write exit
+ Sleep 4
+ Read
+Start Mininet
+ Log Start Mininet
+ Write ${start}
+ Sleep 70
+ Read
+
--- /dev/null
+*** Settings ***
+Documentation Test suite for RESTCONF inventory
+Suite Setup Create Session session http://${CONTROLLER}:8080 auth=${AUTH} headers=${HEADERS_XML}
+Suite Teardown Delete All Sessions
+Library Collections
+Library ../../libraries/RequestsLibrary.py
+Library ../../libraries/Common.py
+Variables ../../variables/Variables.py
+
+*** Variables ***
+${REST_CONTEXT} /restconf/datastore/opendaylight-inventory:nodes
+
+*** Test Cases ***
+Get list of nodes
+ [Documentation] Get the inventory
+ ${resp} Get session ${REST_CONTEXT}
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} openflow:1
+ Should Contain ${resp.content} openflow:2
+ Should Contain ${resp.content} openflow:3
+
+Get nodeconnector for a node
+ [Documentation] Get the inventory for a node
+ ${resp} Get session ${REST_CONTEXT}/node/openflow:2
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} openflow:2:1
+ Should Contain ${resp.content} openflow:2:2
+ Should Contain ${resp.content} openflow:2:3
+
+
+
--- /dev/null
+*** Settings ***
+Documentation Test suite for pushing/verify/remove a flow through RESTCONF
+Suite Setup Create Session session http://${CONTROLLER}:8080 auth=${AUTH} headers=${HEADERS_XML}
+Suite Teardown Delete All Sessions
+Library Collections
+Library ../../libraries/RequestsLibrary.py
+Library ../../libraries/Common.py
+Variables ../../variables/Variables.py
+
+*** Variables ***
+
+${REST_CON} /restconf/config/opendaylight-inventory:nodes
+${REST_OPR} /restconf/operational/opendaylight-inventory:nodes
+${BODY} <flow xmlns="urn:opendaylight:flow:inventory"><priority>2</priority><flow-name>Foo</flow-name><match><ethernet-match><ethernet-type><type>2048</type></ethernet-type></ethernet-match><ipv4-destination>10.0.10.2/24</ipv4-destination></match><id>139</id><table_id>2</table_id><instructions><instruction><order>0</order><apply-actions><action><order>0</order><dec-nw-ttl/></action></apply-actions></instruction></instructions></flow>
+
+*** Test Cases ***
+Add a flow
+ [Documentation] Push a flow through REST-API
+ [Tags] Push
+ ${resp} Putxml session ${REST_CON}/node/openflow:1/table/2/flow/139 data=${BODY}
+ Should Be Equal As Strings ${resp.status_code} 200
+
+Verify after adding flow config
+ [Documentation] Verify the flow
+ [Tags] Get
+ ${resp} Get session ${REST_CON}/node/openflow:1/table/2
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} 10.0.10.2/24
+ Should Contain ${resp.content} 2048
+
+Verify after adding flow operational
+ [Documentation] Verify the flow
+ [Tags] Get
+ ${resp} Get session ${REST_OPR}/node/openflow:1/table/2
+ Should Be Equal As Strings ${resp.status_code} 200
+ Should Contain ${resp.content} "flow-node-inventory:id": 2
+
+Remove a flow
+ [Documentation] Remove a flow
+ [Tags] remove
+ ${resp} Delete session ${REST_CON}/node/openflow:1/table/2/flow/139
+ Should Be Equal As Strings ${resp.status_code} 200
+
+Verify after deleting flow config
+ [Documentation] Verify the flow
+ [Tags] Get
+ ${resp} Get session ${REST_CON}/node/openflow:1/table/2
+ Should Be Equal As Strings ${resp.status_code} 404
+ Should Contain ${resp.content} No data exists
+ Should Not Contain ${resp.content} 10.0.10.2/24
+ Should Not Contain ${resp.content} 2048
+
+
--- /dev/null
+*** Settings ***
+Documentation Test suite for the OpenDaylight base edition with of13
+Suite Setup Start Suite
+Suite Teardown Stop Suite
+Library SSHLibrary
+
+*** Variables ***
+${start}= sudo mn --controller=remote,ip=${CONTROLLER} --topo tree,2 --switch ovsk,protocols=OpenFlow13
+
+*** Keywords ***
+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 ovs-vsctl set-manager ptcp:6640
+ Write sudo mn -c
+ Sleep 2
+ Write ${start}
+ Sleep 70
+ Read
+Stop Suite
+ Log Stop the test on the base edition
+ Read
+ Write exit
+ Sleep 4
+ Read
+ Close Connection
import collections
# Global variables
-CONTROLLER = '127.0.0.1'
+CONTROLLER = '10.125.136.52'
PORT = '8080'
PREFIX = 'http://' + CONTROLLER + ':' + PORT
CONTAINER = 'default'
USER = 'admin'
PWD = 'admin'
AUTH = [u'admin',u'admin']
-HEADERS={'Content-Type':'application/json'}
+HEADERS={'Content-Type': 'application/json'}
+HEADERS_XML={'Content-Type': 'application/xml'}
ODL_CONTROLLER_SESSION=None
TOPO_TREE_LEVEL=2