summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-08-04 00:36:47 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-08-04 00:36:47 +0000
commit40e4d6fa02e801a26c2880840befa32718e55452 (patch)
tree893496547abebfd805e4b28e4ba13f443c66e897
parent97cd057177f18a0e6694aab0e440f86e0bf08d42 (diff)
downloadpuppet-40e4d6fa02e801a26c2880840befa32718e55452.tar.gz
puppet-40e4d6fa02e801a26c2880840befa32718e55452.tar.xz
puppet-40e4d6fa02e801a26c2880840befa32718e55452.zip
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
-rw-r--r--CHANGELOG4
-rw-r--r--lib/puppet/reference/configuration.rb11
-rw-r--r--lib/puppet/util/config.rb5
-rwxr-xr-xtest/util/config.rb80
4 files changed, 72 insertions, 28 deletions
diff --git a/CHANGELOG b/CHANGELOG
index d20ef06f8..a405f951d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/lib/puppet/reference/configuration.rb b/lib/puppet/reference/configuration.rb
index b83992290..65fdbeb7d 100644
--- a/lib/puppet/reference/configuration.rb
+++ b/lib/puppet/reference/configuration.rb
@@ -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
diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb
index ded78f9c4..6d42f0ea6 100644
--- a/lib/puppet/util/config.rb
+++ b/lib/puppet/util/config.rb
@@ -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
diff --git a/test/util/config.rb b/test/util/config.rb
index 8e7215e8e..71343556f 100755
--- a/test/util/config.rb
+++ b/test/util/config.rb
@@ -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)