summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-04 17:29:16 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-04 17:29:16 +0000
commit5d42cd51a3502518a5d0a22928a133768dcaeb1a (patch)
tree599b4ae12a957e141fc114364e5e342102045c9a
parentc8be52b7a9d95c1efcdb8df4ee88ae3f65c6f2df (diff)
downloadpuppet-5d42cd51a3502518a5d0a22928a133768dcaeb1a.tar.gz
puppet-5d42cd51a3502518a5d0a22928a133768dcaeb1a.tar.xz
puppet-5d42cd51a3502518a5d0a22928a133768dcaeb1a.zip
Fixing the class file to actually store class names, not object ids. Also added tests to make sure it all stays that way.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1063 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/config.rb8
-rw-r--r--lib/puppet/parser/ast/hostclass.rb2
-rw-r--r--lib/puppet/parser/interpreter.rb2
-rw-r--r--lib/puppet/parser/scope.rb12
-rw-r--r--lib/puppet/util.rb7
-rw-r--r--test/client/client.rb32
-rwxr-xr-xtest/language/ast.rb8
7 files changed, 61 insertions, 10 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 303c45ed9..5519138fd 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -545,7 +545,13 @@ Generated on #{Time.now}.
raise ArgumentError, "Default %s is not a file" % default
end
- Puppet::Util.asuser(obj.owner, obj.group) do
+ chown = nil
+ if Process.uid == 0
+ chown = [obj.owner, obj.group]
+ else
+ chown = [nil, nil]
+ end
+ Puppet::Util.asuser(*chown) do
mode = obj.mode || 0640
if args.empty?
diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb
index 3952cd4dc..503802b93 100644
--- a/lib/puppet/parser/ast/hostclass.rb
+++ b/lib/puppet/parser/ast/hostclass.rb
@@ -48,7 +48,7 @@ class Puppet::Parser::AST
# Set the mark after we evaluate, so we don't record it but
# then encounter an error
- scope.setclass(self.object_id)
+ scope.setclass(self.object_id, @type)
return retval
end
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index c432e39a8..4f5f1f69a 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -77,8 +77,6 @@ module Puppet
# Create our parser object
parsefiles
-
- evaluate
end
# Connect to the LDAP Server
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 76fb1703e..6e945adb4 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -214,7 +214,7 @@ module Puppet
unless defined? @classtable
raise Puppet::DevError, "Scope did not receive class table"
end
- return @classtable.keys
+ return @classtable.values
end
# Yield each child scope in turn
@@ -590,11 +590,11 @@ module Puppet
# Look up a given class. This enables us to make sure classes are
# singletons
- def lookupclass(klass)
+ def lookupclass(klassid)
unless defined? @classtable
raise Puppet::DevError, "Scope did not receive class table"
end
- return @classtable[klass]
+ return @classtable[klassid]
end
# Collect all of the defaults set at any higher scopes.
@@ -730,11 +730,11 @@ module Puppet
# that gets inherited from the nodescope down, rather than a global
# hash. We store the object ID, not class name, so that we
# can support multiple unrelated classes with the same name.
- def setclass(id)
+ def setclass(id, name)
if self.nodescope? or self.topscope?
- @classtable[id] = true
+ @classtable[id] = name
else
- @parent.setclass(id)
+ @parent.setclass(id, name)
end
end
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 1d4515b3d..e842ffd3f 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -16,6 +16,13 @@ module Util
olduid = nil
oldgid = nil
+ # If they're running as a normal user, then just execute as that same
+ # user.
+ unless Process.uid == 0
+ yield
+ return
+ end
+
begin
# the groupid, if we got passed a group
# The gid has to be changed first, because, well, otherwise we won't
diff --git a/test/client/client.rb b/test/client/client.rb
index fe116bf56..c96feb943 100644
--- a/test/client/client.rb
+++ b/test/client/client.rb
@@ -138,4 +138,36 @@ class TestClient < Test::Unit::TestCase
certbucket.backup("/etc/passwd")
}
end
+
+ def test_classfile
+ manifest = tempfile()
+
+ File.open(manifest, "w") do |file|
+ file.puts "class yaytest {}\n class bootest {}\n include yaytest, bootest"
+ end
+
+ master = client = nil
+ assert_nothing_raised() {
+ master = Puppet::Server::Master.new(
+ :File => manifest,
+ :UseNodes => false,
+ :Local => true
+ )
+ }
+ assert_nothing_raised() {
+ client = Puppet::Client::MasterClient.new(
+ :Master => master
+ )
+ }
+
+ assert_nothing_raised {
+ client.getconfig
+ }
+
+ assert(FileTest.exists?(Puppet[:classfile]), "Class file does not exist")
+
+ classes = File.read(Puppet[:classfile]).split("\n")
+
+ assert_equal(%w{bootest yaytest}, classes.sort)
+ end
end
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 441c7d892..a159f6eba 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -29,6 +29,7 @@ class TestAST < Test::Unit::TestCase
# Create child class two
children << classobj("child2", :parentclass => nameobj("parent"))
+ classes = %w{parent child1 child2}
# Now call the two classes
assert_nothing_raised("Could not add AST nodes for calling") {
@@ -60,6 +61,8 @@ class TestAST < Test::Unit::TestCase
assert_equal(1, scope.find_all { |child|
child.lookupobject(:name => "/parent", :type => "file")
}.length, "Found incorrect number of '/parent' objects")
+
+ assert_equal(classes.sort, scope.classlist.sort)
end
# Test that 'setobject' collects all of an object's parameters and stores
@@ -319,10 +322,12 @@ class TestAST < Test::Unit::TestCase
# Test that we can 'include' variables, not just normal strings.
def test_includevars
children = []
+ classes = []
# Create our class for testin
klassname = "include"
children << classobj(klassname)
+ classes << klassname
# Then add our variable assignment
children << varobj("klassvar", klassname)
@@ -345,6 +350,9 @@ class TestAST < Test::Unit::TestCase
top.evaluate(:scope => scope)
}
+ # Verify we get the right classlist back
+ assert_equal(classes.sort, scope.classlist.sort)
+
# Verify we can find the node via a search list
objects = nil
assert_nothing_raised("Could not retrieve objects") {