summaryrefslogtreecommitdiffhomepage
path: root/tests/unit/app
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-06-30 14:23:03 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-06-30 14:23:03 +0900
commita991fed7e4faa485dc67daf50ba64fe01f83415d (patch)
treea600daa350a36c1fdc7776c111575bef56f78627 /tests/unit/app
parenta67ed2858417b9d795460f05126c01fb0cd344f9 (diff)
Revert "tests: Separate test files from Ryu module"
This reverts commit a67ed2858417b9d795460f05126c01fb0cd344f9. The commit breaks OpenStack neutron dynamic routing.
Diffstat (limited to 'tests/unit/app')
-rw-r--r--tests/unit/app/__init__.py0
-rw-r--r--tests/unit/app/ofctl_rest_json/of10.json101
-rw-r--r--tests/unit/app/ofctl_rest_json/of12.json150
-rw-r--r--tests/unit/app/ofctl_rest_json/of13.json191
-rw-r--r--tests/unit/app/ofctl_rest_json/of14.json195
-rw-r--r--tests/unit/app/ofctl_rest_json/of15.json203
-rw-r--r--tests/unit/app/test_ofctl_rest.py138
-rw-r--r--tests/unit/app/test_tester.py464
-rw-r--r--tests/unit/app/test_ws_topology.py54
-rw-r--r--tests/unit/app/test_wsgi.py104
10 files changed, 0 insertions, 1600 deletions
diff --git a/tests/unit/app/__init__.py b/tests/unit/app/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/unit/app/__init__.py
+++ /dev/null
diff --git a/tests/unit/app/ofctl_rest_json/of10.json b/tests/unit/app/ofctl_rest_json/of10.json
deleted file mode 100644
index 266eb80c..00000000
--- a/tests/unit/app/ofctl_rest_json/of10.json
+++ /dev/null
@@ -1,101 +0,0 @@
-[
- {
- "method": "GET",
- "path": "/stats/switches"
- },
- {
- "method": "GET",
- "path": "/stats/desc/1"
- },
- {
- "method": "GET",
- "path": "/stats/flow/1"
- },
- {
- "method": "POST",
- "path": "/stats/flow/1"
- },
- {
- "method": "GET",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "POST",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/portdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/table/1"
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "DELETE",
- "path": "/stats/flowentry/clear/1"
- },
- {
- "method": "POST",
- "path": "/stats/portdesc/modify",
- "body": {
- "dpid": 1,
- "port_no": 1
- }
- }
-]
diff --git a/tests/unit/app/ofctl_rest_json/of12.json b/tests/unit/app/ofctl_rest_json/of12.json
deleted file mode 100644
index 89a81919..00000000
--- a/tests/unit/app/ofctl_rest_json/of12.json
+++ /dev/null
@@ -1,150 +0,0 @@
-[
- {
- "method": "GET",
- "path": "/stats/switches"
- },
- {
- "method": "GET",
- "path": "/stats/desc/1"
- },
- {
- "method": "GET",
- "path": "/stats/flow/1"
- },
- {
- "method": "POST",
- "path": "/stats/flow/1"
- },
- {
- "method": "GET",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "POST",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/portdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queueconfig/1"
- },
- {
- "method": "GET",
- "path": "/stats/queueconfig/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/table/1"
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "DELETE",
- "path": "/stats/flowentry/clear/1"
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/portdesc/modify",
- "body": {
- "dpid": 1,
- "port_no": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/experimenter/1"
- }
-]
diff --git a/tests/unit/app/ofctl_rest_json/of13.json b/tests/unit/app/ofctl_rest_json/of13.json
deleted file mode 100644
index d515f628..00000000
--- a/tests/unit/app/ofctl_rest_json/of13.json
+++ /dev/null
@@ -1,191 +0,0 @@
-[
- {
- "method": "GET",
- "path": "/stats/switches"
- },
- {
- "method": "GET",
- "path": "/stats/desc/1"
- },
- {
- "method": "GET",
- "path": "/stats/flow/1"
- },
- {
- "method": "POST",
- "path": "/stats/flow/1"
- },
- {
- "method": "GET",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "POST",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/portdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queueconfig/1"
- },
- {
- "method": "GET",
- "path": "/stats/queueconfig/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/meter/1"
- },
- {
- "method": "GET",
- "path": "/stats/meter/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterconfig/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterconfig/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/table/1"
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "DELETE",
- "path": "/stats/flowentry/clear/1"
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/portdesc/modify",
- "body": {
- "dpid": 1,
- "port_no": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/experimenter/1"
- }
-]
diff --git a/tests/unit/app/ofctl_rest_json/of14.json b/tests/unit/app/ofctl_rest_json/of14.json
deleted file mode 100644
index 0cc4eb6c..00000000
--- a/tests/unit/app/ofctl_rest_json/of14.json
+++ /dev/null
@@ -1,195 +0,0 @@
-[
- {
- "method": "GET",
- "path": "/stats/switches"
- },
- {
- "method": "GET",
- "path": "/stats/desc/1"
- },
- {
- "method": "GET",
- "path": "/stats/flow/1"
- },
- {
- "method": "POST",
- "path": "/stats/flow/1"
- },
- {
- "method": "GET",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "POST",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/portdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queuedesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/queuedesc/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queuedesc/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/meter/1"
- },
- {
- "method": "GET",
- "path": "/stats/meter/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterconfig/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterconfig/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/table/1"
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "DELETE",
- "path": "/stats/flowentry/clear/1"
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/portdesc/modify",
- "body": {
- "dpid": 1,
- "port_no": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/experimenter/1"
- }
-]
diff --git a/tests/unit/app/ofctl_rest_json/of15.json b/tests/unit/app/ofctl_rest_json/of15.json
deleted file mode 100644
index a7569223..00000000
--- a/tests/unit/app/ofctl_rest_json/of15.json
+++ /dev/null
@@ -1,203 +0,0 @@
-[
- {
- "method": "GET",
- "path": "/stats/switches"
- },
- {
- "method": "GET",
- "path": "/stats/desc/1"
- },
- {
- "method": "GET",
- "path": "/stats/flow/1"
- },
- {
- "method": "POST",
- "path": "/stats/flow/1"
- },
- {
- "method": "GET",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "POST",
- "path": "/stats/aggregateflow/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1"
- },
- {
- "method": "GET",
- "path": "/stats/port/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/portdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/portdesc/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queue/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queuedesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/queuedesc/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/queuedesc/1/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1"
- },
- {
- "method": "GET",
- "path": "/stats/group/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupdesc/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/groupfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/meter/1"
- },
- {
- "method": "GET",
- "path": "/stats/meter/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterdesc/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterdesc/1/1"
- },
- {
- "method": "GET",
- "path": "/stats/meterfeatures/1"
- },
- {
- "method": "GET",
- "path": "/stats/table/1"
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/modify_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/flowentry/delete_strict",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "DELETE",
- "path": "/stats/flowentry/clear/1"
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/groupentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/portdesc/modify",
- "body": {
- "dpid": 1,
- "port_no": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/add",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/modify",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/meterentry/delete",
- "body": {
- "dpid": 1
- }
- },
- {
- "method": "POST",
- "path": "/stats/experimenter/1"
- }
-]
diff --git a/tests/unit/app/test_ofctl_rest.py b/tests/unit/app/test_ofctl_rest.py
deleted file mode 100644
index 5ed70ec4..00000000
--- a/tests/unit/app/test_ofctl_rest.py
+++ /dev/null
@@ -1,138 +0,0 @@
-# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
-#
-# 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.
-
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-import functools
-import json
-import logging
-import os
-import sys
-import unittest
-try:
- import mock # Python 2
-except ImportError:
- from unittest import mock # Python 3
-from nose.tools import eq_
-
-from ryu.app import ofctl_rest
-from ryu.app.wsgi import Request
-from ryu.app.wsgi import WSGIApplication
-from ryu.controller.dpset import DPSet
-from ryu.ofproto import ofproto_protocol
-from ryu.ofproto import ofproto_v1_0
-from ryu.ofproto import ofproto_v1_2
-from ryu.ofproto import ofproto_v1_3
-from ryu.ofproto import ofproto_v1_4
-from ryu.ofproto import ofproto_v1_5
-
-from tests import test_lib
-
-
-LOG = logging.getLogger(__name__)
-
-
-class DummyDatapath(ofproto_protocol.ProtocolDesc):
-
- def __init__(self, version):
- super(DummyDatapath, self).__init__(version)
- self.id = 1
- _kw = {'port_no': 1, 'hw_addr': 'aa:bb:cc:dd:ee:ff',
- 'name': 's1-eth1', 'config': 1, 'state': 1}
- # for OpenFlow 1.0
- if version in [ofproto_v1_0.OFP_VERSION]:
- _kw.update(
- {'curr': 2112, 'advertised': 0, 'supported': 0, 'peer': 0})
- port_info = self.ofproto_parser.OFPPhyPort(**_kw)
- # for OpenFlow 1.2 or 1.3
- elif version in [ofproto_v1_2.OFP_VERSION, ofproto_v1_3.OFP_VERSION]:
- _kw.update(
- {'curr': 2112, 'advertised': 0, 'supported': 0, 'peer': 0,
- 'curr_speed': 10000000, 'max_speed': 0})
- port_info = self.ofproto_parser.OFPPort(**_kw)
- # for OpenFlow 1.4+
- else:
- _kw.update({'properties': []})
- port_info = self.ofproto_parser.OFPPort(**_kw)
- self.ports = {1: port_info}
-
-
-class Test_ofctl_rest(unittest.TestCase):
-
- def _test(self, name, dp, method, path, body):
- # print('processing %s ...' % name)
-
- dpset = DPSet()
- dpset._register(dp)
- wsgi = WSGIApplication()
- contexts = {
- 'dpset': dpset,
- 'wsgi': wsgi,
- }
- ofctl_rest.RestStatsApi(**contexts)
-
- req = Request.blank(path)
- req.body = json.dumps(body).encode('utf-8')
- req.method = method
-
- with mock.patch('ryu.lib.ofctl_utils.send_stats_request'),\
- mock.patch('ryu.lib.ofctl_utils.send_msg'):
- res = req.get_response(wsgi)
- eq_(res.status, '200 OK')
-
-
-def _add_tests():
- _ofp_vers = {
- 'of10': ofproto_v1_0.OFP_VERSION,
- 'of12': ofproto_v1_2.OFP_VERSION,
- 'of13': ofproto_v1_3.OFP_VERSION,
- 'of14': ofproto_v1_4.OFP_VERSION,
- 'of15': ofproto_v1_5.OFP_VERSION,
- }
-
- this_dir = os.path.dirname(sys.modules[__name__].__file__)
- ofctl_rest_json_dir = os.path.join(this_dir, 'ofctl_rest_json/')
-
- for ofp_ver in _ofp_vers:
- # read a json file
- json_path = os.path.join(ofctl_rest_json_dir, ofp_ver + '.json')
- if os.path.exists(json_path):
- _test_cases = json.load(open(json_path))
- else:
- # print("Skip to load test cases for %s" % ofp_ver)
- continue
-
- # add test
- for test in _test_cases:
- method = test['method']
- path = test['path']
- body = test.get('body', {})
-
- name = 'test_ofctl_rest_' + method + '_' + ofp_ver + '_' + path
- # print('adding %s ...' % name)
- f = functools.partial(
- Test_ofctl_rest._test,
- name=name,
- dp=DummyDatapath(_ofp_vers[ofp_ver]),
- method=test['method'],
- path=test['path'],
- body=body
- )
- test_lib.add_method(Test_ofctl_rest, name, f)
-
-_add_tests()
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/tests/unit/app/test_tester.py b/tests/unit/app/test_tester.py
deleted file mode 100644
index 64657f9e..00000000
--- a/tests/unit/app/test_tester.py
+++ /dev/null
@@ -1,464 +0,0 @@
-# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
-#
-# 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.
-
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-import unittest
-from nose.tools import *
-
-import binascii
-import inspect
-import json
-import logging
-import math
-import netaddr
-import os
-import signal
-import sys
-import time
-import traceback
-from random import randint
-
-from ryu import cfg
-
-# import all packet libraries.
-PKT_LIB_PATH = 'ryu.lib.packet'
-for modname, moddef in sys.modules.items():
- if not modname.startswith(PKT_LIB_PATH) or not moddef:
- continue
- for (clsname, clsdef, ) in inspect.getmembers(moddef):
- if not inspect.isclass(clsdef):
- continue
- exec('from %s import %s' % (modname, clsname))
-
-from ryu.base import app_manager
-from ryu.controller import handler
-from ryu.controller import ofp_event
-from ryu.controller.handler import set_ev_cls
-from ryu.exception import RyuException
-from ryu.lib import dpid as dpid_lib
-from ryu.lib import hub
-from ryu.lib import stringify
-from ryu.lib.packet import packet
-from ryu.ofproto import ofproto_protocol
-from ryu.ofproto import ofproto_v1_3
-from ryu.ofproto import ofproto_v1_3_parser
-from ryu.ofproto import ofproto_v1_4
-
-from ryu.tests.switch.tester import TestPatterns
-from ryu.tests.switch.tester import TestFile
-from ryu.tests.switch.tester import OfTester
-
-CONF = cfg.CONF
-
-LOG = logging.getLogger('test_tester')
-
-SAMPLE_DESC = "action: 00_OUTPUT"
-
-
-class Test_tester(unittest.TestCase):
-
- """ Test case for tester
- """
-
- # action/00_OUTPUT.json
-
- test_json_1 = {
- "description": "ethernet/ipv4/tcp-->'actions=output:2'",
- "prerequisite": [
- {
- "OFPFlowMod": {
- "table_id": 0,
- "instructions": [
- {
- "OFPInstructionActions": {
- "actions": [
- {
- "OFPActionOutput": {
- "port": "target_send_port_1"
- }
- }
- ],
- "type": 4
- }
- }
- ]
- }
- }
- ],
- "tests": [
- {
- "ingress": [
- "ethernet(dst='22:22:22:22:22:22', \
- src='12:11:11:11:11:11', ethertype=2048)",
- "ipv4(tos=32, proto=6, src='192.168.10.10', \
- dst='192.168.20.20', ttl=64)",
- "tcp(dst_port=2222, option=str('\\x00' * 4), \
- src_port=11111)",
- "'\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x0\
- 8\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x1\
- 2\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1\
- b\\x1c\\x1d\\x1e\\x1f'"
- ],
- "egress":[
- "ethernet(dst='22:22:22:22:22:22', \
- src='12:11:11:11:11:11', ethertype=2048)",
- "ipv4(tos=32, proto=6, src='192.168.10.10', \
- dst='192.168.20.20', ttl=64)",
- "tcp(dst_port=2222, option=str('\\x00' * 4), \
- src_port=11111)",
- "'\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x0\
- 8\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x1\
- 2\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1\
- b\\x1c\\x1d\\x1e\\x1f'"
- ]
-
- }
- ]
- }
-
- # group/00_ALL.json
-
- test_json_2 = {
- "description": "2Mbps(ethernet/ipv4/tcp)-->'in_port=1,\
- actions=group:all(actions=output:2/actions=output:3)'",
- "prerequisite": [
- {
- "OFPGroupMod": {
- "group_id": 0,
- "buckets": [
- {
- "OFPBucket": {
- "actions": [
- {
- "OFPActionOutput": {
- "port": "target_send_port_1"
- }
- }
- ]
- }
- },
- {
- "OFPBucket": {
- "actions": [
- {
- "OFPActionOutput": {
- "port": "target_send_port_2"
- }
- }
- ]
- }
- }
- ]
- }
- },
- {
- "OFPFlowMod": {
- "match": {
- "OFPMatch": {
- "oxm_fields": [
- {
- "OXMTlv": {
- "field": "in_port",
- "value": "target_recv_port"
- }
- }
- ]
- }
- },
- "instructions": [
- {
- "OFPInstructionActions": {
- "actions": [
- {
- "OFPActionGroup": {
- "group_id": 0
- }
- }
- ],
- "type": 4
- }
- }
- ]
- }
- }
- ],
- "tests": [
- {
- "ingress": {
- "packets": {
- "data": [
- "ethernet(dst='22:22:22:22:22:22', \
- src='12:11:11:11:11:11', ethertype=2048)",
- "ipv4(proto=6)",
- "tcp()",
- "str('\\x11' * (1500 - 54))"
- ],
- "pktps":175,
- "duration_time":30
- }
- },
- "egress":{
- "throughput": [
- {
- "OFPMatch": {
- "oxm_fields": [
- {
- "OXMTlv": {
- "field": "in_port",
- "value": "tester_recv_port_1"
- }
- }
- ]
- },
- "kbps": 2000
- },
- {
- "OFPMatch": {
- "oxm_fields": [
- {
- "OXMTlv": {
- "field": "in_port",
- "value": "tester_recv_port_2"
- }
- }
- ]
- },
- "kbps": 2000
- }
- ]
- }
- }
- ]
- }
-
- # match/00_IN_PORT.json
-
- test_json_3 = {
- "description": "ethernet/ipv4/tcp-->'in_port=1,actions=output:2'",
- "prerequisite": [
- {
- "OFPFlowMod": {
- "table_id": 0,
- "match": {
- "OFPMatch": {
- "oxm_fields": [
- {
- "OXMTlv": {
- "field": "in_port",
- "value": "target_recv_port"
- }
- }
- ]
- }
- },
- "instructions": [
- {
- "OFPInstructionActions": {
- "actions": [
- {
- "OFPActionOutput": {
- "port": "target_send_port_1"
- }
- }
- ],
- "type": 4
- }
- }
- ]
- }
- }
- ],
- "tests": [
- {
- "ingress": [
- "ethernet(dst='22:22:22:22:22:22', \
- src='12:11:11:11:11:11', ethertype=2048)",
- "ipv4(tos=32, proto=6, src='192.168.10.10', \
- dst='192.168.20.20', ttl=64)",
- "tcp(dst_port=2222, option=str('\\x00' * 4), \
- src_port=11111)",
- "'\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x0\
- 8\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x1\
- 2\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1\
- b\\x1c\\x1d\\x1e\\x1f'"
- ],
- "egress":[
- "ethernet(dst='22:22:22:22:22:22', \
- src='12:11:11:11:11:11', ethertype=2048)",
- "ipv4(tos=32, proto=6, src='192.168.10.10',\
- dst='192.168.20.20', ttl=64)",
- "tcp(dst_port=2222, option=str('\\x00' * 4), \
- src_port=11111)",
- "'\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x0\
- 8\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x1\
- 2\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1\
- b\\x1c\\x1d\\x1e\\x1f'"
- ]
- }
- ]
- }
-
- # meter/01_DROP_00_KBPS_00_1M.json
-
- test_json_4 = {
- "description": "2Mbps(ethernet/ipv4/tcp)-->'in_port=1,\
- actions=meter:1Mbps(drop),output:2'",
- "prerequisite": [
- {
- "OFPMeterMod": {
- "meter_id": 1,
- "bands": [
- {
- "OFPMeterBandDrop": {
- "rate": 1000
- }
- }
- ]
- }
- },
- {
- "OFPFlowMod": {
- "match": {
- "OFPMatch": {
- "oxm_fields": [
- {
- "OXMTlv": {
- "field": "in_port",
- "value": "target_recv_port"
- }
- }
- ]
- }
- },
- "instructions": [
- {
- "OFPInstructionMeter": {
- "meter_id": 1
- }
- },
- {
- "OFPInstructionActions": {
- "actions": [
- {
- "OFPActionOutput": {
- "port": "target_send_port_1"
- }
- }
- ],
- "type": 4
- }
- }
- ]
- }
- }
- ],
- "tests": [
- {
- "ingress": {
- "packets": {
- "data": [
- "ethernet(dst='22:22:22:22:22:22', \
- src='12:11:11:11:11:11', ethertype=2048)",
- "ipv4(proto=6)",
- "tcp()",
- "str('\\x11' * (1500 - 54))"
- ],
- "pktps":175,
- "duration_time":30
- }
- },
- "egress":{
- "throughput": [
- {
- "OFPMatch": {
- "oxm_fields": [
- {
- "OXMTlv": {
- "field": "in_port",
- "value": "tester_recv_port_1"
- }
-
- }
- ]
- },
- "kbps": 1000
- }
- ]
- }
- }
- ]
- }
-
- def setUp(self):
- OfTester.tester_ver = ofproto_v1_3.OFP_VERSION
- OfTester.target_ver = ofproto_v1_3.OFP_VERSION
-
- def tearDown(self):
- pass
-
- def test__normalize_test_json(self):
- self.tests = TestPatterns(
- "../../ryu/tests/switch/of13/action/00_OUTPUT.json",
- logging.getLogger("test_tester"))
-
- self.tests[SAMPLE_DESC]._normalize_test_json(Test_tester.test_json_1)
- self.tests[SAMPLE_DESC]._normalize_test_json(Test_tester.test_json_2)
- self.tests[SAMPLE_DESC]._normalize_test_json(Test_tester.test_json_3)
- self.tests[SAMPLE_DESC]._normalize_test_json(Test_tester.test_json_4)
-
- # action/00_OUTPUT.json
- eq_(Test_tester.test_json_1["prerequisite"][0]["OFPFlowMod"][
- "instructions"][0]["OFPInstructionActions"][
- "actions"][0]["OFPActionOutput"]["port"],
- CONF['test-switch']['target_send_port_1'])
-
- # group/00_ALL.json
- eq_(Test_tester.test_json_2["prerequisite"][1]["OFPFlowMod"][
- "match"]["OFPMatch"]["oxm_fields"][0]["OXMTlv"]["value"],
- CONF['test-switch']['target_recv_port'])
- eq_(Test_tester.test_json_2["prerequisite"][0]["OFPGroupMod"][
- "buckets"][0]["OFPBucket"]["actions"][0]["OFPActionOutput"][
- "port"], CONF['test-switch']['target_send_port_1'])
- eq_(Test_tester.test_json_2["prerequisite"][0]["OFPGroupMod"][
- "buckets"][1]["OFPBucket"]["actions"][0]["OFPActionOutput"][
- "port"], CONF['test-switch']['target_send_port_2'])
- eq_(Test_tester.test_json_2["tests"][0]["egress"]["throughput"][
- 0]["OFPMatch"]["oxm_fields"][0]["OXMTlv"]["value"],
- CONF['test-switch']['tester_recv_port_1'])
- eq_(Test_tester.test_json_2["tests"][0]["egress"]["throughput"][
- 1]["OFPMatch"]["oxm_fields"][0]["OXMTlv"]["value"],
- CONF['test-switch']['tester_recv_port_2'])
-
- # match/00_IN_PORT.json
- eq_(Test_tester.test_json_3["prerequisite"][0]["OFPFlowMod"][
- "match"]["OFPMatch"]["oxm_fields"][0]["OXMTlv"]["value"],
- CONF['test-switch']['target_recv_port'])
- eq_(Test_tester.test_json_3["prerequisite"][0]["OFPFlowMod"][
- "instructions"][0]["OFPInstructionActions"]["actions"][0][
- "OFPActionOutput"]["port"], CONF['test-switch'][
- 'target_send_port_1'])
-
- # meter/01_DROP_00_KBPS_00_1M.json
- eq_(Test_tester.test_json_4["prerequisite"][1]["OFPFlowMod"][
- "match"]["OFPMatch"]["oxm_fields"][0]["OXMTlv"]["value"],
- CONF['test-switch']['target_recv_port'])
- eq_(Test_tester.test_json_4["prerequisite"][1]["OFPFlowMod"][
- "instructions"][1]["OFPInstructionActions"]["actions"][0][
- "OFPActionOutput"]["port"],
- CONF['test-switch']['target_send_port_1'])
- eq_(Test_tester.test_json_4["tests"][0]["egress"]["throughput"][
- 0]["OFPMatch"]["oxm_fields"][0]["OXMTlv"]["value"],
- CONF['test-switch']['tester_recv_port_1'])
diff --git a/tests/unit/app/test_ws_topology.py b/tests/unit/app/test_ws_topology.py
deleted file mode 100644
index 6eaaa0e5..00000000
--- a/tests/unit/app/test_ws_topology.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright (C) 2013 Stratosphere Inc.
-#
-# 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.
-
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-import unittest
-from socket import error as SocketError
-
-import mock
-
-from ryu.app.ws_topology import WebSocketTopology
-
-
-class Test_ws_topology(unittest.TestCase):
-
- def test_when_sock_error(self):
- args = {
- 'wsgi': mock.Mock(),
- }
- app = WebSocketTopology(**args)
-
- rpc_client_mock1 = mock.Mock()
- config = {
- 'get_proxy.return_value.event_link_add.side_effect': SocketError,
- }
- rpc_client_mock1.configure_mock(**config)
-
- rpc_client_mock2 = mock.Mock()
-
- app.rpc_clients = [
- rpc_client_mock1,
- rpc_client_mock2,
- ]
-
- ev_mock = mock.Mock()
- app._event_link_add_handler(ev_mock)
-
- rpc_client_mock1.get_proxy.assert_called_once_with()
- rpc_client_mock2.get_proxy.assert_called_once_with()
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/tests/unit/app/test_wsgi.py b/tests/unit/app/test_wsgi.py
deleted file mode 100644
index bec21ddc..00000000
--- a/tests/unit/app/test_wsgi.py
+++ /dev/null
@@ -1,104 +0,0 @@
-# Copyright (C) 2013 Stratosphere Inc.
-#
-# 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.
-
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-import unittest
-import logging
-
-import nose
-from nose.tools import eq_
-
-from ryu.app.wsgi import ControllerBase
-from ryu.app.wsgi import WSGIApplication
-from ryu.app.wsgi import Response
-from ryu.app.wsgi import route
-from ryu.lib import dpid as dpidlib
-
-LOG = logging.getLogger('test_wsgi')
-
-
-class _TestController(ControllerBase):
-
- def __init__(self, req, link, data, **config):
- super(_TestController, self).__init__(req, link, data, **config)
- eq_(data['test_param'], 'foo')
-
- @route('test', '/test/{dpid}',
- methods=['GET'], requirements={'dpid': dpidlib.DPID_PATTERN})
- def test_get_dpid(self, req, dpid, **_kwargs):
- return Response(status=200, body=dpid)
-
- @route('test', '/test')
- def test_root(self, req, **_kwargs):
- return Response(status=200, body='root')
-
-
-class Test_wsgi(unittest.TestCase):
-
- """ Test case for wsgi
- """
-
- def setUp(self):
- controller_data = {
- 'test_param': 'foo'
- }
- self.wsgi_app = WSGIApplication()
- self.wsgi_app.register(_TestController, controller_data)
-
- def tearDown(self):
- pass
-
- def test_wsgi_decorator_ok(self):
- r = self.wsgi_app({'REQUEST_METHOD': 'GET',
- 'PATH_INFO': '/test/0123456789abcdef'},
- lambda s, _: eq_(s, '200 OK'))
- eq_(r[0], (b'0123456789abcdef'))
-
- def test_wsgi_decorator_ng_path(self):
- self.wsgi_app({'REQUEST_METHOD': 'GET',
- 'PATH_INFO': '/'},
- lambda s, _: eq_(s, '404 Not Found'))
-
- def test_wsgi_decorator_ng_method(self):
- # XXX: If response code is "405 Method Not Allowed", it is better.
- self.wsgi_app({'REQUEST_METHOD': 'PUT',
- 'PATH_INFO': '/test/0123456789abcdef'},
- lambda s, _: eq_(s, '404 Not Found'))
-
- def test_wsgi_decorator_ng_requirements(self):
- # XXX: If response code is "400 Bad Request", it is better.
- self.wsgi_app({'REQUEST_METHOD': 'GET',
- 'PATH_INFO': '/test/hogehoge'},
- lambda s, _: eq_(s, '404 Not Found'))
-
- def test_wsgi_decorator_ok_any_method(self):
- self.wsgi_app({'REQUEST_METHOD': 'GET',
- 'PATH_INFO': '/test'},
- lambda s, _: eq_(s, '200 OK'))
- self.wsgi_app({'REQUEST_METHOD': 'POST',
- 'PATH_INFO': '/test'},
- lambda s, _: eq_(s, '200 OK'))
- self.wsgi_app({'REQUEST_METHOD': 'PUT',
- 'PATH_INFO': '/test'},
- lambda s, _: eq_(s, '200 OK'))
- r = self.wsgi_app({'REQUEST_METHOD': 'DELETE',
- 'PATH_INFO': '/test'},
- lambda s, _: eq_(s, '200 OK'))
- eq_(r[0], b'root')
-
-
-if __name__ == '__main__':
- nose.main(argv=['nosetests', '-s', '-v'], defaultTest=__file__)