Project

General

Profile

Bug #29814

Failed to provision a VM when there are multiple datacenters with the same name in the vcenter

Added by Ondřej Ezr 3 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Compute resources - VMware
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1739340

Description of problem:
Provision a host failed with the following error.

[W|app|<id>] Caught VMware error
Fog::Compute::Vsphere::NotFound: Could not descend into . Please check your path. /Datacenters/<Folder>/<Datacenter name>/vm/
Unix
/opt/theforeman/tfm/root/usr/share/gems/gems/fog-vsphere-2.4.0/lib/fog/vsphere/requests/compute/get_folder.rb:44:in `block in get_r
aw_vmfolder'
/opt/theforeman/tfm/root/usr/share/gems/gems/fog-vsphere-2.4.0/lib/fog/vsphere/requests/compute/get_folder.rb:38:in `each'
/opt/theforeman/tfm/root/usr/share/gems/gems/fog-vsphere-2.4.0/lib/fog/vsphere/requests/compute/get_folder.rb:38:in `reduce'
/opt/theforeman/tfm/root/usr/share/gems/gems/fog-vsphere-2.4.0/lib/fog/vsphere/requests/compute/get_folder.rb:38:in `get_raw_vmfolder'

As we can see above, Satellite fetched the root path of the other datacenter with the same name and caused the regex substitution issue to return empty string.

In /opt/theforeman/tfm/root/usr/share/gems/gems/fog-vsphere-2.4.0/lib/fog/vsphere/requests/compute/get_folder.rb
----------------------------
def get_raw_vmfolder(path, datacenter_name) # The required path syntax - 'topfolder/subfolder

  1. Clean up path to be relative since we're providing datacenter name
    dc = find_raw_datacenter(datacenter_name)
    dc_root_folder = dc.vmFolder
  2. Filter the root path for this datacenter not to be used."
    dc_root_folder_path = dc_root_folder.path.map { |_id, name| name }.join('/')
    paths = path.sub(/^\/?#{Regexp.quote(dc_root_folder_path)}\/?/, '').split('/') <==== Failed here because the root path didn't match the vm path
    ----------------------------

Version-Release number of selected component (if applicable):
6.5

How reproducible:
When vcenter has same datacenter name.

Steps to Reproduce:
1. In vSphere client, create the following folder structures

region 1:
Datacenter:
vm folder 1

region 2:
Datacenter:
vm folder 2

Datacenter

2. Foreman rake console you will see paths for both datacenter

irb(main)> dc = ComputeResource.find(<compute resource id>).send(:dc)
irb(main)> pp dc.vm_folders
[ <Fog::Compute::Vsphere::Folder
id="group-v<Num>",
name="vm",
parent="Datacenter",
datacenter="Datacenter",
path="/Datacenters/Datacenter/vm",
type=:vm
>,
<Fog::Compute::Vsphere::Folder
id="group-v<Num>",
name="vm folder 1",
parent="vm",
datacenter="Datacenter",
path="/Datacenters/region 1/Datacenter/vm/vm folder 1",
type=:vm
>,
<Fog::Compute::Vsphere::Folder
id="group-v<Num>",
name="vm folder 2",
parent="vm",
datacenter="Datacenter",
path="/Datacenters/region 2/Datacenter/vm/vm folder 2",
type=:vm
>]

  1. Returned 3 datacenters with the same name
  2. then "find" method will just fetch the first match.
    irb(main)> dc.service.send(:raw_datacenters).map(&:name)
    => ["Datacenter", "Datacenter", "Datacenter"]

Also available in: Atom PDF