diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-07-21 21:16:09 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-07-21 21:16:09 +0000 |
| commit | 9e61510ac96cc53b2fbc58efa969499eb0c0c11f (patch) | |
| tree | f72e42e9d6cbdf4b45095087d927c5e8c4fa6fea /test | |
| parent | 310b3a11eec563c4687041f9ae1a0b894571bc05 (diff) | |
Fixing #77. As I feared, this was a pretty complicated fix; I had to add a lot of infrastructure to both ParsedFile and Config. All config files now have a timer created for them, and by default they check for file changes every 15 seconds. If there is a change, they get rid of values set by the file (but not set on the cli) and set the new values, then the re-use all of the sections, so that any changed directories or whatever get recreated.
This is still not a 100% solution, since things like open files could still be messed with, but I think this is about as close as we are going to get.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1420 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/other/config.rb | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/test/other/config.rb b/test/other/config.rb index 2b3c985a4..33dad6892 100755 --- a/test/other/config.rb +++ b/test/other/config.rb @@ -695,7 +695,117 @@ inttest = 27 end end + # Make sure we correctly reparse our config files but don't lose CLI values. def test_reparse + Puppet[:filetimeout] = 0 + + config = mkconfig() + config.setdefaults(:mysection, :default => ["default", "yay"]) + config.setdefaults(:mysection, :clichange => ["clichange", "yay"]) + config.setdefaults(:mysection, :filechange => ["filechange", "yay"]) + + file = tempfile() + # Set one parameter in the file + File.open(file, "w") { |f| + f.puts %{[mysection]\nfilechange = filevalue} + } + assert_nothing_raised { + config.parse(file) + } + + # Set another "from the cli" + assert_nothing_raised { + config.handlearg("clichange", "clivalue") + } + + # And leave the other unset + assert_equal("default", config[:default]) + assert_equal("filevalue", config[:filechange]) + assert_equal("clivalue", config[:clichange]) + + # Now rewrite the file + File.open(file, "w") { |f| + f.puts %{[mysection]\nfilechange = newvalue} + } + + cfile = config.file + cfile.send("tstamp=".intern, Time.now - 50) + + # And check all of the values + assert_equal("default", config[:default]) + assert_equal("clivalue", config[:clichange]) + assert_equal("newvalue", config[:filechange]) + end + + def test_parse_removes_quotes + config = mkconfig() + config.setdefaults(:mysection, :singleq => ["single", "yay"]) + config.setdefaults(:mysection, :doubleq => ["double", "yay"]) + config.setdefaults(:mysection, :none => ["noquote", "yay"]) + config.setdefaults(:mysection, :middle => ["midquote", "yay"]) + + file = tempfile() + # Set one parameter in the file + File.open(file, "w") { |f| + f.puts %{[mysection]\n + singleq = 'one' + doubleq = "one" + none = one + middle = mid"quote +} + } + + assert_nothing_raised { + config.parse(file) + } + + %w{singleq doubleq none}.each do |p| + assert_equal("one", config[p], "%s did not match" % p) + end + assert_equal('mid"quote', config["middle"], "middle did not match") + end + + def test_timer + Puppet[:filetimeout] = 0.1 + origpath = tempfile() + config = mkconfig() + config.setdefaults(:mysection, :paramdir => [tempfile(), "yay"]) + + file = tempfile() + # Set one parameter in the file + File.open(file, "w") { |f| + f.puts %{[mysection]\n + paramdir = #{origpath} +} + } + + assert_nothing_raised { + config.parse(file) + config.use(:mysection) + } + + assert(FileTest.directory?(origpath), "dir did not get created") + + # Now start the timer + assert_nothing_raised { + EventLoop.current.monitor_timer config.timer + } + + newpath = tempfile() + + File.open(file, "w") { |f| + f.puts %{[mysection]\n + paramdir = #{newpath} +} + } + config.file.send("tstamp=".intern, Time.now - 50) + sleep 1 + + assert_equal(newpath, config["paramdir"], + "File did not get reparsed from timer") + assert(FileTest.directory?(newpath), "new dir did not get created") + + end end |
