From 6a05ae6acd82c9df493d4e20f59b2e17f62f0147 Mon Sep 17 00:00:00 2001 From: zhangyihui1 Date: Wed, 6 Mar 2019 15:57:34 +0800 Subject: [PATCH 1/3] Merge Add a task to IATF server and run case into one script --- src/start.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/task.json | 18 ++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/start.py create mode 100644 src/task.json diff --git a/src/start.py b/src/start.py new file mode 100644 index 0000000..0b77262 --- /dev/null +++ b/src/start.py @@ -0,0 +1,58 @@ +import requests +from requests.packages import urllib3 +requests.packages.urllib3.disable_warnings() +import json +import os +import subprocess +import argparse + +THIS_PATH = os.path.abspath(os.path.dirname(__file__)) +TASK = json.loads( + open(os.path.join(THIS_PATH, 'task.json'), 'r').read()) + + +def do_request(url, method='GET', data=None, headers=None): + response = None + if method == 'GET': + response = requests.get(url, verify=False) + elif method == 'POST': + response = requests.post(url, data=data, headers=headers, verify=False) + elif method == 'PUT': + response = requests.put(url, data=data, headers=headers, verify=False) + if response.status_code != 200: + print(response.status_code) + print("error", response.text) + else: + return response.text + + +def start(id, server, verify): + cmd = ['python3.7', os.path.abspath(os.path.join(THIS_PATH, 'controller/controller.py')), '--server', server, + '--task', id] + if not verify: + cmd = cmd + ['--no_ssl_verification'] + print(cmd) + subprocess.Popen(cmd).communicate() + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='IATF controller.') + parser.add_argument('--no_ssl_verification', help="Verify server certificate.", + default=True, action='store_false', dest='verify') + required_arguments = parser.add_argument_group('required arguments') + required_arguments.add_argument( + '--server', help='IATF server address.', required=True) + required_arguments.add_argument('--task', help='Task ID.', default=None) + opts = parser.parse_args() + + task_id = opts.task + + if task_id is None: + headers = { + "Content-Type": "application/json" + } + task_id = do_request('https://10.239.44.83:8080/rest/v1/tasks', method="PUT", data=json.dumps(TASK), + headers=headers) + print(task_id) + if task_id is not None: + start(id=task_id, server=opts.server, verify=opts.verify) diff --git a/src/task.json b/src/task.json new file mode 100644 index 0000000..defa1b1 --- /dev/null +++ b/src/task.json @@ -0,0 +1,18 @@ +{ + "roles": [ + { + "name": "role1", + "type": "JavaScript", + "config": { + "url": "http://localhost:8081/javascript/user1.html" + } + }, + { + "name": "role2", + "type": "JavaScript", + "config": { + "url": "http://localhost:8081/javascript/user2.html" + } + } + ] +} \ No newline at end of file From bf688eb13fa72b12d84b98afa5707bea724c082a Mon Sep 17 00:00:00 2001 From: zhangyihui1 Date: Thu, 7 Mar 2019 10:27:46 +0800 Subject: [PATCH 2/3] JavaScript sample testing process automation --- src/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/start.py b/src/start.py index 0b77262..0db84ec 100644 --- a/src/start.py +++ b/src/start.py @@ -51,7 +51,7 @@ def start(id, server, verify): headers = { "Content-Type": "application/json" } - task_id = do_request('https://10.239.44.83:8080/rest/v1/tasks', method="PUT", data=json.dumps(TASK), + task_id = do_request(opts.server + '/rest/v1/tasks', method="PUT", data=json.dumps(TASK), headers=headers) print(task_id) if task_id is not None: From a9eb9b1e31c830f18fc788b05fbced6259a143b5 Mon Sep 17 00:00:00 2001 From: zhangyihui1 Date: Thu, 7 Mar 2019 10:28:36 +0800 Subject: [PATCH 3/3] JavaScript sample testing process automation --- src/start.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/start.py b/src/start.py index 0db84ec..e60bca9 100644 --- a/src/start.py +++ b/src/start.py @@ -44,7 +44,6 @@ def start(id, server, verify): '--server', help='IATF server address.', required=True) required_arguments.add_argument('--task', help='Task ID.', default=None) opts = parser.parse_args() - task_id = opts.task if task_id is None: