diff options
author | Leo Wang <grakiss.wanglei@huawei.com> | 2017-05-02 16:50:02 -0700 |
---|---|---|
committer | Leo Wang <grakiss.wanglei@huawei.com> | 2017-05-03 09:20:13 -0700 |
commit | 03ade964103d88af4d9a4f729d3bb00c12bff489 (patch) | |
tree | b2397cd9c12bedbc9d45085046bf54b846aba56b /dovetail/utils/local_db/init_db.py | |
parent | 3aeab49bb64c6c89da37f3d03f781aec85f39015 (diff) |
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 <grakiss.wanglei@huawei.com>
Diffstat (limited to 'dovetail/utils/local_db/init_db.py')
-rw-r--r-- | dovetail/utils/local_db/init_db.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/dovetail/utils/local_db/init_db.py b/dovetail/utils/local_db/init_db.py new file mode 100644 index 00000000..246139c4 --- /dev/null +++ b/dovetail/utils/local_db/init_db.py @@ -0,0 +1,80 @@ +############################################################################## +# 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 +import sys + +db_host_ip = sys.argv[1] +testapi_port = sys.argv[2] + +target_url = 'http://{}:{}/api/v1'.format(db_host_ip, testapi_port) +print(target_url) + + +def get(url): + return requests.get(url).json() + + +def post(url, data): + headers = {'Content-Type': 'application/json'} + res = requests.post(url, data=json.dumps(data), headers=headers) + print(res.text) + + +def pod(): + target = '{}/pods'.format(target_url) + + with open('pods.json', 'r') as f: + pods = json.load(f) + for p in pods: + post(target, p) + + add_pod('master', 'metal') + add_pod('virtual_136_2', 'virtual') + + +def project(): + target = '{}/projects'.format(target_url) + with open('projects.json', 'r') as f: + projects = json.load(f) + for p in projects: + post(target, p) + + +def cases(): + with open('cases.json', 'r') as f: + for line in f: + try: + cases = json.loads(line) + for c in cases["testcases"]: + target = '{}/projects/{}/cases'.format(target_url, + c['project_name']) + print(target) + post(target, c) + except: + print("useless data") + + +def add_pod(name, mode): + data = { + "role": "", + "name": name, + "details": '', + "mode": mode, + "creation_date": "2017-2-23 11:23:03.765581" + } + pod_url = '{}/pods'.format(target_url) + post(pod_url, data) + + +if __name__ == '__main__': + pod() + project() + cases() |