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

(POOLER-40) Do not return folders with get_pool_vms #272

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vmpooler/providers/vsphere.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def vms_in_pool(pool_name)
return vms if folder_object.nil?

folder_object.childEntity.each do |vm|
vms << { 'name' => vm.name }
vms << { 'name' => vm.name } if vm.is_a? RbVmomi::VIM::VirtualMachine
end
end
vms
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/providers/vsphere_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@
expect(result).to eq(expected_vm_list)
end
end

context 'given a pool folder with a folder and vms' do
let(:expected_vm_list) {[
{ 'name' => 'vm1'},
{ 'name' => 'vm2'},
{ 'name' => 'vm3'}
]}
let(:folder_object2) { mock_RbVmomi_VIM_Folder({ :name => 'pool2'}) }
before(:each) do
expected_vm_list.each do |vm_hash|
mock_vm = mock_RbVmomi_VIM_VirtualMachine({ :name => vm_hash['name'] })
# Add the mocked VM to the folder
folder_object.childEntity << mock_vm
end
folder_object.childEntity << folder_object2
expect(subject).to receive(:find_folder).with(pool_config['folder'],connection,datacenter_name).and_return(folder_object)
end

it 'should return the vms without the folder' do
result = subject.vms_in_pool(poolname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks good, do you want it to also return VMs inside the folder 'pool2' or is it supposed to skip these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's supposed to skip those and just evaluate the objects that are VMs in the base folder object. Previously it would treat the folder as though it was a VM and try to discover and destroy it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I've seen that before. I wonder why we would have subfolders though


expect(result).to eq(expected_vm_list)
end
end
end

describe '#get_vm' do
Expand Down