Revision f8d94608
Added by Amos Benari over 11 years ago
- ID f8d946082e58b60213a27ded3e1e5f5373d976de
test/unit/lookup_key_test.rb | ||
---|---|---|
class LookupKeyTest < ActiveSupport::TestCase
|
||
|
||
def test_element_seperations
|
||
key = LookupKey.create(:key => "ntp", :path => "domain,hostgroup\n domain")
|
||
key = ""
|
||
as_admin do
|
||
key = LookupKey.create!(:key => "ntp", :path => "domain,hostgroup\n domain", :puppetclass => Puppetclass.first)
|
||
end
|
||
elements = key.send(:path_elements) # hack to access private method
|
||
assert_equal "domain", elements[0][0]
|
||
assert_equal "hostgroup", elements[0][1]
|
||
... | ... | |
end
|
||
|
||
def test_path2match_single_domain_path
|
||
key = LookupKey.create(:key => "ntp", :path => "domain", :puppetclass => Puppetclass.first)
|
||
value = LookupValue.create(:value => "ntp.mydomain.net", :match => "domain = mydomain.net", :lookup_key => key)
|
||
key = ""
|
||
value = ""
|
||
as_admin do
|
||
key = LookupKey.create!(:key => "ntp", :path => "domain", :puppetclass => Puppetclass.first)
|
||
value = LookupValue.create!(:value => "ntp.mydomain.net", :match => "domain = mydomain.net", :lookup_key => key)
|
||
end
|
||
|
||
host = hosts(:one)
|
||
host.domain = domains(:mydomain)
|
||
... | ... | |
end
|
||
|
||
def test_fetching_the_correct_value_to_a_given_key
|
||
key = LookupKey.create(:key => "dns", :path => "domain\npuppetversion", :puppetclass => Puppetclass.first)
|
||
value = LookupValue.create(:value => "[1.2.3.4,2.3.4.5]", :match => "domain = mydomain.net", :lookup_key => key)
|
||
key = ""
|
||
value = ""
|
||
as_admin do
|
||
key = LookupKey.create!(:key => "dns", :path => "domain\npuppetversion", :puppetclass => puppetclasses(:one))
|
||
value = LookupValue.create!(:value => "[1.2.3.4,2.3.4.5]", :match => "domain = mydomain.net", :lookup_key => key)
|
||
end
|
||
|
||
key.reload
|
||
assert key.lookup_values_count > 0
|
||
host = hosts(:one)
|
||
host.domain = domains(:mydomain)
|
||
assert_equal value.value, key.value_for(host)
|
||
end
|
||
|
||
def test_path2match_single_hostgroup_path
|
||
key = LookupKey.create(:key => "ntp", :path => "hostgroup", :puppetclass => Puppetclass.first)
|
||
value = LookupValue.create(:value => "ntp.pool.org", :match => "hostgroup = Common", :lookup_key => key)
|
||
key = ""
|
||
value = ""
|
||
as_admin do
|
||
key = LookupKey.create!(:key => "ntp", :path => "hostgroup", :puppetclass => Puppetclass.first)
|
||
value = LookupValue.create!(:value => "ntp.pool.org", :match => "hostgroup = Common", :lookup_key => key)
|
||
end
|
||
host = hosts(:one)
|
||
host.hostgroup = hostgroups(:common)
|
||
assert_equal [value.match], key.send(:path2matches,hosts(:one))
|
||
... | ... | |
host2.hostgroup = hostgroups(:unusual)
|
||
|
||
default = "default"
|
||
key = LookupKey.create(:key => "dns", :path => "environment, hostgroup \n hostgroup", :puppetclass => Puppetclass.first, :default_value => default)
|
||
value1 = LookupValue.create(:value => "v1", :match => "environment = testing, hostgroup = Common", :lookup_key => key)
|
||
value2 = LookupValue.create(:value => "v2", :match => "hostgroup = Unusual", :lookup_key => key)
|
||
key = ""
|
||
value1 = ""
|
||
value2 = ""
|
||
as_admin do
|
||
key = LookupKey.create!(:key => "dns", :path => "environment, hostgroup \n hostgroup", :puppetclass => Puppetclass.first, :default_value => default)
|
||
value1 = LookupValue.create!(:value => "v1", :match => "environment = testing, hostgroup = Common", :lookup_key => key)
|
||
value2 = LookupValue.create!(:value => "v2", :match => "hostgroup = Unusual", :lookup_key => key)
|
||
end
|
||
|
||
assert_equal LookupValue.find(value1).value, key.value_for(host)
|
||
assert_equal LookupValue.find(value2).value, key.value_for(host2)
|
||
key.reload
|
||
|
||
assert_equal value1.value, key.value_for(host)
|
||
assert_equal value2.value, key.value_for(host2)
|
||
assert_equal default, key.value_for(hosts(:redhat))
|
||
end
|
||
|
||
def test_value_should_not_be_changed
|
||
param = lookup_keys(:three)
|
||
default = param.default_value
|
||
param.save
|
||
assert_equal default, param.default_value_before_type_cast
|
||
assert_equal default, param.default_value
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #832 - adds parameterized class support
Credits:
This patch adds the following featuresThis patch is based on the original work of Olivier Favre
<olivier@yakaz.com> many many thanks!
signature - each class can have a different set of parameters per environment.
users can add regexp or class names that the importer should ignore.
common usage case for this is classes such as ::config, ::install etc.
in order to use the new ENC format for puppet 2.6.5+ you should enable the
Parametrized_Classes_in_ENC and Enable_Smart_Variables_in_ENC within Foreman Settings
This is the initial patch just to get param classes support in, follow-up patches
would include a better UI and the relevant UI updates to host edit page etc.
Signed-off-by: Ohad Levy <ohadlevy@gmail.com>