From 061ca938ca6998b4ec33a862c763854259cfeab1 Mon Sep 17 00:00:00 2001 From: ilanap Date: Sun, 4 Aug 2019 10:16:33 +0300 Subject: Issue-ID: SDC-2483 Adding https support for cucumber tests and slight refactoring Signed-off-by: ilanap Change-Id: Ib772d18cd4278238571daf54bcb6372c553d6e4b --- .../cucumber-common/utils/UpdateTestConfig.js | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 cucumber-js-test-apis-ci/cucumber-common/utils/UpdateTestConfig.js (limited to 'cucumber-js-test-apis-ci/cucumber-common/utils/UpdateTestConfig.js') diff --git a/cucumber-js-test-apis-ci/cucumber-common/utils/UpdateTestConfig.js b/cucumber-js-test-apis-ci/cucumber-common/utils/UpdateTestConfig.js new file mode 100644 index 0000000000..a2c1dae2f7 --- /dev/null +++ b/cucumber-js-test-apis-ci/cucumber-common/utils/UpdateTestConfig.js @@ -0,0 +1,81 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict' + +const fs = require('fs'); + +var pathToRoot = process.env.TESTS_BASE; +if (!pathToRoot.endsWith("/")) { + pathToRoot += "/"; +} +var envConfig = require(pathToRoot + 'config.json'); +var protocol = (process.env.PROTOCOL !== undefined) ? process.env.PROTOCOL : 'https'; + +try { + envConfig = require(pathToRoot + 'environments/dockerConfig.json'); +} catch (e) { +} + +function run() { + var inputArgs = process.argv.slice(2); + let changeConfig = false; + if (process.env.K8S_CONF_PATH !== undefined) { + console.log('updating with kubernetes services'); + let k8sConfig = require(pathToRoot + process.env.K8S_CONF_PATH); + mapK8sPod2Docker(k8sConfig, inputArgs[0], inputArgs[1]); + changeConfig = true; + } else { + console.log('not updating at all'); + } + if (changeConfig) { + let data = JSON.stringify(envConfig, null, 2); + console.log('writing config file: ' + pathToRoot+'environments/dockerConfig.json'); + console.log(data); + fs.writeFileSync(pathToRoot+'environments/dockerConfig.json', data); + } +} + +function mapK8sPod2Docker(k8sConfig, id, k8sid) { + let item = k8sConfig.items.find(item => { + if (item.spec !== undefined && item.spec.ports !== undefined) { + let spec = item.spec.ports.find(port => { + if (port.name === k8sid) { + return true; + } + }); + return (spec !== undefined); + } else { + return false; + } + }); + + item.spec.ports.forEach(port => { + if (port.name === k8sid) { + envConfig[id].port = port.nodePort; + let rancherData = JSON.parse(item.metadata.annotations["field.cattle.io/publicEndpoints"]); + let address = rancherData.find(address => { + return address.port === port.nodePort; + }); + envConfig[id].port = address.port; + envConfig[id].server = address.addresses[0]; + envConfig[id].protocol = protocol; + envConfig[id].user = process.env.SDC_USER_ID; + } + }); + +} + +run(); -- cgit 1.2.3-korg