diff options
| author | Luke Kanies <luke@madstop.com> | 2008-07-08 15:03:13 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-07-08 15:03:13 -0500 |
| commit | c1dc92b9a14c04096e0bed0f2c4acc4dfe1ed7d2 (patch) | |
| tree | b3269b4e76edbcb3458fcdf1832421fb11e57890 | |
| parent | b0febd263c0cb8e61d512898f7c79868ea77e619 (diff) | |
| parent | edf99c508dabb58342eeff251ad5701d2755426d (diff) | |
| download | puppet-c1dc92b9a14c04096e0bed0f2c4acc4dfe1ed7d2.tar.gz puppet-c1dc92b9a14c04096e0bed0f2c4acc4dfe1ed7d2.tar.xz puppet-c1dc92b9a14c04096e0bed0f2c4acc4dfe1ed7d2.zip | |
Merge branch '0.24.x'
Conflicts:
CHANGELOG
| -rw-r--r-- | CHANGELOG | 16 | ||||
| -rw-r--r-- | Rakefile | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/function.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/functions.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/provider/group/ldap.rb | 9 | ||||
| -rwxr-xr-x | lib/puppet/provider/package/gem.rb | 45 | ||||
| -rw-r--r-- | lib/puppet/provider/user/ldap.rb | 16 | ||||
| -rwxr-xr-x | spec/integration/node.rb | 7 | ||||
| -rwxr-xr-x | spec/integration/node/catalog.rb | 6 | ||||
| -rwxr-xr-x | spec/integration/node/facts.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/provider/group/ldap.rb | 25 | ||||
| -rw-r--r-- | spec/unit/provider/package/gem.rb | 87 | ||||
| -rwxr-xr-x | spec/unit/provider/user/ldap.rb | 11 |
13 files changed, 216 insertions, 24 deletions
@@ -7,7 +7,21 @@ whether we should even use a CRL. This way we aren't trying to set file paths to 'false' to disable the CRL. -0.24.? +0.24.5 + Added message referencing ReductveLabs build library + + Fixed #1396 - Added sha1 function from DavidS to core + + Fixed #1399 - the ldap user provider now knows it can manage + passwords. + + Fixed #1272 - if you provide a group name as the gid to an ldap + user, the name will be converted to a gid. Note that this only + looks up ldap groups, at this point; if you want to set an ldap + user's primary group to a local group, you have to specify the GID. + + Fixed #1226 - gems can now specify source repositories. + Fixed #1232 - the rundir no longer specifies a user/group, and there are now client- and server-specific yaml directories. @@ -5,7 +5,7 @@ $: << File.expand_path(File.join(File.dirname(__FILE__), 'lib')) begin require 'rake/reductive' rescue LoadError - $stderr.puts "You must have the Reductive build library in your RUBYLIB." + $stderr.puts "You must have the Reductive build library in your RUBYLIB; see http://github.com/lak/reductive-build/tree/master." exit(14) end diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb index 63d7c7abf..eb36fa906 100644 --- a/lib/puppet/parser/ast/function.rb +++ b/lib/puppet/parser/ast/function.rb @@ -42,7 +42,7 @@ class Puppet::Parser::AST raise Puppet::DevError, "Invalid function type %s" % @ftype.inspect end - # Lastly, check the arity + # Lastly, check the parity end end end diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 8decb8227..51903e919 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -317,6 +317,14 @@ module Functions end output end + + newfunction(:sha1, :type => :rvalue, + :doc => "Returns a SHA1 hash value from a provided string.") do |args| + require 'sha1' + + Digest::SHA1.hexdigest(args[0]) + end + end end diff --git a/lib/puppet/provider/group/ldap.rb b/lib/puppet/provider/group/ldap.rb index a4870fc68..37a7e7343 100644 --- a/lib/puppet/provider/group/ldap.rb +++ b/lib/puppet/provider/group/ldap.rb @@ -36,4 +36,13 @@ Puppet::Type.type(:group).provide :ldap, :parent => Puppet::Provider::Ldap do largest + 1 end + # Convert a group name to an id. + def self.name2id(group) + return nil unless result = manager.search("cn=%s" % group) and result.length > 0 + + # Only use the first result. + group = result[0] + gid = group[:gid][0] + return gid + end end diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb index bb09bc5b0..133243c86 100755 --- a/lib/puppet/provider/package/gem.rb +++ b/lib/puppet/provider/package/gem.rb @@ -1,9 +1,12 @@ require 'puppet/provider/package' +require 'uri' # Ruby gems support. Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package do - desc "Ruby Gem support. By default uses remote gems, but you can specify - the path to a local gem via ``source``." + desc "Ruby Gem support. If a URL is passed via ``source``, then that URL is used as the + remote gem repository; if a source is present but is not a valid URL, it will be + interpreted as the path to a local gem file. If source is not present at all, + the gem will be installed from the default gem repositories." has_feature :versionable @@ -65,20 +68,38 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d end def install(useversion = true) - command = ["install"] - if (! @resource.should(:ensure).is_a? Symbol) and useversion - command << "-v" << @resource.should(:ensure) + command = [command(:gemcmd), "install"] + if (! resource[:ensure].is_a? Symbol) and useversion + command << "-v" << resource[:ensure] end # Always include dependencies command << "--include-dependencies" - if source = @resource[:source] - command << source + if source = resource[:source] + begin + uri = URI.parse(source) + rescue => detail + fail "Invalid source '%s': %s" % [uri, detail] + end + + case uri.scheme + when nil: + # no URI scheme => interpret the source as a local file + command << source + when /file/i + command << uri.path + when 'puppet' + # we don't support puppet:// URLs (yet) + raise Puppet::Error.new("puppet:// URLs are not supported as gem sources") + else + # interpret it as a gem repository + command << "--source" << "#{source}" << resource[:name] + end else - command << @resource[:name] + command << resource[:name] end - output = gemcmd(*command) + output = execute(command) # Apparently some stupid gem versions don't exit non-0 on failure if output.include?("ERROR") self.fail "Could not install: %s" % output.chomp @@ -87,17 +108,17 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d def latest # This always gets the latest version available. - hash = self.class.gemlist(:justme => @resource[:name]) + hash = self.class.gemlist(:justme => resource[:name]) return hash[:ensure] end def query - self.class.gemlist(:justme => @resource[:name], :local => true) + self.class.gemlist(:justme => resource[:name], :local => true) end def uninstall - gemcmd "uninstall", "-x", "-a", @resource[:name] + gemcmd "uninstall", "-x", "-a", resource[:name] end def update diff --git a/lib/puppet/provider/user/ldap.rb b/lib/puppet/provider/user/ldap.rb index 0d149ac9a..2e200a88e 100644 --- a/lib/puppet/provider/user/ldap.rb +++ b/lib/puppet/provider/user/ldap.rb @@ -14,6 +14,8 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do confine :feature => :ldap, :false => (Puppet[:ldapuser] == "") + has_feature :manages_passwords + manages(:posixAccount, :person).at("ou=People").named_by(:uid).and.maps :name => :uid, :password => :userPassword, :comment => :cn, @@ -45,6 +47,15 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do largest + 1 end + # Convert our gid to a group name, if necessary. + def gid=(value) + unless [Fixnum, Bignum].include?(value.class) + value = group2id(value) + end + + @property_hash[:gid] = value + end + # Find all groups this user is a member of in ldap. def groups # We want to cache the current result, so we know if we @@ -101,6 +112,11 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do end end + # Convert a gropu name to an id. + def group2id(group) + Puppet::Type.type(:group).provider(:ldap).name2id(group) + end + private def group_manager diff --git a/spec/integration/node.rb b/spec/integration/node.rb index b0375e743..de95d0e79 100755 --- a/spec/integration/node.rb +++ b/spec/integration/node.rb @@ -31,10 +31,11 @@ describe Puppet::Node do Puppet::Node.indirection.stubs(:terminus_class).returns :yaml # Load now, before we stub the exists? method. - Puppet::Node.indirection.terminus(:yaml) + terminus = Puppet::Node.indirection.terminus(:yaml) - file = File.join(Puppet[:yamldir], "node", "me.yaml") - FileTest.expects(:exist?).with(file).returns false + terminus.expects(:path).with(@name).returns "/my/yaml/file" + + FileTest.expects(:exist?).with("/my/yaml/file").returns false Puppet::Node.find(@name).should be_nil end diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb index 285b85869..87d62ea6a 100755 --- a/spec/integration/node/catalog.rb +++ b/spec/integration/node/catalog.rb @@ -19,10 +19,10 @@ describe Puppet::Node::Catalog do Puppet::Node::Catalog.indirection.stubs(:terminus_class).returns :yaml # Load now, before we stub the exists? method. - Puppet::Node::Catalog.indirection.terminus(:yaml) + terminus = Puppet::Node::Catalog.indirection.terminus(:yaml) + terminus.expects(:path).with("me").returns "/my/yaml/file" - file = File.join(Puppet[:yamldir], "catalog", "me.yaml") - FileTest.expects(:exist?).with(file).returns false + FileTest.expects(:exist?).with("/my/yaml/file").returns false Puppet::Node::Catalog.find("me").should be_nil end diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb index cef3d79d4..5a54a6e49 100755 --- a/spec/integration/node/facts.rb +++ b/spec/integration/node/facts.rb @@ -26,10 +26,10 @@ describe Puppet::Node::Facts do Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml # Load now, before we stub the exists? method. - Puppet::Node::Facts.indirection.terminus(:yaml) + terminus = Puppet::Node::Facts.indirection.terminus(:yaml) - file = File.join(Puppet[:yamldir], "facts", "me.yaml") - FileTest.expects(:exist?).with(file).returns false + terminus.expects(:path).with("me").returns "/my/yaml/file" + FileTest.expects(:exist?).with("/my/yaml/file").returns false Puppet::Node::Facts.find("me").should be_nil end diff --git a/spec/unit/provider/group/ldap.rb b/spec/unit/provider/group/ldap.rb index 53d9e8bfc..ab2bd72aa 100755 --- a/spec/unit/provider/group/ldap.rb +++ b/spec/unit/provider/group/ldap.rb @@ -77,4 +77,29 @@ describe provider_class do end end end + + it "should have a method for converting group names to GIDs" do + provider_class.should respond_to(:name2id) + end + + describe "when converting from a group name to GID" do + it "should use the ldap manager to look up the GID" do + provider_class.manager.expects(:search).with("cn=foo") + provider_class.name2id("foo") + end + + it "should return nil if no group is found" do + provider_class.manager.expects(:search).with("cn=foo").returns nil + provider_class.name2id("foo").should be_nil + provider_class.manager.expects(:search).with("cn=bar").returns [] + provider_class.name2id("bar").should be_nil + end + + # We shouldn't ever actually have more than one gid, but it doesn't hurt + # to test for the possibility. + it "should return the first gid from the first returned group" do + provider_class.manager.expects(:search).with("cn=foo").returns [{:name => "foo", :gid => [10, 11]}, {:name => :bar, :gid => [20, 21]}] + provider_class.name2id("foo").should == 10 + end + end end diff --git a/spec/unit/provider/package/gem.rb b/spec/unit/provider/package/gem.rb new file mode 100644 index 000000000..3dc1fa347 --- /dev/null +++ b/spec/unit/provider/package/gem.rb @@ -0,0 +1,87 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +provider_class = Puppet::Type.type(:package).provider(:gem) + +describe provider_class do + it "should have an install method" do + @provider = provider_class.new + @provider.should respond_to(:install) + end + + describe "when installing" do + before do + # Create a mock resource + @resource = stub 'resource' + + # A catch all; no parameters set + @resource.stubs(:[]).returns nil + + # We have to set a name, though + @resource.stubs(:[]).with(:name).returns "myresource" + @resource.stubs(:[]).with(:ensure).returns :installed + + @provider = provider_class.new + @provider.stubs(:resource).returns @resource + end + + it "should use the path to the gem" do + provider_class.stubs(:command).with(:gemcmd).returns "/my/gem" + @provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns "" + @provider.install + end + + it "should specify that the gem is being installed" do + @provider.expects(:execute).with { |args| args[1] == "install" }.returns "" + @provider.install + end + + it "should specify that dependencies should be included" do + @provider.expects(:execute).with { |args| args[2] == "--include-dependencies" }.returns "" + @provider.install + end + + it "should specify the package name" do + @provider.expects(:execute).with { |args| args[3] == "myresource" }.returns "" + @provider.install + end + + describe "when a source is specified" do + describe "as a normal file" do + it "should use the file name instead of the gem name" do + @resource.stubs(:[]).with(:source).returns "/my/file" + @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" + @provider.install + end + end + describe "as a file url" do + it "should use the file name instead of the gem name" do + @resource.stubs(:[]).with(:source).returns "file:///my/file" + @provider.expects(:execute).with { |args| args[3] == "/my/file" }.returns "" + @provider.install + end + end + describe "as a puppet url" do + it "should fail" do + @resource.stubs(:[]).with(:source).returns "puppet://my/file" + lambda { @provider.install }.should raise_error(Puppet::Error) + end + end + describe "as a non-file and non-puppet url" do + it "should treat the source as a gem repository" do + @resource.stubs(:[]).with(:source).returns "http://host/my/file" + @provider.expects(:execute).with { |args| args[3..5] == ["--source", "http://host/my/file", "myresource"] }.returns "" + @provider.install + end + end + describe "with an invalid uri" do + it "should fail" do + URI.expects(:parse).raises(ArgumentError) + @resource.stubs(:[]).with(:source).returns "http:::::uppet:/:/my/file" + lambda { @provider.install }.should raise_error(Puppet::Error) + end + end + end + end +end diff --git a/spec/unit/provider/user/ldap.rb b/spec/unit/provider/user/ldap.rb index 90fc7423f..7e039d582 100755 --- a/spec/unit/provider/user/ldap.rb +++ b/spec/unit/provider/user/ldap.rb @@ -24,6 +24,17 @@ describe provider_class do provider_class.manager.rdn.should == :uid end + it "should be able to manage passwords" do + provider_class.should be_manages_passwords + + it "should use the ldap group provider to convert group names to numbers" do + provider = provider_class.new(:name => "foo") + Puppet::Type.type(:group).provider(:ldap).expects(:name2id).with("bar").returns 10 + + provider.gid = 'bar' + provider.gid.should == 10 + end + {:name => "uid", :password => "userPassword", :comment => "cn", |
