Fixing #735 -- gen_config now uses a single heading, matching the name of the process

git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2743 980ebf18-57e1-0310-9a29-db15c13687c0
This commit is contained in:
luke 2007-08-04 00:36:47 +00:00
Родитель 97cd057177
Коммит 40e4d6fa02
4 изменённых файлов: 72 добавлений и 28 удалений

Просмотреть файл

@ -1,3 +1,7 @@
'gen_config' now generates a configuration with
all parameters under a heading that matches the
process name, rather than keeping section headings.
Refactored how the parser and interpreter relate,
so parsing is now effectively an atomic process (thus
fixing #314 and #729). This makes the interpreter less

Просмотреть файл

@ -109,11 +109,14 @@ the executable in question with the `--genconfig` command. The executable
will print a template configuration to standard output, which can be
redirected to a file like so::
$ puppetd --genconfig > /etc/puppet/puppetd.conf
$ puppetd --genconfig > /etc/puppet/puppet.conf
Note that this invocation will \"clobber\" (throw away) the contents of any
pre-existing `puppetd.conf` file, so make a backup of your present config
if it contains valuable information.
Note that this invocation will replace the contents of any pre-existing
`puppet.conf` file, so make a backup of your present config if it contains
valuable information.
All parameters will be under a single section heading matching the name of
the process used to generate the configuraiton ('puppetd', in this case).
Like the `--genconfig` argument, the executables also accept a `--genmanifest`
argument, which will generate a manifest that can be used to manage all of

Просмотреть файл

@ -541,8 +541,11 @@ Generated on #{Time.now}.
}.gsub(/^/, "# ")
# Add a section heading that matches our name.
if @config.include?(:name)
str += "[%s]\n" % self[:name]
end
eachsection do |section|
str += "[#{section}]\n"
persection(section) do |obj|
str += obj.to_config + "\n"
end

Просмотреть файл

@ -16,6 +16,23 @@ class TestConfig < Test::Unit::TestCase
@config = mkconfig
end
def set_configs(config = nil)
config ||= @config
config.setdefaults("main",
:one => ["a", "one"],
:two => ["a", "two"],
:yay => ["/default/path", "boo"],
:mkusers => [true, "uh, yeah"],
:name => ["testing", "a"]
)
config.setdefaults("section1",
:attr => ["a", "one"],
:attrdir => ["/another/dir", "two"],
:attr3 => ["$attrdir/maybe", "boo"]
)
end
def check_for_users
count = Puppet::Type.type(:user).inject(0) { |c,o|
c + 1
@ -23,10 +40,11 @@ class TestConfig < Test::Unit::TestCase
assert(count > 0, "Found no users")
end
def check_to_transportable(config)
def test_to_transportable
set_configs
trans = nil
assert_nothing_raised("Could not convert to a transportable") {
trans = config.to_transportable
trans = @config.to_transportable
}
comp = nil
@ -34,17 +52,16 @@ class TestConfig < Test::Unit::TestCase
comp = trans.to_type
}
check_for_users()
assert_nothing_raised("Could not retrieve transported config") {
comp.retrieve
}
end
def check_to_manifest(config)
def test_to_manifest
set_configs
manifest = nil
assert_nothing_raised("Could not convert to a manifest") {
manifest = config.to_manifest
manifest = @config.to_manifest
}
Puppet[:parseonly] = true
@ -61,32 +78,51 @@ class TestConfig < Test::Unit::TestCase
assert_nothing_raised("Could not instantiate objects") {
trans.to_type
}
check_for_users()
end
def check_to_comp(config)
def test_to_comp
set_configs
comp = nil
assert_nothing_raised("Could not convert to a component") {
comp = config.to_component
comp = @config.to_component
}
assert_nothing_raised("Could not retrieve component") {
comp.retrieve
}
check_for_users()
end
def check_to_config(config)
newc = config.dup
def test_to_config
set_configs
newc = mkconfig
set_configs(newc)
# Reset all of the values, so we know they're changing.
newc.each do |name, obj|
next if name == :name
newc[name] = true
end
newfile = tempfile()
File.open(newfile, "w") { |f| f.print config.to_config }
File.open(newfile, "w") { |f|
@config.to_config.split("\n").each do |line|
# Uncomment the settings, so they actually take.
if line =~ / = /
f.puts line.sub(/^\s*#/, '')
else
f.puts line
end
end
}
assert_nothing_raised("Could not parse generated configuration") {
newc.parse(newfile)
}
assert_equal(config, newc, "Configurations are not equal")
@config.each do |name, object|
assert_equal(@config[name], newc[name], "Parameter %s is not the same" % name)
end
end
def mkconfig
@ -314,14 +350,6 @@ yay = /a/path
assert_nothing_raised("Could not create transportable config") {
@config.to_transportable
}
check_to_comp(@config)
Puppet::Type.allclear
check_to_manifest(@config)
Puppet::Type.allclear
check_to_config(@config)
Puppet::Type.allclear
check_to_transportable(@config)
end
def test_parse
@ -337,6 +365,12 @@ yay = /a/path
:other => ["a", "b"],
:name => ["puppet", "b"] # our default name
)
@config.setdefaults(:other,
:one => ["whatever", "a"],
:two => ["default", "y"],
:apple => ["a", "b"],
:shoe => ["puppet", "b"] # our default name
)
@config.handlearg("--cliparam", "changed")
@config.expects(:parse_file).returns(result).times(2)