STC scenario for testing posting and removal of configs
Change-Id: I5395d6b42a52ba29063eb9ee139dcfb659247614
diff --git a/tools/test/scenarios/bin/check-dhcp-netcfg.py b/tools/test/scenarios/bin/check-dhcp-netcfg.py
new file mode 100755
index 0000000..ed5622e
--- /dev/null
+++ b/tools/test/scenarios/bin/check-dhcp-netcfg.py
@@ -0,0 +1,49 @@
+#! /usr/bin/env python
+
+import requests
+import sys
+
+from requests.auth import HTTPBasicAuth
+
+if len(sys.argv) < 3:
+ print "usage: find-dhcp-netcfg onos-node name1=value1 ..."
+ sys.exit(1)
+
+node = sys.argv[1]
+
+cfgRequest = requests.get('http://' + node + ':8181/onos/v1/network/configuration',
+ auth=HTTPBasicAuth('onos', 'rocks'))
+
+if cfgRequest.status_code != 200:
+ print cfgRequest.text
+ sys.exit(1)
+
+cfgJson = cfgRequest.json()
+appFound = False
+
+
+for index in range(2, len(sys.argv)):
+ pair = sys.argv[index].split("=")
+ for app in cfgJson["apps"]:
+ if app == "org.onosproject.dhcp":
+ dhcp = cfgJson["apps"][app]["dhcp"]
+ appFound = True
+
+ name = pair[0]
+ value = pair[1]
+
+ if dhcp[name] != value:
+ print name + " differs: expected " + value + " but found " + dhcp[name]
+ print cfgJson
+ sys.exit(1)
+
+if appFound:
+ sys.exit(0)
+
+print "DHCP app not found"
+print cfgJson
+sys.exit(2)
+
+
+
+
diff --git a/tools/test/scenarios/bin/delete-netcfg.py b/tools/test/scenarios/bin/delete-netcfg.py
new file mode 100755
index 0000000..6e309c2
--- /dev/null
+++ b/tools/test/scenarios/bin/delete-netcfg.py
@@ -0,0 +1,27 @@
+#! /usr/bin/env python
+
+import requests
+
+from requests.auth import HTTPBasicAuth
+import sys
+
+
+
+if len(sys.argv) != 3:
+ print "usage: delete-netcfg onos-node config-name"
+ sys.exit(1)
+
+node = sys.argv[1]
+configName = sys.argv[2]
+
+intentRequest = requests.delete('http://' + node + ':8181/onos/v1/network/configuration/' + configName,
+ auth=HTTPBasicAuth('onos', 'rocks'))
+
+if intentRequest.status_code != 204:
+ print intentRequest.text
+ sys.exit(1)
+
+sys.exit(0)
+
+
+
diff --git a/tools/test/scenarios/bin/post-netcfg.py b/tools/test/scenarios/bin/post-netcfg.py
new file mode 100755
index 0000000..6104f2c
--- /dev/null
+++ b/tools/test/scenarios/bin/post-netcfg.py
@@ -0,0 +1,29 @@
+#! /usr/bin/env python
+
+import requests
+
+from requests.auth import HTTPBasicAuth
+import sys
+
+if len(sys.argv) != 3:
+ print "usage: post-netcfg onos-node json-file-name"
+ sys.exit(1)
+
+node = sys.argv[1]
+configFileName = sys.argv[2]
+
+jsonFile = open(configFileName, 'rb')
+configJson = jsonFile.read()
+
+request = requests.post('http://' + node + ':8181/onos/v1/network/configuration',
+ auth=HTTPBasicAuth('onos', 'rocks'),
+ data=configJson)
+
+if request.status_code != 200:
+ print request.text
+ sys.exit(1)
+
+sys.exit(0)
+
+
+
diff --git a/tools/test/scenarios/netcfg-test/dhcp-cfg1.json b/tools/test/scenarios/netcfg-test/dhcp-cfg1.json
new file mode 100644
index 0000000..e03c55f
--- /dev/null
+++ b/tools/test/scenarios/netcfg-test/dhcp-cfg1.json
@@ -0,0 +1,22 @@
+{
+ "apps": {
+ "org.onosproject.dhcp" : {
+ "dhcp" : {
+ "ip": "10.1.11.50",
+ "mac": "ca:fe:ca:fe:ca:fe",
+ "subnet": "255.255.252.0",
+ "broadcast": "10.1.11.255",
+ "router": "10.1.8.1",
+ "domain": "8.8.8.8",
+ "ttl": "1",
+ "lease": "2",
+ "renew": "3",
+ "rebind": "4",
+ "delay": "5",
+ "timeout": "6",
+ "startip": "10.1.11.51",
+ "endip": "10.1.11.100"
+ }
+ }
+ }
+}
diff --git a/tools/test/scenarios/netcfg-test/dhcp-cfg2.json b/tools/test/scenarios/netcfg-test/dhcp-cfg2.json
new file mode 100644
index 0000000..48f82ca
--- /dev/null
+++ b/tools/test/scenarios/netcfg-test/dhcp-cfg2.json
@@ -0,0 +1,22 @@
+{
+ "apps": {
+ "org.onosproject.dhcp" : {
+ "dhcp" : {
+ "ip": "10.1.11.50",
+ "mac": "ca:fe:ca:fe:ca:fe",
+ "subnet": "255.255.252.0",
+ "broadcast": "10.1.11.255",
+ "router": "10.1.8.1",
+ "domain": "8.8.8.8",
+ "ttl": "21",
+ "lease": "22",
+ "renew": "23",
+ "rebind": "24",
+ "delay": "25",
+ "timeout": "26",
+ "startip": "10.1.11.51",
+ "endip": "10.1.11.100"
+ }
+ }
+ }
+}
diff --git a/tools/test/scenarios/netcfg.xml b/tools/test/scenarios/netcfg.xml
new file mode 100644
index 0000000..90da4af
--- /dev/null
+++ b/tools/test/scenarios/netcfg.xml
@@ -0,0 +1,71 @@
+<!--
+ ~ Copyright 2016-present Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<scenario name="netcfg"
+ description="Network configuration REST API test">
+
+ <group name="Netcfg">
+
+ <!-- Activate the DHCP app -->
+ <step name="Netcfg.Activate-Dhcp"
+ exec="onos ${OC1} app activate org.onosproject.dhcp"/>
+
+ <!-- Upload the first set of config changes -->
+ <step name="Netcfg.Post-1" requires="^"
+ exec="post-netcfg.py ${OC1} ${ONOS_SCENARIOS}/netcfg-test/dhcp-cfg1.json"/>
+
+ <group name="Query1" requires="Netcfg.Post-1">
+ <parallel var="${OC#}" starts="Netcfg.Query-1-${#}">
+ <!-- Check that the values made it into the config for the DHCP server -->
+ <step name="Netcfg.QueryDhcp-1-${#}" exec="check-dhcp-netcfg.py ${OC#} ttl=1 lease=2 renew=3 rebind=4 delay=5 timeout=6"/>
+ </parallel>
+ </group>
+
+ <!-- Upload the second set of config changes -->
+ <step name="Netcfg.Post-2" requires="Query1"
+ exec="post-netcfg.py ${OC1} ${ONOS_SCENARIOS}/netcfg-test/dhcp-cfg2.json"/>
+
+ <!-- Check that the values made it into the config for the DHCP server -->
+ <group name="Query2" requires="Netcfg.Post-2">
+ <parallel var="${OC#}" starts="Netcfg.Query-2-${#}">
+ <!-- Check that the values made it into the config for the DHCP server -->
+ <step name="Netcfg.QueryDhcp-2-${#}" exec="check-dhcp-netcfg.py ${OC#} ttl=21 lease=22 renew=23 rebind=24 delay=25 timeout=26"/>
+ </parallel>
+ </group>
+
+
+ <!-- Delete the DHCP server config -->
+ <step name="Netcfg.Delete" requires="Query2"
+ exec="delete-netcfg.py ${OC1} apps/org.onosproject.dhcp/dhcp"/>
+
+ <!-- Check that the config for the DHCP server is no longer there -->
+ <group name="Query3" requires="Netcfg.Delete">
+ <parallel var="${OC#}" starts="Netcfg.Query-3-${#}">
+ <!-- Check that the values were deleted for the config for the DHCP server -->
+ <step name="Netcfg.QueryDhcp-31-${#}" env="!" exec="check-dhcp-netcfg.py ${OC#} ttl=21"/>
+ <step name="Netcfg.QueryDhcp-32-${#}" env="!" exec="check-dhcp-netcfg.py ${OC#} lease=22"/>
+ <step name="Netcfg.QueryDhcp-33-${#}" env="!" exec="check-dhcp-netcfg.py ${OC#} renew=23"/>
+ <step name="Netcfg.QueryDhcp-34-${#}" env="!" exec="check-dhcp-netcfg.py ${OC#} rebind=24"/>
+ <step name="Netcfg.QueryDhcp-35-${#}" env="!" exec="check-dhcp-netcfg.py ${OC#} delay=25"/>
+ <step name="Netcfg.QueryDhcp-36-${#}" env="!" exec="check-dhcp-netcfg.py ${OC#} timeout=26"/>
+ </parallel>
+ </group>
+
+ <!-- Deactivate the DHCP app -->
+ <step name="Netcfg.Deactivate-Dhcp" requires="Query3"
+ exec="onos ${OC1} app deactivate org.onosproject.dhcp"/>
+
+ </group>
+</scenario>
diff --git a/tools/test/scenarios/smoke.xml b/tools/test/scenarios/smoke.xml
index dce57c5..0c82bd4 100644
--- a/tools/test/scenarios/smoke.xml
+++ b/tools/test/scenarios/smoke.xml
@@ -34,6 +34,9 @@
<import file="${ONOS_SCENARIOS}/drivers-test.xml"/>
<dependency name="Drivers-Test" requires="Setup,Net-Smoke,Archetypes"/>
+ <import file="${ONOS_SCENARIOS}/netcfg.xml"/>
+ <dependency name="Netcfg" requires="Setup"/>
+
<import file="${ONOS_SCENARIOS}/wrapup.xml"/>
- <dependency name="Wrapup" requires="~Archetypes,~Setup,~Net-Smoke,~Drivers-Test,~MetaAppReactivated"/>
+ <dependency name="Wrapup" requires="~Archetypes,~Setup,~Net-Smoke,~Drivers-Test,~MetaAppReactivated,~Netcfg"/>
</scenario>