Foreman 版本 1.6.3
当我尝试编辑我的一个主机(更改主机组)时,出现以下错误:
ActiveRecord::RecordInvalid
Validation failed: Match has already been taken
app/models/concerns/host_common.rb:48:in `block in lookup_values_attributes='
app/models/concerns/host_common.rb:41:in `each_value'
app/models/concerns/host_common.rb:41:in `lookup_values_attributes='
app/controllers/hosts_controller.rb:113:in `block in update'
app/models/taxonomy.rb:52:in `block in no_taxonomy_scope'
app/models/taxonomy.rb:59:in `block (2 levels) in as_taxonomy'
app/models/concerns/foreman/thread_session.rb:148:in `as_location'
app/models/taxonomy.rb:58:in `block in as_taxonomy'
app/models/concerns/foreman/thread_session.rb:113:in `as_org'
app/models/taxonomy.rb:57:in `as_taxonomy'
app/models/taxonomy.rb:51:in `no_taxonomy_scope'
app/controllers/hosts_controller.rb:105:in `update'
app/models/concerns/foreman/thread_session.rb:33:in `clear_thread'
lib/middleware/catch_json_parse_errors.rb:9:in `call'
生产日志:
Started PUT "/hosts/puppet-app01" for 10.10.10.24 at 2015-03-05 11:51:32 +0100
Processing by HostsController#update as */*
Parameters: {"utf8"=>"✓", "authenticity_token"=>"/IYvSEW5JWu2dasdadL1Z/6fpjeMLojOFc0I+BIfY=", "host"=>{"name"=>"puppet-app01", "hostgroup_id"=>"", "environment_id"=>"7", "puppet_ca_proxy_id"=>"1", "puppet_proxy_id"=>"2", "config_group_ids"=>[""], "puppetclass_ids"=>["", "339", "293", "348", "349"], "managed"=>"f", "progress_report_id"=>"[FILTERED]", "lookup_values_attributes"=>"[FILTERED]", "is_owned_by"=>"5-Users", "enabled"=>"1", "comment"=>"", "overwrite"=>"false"}, "id"=>"puppet-app01"}
Operation FAILED: Validation failed: Match has already been taken
Rendered common/500.html.erb (3.7ms)
Completed 500 Internal Server Error in 25ms (Views: 4.3ms | ActiveRecord: 3.5ms)
每次我尝试编辑此主机上的任何参数时,都会出现相同的错误。在我分配一个类并将其从此主机中删除后,这种情况开始发生。
这是我的生产环境,必须尽快修复。
有任何想法吗?
答案1
现在我非常确定我的问题一点也不愚蠢,jmp242 的评论只不过是一个愚蠢的变通建议。没有冒犯的意思!:P 无论如何,这是我自己的错,然而是由 Foreman Web 界面的奇怪行为引起的。
我在一个类中为 2 个主机设置了 3 个参数上的 2 个匹配器。我为两个主机设置了第一个匹配器,然后为第二个和第三个匹配器。当我返回第一个参数只是为了在提交更改之前查看一切是否正常时,我发现它只为一个主机设置,而不是为两个主机设置。那么,我做了什么?我又设置了一次 :)
那是“我的”错误!我通过在调试模式下比较两台主机(坏的和好的)上的相同请求来调试此案例。我发现在坏的主机上“验证”事务开始并且正在回滚。我手动运行每个执行的选择查询,发现这个查询返回 1 行而不是 0 行:
SELECT 1 AS one FROM "lookup_values" WHERE ("lookup_values"."match" = 'fqdn=puppet-app01' AND "lookup_values"."id" != 39 AND "lookup_values"."lookup_key_id" = 1153) LIMIT 1;
我检查了什么是什么,然后发现类参数存在冲突。无论如何,当我转到 Puppet 类 - MyClass - 智能类参数 - MyParam 时,我看到一个匹配器!然后我单击另一个参数并返回到第一个参数 - 我同时看到了两个 :) 很奇怪,不是吗!? :)