aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/resources/v2/openrcs.py11
-rw-r--r--api/server.py4
-rw-r--r--yardstick/common/constants.py15
-rw-r--r--yardstick/common/exceptions.py12
4 files changed, 36 insertions, 6 deletions
diff --git a/api/resources/v2/openrcs.py b/api/resources/v2/openrcs.py
index cb506d0e8..4706b856a 100644
--- a/api/resources/v2/openrcs.py
+++ b/api/resources/v2/openrcs.py
@@ -21,6 +21,7 @@ from yardstick.common import constants as consts
from yardstick.common.utils import result_handler
from yardstick.common.utils import makedirs
from yardstick.common.utils import source_env
+from yardstick.common import exceptions as y_exc
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
@@ -57,7 +58,7 @@ class V2Openrcs(ApiResource):
openrc_data = self._get_openrc_dict()
except Exception:
LOG.exception('parse openrc failed')
- return result_handler(consts.API_ERROR, 'parse openrc failed')
+ raise y_exc.UploadOpenrcError()
openrc_id = str(uuid.uuid4())
self._write_into_database(environment_id, openrc_id, openrc_data)
@@ -67,7 +68,7 @@ class V2Openrcs(ApiResource):
self._generate_ansible_conf_file(openrc_data)
except Exception:
LOG.exception('write cloud conf failed')
- return result_handler(consts.API_ERROR, 'genarate ansible conf failed')
+ raise y_exc.UploadOpenrcError()
LOG.info('finish writing ansible cloud conf')
return result_handler(consts.API_SUCCESS, {'openrc': openrc_data, 'uuid': openrc_id})
@@ -102,7 +103,7 @@ class V2Openrcs(ApiResource):
source_env(consts.OPENRC)
except Exception:
LOG.exception('source openrc failed')
- return result_handler(consts.API_ERROR, 'source openrc failed')
+ raise y_exc.UpdateOpenrcError()
LOG.info('source openrc: Done')
openrc_id = str(uuid.uuid4())
@@ -113,7 +114,7 @@ class V2Openrcs(ApiResource):
self._generate_ansible_conf_file(openrc_vars)
except Exception:
LOG.exception('write cloud conf failed')
- return result_handler(consts.API_ERROR, 'genarate ansible conf failed')
+ raise y_exc.UpdateOpenrcError()
LOG.info('finish writing ansible cloud conf')
return result_handler(consts.API_SUCCESS, {'openrc': openrc_vars, 'uuid': openrc_id})
@@ -174,7 +175,7 @@ class V2Openrcs(ApiResource):
makedirs(consts.OPENSTACK_CONF_DIR)
with open(consts.CLOUDS_CONF, 'w') as f:
- yaml.dump(ansible_conf, f, default_flow_style=False)
+ yaml.safe_dump(ansible_conf, f, default_flow_style=False)
class V2Openrc(ApiResource):
diff --git a/api/server.py b/api/server.py
index 37a1ab6a6..914fe8457 100644
--- a/api/server.py
+++ b/api/server.py
@@ -39,11 +39,13 @@ app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 * 1024 * 1024
Swagger(app)
-api = Api(app)
+api = Api(app, errors=consts.API_ERRORS)
@app.teardown_request
def shutdown_session(exception=None):
+ if exception:
+ LOG.warning(exception.message)
db_session.remove()
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index 153bd4bf4..3f5c37456 100644
--- a/yardstick/common/constants.py
+++ b/yardstick/common/constants.py
@@ -145,6 +145,21 @@ BASE_URL = 'http://localhost:5000'
ENV_ACTION_API = BASE_URL + '/yardstick/env/action'
ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask'
+API_ERRORS = {
+ 'UploadOpenrcError': {
+ 'message': "Upload openrc ERROR!",
+ 'status': API_ERROR,
+ },
+ 'UpdateOpenrcError': {
+ 'message': "Update openrc ERROR!",
+ 'status': API_ERROR,
+ },
+ 'ApiServerError': {
+ 'message': "An unkown exception happened to Api Server!",
+ 'status': API_ERROR,
+ },
+}
+
# flags
IS_EXISTING = 'is_existing'
IS_PUBLIC = 'is_public'
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index 439b9cb1b..fb4d33a59 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -166,3 +166,15 @@ class ScenarioCreateFloatingIPError(YardstickException):
class ScenarioDeleteFloatingIPError(YardstickException):
message = 'Delete Neutron Floating IP Scenario failed'
+
+
+class ApiServerError(YardstickException):
+ message = 'An unkown exception happened to Api Server!'
+
+
+class UploadOpenrcError(ApiServerError):
+ message = 'Upload openrc ERROR!'
+
+
+class UpdateOpenrcError(ApiServerError):
+ message = 'Update openrc ERROR!'