aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorJack Chan <chenjiankun1@huawei.com>2018-03-01 02:20:38 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-01 02:20:38 +0000
commit9e2fafb8b86356d7c6719e593c0b086e065706c9 (patch)
tree0d041cce45ac860e293d510e2ef728155a081045 /api/resources
parent710fd29fe4a5e6f747ff397a4f54f966999279a2 (diff)
parent8025653bae0df71c0098225cb85b0b267c93a7a6 (diff)
Merge "fix pep8 problem in env.py"
Diffstat (limited to 'api/resources')
-rw-r--r--api/resources/v1/env.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py
index 7c831fd74..32a8c730b 100644
--- a/api/resources/v1/env.py
+++ b/api/resources/v1/env.py
@@ -22,6 +22,8 @@ import collections
from six.moves import configparser
from oslo_serialization import jsonutils
from docker import Client
+from docker.errors import APIError
+from requests.exceptions import HTTPError
from api.database.v1.handlers import AsyncTaskHandler
from api.utils import influx
@@ -44,7 +46,7 @@ class V1Env(ApiResource):
def post(self):
return self._dispatch_post()
- def create_grafana(self, args):
+ def create_grafana(self, *args):
task_id = str(uuid.uuid4())
thread = threading.Thread(target=self._create_grafana, args=(task_id,))
@@ -82,7 +84,7 @@ class V1Env(ApiResource):
self._update_task_status(task_id)
LOG.info('Finished')
- except Exception as e:
+ except (APIError, HTTPError) as e:
self._update_task_error(task_id, str(e))
LOG.exception('Create grafana failed')
@@ -145,7 +147,7 @@ class V1Env(ApiResource):
return any(t in a['RepoTags'][0]
for a in client.images() if a['RepoTags'])
- def create_influxdb(self, args):
+ def create_influxdb(self, *args):
task_id = str(uuid.uuid4())
thread = threading.Thread(target=self._create_influxdb, args=(task_id,))
@@ -185,7 +187,7 @@ class V1Env(ApiResource):
self._update_task_status(task_id)
LOG.info('Finished')
- except Exception as e:
+ except APIError as e:
self._update_task_error(task_id, str(e))
LOG.exception('Creating influxdb failed')
@@ -217,7 +219,7 @@ class V1Env(ApiResource):
consts.INFLUXDB_DB_NAME)
client.create_database(consts.INFLUXDB_DB_NAME)
LOG.info('Success to config influxDB')
- except Exception:
+ except HTTPError:
LOG.exception('Config influxdb failed')
def _change_output_to_influxdb(self, ip):
@@ -236,7 +238,7 @@ class V1Env(ApiResource):
with open(consts.CONF_FILE, 'w') as f:
parser.write(f)
- def prepare_env(self, args):
+ def prepare_env(self, *args):
task_id = str(uuid.uuid4())
thread = threading.Thread(target=self._prepare_env_daemon,
@@ -287,7 +289,7 @@ class V1Env(ApiResource):
self._update_task_status(task_id)
LOG.info('Finished')
- except Exception as e:
+ except (subprocess.CalledProcessError, OSError) as e:
self._update_task_error(task_id, str(e))
LOG.exception('Prepare env failed')
@@ -373,7 +375,7 @@ class V1Env(ApiResource):
LOG.info('Source openrc: Sourcing')
try:
self._source_file(consts.OPENRC)
- except Exception as e:
+ except subprocess.CalledProcessError as e:
LOG.exception('Failed to source openrc')
return result_handler(consts.API_ERROR, str(e))
LOG.info('Source openrc: Done')