chef / kitchen-vcenter

A test-kitchen driver for vCenter REST API
https://www.chef.io/implementations/vmware
Apache License 2.0
25 stars 26 forks source link

Setting 'folder' (destination folder when new VM should be created) does not work #93

Closed MrCyrus closed 3 years ago

MrCyrus commented 4 years ago

Versions:

Platform Details

Scenario:

I'm trying to define a .kitchen.yml file that will work with a local on-site vSphere. Ideally I'd like to put all kitchen created VMs in a folder dedicated to 'kitchen' so in my kitchen.yml in my 'driver' section I've defined: folder: Kitchen-Servers

With this, the VM does indeed get created in the right place, but in file clone_vm.rb when the line 'dc.find_vm(path)' is run, the VM is not found. When I leave 'folder' empty, then the VM create is put at the top level and the find_vm is able to find the VM

Since we will be supporting multiple teams the folder structure looks something like: DC/Unix/Kitchen-Servers DC/Windows/Kitchen-Servers

Steps to Reproduce:

Specify any folder in which you want the VMs to be put like defining the following in the driver section: folder: Kitchen-Servers then run: kitchen create and you should see the new kitchen VM get created in the correct place, but it will not be found later.

Expected Result:

I'd expect 'kitchen create' to be able to find the VM and spin it up

Actual Result:

I get an error from 'kitchen create' of:

Failed to complete #create action: [Unable to find machine: Kitchen-Servers/default-rhel-6-aed272d3] on default-rhel-6
Belogix commented 4 years ago

I have created a quick patched my own copy and will raise a PR when I have fully tested it. If this is still of interest to you it might unblock you for now: https://github.com/Belogix/kitchen-vcenter/blob/fix-folders/lib/kitchen/driver/vcenter.rb#L332-L339

This would then allow you to specify the full folder as FolderB/SubFolder1 with a setup like:

The current version would also only ever return the FolderA version so is another bug fixed by specifying the full path like this.

cattywampus commented 4 years ago

Hi @MrCyrus

I ran into the same issue and when I dug a bit deeper what I discovered is that the filter used in the VSphere API under the covers only matches specific folder names, not nested ones. In your case you'd have to specify the folder in your Kitchen configuration to be Kitchen-Servers -- however that reveals a new problem in that you have two folders with that same name which would raise an error by the driver.

clintoncwolfe commented 3 years ago

I believe this has been addressed by #108. I am able to create VMs in nested folders, even if the folders have non-unique names, so long as the folders already exist.