Skip to content

Commit

Permalink
Bugfix; runtime vars not being remapped correctly; added total exec t…
Browse files Browse the repository at this point in the history
…ime; new demo workflow
  • Loading branch information
0xHiteshPatel committed Mar 30, 2017
1 parent b9c2401 commit 6d33e26
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 8 deletions.
2 changes: 1 addition & 1 deletion framework/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
globals.postman_globals.json
f5-postman-workflows.postman_globals.json
test_*
29 changes: 22 additions & 7 deletions framework/f5-newman-wrapper/f5-newman-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ var runCollection = function(obj) {

if(typeof workflow.globalOptions.reporters === 'undefined') options.reporters = [];

//mergeEnv(options.environment, runtimeVars);

// Setup our callback
var newmanCallback = function(err, summary) {
// Add run summary to the workflow object
Expand Down Expand Up @@ -265,18 +263,23 @@ var runCollection = function(obj) {

if(typeof obj.options.remapPostRun !== 'undefined') {
for(var i = 0; i < runtimeTemp.values.length; i++) {
//printOut(`[remapPostRun] pre=` + JSON.stringify(runtimeTemp.values[i],null,1), 2);
printOut(`[remapPostRun] pre=` + JSON.stringify(runtimeTemp.values[i],null,1), 10);
var k = runtimeTemp.values[i].key;
var v = runtimeTemp.values[i].value;
if(typeof obj.options.remapPostRun[k] !== 'undefined') {
printOut(`[remapPostRun] remapping ${k} -> ${obj.options.remapPostRun[k]}`, 2);
runtimeTemp.values[i].key = obj.options.remapPostRun[k];
if(typeof workflow.globalVars[obj.options.remapPostRun[k]] === 'undefined') {
workflow.globalVars[obj.options.remapPostRun[k]] = v;
} else {
printOut(`[remapPostRun] WARNING: There was a collision in globalVars trying to remap '${k}' -> '${obj.options.remapPostRun[k]}'`, 1, console.error)
}
}
//printOut(`[remapPostRun] post=` + JSON.stringify(runtimeTemp.values[i],null,1) , 2);
printOut(`[remapPostRun] post=` + JSON.stringify(runtimeTemp.values[i],null,1) , 10);
};

};
runtimeVars = runtimeTemp;
//runtimeVars = summary.environment;

if (err || summary.error || summary.run.failures.length > 0) {
callback(1, summary);
Expand Down Expand Up @@ -347,14 +350,26 @@ var main = function() {
// Output the initial run data
jsonfile.writeFileSync(workflow.outputFile, workflow, {spaces: 2});

// Measure total execution time
var startTime = process.hrtime();
var stopTime = null;

// Execute the stack in series
async.series(asyncStack, function(err, results) {
printOut("[stack] done, err=" + err, 10);
printOut("[stack] done, results=" + JSON.stringify(results), 10);
if(workflow.saveEnvVars) {
jsonfile.writeFileSync(workflow.envOutputFile, results.pop().environment, {spaces: 2});
jsonfile.writeFileSync(workflow.envOutputFile, runtimeVars, {spaces: 2});
}
process.stdout.write("");
var stopTime = process.hrtime(startTime)[1] / 1000000;

var runComplete = function() {
var totalRunTime = process.hrtime(startTime)[0] + "s, " + stopTime.toFixed(3) + " ms";
printOut(`run completed in ${totalRunTime}`, 1);
}
printOut(`run completed`, 1);
// Delay 100 ms so newman can finish flushing it's output to console
setTimeout(runComplete, 100);
});

};
Expand Down
88 changes: 88 additions & 0 deletions workflows/Wrapper_Demo_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"name":"Wrapper_Demo_2",
"description":"Execute a chained workflow that authenticates to two BIG-IPs and retrieves their software version",
"globalEnvVars":"../framework/f5-postman-workflows.postman_globals.json",
"globalOptions": {
"insecure":true,
"reporters":["cli"]
},
"globalVars": {
"bigip_a_mgmt": "",
"bigip_b_mgmt": "",
"bigip_username":"admin",
"bigip_password":"admin"
},
"saveEnvVars":true,
"outputFile":"Wrapper_Demo_2-run.json",
"envOutputFile":"Wrapper_Demo_2-env.json",
"workflow": [
{
"name":"Authenticate to BIG-IPs",
"skip":true,
"children": [
{
"name":"Authenticate to BIG-IP A",
"options": {
"collection":"../collections/BIG_IP/BIGIP_API_Authentication.postman_collection.json",
"remapPreRun": {
"bigip_a_mgmt": "bigip_mgmt"
},
"folder":"1_Authenticate",
"remapPostRun": {
"bigip_token": "bigip_a_token"
}
}
},
{
"name":"Authenticate to BIG-IP B",
"options": {
"collection":"../collections/BIG_IP/BIGIP_API_Authentication.postman_collection.json",
"remapPreRun": {
"bigip_b_mgmt": "bigip_mgmt"
},
"folder":"1_Authenticate",
"remapPostRun": {
"bigip_token": "bigip_b_token"
}
}
}
]
},
{
"name":"Get BIG-IP Software Versions",
"skip":true,
"children": [
{
"name":"Get BIG-IP A Software Version",
"options": {
"collection":"../collections/BIG_IP/BIGIP_Operational_Workflows.postman_collection.json",
"remapPreRun": {
"bigip_a_mgmt": "bigip_mgmt",
"bigip_a_token": "bigip_token"
},
"folder":"4A_Get_BIGIP_Version",
"remapPostRun": {
"bigip_version": "bigip_a_version",
"bigip_build": "bigip_a_build"
}
}
},
{
"name":"Get BIG-IP B Software Version",
"options": {
"collection":"../collections/BIG_IP/BIGIP_Operational_Workflows.postman_collection.json",
"remapPreRun": {
"bigip_b_mgmt": "bigip_mgmt",
"bigip_b_token": "bigip_token"
},
"folder":"4A_Get_BIGIP_Version",
"remapPostRun": {
"bigip_version": "bigip_b_version",
"bigip_build": "bigip_b_build"
}
}
}
]
}
]
}

0 comments on commit 6d33e26

Please sign in to comment.