Skip to content

Commit

Permalink
Add schedule/duration #76
Browse files Browse the repository at this point in the history
  • Loading branch information
apertome committed Sep 16, 2019
1 parent 823a507 commit aec8cf4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
19 changes: 16 additions & 3 deletions api/admin/controllers/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,35 @@ exports._extract_psconfig_tests = function( importedConfig, sub, mainConfig ) {
var tool = importedConfig.tasks[ testName ].tools[0];
tool = tool.replace("bwctl", "");
if ( tool ) {
testObj.tool= shared.convert_tool( tool, true );
testObj.spec.tool= shared.convert_tool( tool, true );

}
}
if ("duration" in testObj.spec && isNaN(testObj.spec.duration)) {
testObj.spec.duration = shared.iso8601_to_seconds( testObj.spec.duration );
}
// TODO: review - hostgroups not required when creating testspecs
console.log("BEFORE ADDING HOSTGROUPS testObj", testObj);
var groups = importedConfig.groups;
var tasksObj = importedConfig.tasks;



var hosts = [];
_.each( tasksObj, function( taskObj, taskName ) {
if ( taskObj.test == testName ) {
var groupName = taskObj.group;
//hosts = importedConfig.tests[ taskObj.test ].type;
var thisTask = taskObj;
var groupName = thisTask.group;
//var tools = thisTask.tools;
//testObj.spec.tool = tools;
//hosts = importedConfig.tests[ thisTask.test ].type;
hosts = _.map(groups[ groupName ].addresses, function(obj, index) {return obj.name;});
var scheduleName = thisTask.schedule;
if ( scheduleName in importedConfig.schedules ) {
var scheduleObj = importedConfig.schedules[ scheduleName ];
var interval = shared.iso8601_to_seconds( scheduleObj.repeat );
testObj.spec.interval = interval;
}
}

});
Expand Down
19 changes: 19 additions & 0 deletions api/sharedFunctions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const moment = require('moment');

exports.convert_tool = function( tool, reverse ) {
var tool_conversions = {
Expand Down Expand Up @@ -77,3 +78,21 @@ exports.rename_field = function( obj, oldname, newname ) {
return obj;

};

exports.seconds_to_iso8601 = function( dur ) {
var isoOut = moment.duration(dur * 1000); // moment.duration expects milliseconds
isoOut = isoOut.toISOString();
return isoOut;
};


exports.iso8601_to_seconds = function( iso ) {
console.log("iso duration", iso);
var mom = moment.duration(iso);
//console.log("ms", ms);
var seconds = mom.asSeconds();
console.log("seconds", seconds);
return seconds;
};


0 comments on commit aec8cf4

Please sign in to comment.