Bug 1565093

Summary: Do not prevent host discovery for existing MAC/IP addresses
Product: Red Hat Satellite Reporter: Lukas Zapletal <lzap>
Component: Discovery PluginAssignee: Lukas Zapletal <lzap>
Status: CLOSED ERRATA QA Contact: Lukáš Hellebrandt <lhellebr>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.3.1CC: gkonda, gsigrisi, janarula, lhellebr, lzap, mlele, mmccune, rabajaj, rajgupta
Target Milestone: 6.4.0Keywords: Regression, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/23174
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1624034 (view as bug list) Environment:
Last Closed: 2018-10-16 19:16:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Lukas Zapletal 2018-04-09 11:22:18 UTC
We prevented discovering a host with existing MAC managed address in #16890 because Foreman was supposed to prevent creation of NICs with same MAC addresses. It turns out this validation does not work (#23173) and the discovery prevention patch created an unnecessary regression to existing users.

In this patch, we will revert back the old behavior, the new preventing will be only available as discovery opt-in setting.

Links:
http://projects.theforeman.org/issues/23173
http://projects.theforeman.org/issues/16890

Comment 1 Lukas Zapletal 2018-04-09 11:24:18 UTC
WORKAROUND for Satellite 6.3:

Locate file /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-*/app/models/host/discovered.rb and delete this line:

raise ::Foreman::Exception.new("Host already exists as managed: %s", "#{host.name}/#{bootif_mac}") if host.type != "Host::Discovered"

Then restart httpd service to revert back to old behavior.

There is a GNU diff:

diff --git a/app/models/host/discovered.rb b/app/models/host/discovered.rb
index 4201876..c495b3b 100644
--- a/app/models/host/discovered.rb
+++ b/app/models/host/discovered.rb
@@ -65,7 +65,6 @@ class Host::Discovered < ::Host::Base
       Rails.logger.warn "Multiple discovered hosts found with MAC address #{name_fact}, choosing one" if hosts.size > 1
       host = hosts.first.host
     end
-    raise ::Foreman::Exception.new("Host already exists as managed: %s", "#{host.name}/#{bootif_mac}") if host.type != "Host::Discovered"
 
     # and save (interfaces are created via puppet parser extension)
     host.save(:validate => false) if host.new_record?

Comment 6 Lukas Zapletal 2018-04-11 13:48:31 UTC
Please revert the patch, it won't work. Sorry, I had to investigate this and test on both 6.2 and 6.3 to finally come up with a working patch. I am just creating upstream PR open for review and will ask folks to take a look shortly. It's up here: https://github.com/theforeman/foreman_discovery/pull/422

Comment 7 Satellite Program 2018-04-13 10:28:21 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/23174 has been resolved.

Comment 8 Lukas Zapletal 2018-04-13 11:52:42 UTC
Not clean cherry pick, resolved conflicts:

https://gitlab.sat.lab.tlv.redhat.com/satellite6/foreman_discovery/merge_requests/31

Comment 9 Lukas Zapletal 2018-04-13 12:50:36 UTC
*** Bug 1564674 has been marked as a duplicate of this bug. ***

Comment 11 Lukas Zapletal 2018-04-17 08:52:59 UTC
HOTFIX AVAILABLE for Satellite 6.3.0-6.3.2:

http://file.rdu.redhat.com/~cduryee/tfm-rubygem-foreman_discovery-9.1.5.3-2.HOTFIXRHBZ1565093.fm1_15.el7sat.noarch.rpm

Upgrade the RPM and restart httpd service.

This hotfix reverts to old behavior and also adds new option "discovery_error_on_existing" to Administer - Settings for users who want to opt-in the new behavior (early error during discovery).

Comment 14 Lukáš Hellebrandt 2018-08-27 14:33:50 UTC
Verified with Sat 6.4 snap 18 with RHEV VMs.

1) Setup Capsule for provisioning, discovery, setup a (RHEV) CR, setup network...
2) In RHEV, create a machine with MAC=X, do PXEless Foreman discovery
3) In Hosts -> Discovered Hosts, Provision the discovered machine
4) In Administer -> Settings, set discovery_error_on_existing to True
5) In RHEV, delete the original machine and create another machine with MAC=X, do PXEless Foreman discovery -> get error 422 saying the machine is managed already
6) Set discovery_error_on_existing to False
7) Do PXEless Foreman discovery again, now successfully -> the machine gets added to Hosts -> Discovered Hosts

Comment 16 Bryan Kearney 2018-10-16 19:16:40 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927