microsoft / vsts-vmware

17 stars 14 forks source link

Loop to find a snapshot on the virtual machine doesn't return when it actually finds a snapshot #67

Open icnocop opened 8 years ago

icnocop commented 8 years ago

Visual Studio Team Foundation Server 2015 Update 3 (on premise) VMware Resource Deployment 1.0.0 (ms-vscs-rm.vmwareapp)

The loop to find a snapshot on the virtual machine doesn't return when it actually finds a snapshot.

https://github.com/Microsoft/vsts-vmware/blob/master/src/Tools/vmOpsTool/VMWareImpl.java#L614

Right after that line, there should be a check to see if snapshotMor is not null and if so, break out of the loop or return snapshotMor.

The problematic behavior is observed when there's a snapshot hierarchy similar to the following:

- Root Snapshot
     |- Child Snapshot A
              |- Grandchild Snapshot 1
     |- Child Snapshot B

When trying to revert to "Grandchild Snapshot 1", the output log is similar to the follow:

...
Successfully established session with vCenter server.
Restoring snapshot [ Grandchild Snapshot 1 ] on virtual machine [ My Virtual Machine ].
Querying VirtualMachine objects on vCenter server.
Querying snapshot information for virtual machine [ My Virtual Machine ].
Found snapshot [ Grandchild Snapshot 1 ] for virtual machine.
No snapshot found on virtual machine [ My Virtual Machine ] with name Grandchild Snapshot 1
Failed to [restore] snapshot [Grandchild Snapshot 1] on virtual machines  [My Virtual Machine ].
Return code: 1
##[debug]rc:1
##[debug]success:false
##[error]Failure reason : Error: C:\ProgramData\Oracle\Java\javapath\java.exe failed with return code: 1
##[debug]load strings from: C:\agent\tasks\VMwareTask\1.0.0\node_modules\vsts-task-lib\lib.json
##[debug]load loc strings from: C:\agent\tasks\VMwareTask\1.0.0\node_modules\vsts-task-lib\strings\resources.resjson\en-US\resources.resjson
##[debug]task result: Failed
Finishing task: VMwareTask
##[error]Task VMwareTask failed. This caused the job to fail. Look at the logs for the task for more details.

Ideally, I would like to be able to specify the specific snapshot hierarchy in the case where there's more than one snapshot with the same name.

For example, I want to explicitly specify the snapshot name "Root Snapshot\Child Snapshot B\Grandchild Snapshot 1", in the case where there's already a snapshot named "Grandchild Snapshot 1" higher up in the hierarchy, i.e. "Root Snapshot\Child Snapshot A\Grandchild Snapshot 1". Currently, there isn't a way to specify which snapshot I want to revert to.

Thank you!

ghost commented 8 years ago

I think the same is happening to me. I get "No snapshot found on virtual machine" error even though, snapshot exists and the tools finds the snapshot, but it still returns an error. It could be because snapshot is buried deep in the snapshot hierarchy. Please advise.

KrishnaAdityaB commented 8 years ago

@icnocop Thanks for reporting the issue and pinning the root cause in source code. you can raise a PR with the fix. here are the steps to build and run tests.

ghost commented 8 years ago

I'm not a Java guy, so there is not much I can do to help. @icnocop can you help? Or perhaps, any of the contributors can take a look at it.

ghost commented 8 years ago
private ManagedObjectReference findSnapshotInTree(List<VirtualMachineSnapshotTree> vmSnapshotList,
                                                  String snapshotName) {
    ManagedObjectReference snapshotMor = null;

    for (VirtualMachineSnapshotTree vmSnapshot : vmSnapshotList) {

        if (vmSnapshot.getName().equalsIgnoreCase(snapshotName)) {
            System.out.println(String.format("Found snapshot [ %s ] for virtual machine.", snapshotName));
            **snapshotMor =  vmSnapshot.getSnapshot();
            break;**

        } else {
            List<VirtualMachineSnapshotTree> childTree = vmSnapshot.getChildSnapshotList();
            snapshotMor = findSnapshotInTree(childTree, snapshotName);
        }
    }
    return snapshotMor;
}
mvvsubbu commented 8 years ago

@yermax created a PR with the fix https://github.com/Microsoft/vsts-vmware/pull/72

melaniesaraj commented 3 years ago

Hello, I see that this is merged into master, but the version in the marketplace is still 1.0.0 from 5/24/2016. Are you planning to push out this fix?

I did notice that in the commit, the patch number in task.json (1.0.2) is different from the one in vss-extension.json (1.0.1); not sure if the two have anything to do with each other. This requirement could also be related: https://devblogs.microsoft.com/devops/new-requirement-when-updating-team-services-extensions-on-the-marketplace