From 03ade964103d88af4d9a4f729d3bb00c12bff489 Mon Sep 17 00:00:00 2001 From: Leo Wang Date: Tue, 2 May 2017 16:50:02 -0700 Subject: local db support offline mode JIRA: DOVETAIL-415 The local db also need to support offline, move all the git clone/apt/yum/pip/wget/curl into the Dockerfile Change-Id: I2392dc9f4a6bd6f6a5a3f4849625a576c51a44f8 Signed-off-by: Leo Wang --- docker/Dockerfile | 5 ++++ docker/get_db_schema.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 docker/get_db_schema.py (limited to 'docker') diff --git a/docker/Dockerfile b/docker/Dockerfile index 7b3d99ed..499624f8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,3 +40,8 @@ RUN \ pip install -e . WORKDIR ${REPOS_DIR}/dovetail + +# get db schema from opnfv sites +RUN mkdir -p ${REPOS_DIR}/dovetail/utils/local_db +ADD get_db_schema.py ${REPOS_DIR}/dovetail/utils/local_db +RUN cd ${REPOS_DIR}/dovetail/utils/local_db && python get_db_schema.py diff --git a/docker/get_db_schema.py b/docker/get_db_schema.py new file mode 100644 index 00000000..9a9d10d4 --- /dev/null +++ b/docker/get_db_schema.py @@ -0,0 +1,61 @@ +############################################################################## +# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import requests +import json + + +source_url = 'http://testresults.opnfv.org/test/api/v1' + + +def get(url): + try: + ret = requests.get(url) + return ret.json() + except: + return None + + +def pod(): + source = '{}/pods'.format(source_url) + try: + pods = get(source)['pods'] + with open("pods.json", "w") as f: + f.write(json.dumps(pods, indent=4)) + except: + return + + +def project(): + source = '{}/projects'.format(source_url) + + try: + projects = get(source)['projects'] + with open("projects.json", "w") as f: + f.write(json.dumps(projects, indent=4)) + except: + return + + for p in projects: + source = '{}/projects/{}/cases'.format(source_url, p['name']) + print(p['name']) + print(source) + try: + cases = get(source) + with open("cases.json", "a+") as f: + f.write(json.dumps(cases)) + f.write('\n') + f.close() + except: + print("useless data") + + +if __name__ == '__main__': + pod() + project() -- cgit 1.2.3-korg