Revision c1f06a4f
Added by Ori Rabin about 9 years ago
app/models/lookup_value.rb | ||
---|---|---|
end
|
||
|
||
def ensure_fqdn_exists
|
||
md = match.match(/\Afqdn=(.*)/)
|
||
md = match.match(/fqdn=(.*)/)
|
||
return true unless md
|
||
return true if Host.unscoped.find_by_name(md[1]) || host_or_hostgroup.try(:new_record?)
|
||
errors.add(:match, _("%{match} does not match an existing host") % { :match => match }) and return false
|
||
fqdn = md[1].split(LookupKey::KEY_DELM)[0]
|
||
return true if Host.unscoped.find_by_name(fqdn) || host_or_hostgroup.try(:new_record?)
|
||
errors.add(:match, _("fqdn=%{match} does not match an existing host") % { :match => fqdn }) and return false
|
||
end
|
||
|
||
def ensure_hostgroup_exists
|
||
md = match.match(/\Ahostgroup=(.*)/)
|
||
md = match.match(/hostgroup=(.*)/)
|
||
return true unless md
|
||
return true if Hostgroup.unscoped.find_by_name(md[1]) || Hostgroup.unscoped.find_by_title(md[1]) || host_or_hostgroup.try(:new_record?)
|
||
errors.add(:match, _("%{match} does not match an existing host group") % { :match => match }) and return false
|
||
hostgroup = md[1].split(LookupKey::KEY_DELM)[0]
|
||
return true if Hostgroup.unscoped.find_by_name(hostgroup) || Hostgroup.unscoped.find_by_title(hostgroup) || host_or_hostgroup.try(:new_record?)
|
||
errors.add(:match, _("hostgroup=%{match} does not match an existing host group") % { :match => hostgroup }) and return false
|
||
end
|
||
end
|
test/factories/puppet_related.rb | ||
---|---|---|
end
|
||
end
|
||
|
||
factory :lookup_value
|
||
factory :lookup_value do
|
||
sequence(:value) {|n| "value#{n}" }
|
||
|
||
trait :with_use_puppet_default do
|
||
use_puppet_default true
|
||
end
|
||
end
|
||
|
||
factory :puppetclass do
|
||
sequence(:name) {|n| "class#{n}" }
|
test/unit/classification_test.rb | ||
---|---|---|
assert_equal [3,4], classification.enc['base'][key.key]
|
||
end
|
||
|
||
test 'enc should return correct values for multi-key matchers' do
|
||
hostgroup = FactoryGirl.create(:hostgroup)
|
||
host = classification.send(:host)
|
||
host.update_attributes(:hostgroup => hostgroup)
|
||
|
||
key = FactoryGirl.create(:lookup_key, :as_smart_class_param, :with_use_puppet_default,
|
||
:override => true, :key_type => 'string', :merge_overrides => false,
|
||
:path => "hostgroup,organization\nlocation",
|
||
:puppetclass => puppetclasses(:two))
|
||
|
||
parent_hostgroup = FactoryGirl.create(:hostgroup,
|
||
:puppetclasses => [puppetclasses(:two)],
|
||
:environment => environments(:production))
|
||
hostgroup.update_attributes(:parent => parent_hostgroup)
|
||
|
||
FactoryGirl.create(:lookup_value, :lookup_key_id => key.id, :match => "hostgroup=#{parent_hostgroup},organization=#{taxonomies(:organization1)}")
|
||
lv = FactoryGirl.create(:lookup_value, :lookup_key_id => key.id, :match => "hostgroup=#{hostgroup},organization=#{taxonomies(:organization1)}")
|
||
FactoryGirl.create(:lookup_value, :lookup_key_id => key.id, :match => "location=#{taxonomies(:location1)}")
|
||
|
||
enc = classification.enc
|
||
key.reload
|
||
assert_equal lv.value, enc["apache"][key.key]
|
||
end
|
||
|
||
test 'smart class parameter with erb values is validated after erb is evaluated' do
|
||
key = FactoryGirl.create(:lookup_key, :as_smart_class_param,
|
||
:override => true, :key_type => 'string', :merge_overrides => false,
|
test/unit/orchestration/dhcp_test.rb | ||
---|---|---|
end
|
||
|
||
test "when an existing host change multiple attributes, both his dhcp and bmc dhcp records should be updated" do
|
||
h = FactoryGirl.create(:host, :with_dhcp_orchestration)
|
||
h = FactoryGirl.create(:host, :with_dhcp_orchestration, :mac => "aa:aa:ad:ab:bb:cc")
|
||
as_admin do
|
||
Nic::BMC.create!(:host => h, :mac => "aa:aa:ad:ab:bb:bb", :domain => h.domain, :subnet => h.subnet,
|
||
:name => "bmc-it", :provider => 'IPMI', :ip => h.ip.succ)
|
Also available in: Unified diff
Fixes #5554 - fixed hostgroup and fqdn validations in multiple matchers
(cherry picked from commit eb414b8bbdc7897f396d184996fac402b3277cef)