Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] vcsim: cloning a vm with the duplicated name should fail #2983

Closed
Syuparn opened this issue Nov 5, 2022 · 0 comments · Fixed by #2984
Closed

[BUG] vcsim: cloning a vm with the duplicated name should fail #2983

Syuparn opened this issue Nov 5, 2022 · 0 comments · Fixed by #2984

Comments

@Syuparn
Copy link
Contributor

Syuparn commented Nov 5, 2022

Describe the bug

When the duplicated vm name is specified to CloneVM_Task request, it succeeds and the created vm has same path to the existng one.

To Reproduce
Steps to reproduce the behavior:

  1. run vcsim without any options
  2. run a script below
source code (click to open)
package main

import (
        "context"
        "fmt"
        "net/url"
        "path"

        "github.com/vmware/govmomi"
        "github.com/vmware/govmomi/find"
        "github.com/vmware/govmomi/vim25/types"
)

func main() {
        ctx := context.Background()
        u, _ := url.Parse("https://user:pass@127.0.0.1:8989/sdk")
        c, _ := govmomi.NewClient(ctx, u, true)

        finder := find.NewFinder(c.Client)
        vm, _ := finder.VirtualMachine(ctx, "DC0_H0_VM0")

        folder, _ := finder.Folder(ctx, path.Dir(vm.InventoryPath))

        config := types.VirtualMachineCloneSpec{
                Template: false,
                PowerOn:  true,
        }
        // name and folder are same as original's ones
        task, err := vm.Clone(ctx, folder, vm.Name(), config)
        if err != nil {
                fmt.Printf("failed to clone: %s", err)
                return
        }

        result, err := task.WaitForResult(ctx)
        if err != nil {
                fmt.Printf("task failed: %s", err)
                return
        }

        fmt.Printf("state: %#v\n", result.State)
}

Expected behavior

The task failed by a name duplication error.

$ go run .\main.go
task failed: The name 'DC0_H0_VM0' already exists.

Affected version

  • vcsim v0.29.0

Screenshots/Debug Output

The task succeeds and two vms are located in the same path.

$ go run main.go
state: "success"

$ govc vm.info DC0_H0_VM0
Name:           DC0_H0_VM0
  Path:         /DC0/vm/DC0_H0_VM0
  UUID:         265104de-1472-547c-b873-6dc7883fb6cb
  Guest name:   otherGuest
  Memory:       32MB
  CPU:          1 vCPU(s)
  Power state:  poweredOn
  Boot time:    2022-11-03 20:34:07.225752728 +0900 JST
  IP address:
  Host:         DC0_H0
Name:           DC0_H0_VM0
  Path:         /DC0/vm/DC0_H0_VM0
  UUID:         0d844f57-2f52-591a-bcff-16c283cd5559
  Guest name:   otherGuest
  Memory:       32MB
  CPU:          1 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:
  Host:         DC0_H0

Additional context

govc is not affected by this issue since it checks vmx file collision before CloneVM_Task.

$ govc vm.clone -host DC0_H0 -vm DC0_H0_VM0 DC0_H0_VM0
govc: file [LocalDS_0] DC0_H0_VM0/DC0_H0_VM0.vmx already exists
Syuparn added a commit to Syuparn/govmomi that referenced this issue Nov 5, 2022
Closes: vmware#2983
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
Syuparn added a commit to Syuparn/govmomi that referenced this issue Nov 5, 2022
Closes: vmware#2983
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
priyanka19-98 pushed a commit to priyanka19-98/govmomi that referenced this issue Jan 17, 2024
Closes: vmware#2983
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant