Skip to content

Commit

Permalink
Testspecs mostly set #76
Browse files Browse the repository at this point in the history
  • Loading branch information
apertome committed Sep 6, 2019
1 parent 1b02309 commit 735a066
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/admin/controllers/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" );

Expand Down Expand Up @@ -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);
Expand All @@ -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 = {};

Expand Down
58 changes: 58 additions & 0 deletions api/sharedFunctions.js
Original file line number Diff line number Diff line change
@@ -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;

};

0 comments on commit 735a066

Please sign in to comment.