A proof of concept web configuration server for cord-tester using flask (thin python webframework)
With this, you can pretty much load the test case configure before running cord-tester.
Then run the cord-tester and finally restore.
To try:
Start the web server first:
./webserver-run.py
Then run a curl get to retrieve test case config.
./webserver-get.curl
Then post the test case config (example for cluster test):
./webserver-post.curl
If you want to restore, answer y and it would restore the config back.
This allows us to load test case configuration profiles before running automation with the config.
And finally restore the config on automation complete.
Change-Id: I90c603856761fbe2ee9c0fad23d10626899d35d3
diff --git a/src/test/setup/webserver/cordTestConfig.py b/src/test/setup/webserver/cordTestConfig.py
new file mode 100644
index 0000000..33bdc1e
--- /dev/null
+++ b/src/test/setup/webserver/cordTestConfig.py
@@ -0,0 +1,91 @@
+from webserver import app
+from flask import request, jsonify
+import httplib
+import json
+import os
+import sys
+
+class CordTesterWebConfig(object):
+ our_path = os.path.dirname(os.path.realpath(__file__))
+ test_base = os.path.realpath(os.path.join(our_path, '..', '..'))
+
+ def __init__(self, test_case):
+ self.test_case = test_case
+ self.test_path = None
+ self.test_config = None
+ test_path = os.path.join(self.test_base, self.test_case)
+ if os.path.isdir(test_path):
+ self.test_path = test_path
+ self.test_config = os.path.join(self.test_path, '{}Test.json'.format(self.test_case))
+
+ def update(self, config):
+ cur_config = {}
+ if self.test_config:
+ if os.access(self.test_config, os.F_OK):
+ with open(self.test_config, 'r') as f:
+ cur_config = json.load(f)
+ os.rename(self.test_config, '{}.save'.format(self.test_config))
+ for k, v in config.iteritems():
+ cur_config[k] = v
+ with open(self.test_config, 'w') as f:
+ json.dump(cur_config, f, indent = 4)
+ return True
+ return False
+
+ def restore(self):
+ if self.test_config:
+ if os.access(self.test_config, os.F_OK):
+ restore_file = '{}.save'.format(self.test_config)
+ if os.access(restore_file, os.F_OK):
+ os.rename(restore_file, self.test_config)
+ return True
+ return False
+
+ def get(self):
+ cur_config = {}
+ if self.test_config:
+ if os.access(self.test_config, os.F_OK):
+ with open(self.test_config) as f:
+ cur_config = json.load(f)
+ return cur_config
+
+@app.route('/')
+@app.route('/index')
+def index():
+ return 'Welcome to Cord Tester configuration page'
+
+@app.route('/get')
+def get():
+ data = request.get_json(force = True)
+ test_case = data.get('test_case', None)
+ if test_case:
+ cordWeb = CordTesterWebConfig(test_case)
+ config = cordWeb.get()
+ return jsonify(config)
+ return ('', httplib.NOT_FOUND)
+
+@app.route('/update', methods = ['POST'])
+def update():
+ data = request.get_json(force = True)
+ test_case = data.get('test_case', None)
+ config = data.get('config', None)
+ response = ('', httplib.NOT_FOUND)
+ if test_case:
+ cordWeb = CordTesterWebConfig(test_case)
+ status = cordWeb.update(config)
+ if status:
+ response = ('', httplib.OK)
+
+ return response
+
+@app.route('/restore', methods = ['POST'])
+def restore():
+ data = request.get_json(force = True)
+ test_case = data.get('test_case', None)
+ response = ('', httplib.NOT_FOUND)
+ if test_case:
+ cordWeb = CordTesterWebConfig(test_case)
+ status = cordWeb.restore()
+ if status:
+ response = ('', httplib.OK)
+ return response