From 90be61207b33567ac8ff1b7288dbff5863bf12d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 31 Oct 2018 15:25:56 +0100 Subject: [PATCH] software/jstestnode: move selenium configuration in test-runner key Also fix JSON schema, that was just invalid. Now we have a schema that renders properly on https://lab.nexedi.com/bk/rjs_json_form and is similar to the one from erp5, so maybe one day we can have a convention on erp5 testnode to push the URL of a selenium server as test-runner.server-url . In any case, it's good for now to have consistency. Most of this work comes from Boris Kocherov from https://www.raskon.org/ Thanks ! --- software/jstestnode/buildout.hash.cfg | 2 +- .../instance-jstestnode-input-schema.json | 140 ++++++++++-------- software/jstestnode/runTestSuite.in | 25 ++-- 3 files changed, 96 insertions(+), 71 deletions(-) diff --git a/software/jstestnode/buildout.hash.cfg b/software/jstestnode/buildout.hash.cfg index c15ff5180..29743e4e4 100644 --- a/software/jstestnode/buildout.hash.cfg +++ b/software/jstestnode/buildout.hash.cfg @@ -27,4 +27,4 @@ md5sum = 9f22db89a2679534aa8fd37dbca86782 [template-runTestSuite] filename = runTestSuite.in -md5sum = bd9ff3543f0dfaf2702624e3ed74d334 +md5sum = b44268d46a41042a879f47babb66c922 diff --git a/software/jstestnode/instance-jstestnode-input-schema.json b/software/jstestnode/instance-jstestnode-input-schema.json index 8e153623d..7159a6fed 100644 --- a/software/jstestnode/instance-jstestnode-input-schema.json +++ b/software/jstestnode/instance-jstestnode-input-schema.json @@ -1,7 +1,11 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "description": "Parameters to instantiate JSTestNode", "additionalProperties": false, + "required": [ + "test-suite", + "test-runner" + ], "properties": { "test-suite": { "description": "The test suite to run", @@ -18,68 +22,86 @@ "default": "(the web server started by this instance)", "example": "https://softinst1234.host.vifib.net/" }, - "oneOf": [ - { - "title": "selenium server", - "description": "Configuration for running tests on selenium server", - "properties": { - "target": { - "description": "Target system", - "const": "selenium-server" - }, - "server-url": { - "description": "URL of the selenium server", - "type": "string" - }, - "verify-server-certificate": { - "description": "Verify the SSL/TLS Certificats of the selenium server when using HTTPS", - "type": "boolean", - "default": true - }, - "server-ca-certificate": { - "description": "PEM encoded bundle of CA Certificates to verify the SSL/TLS Certificate of the selenium server when using HTTPS", - "type": "string", - "default": "root certificates from http://certifi.io/en/latest/" - }, - "desired-capabilities": { - "description": "Desired browser capabilities", - "type": "object", - "properties": { - "browserName": { - "description": "Name of the browser being used, for example firefox, chrome", - "type": "string", - "required": true - }, - "version": { - "description": "The browser version", - "type": "string" - } + "test-runner": { + "oneOf": [ + { + "type": "object", + "title": "Selenium Server", + "description": "Configuration for Selenium server", + "additionalProperties": false, + "required": [ + "desired-capabilities", + "server-url", + "target" + ], + "properties": { + "target": { + "description": "Target system", + "type": "string", + "const": "selenium-server" + }, + "server-url": { + "description": "URL of the selenium server", + "type": "string", + "format": "uri" + }, + "verify-server-certificate": { + "description": "Verify the SSL/TLS Certificats of the selenium server when using HTTPS", + "type": "boolean", + "default": true + }, + "server-ca-certificate": { + "description": "PEM encoded bundle of CA Certificates to verify the SSL/TLS Certificate of the selenium server when using HTTPS", + "type": "string", + "default": "root certificates from http://certifi.io/en/latest/" }, - "additionalProperties": true + "desired-capabilities": { + "description": "Desired browser capabilities", + "required": [ + "browserName" + ], + "type": "object", + "properties": { + "browserName": { + "description": "Name of the browser being used, for example firefox, chrome", + "type": "string" + }, + "version": { + "description": "The browser version", + "type": "string" + } + } + } } - } - }, - { - "title": "firefox", - "description": "Configuration for running tests on local firefox process", - "properties": { - "target": { - "description": "Target system", - "const": "firefox", - "default": "firefox" + }, + { + "type": "object", + "title": "Firefox", + "description": "Configuration for Firefox", + "additionalProperties": false, + "properties": { + "target": { + "description": "Target system", + "const": "firefox", + "type": "string", + "default": "firefox" + } } - } - }, - { - "title": "node", - "description": "Configuration for running tests on local nodejs", - "properties": { - "target": { - "description": "Target system", - "const": "node" + }, + { + "type": "object", + "title": "NodeJS", + "description": "Configuration for NodeJS", + "additionalProperties": false, + "properties": { + "target": { + "description": "Target system", + "const": "node", + "type": "string" + } } } - } - ] + ] + } } } diff --git a/software/jstestnode/runTestSuite.in b/software/jstestnode/runTestSuite.in index ae463a938..71e137a6e 100644 --- a/software/jstestnode/runTestSuite.in +++ b/software/jstestnode/runTestSuite.in @@ -25,8 +25,14 @@ BASE_URL = 'http://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/' ETC_DIRECTORY = '$${directory:etc}' def main(): + parsed_parameters = json.load( + open('$${runTestSuite-config-file:rendered}', 'rb')) + test_runner = parsed_parameters.get('test-runner', {}) + parser = argparse.ArgumentParser(description='Run a test suite.') - parser.add_argument('--test_suite', help='The test suite name') + parser.add_argument('--test_suite', help='The test suite name', + default=parsed_parameters.get('test-suite', ''), + required=not parsed_parameters.has_key('test-suite')) parser.add_argument('--test_suite_title', help='The test suite title') parser.add_argument('--test_node_title', help='The test node title') parser.add_argument('--project_title', help='The project title') @@ -40,9 +46,6 @@ def main(): args = parser.parse_args() - parsed_parameters = json.load( - open('$${runTestSuite-config-file:rendered}', 'rb')) - is_browser_running = False try: test_suite_title = args.test_suite_title or args.test_suite @@ -62,7 +65,7 @@ def main(): ########################## # Run all tests ########################## - target = parsed_parameters.get('target', 'firefox') + target = test_runner.get('target', 'firefox') if target == 'node': # Execute NodeJS tests result_string = check_output(['${nodejs-output:node}', '${jio-repository.git:location}/test/node.js'], @@ -92,24 +95,24 @@ def main(): firefox_binary='${firefox-wrapper:location}', executable_path='${geckodriver:location}') else: - assert target == 'selenium-server', "Unsupported target {}".format(parsed_parameters['target']) + assert target == 'selenium-server', "Unsupported target {}".format(test_runner['target']) # use a remote connection which verifies TLS certificate # workaround for https://github.com/SeleniumHQ/selenium/issues/6534 - executor = RemoteConnection(parsed_parameters['server-url'], keep_alive=True) + executor = RemoteConnection(test_runner['server-url'], keep_alive=True) cert_reqs = 'CERT_REQUIRED' ca_certs = certifi.where() - if not parsed_parameters.get('verify-server-certificate', True): + if not test_runner.get('verify-server-certificate', True): cert_reqs = 'CERT_NONE' ca_certs = None - if parsed_parameters.get('server-ca-certificate'): + if test_runner.get('server-ca-certificate'): ca_certs = os.path.join(ETC_DIRECTORY, "cacerts.pem") with open(ca_certs, 'w') as f: - f.write(parsed_parameters.get('server-ca-certificate')) + f.write(test_runner.get('server-ca-certificate')) executor._conn = urllib3.PoolManager(cert_reqs=cert_reqs, ca_certs=ca_certs) browser = webdriver.Remote( command_executor=executor, - desired_capabilities=parsed_parameters['desired-capabilities'], + desired_capabilities=test_runner['desired-capabilities'], ) # adjust path for remote test url -- 2.30.9