1. Cleaning up log message clutter in task output
2. Fixing Restore operation name as per task.json 3. For invalid action showing proper message in task out 4. Fixing invoke jar file command Test changes related to the above fixes
This commit is contained in:
Родитель
5580d3f40a
Коммит
4213072ca7
|
@ -11,18 +11,12 @@ export class VmOperations {
|
|||
var cmdArgs = "";
|
||||
var vCenterConnectionName: string = tl.getInput("vCenterConnection", true);
|
||||
var vCenterUrl: string = tl.getEndpointUrl(vCenterConnectionName, false);
|
||||
var vCenterUserName: string =
|
||||
this.escapeDoubleQuotes(tl.getEndpointAuthorization(vCenterConnectionName, false)["parameters"]["username"]);
|
||||
var vCenterPassword: string =
|
||||
this.escapeDoubleQuotes(tl.getEndpointAuthorization(vCenterConnectionName, false)["parameters"]["password"]);
|
||||
var endPointAuthCreds = tl.getEndpointAuthorization(vCenterConnectionName, false)["parameters"];
|
||||
var vCenterUserName: string = this.escapeDoubleQuotes(endPointAuthCreds["username"]);
|
||||
var vCenterPassword: string = this.escapeDoubleQuotes(endPointAuthCreds["password"]);
|
||||
var vmList: string = this.escapeDoubleQuotes(tl.getInput("vmList", true));
|
||||
this.validateVmListInput(vmList);
|
||||
|
||||
tl.debug("vCenterConnectionName = " + vCenterConnectionName);
|
||||
tl.debug("vCenterUrl = " + vCenterUrl);
|
||||
tl.debug("vCenterUserName = " + vCenterUserName);
|
||||
tl.debug("vmList = " + vmList);
|
||||
|
||||
cmdArgs += " -vCenterUrl \"" + vCenterUrl + "\" -vCenterUserName \"" + vCenterUserName + "\" -vCenterPassword \"" +
|
||||
vCenterPassword + "\" -vmList \"" + vmList + "\"";
|
||||
tl.debug(util.format("common args: -vCenterUrl \"%s\" -vCenterUserName \"%s\" -vCenterPassword \"%s\" -vmList \"%s\"",
|
||||
|
@ -34,15 +28,13 @@ export class VmOperations {
|
|||
var cmdArgs = "";
|
||||
var snapshotName = null;
|
||||
switch (actionName) {
|
||||
case "RestoreSnapshot":
|
||||
case "Restore Snapshot on Virtual Machines":
|
||||
snapshotName = this.escapeDoubleQuotes(tl.getInput("snapshotName", true));
|
||||
tl.debug("snapshotName = " + snapshotName );
|
||||
cmdArgs += " -snapshotOps restore -snapshotName \"" + snapshotName + "\"";
|
||||
tl.debug(util.format("action args: %s", cmdArgs));
|
||||
break;
|
||||
default:
|
||||
tl.debug("actionName = " + actionName);
|
||||
throw "Invalid action name";
|
||||
tl.error("Invalid action name : " + actionName);
|
||||
}
|
||||
return cmdArgs;
|
||||
}
|
||||
|
@ -51,7 +43,7 @@ export class VmOperations {
|
|||
var actionName: string = tl.getInput("action", true);
|
||||
var commonArgs: string = this.getCmdCommonArgs();
|
||||
var cmdArgsForAction: string = this.getCmdArgsForAction(actionName);
|
||||
var cmdArgs = "./vmOpsTool-1.0.jar " + cmdArgsForAction + commonArgs;
|
||||
var cmdArgs = "-jar ./vmOpsTool-1.0.jar " + cmdArgsForAction + commonArgs;
|
||||
util.log("Invoking command to perform vm operations ...\n");
|
||||
return tl.exec("java", cmdArgs)
|
||||
.then((code) => {
|
||||
|
|
|
@ -106,9 +106,11 @@ describe("getCmdCommonArgs", (): void => {
|
|||
describe("getCmdArgsForAction", (): void => {
|
||||
var sandbox;
|
||||
var getInputStub;
|
||||
var logErrorStub;
|
||||
beforeEach((): void => {
|
||||
sandbox = sinon.sandbox.create();
|
||||
getInputStub = sandbox.stub(tl, "getInput");
|
||||
logErrorStub = sandbox.stub(tl, "error");
|
||||
});
|
||||
|
||||
afterEach((): void => {
|
||||
|
@ -118,7 +120,7 @@ describe("getCmdArgsForAction", (): void => {
|
|||
it("Should read snapshot name for restore snapshot action", (): void => {
|
||||
getInputStub.withArgs("snapshotName", true).returns("dummySnap\"shotName");
|
||||
|
||||
var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("RestoreSnapshot");
|
||||
var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Restore Snapshot on Virtual Machines");
|
||||
|
||||
cmdArgs.should.contain("-snapshotOps restore -snapshotName \"dummySnap\\\"shotName\"");
|
||||
});
|
||||
|
@ -127,15 +129,15 @@ describe("getCmdArgsForAction", (): void => {
|
|||
getInputStub.withArgs("snapshotName", true).throws();
|
||||
|
||||
expect( (): void => {
|
||||
vmOperations.VmOperations.getCmdArgsForAction("RestoreSnapshot");
|
||||
vmOperations.VmOperations.getCmdArgsForAction("Restore Snapshot on Virtual Machines");
|
||||
}).to.throw("Error");
|
||||
getInputStub.should.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it("Should throw on failure for invalid action name", (): void => {
|
||||
expect( (): void => {
|
||||
vmOperations.VmOperations.getCmdArgsForAction("InvalidAction");
|
||||
}).to.throw("Invalid action name");
|
||||
vmOperations.VmOperations.getCmdArgsForAction("InvalidAction");
|
||||
|
||||
logErrorStub.withArgs(("Invalid action name : InvalidAction")).should.have.been.calledOnce;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -164,7 +166,7 @@ describe("runMain", (): void => {
|
|||
|
||||
var commonArgs = " -vCenterUrl \"http://localhost:8080\" -vCenterUserName \"dummydomain\\dummyuser\" -vCenterPassword \" pas\\\" w,o ;d\" ";
|
||||
var cmdArgsForAction = " -snapshotOps restore -snapshotName \"dummysnapshot\"";
|
||||
var cmdArgs = "./vmOpsTool-1.0.jar " + cmdArgsForAction + commonArgs;
|
||||
var cmdArgs = "-jar ./vmOpsTool-1.0.jar " + cmdArgsForAction + commonArgs;
|
||||
var actionName = "RestoreSnapshot";
|
||||
|
||||
it("Should return 0 on successful exection of the command", (done): void => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче