Skip to content

Commit a87e458

Browse files
authored
Fixing the disabled Ansible tests and enabling them (#592)
Fixing the disabled Ansible tests and enabling them.
1 parent 9cc089e commit a87e458

File tree

4 files changed

+56
-44
lines changed

4 files changed

+56
-44
lines changed

Extensions/Ansible/Src/Tasks/Ansible/ansibleCommandLineInterface.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as ansibleUtils from './ansibleUtils';
44
import { RemoteCommandOptions } from './ansibleUtils'
55
import { ansibleTaskParameters } from './ansibleTaskParameters';
66

7-
var uuid = require('uuid/v4'); //randomly generated uid
87
var os = require('os');
98
var shell = require('shelljs');
109

@@ -131,7 +130,7 @@ export class ansibleCommandLineInterface extends ansibleInterface {
131130

132131
return new Promise<string>(async (resolve, reject) => {
133132
try {
134-
let remoteInventory = '/tmp/' + uuid() + 'inventory.ini';
133+
let remoteInventory = ansibleUtils.getTemporaryInventoryFilePath();
135134
let remoteInventoryPath = '"' + remoteInventory + '"';
136135
tl.debug('RemoteInventoryPath = ' + remoteInventoryPath);
137136

Extensions/Ansible/Src/Tasks/Ansible/ansibleUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import tl = require("vsts-task-lib/task");
22
import Q = require("q");
33
import util = require("util");
44
import querystring = require('querystring');
5+
6+
var uuid = require('uuid/v4');
57
var httpClient = require('vso-node-api/HttpClient');
68
var httpObj = new httpClient.HttpCallbackClient(tl.getVariable("AZURE_HTTP_USER_AGENT"));
79

@@ -195,6 +197,10 @@ function beginRequestInternal(request: WebRequest): Promise<WebResponse> {
195197
});
196198
}
197199

200+
export function getTemporaryInventoryFilePath(): string {
201+
return '/tmp/' + uuid() + 'inventory.ini';
202+
}
203+
198204
function toWebResponse(response, body): WebResponse {
199205
var res = new WebResponse();
200206

Extensions/Ansible/Tests/Tasks/Ansible/_suite.ts

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert = require('assert');
22
import path = require('path');
3+
import {TestGuid} from './mockAnsibleUtils';
34

45
var mocktest = require('vsts-task-lib/mock-test');
56

@@ -73,28 +74,28 @@ describe('Ansible Suite', function () {
7374
}
7475
});
7576

76-
// it('should run when inventory is inline content for remote machine', (done: MochaDone) => {
77-
// this.timeout(1000);
78-
// let testPath = path.join(__dirname, 'testInventoryToBeInlineForRemoteMachine');
79-
// let runner = new mocktest.MockTestRunner(testPath);
80-
// runner.run();
81-
82-
// try {
83-
// assert(runner.succeeded, "Should have succeeded");
84-
// assert(runner.stdOutContained('cmd run on remote machine = echo "DUMMY_IP_ADDRESS" > /tmp/inventory.ini'), 'should able to copy the inline content to inventory.ini file on remote machine');
85-
// assert(runner.stdOutContained('cmd run on remote machine = chmod +x /tmp/inventory.ini'), 'should able to make the inventory.ini file as executable for dynamic inventory');
86-
// assert(runner.stdOutContained('cmd run on remote machine = ansible-playbook -i /tmp/inventory.ini /path/to/ansiblePlaybookRoot/ansiblePlaybook.yml'), 'should able to run playbook on remote machine');
87-
// assert(runner.stdOutContained('connection to dummy client established'), 'should able connect to client');
88-
// assert(runner.stdOutContained('connection to dummy client terminated'), 'should able disconnect to client');
89-
// assert(runner.stdOutContained('cmd run on remote machine = rm -f /tmp/inventory.ini', 'should clean all the temporary inventory file on remote machine'));
90-
// done();
91-
// }
92-
// catch (error) {
93-
// console.log("STDERR", runner.stderr);
94-
// console.log("STDOUT", runner.stdout);
95-
// done(error);
96-
// }
97-
// });
77+
it('should run when inventory is inline content for remote machine', (done: MochaDone) => {
78+
this.timeout(1000);
79+
let testPath = path.join(__dirname, 'testInventoryToBeInlineForRemoteMachine');
80+
let runner = new mocktest.MockTestRunner(testPath);
81+
runner.run();
82+
83+
try {
84+
assert(runner.succeeded, "Should have succeeded");
85+
assert(runner.stdOutContained(`cmd run on remote machine = echo "DUMMY_IP_ADDRESS" > /tmp/${TestGuid}inventory.ini`), 'should able to copy the inline content to inventory.ini file on remote machine');
86+
assert(runner.stdOutContained(`cmd run on remote machine = chmod +x /tmp/${TestGuid}inventory.ini`), 'should able to make the inventory.ini file as executable for dynamic inventory');
87+
assert(runner.stdOutContained(`cmd run on remote machine = ansible-playbook -i /tmp/${TestGuid}inventory.ini /path/to/ansiblePlaybookRoot/ansiblePlaybook.yml`), 'should able to run playbook on remote machine');
88+
assert(runner.stdOutContained('connection to dummy client established'), 'should able connect to client');
89+
assert(runner.stdOutContained('connection to dummy client terminated'), 'should able disconnect to client');
90+
assert(runner.stdOutContained(`cmd run on remote machine = rm -f /tmp/${TestGuid}inventory.ini`, 'should clean all the temporary inventory file on remote machine'));
91+
done();
92+
}
93+
catch (error) {
94+
console.log("STDERR", runner.stderr);
95+
console.log("STDOUT", runner.stdout);
96+
done(error);
97+
}
98+
});
9899

99100
it('should run when sudo and additional parameters is present for remote machine', (done: MochaDone) => {
100101
this.timeout(1000);
@@ -171,24 +172,24 @@ describe('Ansible Suite', function () {
171172
}
172173
});
173174

174-
// it('should run when inventory is inline content for agent machine', (done: MochaDone) => {
175-
// this.timeout(1000);
176-
// let testPath = path.join(__dirname, 'testInventoryToBeInlineForAgentMachine');
177-
// let runner = new mocktest.MockTestRunner(testPath);
178-
// runner.run();
179-
180-
// try {
181-
// assert(runner.succeeded, "Should have succeeded");
182-
// assert(runner.stdOutContained('cmd run on agent machine = echo "DUMMY_IP_ADDRESS" > /tmp/inventory.ini'), 'should able to copy the inline content to inventory.ini file on remote machine');
183-
// assert(runner.stdOutContained('cmd run on agent machine = chmod +x /tmp/inventory.ini'), 'should able to make the inventory.ini file as executable for dynamic inventory');
184-
// assert(runner.stdOutContained('cmd run on agent machine = ansible-playbook -i /tmp/inventory.ini /path/to/ansiblePlaybookRoot/ansiblePlaybook.yml'), 'should able to run playbook on remote machine');
185-
// assert(runner.stdOutContained('cmd run on agent machine = rm -f /tmp/inventory.ini', 'should clean all the temporary inventory file on remote machine'));
186-
// done();
187-
// }
188-
// catch (error) {
189-
// console.log("STDERR", runner.stderr);
190-
// console.log("STDOUT", runner.stdout);
191-
// done(error);
192-
// }
193-
// });
175+
it('should run when inventory is inline content for agent machine', (done: MochaDone) => {
176+
this.timeout(1000);
177+
let testPath = path.join(__dirname, 'testInventoryToBeInlineForAgentMachine');
178+
let runner = new mocktest.MockTestRunner(testPath);
179+
runner.run();
180+
181+
try {
182+
assert(runner.succeeded, "Should have succeeded");
183+
assert(runner.stdOutContained(`cmd run on agent machine = echo "DUMMY_IP_ADDRESS" > /tmp/${TestGuid}inventory.ini`), 'should able to copy the inline content to inventory.ini file on remote machine');
184+
assert(runner.stdOutContained(`cmd run on agent machine = chmod +x /tmp/${TestGuid}inventory.ini`), 'should able to make the inventory.ini file as executable for dynamic inventory');
185+
assert(runner.stdOutContained(`cmd run on agent machine = ansible-playbook -i /tmp/${TestGuid}inventory.ini /path/to/ansiblePlaybookRoot/ansiblePlaybook.yml`), 'should able to run playbook on remote machine');
186+
assert(runner.stdOutContained(`cmd run on agent machine = rm -f /tmp/${TestGuid}inventory.ini`, 'should clean all the temporary inventory file on remote machine'));
187+
done();
188+
}
189+
catch (error) {
190+
console.log("STDERR", runner.stderr);
191+
console.log("STDOUT", runner.stdout);
192+
done(error);
193+
}
194+
});
194195
});

Extensions/Ansible/Tests/Tasks/Ansible/mockAnsibleUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Q = require("q");
22

3+
export const TestGuid: string = "7d9b7f32-41e5-43ed-8b0e-c6f2874836f8";
4+
35
export function _writeLine(str) {
46
console.log(str);
57
}
@@ -151,4 +153,8 @@ export function beginRequest(request) {
151153
res.body = JSON.parse(body);
152154
return res;
153155
}
156+
}
157+
158+
export function getTemporaryInventoryFilePath(): string {
159+
return '/tmp/' + TestGuid + 'inventory.ini';
154160
}

0 commit comments

Comments
 (0)