diff options
Diffstat (limited to 'moon_wrapper')
-rw-r--r-- | moon_wrapper/Changelog | 28 | ||||
-rw-r--r-- | moon_wrapper/Dockerfile | 11 | ||||
-rw-r--r-- | moon_wrapper/moon_wrapper/__init__.py | 2 | ||||
-rw-r--r-- | moon_wrapper/moon_wrapper/api/oslowrapper.py | 16 | ||||
-rw-r--r-- | moon_wrapper/moon_wrapper/http_server.py | 11 | ||||
-rw-r--r-- | moon_wrapper/tests/unit_python/api/test_wrapper.py | 3 | ||||
-rw-r--r-- | moon_wrapper/tests/unit_python/conftest.py | 14 |
7 files changed, 64 insertions, 21 deletions
diff --git a/moon_wrapper/Changelog b/moon_wrapper/Changelog new file mode 100644 index 00000000..071e4ef9 --- /dev/null +++ b/moon_wrapper/Changelog @@ -0,0 +1,28 @@ +# Copyright 2018 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# license which can be found in the file 'LICENSE' in this package distribution +# or at 'http://www.apache.org/licenses/LICENSE-2.0'. + + +CHANGES +======= + +1.0.0 +----- +- First version of the manager + +2.0.0 +----- +- Version built inside the Keystone component + +3.0.0 +----- +- Version built outside the Keystone component + +4.0.0 +----- +- First micro-architecture version + +4.5.1 +----- +- use the threading capability of Flask app diff --git a/moon_wrapper/Dockerfile b/moon_wrapper/Dockerfile index 77ffaee9..e3ad9020 100644 --- a/moon_wrapper/Dockerfile +++ b/moon_wrapper/Dockerfile @@ -1,8 +1,15 @@ FROM python:3 +LABEL Name=Wrapper +LABEL Description="Wrapper component for the Moon platform" +LABEL Maintainer="Thomas Duval" +LABEL Url="https://wiki.opnfv.org/display/moon/Moon+Project+Proposal" + +USER root + ADD . /root WORKDIR /root/ -RUN pip3 install -r requirements.txt -RUN pip3 install . +RUN pip3 install --no-cache-dir -r requirements.txt +RUN pip3 install --no-cache-dir . CMD ["python3", "-m", "moon_wrapper"] diff --git a/moon_wrapper/moon_wrapper/__init__.py b/moon_wrapper/moon_wrapper/__init__.py index 903c6518..98a98146 100644 --- a/moon_wrapper/moon_wrapper/__init__.py +++ b/moon_wrapper/moon_wrapper/__init__.py @@ -3,4 +3,4 @@ # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. -__version__ = "0.1.0" +__version__ = "4.5.1" diff --git a/moon_wrapper/moon_wrapper/api/oslowrapper.py b/moon_wrapper/moon_wrapper/api/oslowrapper.py index ad9e430a..905c32db 100644 --- a/moon_wrapper/moon_wrapper/api/oslowrapper.py +++ b/moon_wrapper/moon_wrapper/api/oslowrapper.py @@ -37,8 +37,14 @@ class OsloWrapper(Resource): def post(self): logger.debug("POST {}".format(request.form)) response = flask.make_response("False") - if self.manage_data(): - response = flask.make_response("True") + try: + if self.manage_data(): + response = flask.make_response("True") + except exceptions.AuthzException as e: + logger.error(e, exc_info=True) + except Exception as e: + logger.error(e, exc_info=True) + response.headers['content-type'] = 'application/octet-stream' return response @@ -109,10 +115,10 @@ class OsloWrapper(Resource): _object, _action )) - ''' - [Note] i think here if status != 200, should raise an exception - ''' + logger.debug("Get interface {}".format(req.text)) if req.status_code == 200: if req.json().get("result", False): return True + + raise exceptions.AuthzException("error in authz request")
\ No newline at end of file diff --git a/moon_wrapper/moon_wrapper/http_server.py b/moon_wrapper/moon_wrapper/http_server.py index 8027a0d3..dfbaed9f 100644 --- a/moon_wrapper/moon_wrapper/http_server.py +++ b/moon_wrapper/moon_wrapper/http_server.py @@ -3,6 +3,7 @@ # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. +import flask from flask import Flask, jsonify from flask_restful import Resource, Api import logging @@ -112,13 +113,13 @@ class HTTPServer(Server): def __hook_errors(self): def get_404_json(e): - return jsonify({"result": False, "code": 404, - "description": str(e)}), 404 + return flask.make_response("False") + self.app.register_error_handler(404, get_404_json) def get_400_json(e): - return jsonify({"result": False, "code": 400, - "description": str(e)}), 400 + return flask.make_response("False") + self.app.register_error_handler(400, lambda e: get_400_json) self.app.register_error_handler(403, exceptions.AuthException) @@ -135,5 +136,5 @@ class HTTPServer(Server): ) def run(self): - self.app.run(host=self._host, port=self._port) # nosec + self.app.run(host=self._host, port=self._port, threaded=True) # nosec diff --git a/moon_wrapper/tests/unit_python/api/test_wrapper.py b/moon_wrapper/tests/unit_python/api/test_wrapper.py index be3e8576..bd6baf32 100644 --- a/moon_wrapper/tests/unit_python/api/test_wrapper.py +++ b/moon_wrapper/tests/unit_python/api/test_wrapper.py @@ -68,4 +68,5 @@ def test_authz_error_no_interface_key(context): 'target': json.dumps(_target), 'credentials': 'null'} req = client.post("/authz/oslo", data=json.dumps(authz_data)) - assert req.status_code == 403
\ No newline at end of file + + assert req.data == b"False"
\ No newline at end of file diff --git a/moon_wrapper/tests/unit_python/conftest.py b/moon_wrapper/tests/unit_python/conftest.py index 621c2014..2c332c89 100644 --- a/moon_wrapper/tests/unit_python/conftest.py +++ b/moon_wrapper/tests/unit_python/conftest.py @@ -415,7 +415,7 @@ def set_consul_and_db(monkeypatch): "name": "testuser", "email": "mail", "id": "89ba91c18dd54abfbfde7a66936c51a6", - "partner_id": "" + "extra": {} }, "31fd15ad14784a9696fcc887dddbfaf9": { "description": "test", @@ -426,7 +426,7 @@ def set_consul_and_db(monkeypatch): "name": "adminuser", "email": "mail", "id": "31fd15ad14784a9696fcc887dddbfaf9", - "partner_id": "" + "extra": {} } } } @@ -439,7 +439,7 @@ def set_consul_and_db(monkeypatch): "name": "vm1", "description": "test", "id": "67b8008a3f8d4f8e847eb628f0f7ca0e", - "partner_id": "", + "extra": {}, "policy_list": [ "f8f49a779ceb47b3ac810f01ef71b4e0", "636cd473324f4c0bbd9102cb5b62a16d" @@ -449,7 +449,7 @@ def set_consul_and_db(monkeypatch): "name": "vm0", "description": "test", "id": "9089b3d2ce5b4e929ffc7e35b55eba1a", - "partner_id": "", + "extra": {}, "policy_list": [ "f8f49a779ceb47b3ac810f01ef71b4e0", "636cd473324f4c0bbd9102cb5b62a16d" @@ -466,7 +466,7 @@ def set_consul_and_db(monkeypatch): "name": "boot", "description": "test", "id": "cdb3df220dc04a6ea3334b994827b068", - "partner_id": "", + "extra": {}, "policy_list": [ "f8f49a779ceb47b3ac810f01ef71b4e0", "636cd473324f4c0bbd9102cb5b62a16d" @@ -476,7 +476,7 @@ def set_consul_and_db(monkeypatch): "name": "stop", "description": "test", "id": "cdb3df220dc04a6ea3334b994827b068", - "partner_id": "", + "extra": {}, "policy_list": [ "f8f49a779ceb47b3ac810f01ef71b4e0", "636cd473324f4c0bbd9102cb5b62a16d" @@ -486,7 +486,7 @@ def set_consul_and_db(monkeypatch): "name": "start", "description": "test", "id": "9f5112afe9b34a6c894eb87246ccb7aa", - "partner_id": "", + "extra": {}, "policy_list": [ "f8f49a779ceb47b3ac810f01ef71b4e0", "636cd473324f4c0bbd9102cb5b62a16d" |