VMware "Could not match network interface" related to issue #19623

I’ve found an edge case where the fix for Bug #19623: Changes to vmware vm gives ‘Could not find network X on VMWare compute resource’ - Foreman isn’t working. This may also relate to Bug #11106: Foreman 1.8.2 with VMware errors with: Could not find virtual machine network interface matching x.x.x.x - Foreman. The error message is a closer fit to #11106, but the root cause looks like a variation on #19623.

As far as I can tell, the issue is caused by collisions between the id/key and ref attributes of two vCenter network objects. Our environment matches the conditions in the original bug where we’re post-vCenter migration with legacy id ref’s on the distributed virtual switches. It looks like we have an object where the ref matches the id of another object’s key.

The select_nic function in FogExtensions::Vsphere::Server (app/models/concerns/fog_extensions/vsphere/server.rb) calls all_networks.detect first with the nic_attrs structure which looks like it matches against network._ref. IE:
vm_network = all_networks.detect { |network| network._ref == nic_attrs['network'] }
Only if that doesn’t match anything would the check below it which checks for network.key execute:
vm_network ||= all_networks.detect { |network| nic_attrs['network'] && [network.name, network.try(:key)].include?(nic_attrs['network']) }

In our environment, this makes a false positive match due to one object have a ref attribute that matches the desired object’s key. I’m pretty sure the check a few lines later that compares the vm_network.name and vm_network.key nil’s out selected_nic, ultimately returning nil to match_macs_to_nics in Orchestration::Compute which then fails with “Orchestration::Compute: Could not match network interface.”

In my environment, I was able to fix the issue by reversing the search by name & key and the search for nic_attrs. IE:

--- app/models/concerns/fog_extensions/vsphere/server.rb-orig	2018-06-08 11:13:50.534459137 -0400
+++ app/models/concerns/fog_extensions/vsphere/server.rb	2018-06-07 16:48:16.890547789 -0400
@@ -38,8 +38,8 @@
       def select_nic(fog_nics, nic)
         nic_attrs = nic.compute_attributes
         all_networks = service.raw_networks(datacenter)
-        vm_network = all_networks.detect { |network| network._ref == nic_attrs['network'] }
-        vm_network ||= all_networks.detect { |network| nic_attrs['network'] && [network.name, network.try(:key)].include?(nic_attrs['network']) }
+        vm_network = all_networks.detect { |network| nic_attrs['network'] && [network.name, network.try(:key)].include?(nic_attrs['network']) }
+        vm_network ||= all_networks.detect { |network| network._ref == nic_attrs['network'] }
         unless vm_network
           Rails.logger.info "Could not find Vsphere network for #{nic_attrs.inspect}"
           return

I think this should be a safe change in the other cases where #19623 applies, but I’m nowhere near familiar enough with the Foreman codebase to be certain of that.

Does this look like a reasonable change? I’ll gladly submit a PR if it looks reasonable. I’m not sure if I should re-open #19623 or open a new bug for this issue.

Best regards,
Zac Bedell

Ping @vmware team for looking into this on the vmware side.
Regarding reopening or creating a new issue - please create a new one, we use the issues to tell which release shipped certain code, so further issues with code that has been merged already should be treated as new issue. One exception is when code has been merged to develop but still hasn’t been shipped in any release, in which case you can open a new PR using “Refs #1111…” as the commit message to add another commit to the same issue.

@tbrisker I am assigning the issue to me, I will look more into it tomorrow during NA hours.

1 Like

I created an new issue for this:

http://projects.theforeman.org/issues/23909

@pendor Thanks for creating the issue I will start looking at it. sorry for the delay I have been working the other 2 issues that came in and trying to catch up from being on PTO/Conference.

It looks like this issue regressed in commit 5150a1d. That commit switched back to checking by network[:id] and network[:_ref] rather than network[:key]. The result is that the non-unique _ref attribute left over from vCenter migration is getting falsely selected in vm_network, and we get the same “could not find virtual machine network interface matching…” error as before.

I don’t know enough to understand why 5150a1d made that change. Can anyone more familiar with that code assist in finding a way that satisfies the intent of this new commit without causing bug #23909 to regress?

Well fog-vsphere isn’t assinging the key anymore, so I guess the key should be always nil.
@pendor could you share where you’re assigning the name?

There is a PR of mine, which should be selecting the network firstly by ID:

Maybe working just with the ID would solve the issue?
Only place where the name is really needed is hammer, but we can expose a API-only parameter network_name, for user to set name through and it would transfer such name to the _ref.
Would that work for you?

