summaryrefslogtreecommitdiffstats
path: root/test/language/snippets.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch '2.6.x' into nextNick Lewis2010-12-161-0/+3
|\ | | | | | | | | | | | | | | | | Manually Resolved Conflicts: lib/puppet/resource/type_collection.rb spec/unit/configurer_spec.rb spec/unit/indirector/catalog/active_record_spec.rb spec/unit/resource/type_collection_spec.rb spec/unit/transaction/resource_harness_spec.rb
| * Fix #1757 Change file mode representation to octalJesse Wolfe2010-12-081-0/+3
| | | | | | | | | | | | This patch changes the internal representation of a file's mode to a string instead of an integer. This simplifies the problem of displaying the value consistently throughout all of puppet.
* | maint: Use expand_path when requiring spec_helper or puppettestMatt Robinson2010-12-061-1/+1
| | | | | | | | | | | | | | | | | | Doing a require to a relative path can cause files to be required more than once when they're required from different relative paths. If you expand the path fully, this won't happen. Ruby 1.9 also requires that you use expand_path when doing these requires. Paired-with: Jesse Wolfe
* | Maint: Refactor tests to use <class>.indirection.<method>Paul Berry2010-11-291-1/+1
|/ | | | | | Replaced uses of the find, search, destroy, and expire methods on model classes with direct calls to the indirection objects. This change affects tests only.
* Code smell: Two space indentationMarkus Roberts2010-07-091-434/+434
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-22/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* Code smell: Inconsistent indentation and related formatting issuesMarkus Roberts2010-07-091-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 163 occurances of defined\? +([@a-zA-Z_.0-9?=]+) with defined?(\1) This makes detecting subsequent patterns easier. 3 Examples: The code: if ! defined? @parse_config becomes: if ! defined?(@parse_config) The code: return @option_parser if defined? @option_parser becomes: return @option_parser if defined?(@option_parser) The code: if defined? @local and @local becomes: if defined?(@local) and @local * Eliminate trailing spaces. Replaced 428 occurances of ^(.*?) +$ with \1 1 file was skipped. test/ral/providers/host/parsed.rb because 0 * Replace leading tabs with an appropriate number of spaces. Replaced 306 occurances of ^(\t+)(.*) with Tabs are not consistently expanded in all environments. * Don't arbitrarily wrap on sprintf (%) operator. Replaced 143 occurances of (.*['"] *%) +(.*) with Splitting the line does nothing to aid clarity and hinders further refactorings. 3 Examples: The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] The code: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] becomes: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] * Don't break short arrays/parameter list in two. Replaced 228 occurances of (.*) +(.*) with 3 Examples: The code: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) becomes: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) The code: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) becomes: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) The code: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") becomes: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") * If arguments must wrap, treat them all equally Replaced 510 occurances of lines ending in things like ...(foo, or ...(bar(1,3), with \1 \2 3 Examples: The code: midscope.to_hash(false), becomes: assert_equal( The code: botscope.to_hash(true), becomes: # bottomscope, then checking that we see the right stuff. The code: :path => link, becomes: * Replaced 4516 occurances of ^( *)(.*) with The present code base is supposed to use four-space indentation. In some places we failed to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question. 15 Examples: The code: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc becomes: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc The code: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( becomes: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( The code: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } becomes: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } The code: #passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } becomes: # passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } The code: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") becomes: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") The code: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", becomes: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", The code: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do becomes: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do The code: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') becomes: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') The code: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) becomes: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) The code: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") becomes: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") The code: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } becomes: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } The code: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid becomes: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid The code: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' becomes: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' The code: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs becomes: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs The code: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element| becomes: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element|
* Fixing #2658 - adding backward compatibility for 0.24Luke Kanies2010-02-171-5/+1
| | | | | | | | | | | | | The way stages were implemented caused backward compatibility to be completely broken for 0.24.x. This commit fixes that, mostly by assuming Stage[main] will be the top node in the graph rather than Class[main]. Other stages are not supported in 0.24.x, and explicitly throw a warning (although not an error). Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* Finishing renaming :params to :parameters internallyLuke Kanies2010-02-171-2/+2
| | | | | | | | | | | | I had only done this partway, because it seemed easier, but not surprisingly, it ended up being more complex. In addition to those renames, this commit includes fixes to whatever tests I needed to fix to confirm that things were again working. I think most of these broken tests have been broken for a while. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Fixing most of the broken tests in test/Luke Kanies2010-02-171-4/+0
| | | | | | | | This involves a bit of refactoring in the rest of the code to make it all work, but most of the changes are fixing or removing old tests. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Resolving conflicts with ???Markus Roberts2010-02-171-1/+0
|
* Fix #2389 - Enhance Puppet DSL with HashesBrice Figureau2010-02-171-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bring a new container syntax to the Puppet DSL: hashes. Hashes are defined like Ruby Hash: { key1 => val1, ... } Hash keys are strings, but hash values can be any possible right values admitted in Puppet DSL (ie function call, variables access...) Currently it is possible: 1) to assign hashes to variable $myhash = { key1 => "myval", key2 => $b } 2) to access hash members (recursively) from a variable containing a hash (works for array too): $myhash = { key => { subkey => "b" }} notice($myhash[key][subjey]] 3) to use hash member access as resource title 4) to use hash in default definition parameter or resource parameter if the type supports it (known for the moment). It is not possible to string interpolate an hash access. If it proves to be an issue it can be added or work-arounded with a string concatenation operator easily. It is not possible to use an hash as a resource title. This might be possible once we support compound resource title. Unlike the proposed syntax in the ticket it is not possible to assign individual hash member (mostly to respect write once nature of variable in puppet). Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Enhance selector and case statements to match with regexpBrice Figureau2009-08-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | The case and selector statements define ephemeral vars, like 'if'. Usage: case statement: $var = "foobar" case $var { "foo": { notify { "got a foo": } } /(.*)bar$/: { notify{ "hey we got a $1": } } } and for selector: $val = $test ? { /^match.*$/ => "matched", default => "default" } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #2033 - Allow regexp in if expressionBrice Figureau2009-08-011-0/+4
| | | | | | | | | | | | | | | | | | | This changeset introduces regexp in if expression with the use of the =~ (match) and !~ (not match) operator. Usage: if $uname =~ /Linux|Debian/ { ... } Moreover this patch creates ephemeral variables ($0 to $9) in the current scope which contains the regex captures: if $uname =~ /(Linux|Debian)/ { notice("this is a $1 system") } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Removed extra whitespace from end of linesIan Taylor2009-06-061-4/+4
|
* Changed tabs to spaces without interfering with indentation or alignmentIan Taylor2009-06-061-1/+1
|
* Fix #1088 - part2 - Add rspec testsBrice Figureau2009-03-141-0/+6
| | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fixing tests broken in previous commitsLuke Kanies2009-03-111-2/+2
| | | | Signed-off-by: Luke Kanies <luke@madstop.com>
* Renaming Puppet::Node::Catalog to Puppet::Resource::CatalogLuke Kanies2008-12-181-1/+1
| | | | Signed-off-by: Luke Kanies <luke@madstop.com>
* Fixing forward-compatibility issues resulting from no global resourcesLuke Kanies2008-10-311-1/+1
| | | | Signed-off-by: Luke Kanies <luke@madstop.com>
* Merge branch '0.24.x'Luke Kanies2008-10-311-0/+16
|\ | | | | | | | | | | Conflicts: CHANGELOG
| * Fix #1402 - Allow multiline commentsBrice Figureau2008-10-291-0/+11
| | | | | | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
| * Fix #857 - Multiple class of the same name don't append codeBrice Figureau2008-10-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following manifest wasn't working: class one { notice('class one') } class one { notice('second class one') } include one It all boiled down to class code not being arrays. Encapsulating code in ASTArray when needed is enough to append code, because of the property of ASTArray to evaluate all their members in turn. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* | Merge branch '0.24.x'Luke Kanies2008-10-221-0/+14
|\| | | | | | | | | | | Conflicts: lib/puppet/type/user.rb
| * Fix #936 - Allow trailing comma in array definitionBrice Figureau2008-10-211-0/+7
| | | | | | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
| * Fix #636 - Allow extraneous comma in function argument listBrice Figureau2008-10-211-0/+7
| | | | | | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* | Merge branch 'master' into master_no_global_resourcesLuke Kanies2008-03-311-0/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: lib/puppet/node/catalog.rb lib/puppet/type/pfile.rb lib/puppet/type/pfilebucket.rb lib/puppet/util/filetype.rb spec/unit/node/catalog.rb spec/unit/other/transbucket.rb spec/unit/ral/provider/mount/parsed.rb spec/unit/ral/types/file.rb spec/unit/ral/types/interface.rb spec/unit/ral/types/mount.rb spec/unit/ral/types/package.rb spec/unit/ral/types/schedule.rb spec/unit/ral/types/service.rb test/language/compile.rb test/language/lexer.rb test/language/snippets.rb test/lib/puppettest.rb test/ral/types/basic.rb test/ral/types/cron.rb test/ral/types/exec.rb test/ral/types/file.rb test/ral/types/file/target.rb test/ral/types/filebucket.rb test/ral/types/fileignoresource.rb test/ral/types/filesources.rb test/ral/types/group.rb test/ral/types/host.rb test/ral/types/parameter.rb test/ral/types/sshkey.rb test/ral/types/tidy.rb test/ral/types/user.rb test/ral/types/yumrepo.rb
| * Fixed #997 -- virtual defined types are no longer evaluated.Luke Kanies2008-02-121-0/+5
| | | | | | | | | | | | | | NOTE: This introduces a behaviour change, in that you previously could realize a resource within a virtual defined resource, and now you must realize the entire defined resource, rather than just the contained resource.
| * Stubbing Facter during the snippet tests, so they are faster and work with ↵Luke Kanies2008-02-081-0/+2
| | | | | | | | no network
* | Another round of fixes toward making global resources work.Luke Kanies2008-01-091-23/+13
|/ | | | | | The only remaining failures are more complicated ones (which I'll need to not be on a plane to debug, for battery reasons) or those related to the broken directory_service providers.
* Renaming 'configuration' to 'catalog', fixing #954.Luke Kanies2007-12-111-7/+7
|
* Reverting the changes I'd made toward removing the globalLuke Kanies2007-11-191-11/+12
| | | | | | | | resources. These are commits: c19835ce9f8a5138b30a1a32ca741c996b0916d2 9290cc89a2206fb5204578f8e91208857a48b147 ffb4c2dbc7314b364d25e4f7be599ef05b767b44
* Fixed most failing tests, but there are still over thirty failing.Luke Kanies2007-11-181-12/+11
| | | | | | At this point, I'm holding the experiment until after the release, so I'm committing this for now and will take it back up after 0.24.0 is out.
* Changing the test/ classes so that they work from the mainLuke Kanies2007-10-261-1/+1
| | | | | | test/ dir or from their own working dir, like the specs do. This was just a question of changing how their libraries are loaded.
* All tests should now pass again.Luke Kanies2007-10-081-2/+2
| | | | | | | | | | | | | | This is the first real pass towards using caching. The `puppet` executable actually uses the indirection work, instead of handlers and such (and man! is it cleaner). Most of this work was a result of trying to get the client-side story working, with correct yaml caching of configurations, which means this commit also covers converting configurations to yaml, which was a much bigger PITA than it needed to be. I still need to write integration tests, and I also need to cover the server-side story of a normal configuration retrieval.
* This commit is focused on getting the 'puppet' executableLuke Kanies2007-10-051-34/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | to work. As a result, it involves a lot of integration-level testing, and a lot of small design changes to make the code actually work. In particular, indirections can now have default termini, so that configurations and facts default to their code terminus Also, I've removed the ability to manually control whether ast nodes are used. I might need to add it back in later, but if so it will be in the form of a global setting, rather than the previous system of passing it through 10 different classes. Instead, the parser detects whether there are AST nodes defined and requires them if so or ignores them if not. About 75 tests are still failing in the main set of tests, but it's going to be a long slog to get them working -- there are significant design issues around them, as most of the failures are a result of tests trying to emulate both the client and server sides of a connection, which normally would have different fact termini but in this case must have the same terminus just because they're in the same process and are global. The next step, then, is to figure that process out, thus finding a way to make this all work.
* Merge branch 'configurations' into indirectionLuke Kanies2007-09-221-11/+4
|\ | | | | | | | | | | | | | | | | Conflicts: lib/puppet/defaults.rb lib/puppet/indirector/facts/yaml.rb spec/unit/indirector/indirection.rb spec/unit/indirector/indirector.rb
| * All tests now pass in this configuration branch, which meansLuke Kanies2007-09-221-9/+2
|/ | | | | | | | it's time to merge it back into the indirection branch. Considering that this work was what drove me to create the indirection branch in the first place, i should now be able to merge both back in the master branch.
* Another intermediate commit. The node and fact classes are now functional ↵Luke Kanies2007-09-121-3/+4
| | | | and are used instead of the network handlers, which have been removed. There are some failing tests as a result, but I want to get this code committed before I massage the rest of the system to make it work again.
* We now have a real configuration object, as a subclass of GRATR::Digraph, ↵Luke Kanies2007-09-041-5/+0
| | | | that has a resource graph including resources for the container objects like classes and nodes. It is apparently functional, but I have not gone through all of the other tests to fix them yet. That is next.
* Deleting old documentation that somehow made it back into the tree in the ↵Luke Kanies2007-09-011-1/+13
| | | | switch to git, and refactoring the evaluate_classes method on the compile object so I can use resources as intermediaries, thus making classes do late-binding evaluation.
* Consolidating all of the configuration parameter declarations into ↵luke2007-05-041-1/+0
| | | | | | configuration, at least partially just because then the docs for each parameter have to be a bit better. Also, I have gotten rid of the "puppet" section, replacing it with "main", and changed, added, or removed a couple of other sections. In general, we should now prefer more sections, rather than fewer. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2463 980ebf18-57e1-0310-9a29-db15c13687c0
* Fixing #615 (subclasses with similar names) by getting rid of the class ↵luke2007-05-031-150/+114
| | | | | | "type" and "fqname", and instead using "classname" everywhere. You should no longer see unqualified class/definition names anywhere. Also, rewriting how snippet tests work, to avoid creating all of the files, since the point was the parsing tests, not functional tests. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2458 980ebf18-57e1-0310-9a29-db15c13687c0
* Merging the webserver_portability branch from version 2182 to version 2258.luke2007-03-061-4/+4
| | | | git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2259 980ebf18-57e1-0310-9a29-db15c13687c0
* Moving all of the client and server code into a single network/ directory. ↵luke2007-02-081-6/+6
| | | | | | In other words, more code structure cleanup. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2179 980ebf18-57e1-0310-9a29-db15c13687c0
* Merging the state-rename branch. This includes the diff from version 2156 ↵luke2007-02-071-4/+4
| | | | | | to 2168. All states should now be properties, with backward compatibility for the types that restricted themselves to the methods. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2169 980ebf18-57e1-0310-9a29-db15c13687c0
* Partially fixing #460, take 2 -- fully-qualified definitions can now be used.luke2007-01-301-0/+12
| | | | git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2127 980ebf18-57e1-0310-9a29-db15c13687c0