summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-08-30 01:33:36 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-08-30 01:33:36 +0000
commitcff3a5b6cf3867287e1d1d76100f5f7744faa383 (patch)
tree6d7db4e78b14077cd464c0e5f3ee0d23f9426db0
parent998b4155dfc7a783b6dba5beafa272b579e98381 (diff)
downloadpuppet-cff3a5b6cf3867287e1d1d76100f5f7744faa383.tar.gz
puppet-cff3a5b6cf3867287e1d1d76100f5f7744faa383.tar.xz
puppet-cff3a5b6cf3867287e1d1d76100f5f7744faa383.zip
fileserver config file now reloads when it is more than 60 seconds out of date
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@610 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-xlib/puppet/server/fileserver.rb19
-rwxr-xr-xtest/server/tc_fileserver.rb64
2 files changed, 83 insertions, 0 deletions
diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb
index aa513d68c..f7a15e6b9 100755
--- a/lib/puppet/server/fileserver.rb
+++ b/lib/puppet/server/fileserver.rb
@@ -42,6 +42,7 @@ class Server
end
def describe(file, client = nil, clientip = nil)
+ readconfig
mount, path = splitpath(file)
unless @mounts[mount].allowed?(client, clientip)
@@ -97,7 +98,9 @@ class Server
@noreadconfig = false
end
+ @configtimeout = hash[:ConfigTimeout] || 60
@configstamp = nil
+ @congigstatted = nil
if hash.include?(:Mount)
@passedconfig = true
@@ -118,6 +121,7 @@ class Server
end
def list(dir, recurse = false, client = nil, clientip = nil)
+ readconfig
mount, path = splitpath(dir)
unless @mounts[mount].allowed?(client, clientip)
@@ -177,6 +181,17 @@ class Server
def readconfig
return if @noreadconfig
+ if @configstamp and FileTest.exists?(@config)
+ if @configtimeout and @configstatted and
+ (Time.now - @configstatted > @configtimeout)
+ tmp = File.stat(@config).ctime
+
+ if tmp == @configstamp
+ return
+ end
+ end
+ end
+
@mounts.clear
begin
@@ -245,9 +260,13 @@ class Server
rescue Errno::ENOENT => detail
raise Puppet::Error, "%s does not exit" % @config
end
+
+ @configstamp = File.stat(@config).ctime
+ @configstatted = Time.now
end
def retrieve(file, client = nil, clientip = nil)
+ readconfig
mount, path = splitpath(file)
unless (@mounts.include?(mount))
diff --git a/test/server/tc_fileserver.rb b/test/server/tc_fileserver.rb
index 29895a38e..7c0ad9570 100755
--- a/test/server/tc_fileserver.rb
+++ b/test/server/tc_fileserver.rb
@@ -531,6 +531,70 @@ class TestFileServer < TestPuppet
}
end
+
+ def test_filereread
+ server = nil
+ testdir = "/tmp/filerereadtesting"
+
+ @@tmpfiles << testdir
+
+ #Dir.mkdir(testdir)
+ files = mktestfiles(testdir)
+
+ conffile = "/tmp/fileservertestingfile"
+ @@tmpfiles << conffile
+
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
+
+[thing]
+ path #{testdir}
+ allow test1.domain.com
+"
+ }
+
+
+ assert_nothing_raised {
+ server = Puppet::Server::FileServer.new(
+ :Local => true,
+ :ConfigTimeout => 0.5,
+ :Config => conffile
+ )
+ }
+
+ list = nil
+ assert_nothing_raised {
+ list = server.list("/thing/", false, "test1.domain.com", "127.0.0.1")
+ }
+ assert(list != "", "List returned nothing in rereard test")
+
+ assert_raise(Puppet::Server::AuthorizationError, "List allowed invalid host") {
+ list = server.list("/thing/", false, "test2.domain.com", "127.0.0.1")
+ }
+
+ sleep 1
+ File.open(conffile, "w") { |f|
+ f.print "# a test config file
+
+[thing]
+ path #{testdir}
+ allow test2.domain.com
+"
+ }
+
+ assert_raise(Puppet::Server::AuthorizationError, "List allowed invalid host") {
+ list = server.list("/thing/", false, "test1.domain.com", "127.0.0.1")
+ }
+
+ assert_nothing_raised {
+ list = server.list("/thing/", false, "test2.domain.com", "127.0.0.1")
+ }
+
+ assert(list != "", "List returned nothing in rereard test")
+
+ list = nil
+ end
+
end
# $Id$