I don’t think I’m assigning the name anywhere that I can share? I’m trying to create a VMware backed machine in Foreman and select the desired network from the drop-down in the host’s Interfaces settings. When I click Submit to create the host, it fails as described above. The patch I submitted last year to search by network id before _ref fixes the issue and has worked for a year. That change was reverted, and the network search fails the same way it did previously. I have another patch & will PR it today.

Yeah, please do :slight_smile: I can’t see the key being present in the networks anymore. So I would like to see how you’ve fixed this now.

Ok, I can see the problem now :slight_smile:
I left a comment just if you care to clean it up a bit more, thanks for taking care of it! :+1:

I have this issue too please could I get some assistance foreman 3.7

1 Like

I have this issue too on foreman 3.7.1
fog-vsphere version: rubygem-fog-vsphere-3.6.0-1.el8.noarch
Can I update fog-vsphere version from https://yum.theforeman.org/releases/3.8/el8/x86_64/rubygem-fog-vsphere-3.6.2-1.el8.noarch.rpm ?
I search from Redhat portal may be update fog-vsphere will resolve the problem.

here is my error log:

2024-04-10T19:03:43 [W|app|25407c91] Orchestration::Compute: Could not match network interface #<Nic::Managed id: nil, mac: nil, ip: “10.150.5.50”, type: “Nic::Managed”, name: “mplv5020.abc.com”, host_id: nil, subnet_id: 7, domain_id: 1, attrs: {}, created_at: nil, updated_at: nil, provider: nil, username: nil, password: nil, virtual: false, link: true, identifier: “”, tag: “”, attached_to: “”, managed: true, mode: “balance-rr”, attached_devices: “”, bond_options: “”, primary: true, provision: true, compute_attributes: {“type”=>“VirtualVmxnet3”, “network”=>“dvportgroup-3280”}, execution: true, ip6: “”, subnet6_id: nil>
2024-04-10T19:03:43 [W|app|25407c91] Could not find virtual machine network interface matching 10.150.5.50
2024-04-10T19:03:43 [W|app|25407c91] Rolling back due to a problem: [#<Orchestration::Task:0x0000562ef20e4f30 @name=“Query instance details for mplv5020.abc.com”, @id=“Query instance details for mplv5020.abc.com”, @status=“failed”, @priority=5, @action=[#<Host::Managed id: nil, name: “mplv5020.abc.com”, last_compile: nil, last_report: nil, updated_at: nil, created_at: nil, root_pass: [FILTERED], architecture_id: 1, operatingsystem_id: 2, ptable_id: 217, medium_id: 17, build: true, comment: “”, disk: “”, installed_at: nil, model_id: nil, hostgroup_id: 8, owner_id: 5, owner_type: “User”, enabled: true, puppet_ca_proxy_id: nil, managed: true, use_image: nil, image_file: nil, uuid: “5004efc6-f703-c9ec-9605-c7fd92afc73c”, compute_resource_id: 1, puppet_proxy_id: nil, certname: nil, image_id: nil, organization_id: 1, location_id: 2, type: “Host::Managed”, otp: nil, realm_id: nil, compute_profile_id: 8, provision_method: “bootdisk”, grub_pass: nil, global_status: 0, lookup_value_matcher: [FILTERED], pxe_loader: “PXELinux BIOS”, initiated_at: nil, build_errors: nil, creator_id: nil>, :setComputeDetails], @created=1712747021.7489023, @timestamp=2024-04-10 11:03:43.822460739 UTC>]
2024-04-10T19:03:43 [I|app|25407c91] Removing Compute instance for mplv5020.abc.com
2024-04-10T19:03:44 [I|app|25407c91] Processed 2 tasks from queue ‘Host::Managed Main’, completed 0/6
2024-04-10T19:03:44 [E|app|25407c91] Task ‘Set up compute instance mplv5020.abc.comrollbacked
2024-04-10T19:03:44 [E|app|25407c91] Task ‘Query instance details for mplv5020.abc.comfailed
2024-04-10T19:03:44 [E|app|25407c91] Task ‘Generating ISO image for mplv5020.abc.comcanceled
2024-04-10T19:03:44 [E|app|25407c91] Task ‘Upload ISO image to datastore for mplv5020.abc.comcanceled
2024-04-10T19:03:44 [E|app|25407c91] Task ‘Power up compute instance mplv5020.abc.comcanceled
2024-04-10T19:03:44 [E|app|25407c91] Task ‘Attach ISO image to CDROM drive for mplv5020.abc.comcanceled
2024-04-10T19:03:44 [E|app|25407c91] Failed to save: Could not find virtual machine network interface matching 10.150.5.50