From 735a0661fecad3f54ba393cdaa643fc39a5fed0c Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 6 Sep 2019 20:57:52 +0000 Subject: [PATCH] Testspecs mostly set #76 --- api/admin/controllers/importer.js | 39 +++++++++++++++++++++ api/sharedFunctions.js | 58 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 api/sharedFunctions.js diff --git a/api/admin/controllers/importer.js b/api/admin/controllers/importer.js index 06b8a805..7f7cb7db 100644 --- a/api/admin/controllers/importer.js +++ b/api/admin/controllers/importer.js @@ -13,6 +13,7 @@ const _ = require('underscore'); const config = require('../../config'); const logger = new winston.Logger(config.logger.winston); const db = require('../../models'); +const shared = require('../../sharedFunctions'); const pSConfigKeys = [ "archives", @@ -74,7 +75,10 @@ function ensure_hosts(hosts_info, tests, cb) { if(err) return next_host(err); if(_host) { + //console.log("_HOST", _host); + console.log("_HOST._ID", _host._id); logger.debug("host already exists", host.hostname); + host._id = _host._id; if(_host.lsid) { if ( "sitename" in host ) { var sitename = host.sitename; @@ -243,6 +247,8 @@ exports._process_imported_config = function ( importedConfig, sub, cb, disable_e var testspecs = mainConfig.testspecs; var hostgroups = mainConfig.hostgroups; + console.log("hostgroups", hostgroups); + //var out = importedConfig; //out = JSON.stringify( out, null, "\t" ); @@ -458,6 +464,7 @@ exports._process_psconfig = function ( importedConfig, sub, config_params, mainC console.log("hosts_info", hosts_info); config_params.addresses = hosts_info.addresses; + testspecs = exports._extract_psconfig_tests( importedConfig, sub ); console.log("config_params psconfig", config_params); @@ -466,6 +473,38 @@ exports._process_psconfig = function ( importedConfig, sub, config_params, mainC return hosts_info; }; +exports._extract_psconfig_tests = function( importedConfig, sub ) { + var importedTests = importedConfig.tests; + var testspecs = []; + _.each( importedTests, function( testObj, testName ) { + testObj.name = testName; + + delete testObj.spec.source; + delete testObj.spec.dest; + + if ( testObj.type == "latencybg" ) { + testObj.schedule_type = "continuous"; + } else { + testObj.schedule_type = "interval"; + } + if ( importedConfig.tasks[ testName ].tools ) { + var tool = importedConfig.tasks[ testName ].tools[0]; + tool = tool.replace("bwctl", ""); + if ( tool ) { + testObj.tool= shared.convert_tool( tool, true ); + + } + } + shared.rename_dashes_to_underscores( testObj.spec ); + + + console.log("testObj", testObj); + }); + + return testspecs; + +}; + exports._extract_psconfig_hosts = function( importedConfig, config_params, sub ) { var hosts_obj = {}; diff --git a/api/sharedFunctions.js b/api/sharedFunctions.js new file mode 100644 index 00000000..0ad97a57 --- /dev/null +++ b/api/sharedFunctions.js @@ -0,0 +1,58 @@ + +exports.convert_tool = function( tool, reverse ) { + var tool_conversions = { + "bwctl/nuttcp": "nuttcp", + "bwctl/iperf": "iperf", + "bwctl/iperf3": "iperf3", + // "bwctl/iperf3": "bwctliperf3" + + }; + // update tool names + if ( reverse ) { + tool_conversions = exports.swap( tool_conversions ); + } + if ( tool in tool_conversions ) { + console.log("changing tool ", tool, " to ", tool_conversions[tool]); + tool = tool_conversions[ tool ]; + } + return tool; + +}; + +exports.swap = function (json){ + var ret = {}; + for(var key in json){ + ret[json[key]] = key; + } + return ret; +}; + +exports.rename_underscores_to_dashes = function( obj ) { + for(var key in obj ) { + var newkey = key.replace(/_/g, "-"); + obj[ newkey ] = obj[ key ]; + if (key.match(/_/) ) delete obj[ key ]; + } + +}; + +exports.rename_dashes_to_underscores = function( obj ) { + for(var key in obj ) { + var newkey = key.replace(/-/g, "_"); + obj[ newkey ] = obj[ key ]; + if (key.match(/-/) ) delete obj[ key ]; + } + +}; + +exports.rename_field = function( obj, oldname, newname ) { + if ( typeof obj == "undefined" ) { + return; + } + if ( oldname in obj ) { + obj[ newname ] = obj[ oldname ]; + delete obj[ oldname ]; + } + return obj; + +};