Try to change to :validate => true but beware there might be dragons. I do not remember why we set this.
LZ On Thu, Oct 26, 2017 at 6:20 PM, 'Konstantin Orekhov' via Foreman users < [email protected]> wrote: > Ok. Is there anything I could do now to workaround this? The only thing > worked for me so far was to periodically go through discovered hosts and > remove duplicate entries. > > Thanks! > Konstantin. > > On Oct 26, 2017, at 07:18, Lukas Zapletal <[email protected]> wrote: > > Ok this confirms it. http://projects.theforeman.org/issues/21479 we will > fix later. > > We don't have an unique index on DB level, just in Rails level and a > second NIC with same MAC can sneak in. The relevant code in core is: > > validate :mac_uniqueness, :if => Proc.new { |nic| nic.managed? && > nic.host && nic.host.managed? && !nic.host.compute? && !nic.virtual? && > nic.mac.present? } > > which will not trigger for Discovery at all (host is not managed). In > discovery we try to search for existing host and if not found, we will > create new discovered host. This does not work correctly, we have turned > off validator for some reason: > > host.save(:validate => false) if host.new_record? > > So the validation for uniqueness won't hit. > > > On Wed, Oct 25, 2017 at 6:50 PM, 'Konstantin Orekhov' via Foreman users < > [email protected]> wrote: > >> >> >>> Please use foreman-rake (I assume this is a packaged .deb install). >>> >>> >> This is CentOS7 install and foreman-rake did work. Here's the result: >> >> [root@spc01 ~]# cd ~foreman >> [root@spc01 foreman]# foreman-rake console >> Successfully encrypted field for Setting::Auth oauth_consumer_key >> Successfully decrypted field for Setting::Auth oauth_consumer_key >> Successfully decrypted field for Setting::Auth oauth_consumer_key >> Successfully decrypted field for Setting::Auth oauth_consumer_key >> Successfully decrypted field for Setting::Auth oauth_consumer_key >> Successfully encrypted field for Setting::Auth oauth_consumer_secret >> Successfully decrypted field for Setting::Auth oauth_consumer_secret >> Successfully decrypted field for Setting::Auth oauth_consumer_secret >> Successfully decrypted field for Setting::Auth oauth_consumer_secret >> Successfully decrypted field for Setting::Auth oauth_consumer_secret >> /usr/share/foreman/lib/tasks/console.rake:6: warning: already >> initialized constant ARGV >> For some operations a user must be set, try User..current = User.first >> >> Loading production environment (Rails 4.2.5.1) >> Failed to load console gems, starting anyway >> irb(main):001:0> ::Nic::Managed.where(:mac => "b4:99:ba:aa:4b:64", >> :primary => true) >> => #<ActiveRecord::Relation [#<Nic::Managed id: 619163, mac: >> "b4:99:ba:aa:4b:64", ip: "10.8.161.191", type: "Nic::Managed", name: >> "macb499baaa4b64", host_id: 458555, subnet_id: nil, domain_id: nil, attrs: >> {"netmask"=>"255.255.255.0", "mtu"=>"1500", "network"=>"10.8.161.0", >> "speed"=>"1000", "duplex"=>"full", "port"=>"Twisted Pair", >> "auto_negotiation"=>"true", "wol"=>true}, created_at: "2017-10-20 >> 03:44:00", updated_at: "2017-10-20 03:44:02", provider: nil, username: nil, >> password: nil, virtual: false, link: true, identifier: "eth0", tag: "", >> attached_to: "", managed: true, mode: "balance-rr", attached_devices: "", >> bond_options: "", primary: true, provision: true, compute_attributes: {}, >> execution: true, ip6: nil, subnet6_id: nil>]> >> irb(main):002:0> >> >> However, just as in my previous example, DB has 2 different IDs with that >> MAC: >> >> [root@spc01 ~]# mysql -u foreman -p$DB_PASS foreman -e "SELECT * FROM >> hosts WHERE type = 'Host::Discovered' and NAME = 'macb499baaa4b64'\G;" >> *************************** 1. row *************************** >> id: 430926 >> name: macb499baaa4b64 >> last_compile: NULL >> last_report: 2017-09-30 06:56:07 >> updated_at: 2017-09-30 06:56:09 >> created_at: 2017-03-17 14:09:15 >> root_pass: NULL >> architecture_id: NULL >> operatingsystem_id: NULL >> environment_id: NULL >> ptable_id: NULL >> medium_id: NULL >> build: 0 >> comment: NULL >> disk: NULL >> installed_at: NULL >> model_id: 7 >> >> hostgroup_id: NULL >> owner_id: 10 >> owner_type: User >> enabled: 1 >> puppet_ca_proxy_id: NULL >> managed: 0 >> use_image: NULL >> image_file: NULL >> uuid: NULL >> compute_resource_id: NULL >> puppet_proxy_id: NULL >> certname: NULL >> image_id: NULL >> organization_id: NULL >> location_id: NULL >> type: Host::Discovered >> otp: NULL >> realm_id: NULL >> compute_profile_id: NULL >> provision_method: NULL >> grub_pass: >> global_status: 0 >> lookup_value_matcher: NULL >> discovery_rule_id: NULL >> salt_proxy_id: NULL >> salt_environment_id: NULL >> pxe_loader: NULL >> *************************** 2. row *************************** >> id: 458555 >> name: macb499baaa4b64 >> last_compile: NULL >> last_report: 2017-10-25 16:47:08 >> updated_at: 2017-10-25 16:47:09 >> created_at: 2017-10-20 03:44:00 >> >> root_pass: NULL >> architecture_id: NULL >> operatingsystem_id: NULL >> environment_id: NULL >> ptable_id: NULL >> medium_id: NULL >> build: 0 >> comment: NULL >> disk: NULL >> installed_at: NULL >> model_id: NULL >> hostgroup_id: NULL >> owner_id: NULL >> owner_type: NULL >> enabled: 1 >> puppet_ca_proxy_id: NULL >> managed: 0 >> use_image: NULL >> image_file: NULL >> uuid: NULL >> compute_resource_id: NULL >> puppet_proxy_id: NULL >> certname: NULL >> image_id: NULL >> organization_id: NULL >> location_id: NULL >> type: Host::Discovered >> otp: NULL >> realm_id: NULL >> compute_profile_id: NULL >> provision_method: NULL >> grub_pass: >> global_status: 0 >> lookup_value_matcher: NULL >> discovery_rule_id: NULL >> salt_proxy_id: NULL >> salt_environment_id: NULL >> pxe_loader: NULL >> [root@spc01 ~]# >> >> >> <https://lh3.googleusercontent.com/-wBk_VPoo0Fs/WfDA4guCc6I/AAAAAAAAAEs/ZIrmiIJEh64IGPxH0dz0y3aqO90F7WDdgCLcBGAs/s1600/Screen%2BShot%2B2017-10-25%2Bat%2B9.49.21%2BAM.png> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Foreman users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/foreman-users. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Later, > Lukas @lzap Zapletal > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Foreman users" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/foreman-users/xGZvRqHbWcA/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout. > -- Later, Lukas @lzap Zapletal -- You received this message because you are subscribed to the Google Groups "Foreman users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/foreman-users. For more options, visit https://groups.google.com/d/optout.
