From 718b687734f4a3d602a52f882474e726bca88bf6 Mon Sep 17 00:00:00 2001 From: Subrahmanyam Mandavilli Date: Thu, 19 May 2016 11:35:59 +0530 Subject: [PATCH] Type script layer changes to timeout configurable --- src/Tasks/vmOperations/task.json | 9 ++++++ src/Tasks/vmOperations/vmOperations.ts | 16 ++++++---- tests/Tasks/vmOperations/vmOperationsTests.ts | 29 ++++++++++++------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/Tasks/vmOperations/task.json b/src/Tasks/vmOperations/task.json index be2b26c..17d2e7b 100644 --- a/src/Tasks/vmOperations/task.json +++ b/src/Tasks/vmOperations/task.json @@ -150,6 +150,15 @@ "visibleRule": "action = Take Snapshot of Virtual Machines || action = Deploy Virtual Machines using Template", "helpMarkDown": "Provide a description for the action." }, + { + "name": "timeout", + "type": "string", + "label": "Wait Time", + "defaultValue": "1200", + "required": false, + "helpMarkDown": "Specify wait time in seconds for the Virtual Machine to be in ready state for deployment.", + "visibleRule": "action = Power On Virtual Machines || action = Shutdown Virtual Machines || action = Take Snapshot of Virtual Machines || action = Revert Snapshot of Virtual Machines || action = Deploy Virtual Machines using Template" + }, { "name": "skipca", "type": "boolean", diff --git a/src/Tasks/vmOperations/vmOperations.ts b/src/Tasks/vmOperations/vmOperations.ts index 4511815..f0b0847 100644 --- a/src/Tasks/vmOperations/vmOperations.ts +++ b/src/Tasks/vmOperations/vmOperations.ts @@ -29,6 +29,7 @@ export class VmOperations { public static getCmdArgsForAction(actionName: string): string { var cmdArgs = ""; + var timeout = ""; switch (actionName) { case "Deploy Virtual Machines using Template": var template = tl.getInput("template", true); @@ -36,6 +37,7 @@ export class VmOperations { var datastore = tl.getInput("datastore", true); var description = tl.getInput("description", false); var customizationspec = tl.getInput("customizationspec", false); + timeout = tl.getInput("timeout", false); var computeName = null; switch (computeType) { case "ESXi Host": @@ -52,19 +54,21 @@ export class VmOperations { tl.exit(1); } cmdArgs += " -clonetemplate \"" + template + "\" -computetype \"" + computeType + "\" -computename \"" + - computeName + "\" -datastore \"" + datastore + "\" -customizationspec \"" + customizationspec + "\" -description \"" + description + "\""; + computeName + "\" -datastore \"" + datastore + "\" -customizationspec \"" + customizationspec + "\" -description \"" + description + "\" -timeout " + timeout; break; case "Take Snapshot of Virtual Machines": var snapshotName = tl.getInput("snapshotName", true); var snapshotVMMemory = "true"; var quiesceGuestFileSystem = "false"; var description: string = tl.getInput("description", false); + timeout = tl.getInput("timeout", false); cmdArgs += " -snapshotOps create -snapshotName \"" + snapshotName + "\" -snapshotVMMemory " + snapshotVMMemory + " -quiesceGuestFileSystem " + - quiesceGuestFileSystem + " -description \"" + description + "\""; + quiesceGuestFileSystem + " -description \"" + description + "\" -timeout " + timeout; break; case "Revert Snapshot of Virtual Machines": var snapshotName = tl.getInput("snapshotName", true); - cmdArgs += " -snapshotOps restore -snapshotName \"" + snapshotName + "\""; + timeout = tl.getInput("timeout", false); + cmdArgs += " -snapshotOps restore -snapshotName \"" + snapshotName + "\" -timeout " + timeout; break; case "Delete Snapshot of Virtual Machines": var snapshotName = tl.getInput("snapshotName", true); @@ -74,10 +78,12 @@ export class VmOperations { cmdArgs += " -deletevm delete"; break; case "Power On Virtual Machines": - cmdArgs += " -powerops poweron"; + timeout = tl.getInput("timeout", false); + cmdArgs += " -powerops poweron -timeout " + timeout; break; case "Shutdown Virtual Machines": - cmdArgs += " -powerops shutdown"; + timeout = tl.getInput("timeout", false); + cmdArgs += " -powerops shutdown -timeout " + timeout; break; case "Power off Virtual Machines": cmdArgs += " -powerops poweroff"; diff --git a/tests/Tasks/vmOperations/vmOperationsTests.ts b/tests/Tasks/vmOperations/vmOperationsTests.ts index 10c632e..1a36a5d 100644 --- a/tests/Tasks/vmOperations/vmOperationsTests.ts +++ b/tests/Tasks/vmOperations/vmOperationsTests.ts @@ -143,13 +143,14 @@ describe("getCmdArgsForAction", (): void => { sandbox.restore(); }); - it("Should read snapshot name, snapshot vm memory, quiesce file system and description for create snapshot", (): void => { + it("Should read snapshot name, snapshot vm memory, quiesce file system,description and timeout for create snapshot", (): void => { getInputStub.withArgs("snapshotName", true).returns("dummySnapshotName"); getInputStub.withArgs("description", false).returns("Sample description"); + getInputStub.withArgs("timeout", false).returns("1200"); var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Take Snapshot of Virtual Machines"); - cmdArgs.should.contain("-snapshotOps create -snapshotName \"dummySnapshotName\" -snapshotVMMemory true -quiesceGuestFileSystem false -description \"Sample description\""); + cmdArgs.should.contain("-snapshotOps create -snapshotName \"dummySnapshotName\" -snapshotVMMemory true -quiesceGuestFileSystem false -description \"Sample description\" -timeout 1200"); debugStub.should.have.been.calledOnce; }); @@ -159,15 +160,16 @@ describe("getCmdArgsForAction", (): void => { var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Take Snapshot of Virtual Machines"); cmdArgs.should.contain("-snapshotOps create -snapshotName \"dummySnapshotName\" -snapshotVMMemory true -quiesceGuestFileSystem false -description \"undefined\""); - getInputStub.should.have.callCount(2); + getInputStub.should.have.callCount(3); }); - it("Should read snapshot name for restore snapshot action", (): void => { + it("Should read snapshot name for restore snapshot action and timeout", (): void => { getInputStub.withArgs("snapshotName", true).returns("dummySnapshotName"); + getInputStub.withArgs("timeout", false).returns("1200"); var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Revert Snapshot of Virtual Machines"); - cmdArgs.should.contain("-snapshotOps restore -snapshotName \"dummySnapshotName\""); + cmdArgs.should.contain("-snapshotOps restore -snapshotName \"dummySnapshotName\" -timeout 1200"); }); it("Should read snapshot name for delete snapshot action", (): void => { @@ -178,17 +180,18 @@ describe("getCmdArgsForAction", (): void => { cmdArgs.should.contain("-snapshotOps delete -snapshotName \"dummySnapshotName\""); }); - it("Should read template, computeType, hostname, datastore, customization spec and description for clone template", (): void => { + it("Should read template, computeType, hostname, datastore, customization spec,description and timeout for clone template", (): void => { getInputStub.withArgs("template", true).returns("dummyTemplate"); getInputStub.withArgs("computeType", true).returns("ESXi Host"); getInputStub.withArgs("hostname", true).returns("Dummy Host"); getInputStub.withArgs("datastore", true).returns("Dummy Datastore"); getInputStub.withArgs("description", false).returns("Dummy description"); getInputStub.withArgs("customizationspec", false).returns("Dummy Customization Spec"); + getInputStub.withArgs("timeout", false).returns("1200"); var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Deploy Virtual Machines using Template"); - cmdArgs.should.contain("-clonetemplate \"dummyTemplate\" -computetype \"ESXi Host\" -computename \"Dummy Host\" -datastore \"Dummy Datastore\" -customizationspec \"Dummy Customization Spec\" -description \"Dummy description\""); + cmdArgs.should.contain("-clonetemplate \"dummyTemplate\" -computetype \"ESXi Host\" -computename \"Dummy Host\" -datastore \"Dummy Datastore\" -customizationspec \"Dummy Customization Spec\" -description \"Dummy description\" -timeout 1200"); }); it("Should read cluster name if compute is cluster and read empty description", (): void => { @@ -225,16 +228,20 @@ describe("getCmdArgsForAction", (): void => { cmdArgs.should.contain("-deletevm delete"); }); - it("Should construct command action for power on vm operation", (): void => { + it("Should construct command action for power on vm operation and read timeout", (): void => { + getInputStub.withArgs("timeout", false).returns("1200"); + var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Power On Virtual Machines"); - cmdArgs.should.contain("-powerops poweron"); + cmdArgs.should.contain("-powerops poweron -timeout 1200"); }); - it("Should construct command action for shutdown vm operation", (): void => { + it("Should construct command action for shutdown vm operation and read timeout", (): void => { + getInputStub.withArgs("timeout", false).returns("1200"); + var cmdArgs = vmOperations.VmOperations.getCmdArgsForAction("Shutdown Virtual Machines"); - cmdArgs.should.contain("-powerops shutdown"); + cmdArgs.should.contain("-powerops shutdown -timeout 1200"); }); it("Should construct command action for power off vm operation", (): void => {