summaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2018-03-14 09:41:01 +0000
committerchenjiankun <chenjiankun1@huawei.com>2018-03-15 06:56:37 +0000
commitc3f91fac56cd938c408c62ff44f5ff039b1fd8e6 (patch)
treebe2c5a64a4908fc5acc0ddf28e798720cbf01cb8 /api/resources
parent4b8b674b65830a24230faed71e8d9a1048139c89 (diff)
Create API to get SUT information
JIRA: YARDSTICK-1072 We need to show SUT information in GUI. Change-Id: I40bcd513f3c6a443c82764687637ac5258b99584 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources')
-rw-r--r--api/resources/v2/environments.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/api/resources/v2/environments.py b/api/resources/v2/environments.py
index 158e98be7..7e587be85 100644
--- a/api/resources/v2/environments.py
+++ b/api/resources/v2/environments.py
@@ -11,6 +11,7 @@ import logging
from oslo_serialization import jsonutils
from docker import Client
+from docker.errors import APIError
from api import ApiResource
from api.database.v2.handlers import V2EnvironmentHandler
@@ -20,6 +21,7 @@ from api.database.v2.handlers import V2ContainerHandler
from yardstick.common.utils import result_handler
from yardstick.common.utils import change_obj_to_dict
from yardstick.common import constants as consts
+from yardstick.service.environment import Environment
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
@@ -124,10 +126,41 @@ class V2Environment(ApiResource):
LOG.debug('container name: %s', container.name)
try:
client.remove_container(container.name, force=True)
- except Exception:
+ except APIError:
LOG.exception('remove container failed')
container_handler.delete_by_uuid(v)
environment_handler.delete_by_uuid(environment_id)
return result_handler(consts.API_SUCCESS, {'environment': environment_id})
+
+
+class V2SUT(ApiResource):
+
+ def get(self, environment_id):
+ try:
+ uuid.UUID(environment_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'invalid environment id')
+
+ environment_handler = V2EnvironmentHandler()
+ try:
+ environment = environment_handler.get_by_uuid(environment_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'no such environment id')
+
+ if not environment.pod_id:
+ return result_handler(consts.API_SUCCESS, {'sut': {}})
+
+ pod_handler = V2PodHandler()
+ try:
+ pod = pod_handler.get_by_uuid(environment.pod_id)
+ except ValueError:
+ return result_handler(consts.API_ERROR, 'no such pod id')
+ else:
+ pod_content = pod.content
+
+ env = Environment(pod=pod_content)
+ sut_info = env.get_sut_info()
+
+ return result_handler(consts.API_SUCCESS, {'sut': sut_info})