Skip to content

Commit

Permalink
ryu/app: Use Request/Response wrappers in REST Apps
Browse files Browse the repository at this point in the history
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
  • Loading branch information
iwaseyusuke authored and fujita committed Dec 29, 2016
1 parent 40178c9 commit 49461e8
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 30 deletions.
7 changes: 3 additions & 4 deletions ryu/app/ofctl_rest.py
Expand Up @@ -14,10 +14,8 @@
# limitations under the License.

import logging

import json
import ast
from webob import Response

from ryu.base import app_manager
from ryu.controller import ofp_event
Expand All @@ -35,8 +33,9 @@
from ryu.lib import ofctl_v1_3
from ryu.lib import ofctl_v1_4
from ryu.lib import ofctl_v1_5
from ryu.app.wsgi import ControllerBase, WSGIApplication

from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.app.wsgi import WSGIApplication

LOG = logging.getLogger('ryu.app.ofctl_rest')

Expand Down
6 changes: 3 additions & 3 deletions ryu/app/rest_conf_switch.py
Expand Up @@ -21,12 +21,12 @@
Used by OpenStack Ryu agent.
"""

from six.moves import http_client
import json
import logging
from webob import Response

from six.moves import http_client

from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.base import app_manager
from ryu.controller import conf_switch
from ryu.lib import dpid as dpid_lib
Expand Down
3 changes: 1 addition & 2 deletions ryu/app/rest_firewall.py
Expand Up @@ -17,9 +17,8 @@
import logging
import json

from webob import Response

from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.app.wsgi import WSGIApplication
from ryu.base import app_manager
from ryu.controller import ofp_event
Expand Down
7 changes: 4 additions & 3 deletions ryu/app/rest_qos.py
Expand Up @@ -18,10 +18,11 @@
import json
import re

from webob import Response

from ryu.app import conf_switch_key as cs_key
from ryu.app.wsgi import ControllerBase, WSGIApplication, route
from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.app.wsgi import route
from ryu.app.wsgi import WSGIApplication
from ryu.base import app_manager
from ryu.controller import conf_switch
from ryu.controller import ofp_event
Expand Down
2 changes: 1 addition & 1 deletion ryu/app/rest_router.py
Expand Up @@ -20,9 +20,9 @@
import struct

import json
from webob import Response

from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.app.wsgi import WSGIApplication
from ryu.base import app_manager
from ryu.controller import dpset
Expand Down
6 changes: 4 additions & 2 deletions ryu/app/rest_topology.py
Expand Up @@ -14,9 +14,11 @@
# limitations under the License.

import json
from webob import Response

from ryu.app.wsgi import ControllerBase, WSGIApplication, route
from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.app.wsgi import route
from ryu.app.wsgi import WSGIApplication
from ryu.base import app_manager
from ryu.lib import dpid as dpid_lib
from ryu.topology.api import get_switch, get_link, get_host
Expand Down
6 changes: 4 additions & 2 deletions ryu/app/simple_switch_rest_13.py
Expand Up @@ -16,11 +16,13 @@
import json

from ryu.app import simple_switch_13
from webob import Response
from ryu.controller import ofp_event
from ryu.controller.handler import CONFIG_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.app.wsgi import ControllerBase, WSGIApplication, route
from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import Response
from ryu.app.wsgi import route
from ryu.app.wsgi import WSGIApplication
from ryu.lib import dpid as dpid_lib

simple_switch_instance_name = 'simple_switch_api_app'
Expand Down
11 changes: 5 additions & 6 deletions ryu/app/simple_switch_websocket_13.py
Expand Up @@ -42,15 +42,14 @@
15:0c:de:49": 2}}}
"""

import json

from webob import Response
from ryu.app import simple_switch_13
from ryu.app.wsgi import route, websocket, ControllerBase, WSGIApplication
from ryu.app.wsgi import rpc_public, WebSocketRPCServer
from ryu.app.wsgi import ControllerBase
from ryu.app.wsgi import rpc_public
from ryu.app.wsgi import websocket
from ryu.app.wsgi import WebSocketRPCServer
from ryu.app.wsgi import WSGIApplication
from ryu.controller import ofp_event
from ryu.controller.handler import set_ev_cls
from ryu.lib import hub
from ryu.lib.packet import packet


Expand Down
12 changes: 6 additions & 6 deletions ryu/tests/unit/app/test_ofctl_rest.py
Expand Up @@ -18,17 +18,17 @@
import functools
import json
import logging
from nose.tools import eq_
import os
import sys
import unittest
from webob.request import Request
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
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, version):
class Test_ofctl_rest(unittest.TestCase):

def _test(self, name, dp, method, path, body):
print('processing %s ...' % name)
# print('processing %s ...' % name)

dpset = DPSet()
dpset._register(dp)
Expand Down Expand Up @@ -104,13 +104,13 @@ def _add_tests():
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.keys():
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)
# print("Skip to load test cases for %s" % ofp_ver)
continue

# add test
Expand All @@ -120,7 +120,7 @@ def _add_tests():
body = test.get('body', {})

name = 'test_ofctl_rest_' + method + '_' + ofp_ver + '_' + path
print('adding %s ...' % name)
# print('adding %s ...' % name)
f = functools.partial(
Test_ofctl_rest._test,
name=name,
Expand Down
2 changes: 1 addition & 1 deletion ryu/tests/unit/app/test_wsgi.py
Expand Up @@ -20,10 +20,10 @@

import nose
from nose.tools import eq_
from webob.response import Response

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

Expand Down

0 comments on commit 49461e8

Please sign in to comment.