summaryrefslogtreecommitdiffstats
path: root/lib/puppet/module.rb
Commit message (Collapse)AuthorAgeFilesLines
* (#4142) Fix module check not to fail when empty metadata.jsonMatt Robinson2011-07-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Even though the puppet module tool was fixed to generate the required metadata attributes when it packages modules, it still creates an empty metadata.json file that gets checked into everybody's module repos. This causes the module to be unusable straight from a git clone since puppet was requiring all the required metadata attributes just with the presence of that file, and resulting in the error: No source module metadata provided for mcollective at This change makes it so that if you have an empty metadata.json (like the moduletool generates), puppet doesn't consider it to have metadata. If you have ANY metadata attributes in that file, it will still check to make sure all the required attributes are present. The work around up to this point has just been to delete the metadata.json file in git cloned modules. This also fixed the tests around this to actually run, since previously the tests depended on the a json feature, which we didn't have. We do, however, have a pson feature. Reviewed-by: Nick Lewis <nick@puppetlabs.com>
* Fixing Module#path detectionLuke Kanies2011-03-251-1/+1
| | | | | | | | | | For some reason FileTest.exist? was returning false, and FileTest.directory? returns true. I've also added much better tests for this behavior. Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
* maint: Remove spec run noiseMatt Robinson2011-03-081-1/+1
| | | | | | | | | | | | | | | | | | | | | There were some warnings and stack traces in the spec output that aren't necessary. The only interesting fix is of the message: lib/puppet/module.rb:79 warning: multiple values for a block parameter (0 for 1) from lib/puppet/util/logging.rb:30 If you call any form of logging on a module you end calling the file method on the module just because logging always checks for that method and calls it if it's defined, but in this case it's not defined in the way that logging expected so passes the wrong paramters. The easy solution is just to call logging on Puppet, which makes sense in this case anyway, and I don't think it's worth a separate ticket to deal with that logging warning. Reviewed-by: Nick Lewis <nick@puppetlabs.com>
* Fix for #4220 -- modules not implicitly loading their init filesMarkus Roberts2010-07-131-1/+1
| | | | | | The module init loading was broken in 7504f1e..b938edf and then gradually removed as dead code. This is a minimal (and mildly ugly) reinsertion os it with the addition of .rb support.
* Code smell: Two space indentationMarkus Roberts2010-07-091-197/+197
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
* Code smell: Avoid needless decorationsMarkus Roberts2010-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2 3 Examples: The code: ctx = OpenSSL::SSL::SSLContext.new() becomes: ctx = OpenSSL::SSL::SSLContext.new The code: skip() becomes: skip The code: path = tempfile() becomes: path = tempfile * Replaced 31 occurances of ^( *)end *#.* with \1end 3 Examples: The code: becomes: The code: end # Dir.foreach becomes: end The code: end # def becomes: end
* Code smell: Avoid explicit returnsMarkus Roberts2010-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaced 583 occurances of (DEF) (LINES) return (.*) end with 3 Examples: The code: def consolidate_failures(failed) filters = Hash.new { |h,k| h[k] = [] } failed.each do |spec, failed_trace| if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } filters[f] << spec break end end return filters end becomes: def consolidate_failures(failed) filters = Hash.new { |h,k| h[k] = [] } failed.each do |spec, failed_trace| if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } filters[f] << spec break end end filters end The code: def retrieve return_value = super return_value = return_value[0] if return_value && return_value.is_a?(Array) return return_value end becomes: def retrieve return_value = super return_value = return_value[0] if return_value && return_value.is_a?(Array) return_value end The code: def fake_fstab os = Facter['operatingsystem'] if os == "Solaris" name = "solaris.fstab" elsif os == "FreeBSD" name = "freebsd.fstab" else # Catchall for other fstabs name = "linux.fstab" end oldpath = @provider_class.default_target return fakefile(File::join("data/types/mount", name)) end becomes: def fake_fstab os = Facter['operatingsystem'] if os == "Solaris" name = "solaris.fstab" elsif os == "FreeBSD" name = "freebsd.fstab" else # Catchall for other fstabs name = "linux.fstab" end oldpath = @provider_class.default_target fakefile(File::join("data/types/mount", name)) end
* Code smell: Line modifiers are preferred to one-line blocks.Markus Roberts2010-07-091-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 6 occurances of (while .*?) *do$ with The do is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: while line = f.gets do becomes: while line = f.gets The code: while line = shadow.gets do becomes: while line = shadow.gets The code: while wrapper = zeros.pop do becomes: while wrapper = zeros.pop * Replaced 19 occurances of ((if|unless) .*?) *then$ with The then is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then becomes: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } The code: unless defined?(@spec_command) then becomes: unless defined?(@spec_command) The code: if c == ?\n then becomes: if c == ?\n * Replaced 758 occurances of ((?:if|unless|while|until) .*) (.*) end with The one-line form is preferable provided: * The condition is not used to assign a variable * The body line is not already modified * The resulting line is not too long 3 Examples: The code: if Puppet.features.libshadow? has_feature :manages_passwords end becomes: has_feature :manages_passwords if Puppet.features.libshadow? The code: unless (defined?(@current_pool) and @current_pool) @current_pool = process_zpool_data(get_pool_data) end becomes: @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool) The code: if Puppet[:trace] puts detail.backtrace end becomes: puts detail.backtrace if Puppet[:trace]
* Code smell: Use string interpolationMarkus Roberts2010-07-091-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
* Fix for #4178 - generalize autoloading to include .rbLuke Kanies2010-07-091-15/+5
| | | | | | | | | | This mostly modifies autoloading to look for files ending in either 'pp' or 'rb' using Dir globing with {,.pp,.rb} or .{pp,rb} as appropriate. It could easily be extended to add support for other formats (e.g. xml) by adding them to the globs (though, if this were to be done often, having a centralized list of supported extensions would be a good (and easy) refactor). Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* Fix for #4142 stray use of JSON instead of PSONMarkus Roberts2010-07-061-1/+1
| | | | Somehow one use of JSON escaped the global find and replace of PSON --> JSON.
* Improve error messageDavid Schmitt2010-02-171-1/+1
|
* Making a Puppet::Module test more resilientLuke Kanies2010-04-131-3/+3
| | | | | | It would fail if a directory unexpectedly existed. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* Fixing #3407 Failing tests in spec/unit/node/environment.rbJesse Wolfe2010-03-221-12/+8
| | | | | | | | | A naked rescue in Puppet::Node::Environment was hiding expectation violations from the Mocha mocks. Specifically, 'modulepath' expectations were failing, as Puppet::Module now calls Puppet::Node::Environment#modulepath internally. Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
* Adding module metadataLuke Kanies2009-12-091-0/+74
| | | | | | | | | | | | | This is a first version that does very little - it has a few fields, and allows speciification of dependencies with other modules as well as compatibility with individual Puppet versions. It's not really sufficient, because it only allows specific versions, rather than a range of versions, but it's a good demo of what it takes and what we provide. Signed-off-by: Luke Kanies <luke@madstop.com>
* Ticket #2525 don't fail find_manifest on invalid module namesMarkus Roberts2009-09-051-1/+1
| | | | | | | | | The patch that put validity assertions in for module names broke find_manifest because rather than returning a failure it now rasies an exception. This patch catches the exception and treats it as a negative result. Signed-off-by: Markus Roberts <Markus@reality.com>
* Refactoring the Module/Environment co-interfaceLuke Kanies2009-08-181-22/+13
| | | | | | | This simplifies who owns what code in these two classes, and the result should be much cleaner and simpler. Signed-off-by: Luke Kanies <luke@madstop.com>
* Fixing #1544 - plugins in modules now works againLuke Kanies2009-08-181-0/+2
| | | | | | | | | | | | We had to fix the fileserving plumbing to use the request environment instead of trying to use the node environment. This was apparently never fixed after we added the environment to the URI in REST calls. There's still a bit of refactoring left to clean up the APIs used in some of this code. Signed-off-by: Luke Kanies <luke@madstop.com>
* Using the logging utilities to clean up module warningsLuke Kanies2009-06-191-1/+12
| | | | | | | This just makes it easier to add context to warnings and other logs from the module. Signed-off-by: Luke Kanies <luke@madstop.com>
* Fixing #1064 - Deprecating module 'plugins' directoriesLuke Kanies2009-06-191-1/+12
| | | | | | | | | You should now use 'lib' instead of 'plugins'. The old directory still works, but you get a warning for every module that uses it. Signed-off-by: Luke Kanies <luke@madstop.com>
* Fixing #2323 - Modules use environments correctlyLuke Kanies2009-06-121-1/+1
| | | | | | | | Previously, modules were not using their environments when looking up their paths, which meant that they often found files in the wrong environment. Signed-off-by: Luke Kanies <luke@madstop.com>
* Removed extra whitespace from end of linesIan Taylor2009-06-061-1/+1
|
* Modules now can find their own pathsLuke Kanies2009-05-151-23/+65
| | | | | | | | | | | | Previously, when you created a module you had to specify the path. Now Module instances can use the module path to look up their paths, and there are methods for determining whether the module is present (if the path is present). Also cleaned up the methods for figuring out what's in the module (plugins, etc.). Signed-off-by: Luke Kanies <luke@madstop.com>
* Moving file-searching code out of Puppet::ModuleLuke Kanies2009-05-151-88/+1
| | | | | | | | | | The Module class had a bunch of code for finding manifests and templates even when not in a module, and it complicated the class unnecessarily. This moves that code to a new, hackish-but-sufficient module for just that purpose. Signed-off-by: Luke Kanies <luke@madstop.com>
* Adding pluginsyncing support to the IndirectorLuke Kanies2009-02-191-1/+5
| | | | | | | | | This switches away from the use of terminii for each type of fileserving - it goes back to the traditional fileserving method, and is much cleaner and simpler as a result. Signed-off-by: Luke Kanies <luke@madstop.com>
* Using the Environments to handle a lot of Module searchingLuke Kanies2009-02-181-37/+2
| | | | | | | | | | Since Environments now know how to look for modules, a lot of the Module code was able to be pushed into them. Also moving some of the tests to instance-level tests, rather than just testing the class-level interfaces. Signed-off-by: Luke Kanies <luke@madstop.com>
* Adding support for finding all modules in a given path.Luke Kanies2009-02-181-0/+22
| | | | | | | | This 'each_module' method will be used by environments to find all or a given module, and will likely eventually be used internally, too. Signed-off-by: Luke Kanies <luke@madstop.com>
* Adding new methods to Puppet::Module.Luke Kanies2009-02-181-7/+20
| | | | | | | | | | | | There are now boolean methods to test whether a given kind of file is present in a given module. E.g, you can do: Puppet::Module.new("mod", "/my/path").plugins? There are also accessor-style methods that return the full path for a given kind of file. Signed-off-by: Luke Kanies <luke@madstop.com>
* Refactoring Puppet::Module a bit.Luke Kanies2009-02-181-22/+18
| | | | | | | No behaviour change here, just some internal changes to make way for methods I want to add. Signed-off-by: Luke Kanies <luke@madstop.com>
* Finishing the work to use Puppet::Resource instead of TransObjectLuke Kanies2008-12-181-2/+7
| | | | | | | | | | | | This was a complicated project because TransObject had made its way into too many classes. The usage by Util::Settings was particularly nefarious. Refactoring and fixing this exposed some other issues. The main complication, though, was the extent to which the Puppet::Type class depended on TransObject. Signed-off-by: Luke Kanies <luke@madstop.com>
* Fixes #1773 - no longer check for absolute pathsThom May2008-11-291-1/+1
|
* Fix regression when templatedir doesn't exist.Brice Figureau2008-10-081-8/+14
| | | | | | | | When searching for a module template and if the default templatedir is inexistant, puppet was raising an error without trying the modules templates directories. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Bug #1550 - Rework to avoid regressing rspec tests, add new rspec tests for ↵Paul Nasrat2008-09-201-9/+15
| | | | | | templatedir as a path Signed-off-by: Paul Nasrat <pnasrat@googlemail.com>
* Allow a templatedir to be colon separated.Thom May2008-09-201-3/+15
| | | | | Signed-off-by: Thom May <thom@clearairturbulence.org> Signed-off-by: Paul Nasrat <pnasrat@googlemail.com>
* Fixed #1012 - templates in the templatedir are preferred to module templates.Luke Kanies2008-06-161-1/+5
|
* Fixing #1173 -- classes and definitions can now have the sameLuke Kanies2008-04-101-1/+1
| | | | name as a directory with no failures.
* Integrating Matt Palmer's patch to provide a 'plugins'Luke Kanies2007-11-241-1/+3
| | | | | | | | | | mount, fixing #891. The patch was ported to the current code by David Schmitt, I applied the rest of Matt's patches, and I then fixed all of the code so that the tests passed. The primary change I had to make to the patch was reenabling host expansion in paths -- his patch had disabled it.
* fix #891: create a plugins mount which collects all modules' plugins/ subdirsDavid Schmitt2007-11-081-4/+17
| | | | | | | This is Matthew Palmer's work, from his debian package at http://theshed.hezmatt.org/mattshacks/puppet/_patches/load_plugins_from_modules/20070831054902-6856b-0fd1481621def5d0c4d1ae48fb2f1dc357767c1e.patch I just wriggled a few hunks so they apply.
* Adding more behaviours to the Puppet::Module spec,Luke Kanies2007-10-031-6/+7
| | | | | | | and fixing some bugs in the process. Specifically, modules were no longer correctly handling fully qualified files, and they do so once again.
* Renaming the 'Puppet::Util::Config' class toLuke Kanies2007-09-221-2/+2
| | | | | | | 'Puppet::Util::Settings'. This is to clear up confusion caused by the fact that we now have a 'Configuration' class to model host configurations, or any set of resources as a "configuration".
* And we have multiple environment support in the parser. The only remaining ↵Luke Kanies2007-08-251-6/+14
| | | | piece to make this complete is to add multiple environment support to the fileserver. I also renamed Configuration.rb to Compile.rb (that is, I fixed all the classes that used to know it as a configuration).
* Modules are now tested with spec, and they now can handle ↵Luke Kanies2007-08-251-26/+30
| | | | environment-specific module paths.
* Fixing #596 -- classes in modules now autoloadluke2007-07-061-0/+115
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2655 980ebf18-57e1-0310-9a29-db15c13687c0