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] simulator: Object of DuplicateName fault of CreateFolder is incorrect #3610

Closed
prziborowski opened this issue Nov 4, 2024 · 1 comment · Fixed by #3612
Closed

[BUG] simulator: Object of DuplicateName fault of CreateFolder is incorrect #3610

prziborowski opened this issue Nov 4, 2024 · 1 comment · Fixed by #3612
Assignees

Comments

@prziborowski
Copy link
Contributor

Describe the bug

I was automating a flow of (pseudo-code)

folder, err := vmFolder.CreateFolder("some name")
if err != nil {
    var dup *types.DuplicateName
    if _, ok faults.As(err, &dup); ok {
        folder = dup.Object
    }
}
folder.CreateVM(...)

And then I was having some weird issues when I was verifying that vmFolder didn't have the VM from above.
I resorted to fmt.Printf of folder and I noticed the first CreateVM was the right folder and all the rest after was vmFolder.
I looked at the simulator code and noticed:

      if obj := ctx.Map.FindByName(name, f.ChildEntity); obj != nil {
         r.Fault_ = Fault("", &types.DuplicateName{
            Name:   name,
            Object: f.Self,
         })

that didn't seem right.
I look at resource pool and it has:

   if e := Map.FindByName(name, p.ResourcePool.ResourcePool); e != nil {
      return nil, Fault("", &types.DuplicateName{
         Name:   e.Entity().Name,
         Object: e.Reference(),
      })

which seems right.

To Reproduce
Steps to reproduce the behavior:

Non-pseudo-code of above description.
Should be able to just call CreateFolder a couple times and the fault will point to the caller object rather than the duplicate object.

Expected behavior

diff --git a/simulator/folder.go b/simulator/folder.go
index 4d6e96ec..df9e04b2 100644
--- a/simulator/folder.go
+++ b/simulator/folder.go
@@ -208,7 +208,7 @@ func (f *Folder) CreateFolder(ctx *Context, c *types.CreateFolder) soap.HasFault
                if obj := ctx.Map.FindByName(name, f.ChildEntity); obj != nil {
                        r.Fault_ = Fault("", &types.DuplicateName{
                                Name:   name,
-                               Object: f.Self,
+                               Object: obj.Reference(),
                        })

                        return r

(probably should do the same for the storagePod)

Affected version

82b4ad6

Copy link
Contributor

github-actions bot commented Nov 4, 2024

Howdy 🖐   prziborowski ! Thank you for your interest in this project. We value your feedback and will respond soon.

If you want to contribute to this project, please make yourself familiar with the CONTRIBUTION guidelines.

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