Граф коммитов

1584 Коммитов

Автор SHA1 Сообщение Дата
Jesse Wolfe f38c36c63d (#5408) Attributes can be both audited and managed
This patch makes it possible to both audit and manage an attribute.
It introduces a new field on Event objects "historical_value", which is
the value from state.yaml. The value from the RAL is written to
state.yaml, and then the RAL is updated with the desired value.

Paired-With: Nick Lewis <nick@puppetlabs.com>
Paired-With: Matt Robinson <matt@puppetlabs.com>
2010-12-10 14:56:19 -08:00
Jesse Wolfe 3e5927773c Fix #1757 Change file mode representation to octal
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.
2010-12-08 14:57:50 -08:00
Matt Robinson 626d756446 maint: Use expand_path when requiring spec_helper or puppettest
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
2010-12-06 12:01:18 -08:00
Matt Robinson dac675c94e Merge branch '2.6.x' into next
* 2.6.x:
  (#5304) Use internal_name rather than real_name for maillist provider
  Updated CHANGELOG and version for 2.6.4
  Revert "(#5304) Use internal_name rather than real_name for maillist provider"
  Disable remote ralsh by default
  (#5424) Ship auth.conf as part of installing from source
  (#5304) Use internal_name rather than real_name for maillist provider
  Renamed Reductive to Puppet

Manually Resolved Conflicts:
	lib/puppet/provider/maillist/mailman.rb
2010-12-02 14:43:15 -08:00
Matt Robinson e005cc79fa maint: Remove bogus mongrel test
Why test that mongrel responds to daemonize?  EVERYTHING responds to
daemonize thanks to activesupport.

Paired-with: Paul Berry
2010-12-02 11:27:27 -08:00
Paul Berry 0747b58bfe Maint: Modified uses of indirector.save to call the indirection directly.
This change replaces calls to <model object>.save with calls to <model
class>.indirection.save(<model object>).  This makes the use of the
indirector explicit rather than implicit so that it will be easier to
search for all indirector call sites using grep.  This is an
intermediate refactor on the way towards allowing indirector calls to
be explicitly routed to multiple termini.

This patch affects production code.
2010-11-30 14:39:39 -08:00
Paul Berry f77764de3a Maint: Modified tests of indirector.save to call the indirection directly.
This change replaces calls to <model object>.save with calls to <model
class>.indirection.save(<model object>).  This makes the use of the
indirector explicit rather than implicit so that it will be easier to
search for all indirector call sites using grep.  This is an
intermediate refactor on the way towards allowing indirector calls to
be explicitly routed to multiple termini.

This patch affects tests only; the next patch will make the
corresponding change to the code.
2010-11-30 14:39:38 -08:00
Paul Berry 14f8160674 Maint: Refactor tests to use <class>.indirection.<method>
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.
2010-11-29 12:08:19 -08:00
James Turnbull 83f878e230 Renamed Reductive to Puppet
I swear I've done this before. *confused*
2010-11-29 18:37:44 +11:00
Paul Berry cf18353472 Maint: Switched spec tests to use a class rather than Array as the log destination.
Using an Array as a log destination is unreliable because Puppet's log
mechanism stores log destinations in a hash whose key is the
destination itself.  Since arrays can change their hash when they are
modified, this was causing the log destination hash to become
corrupted, producing sporadic spec test failures.
2010-11-18 14:55:05 -08:00
Paul Berry 263cc46ce0 Merge branch 'ticket/next/5274' into next 2010-11-18 14:24:08 -08:00
Paul Berry 6e51d11c53 (#5274) Fixed some "rake unit" tests that were inadvertently broken by
commit:ee7d2f92f9d3ec45b5c3a9cd3fe2f5832b17f23b
2010-11-18 14:15:41 -08:00
Nick Lewis b5261cddc1 Merge branch 'ticket/next/5274' into next 2010-11-17 16:01:06 -08:00
Stefan Schulte 2052f3611f (#5274) New tests for new hosttype/parsedprovider
Just a few additional tests for the new property "comment" of the
host type.
2010-11-17 15:55:49 -08:00
Stefan Schulte 8efdc769db (#5274) Tests for hostprovider removes comments
I noticed that the hostprovider will remove all inline comments from the
/etc/hosts file, when puppet updates at least one entry. Puppet will also
remove comments from entries, the user doesnt want to manage with
puppet.

To split up changes a bit this commit will only introduce tests for the
host type and the hostprovider. A few will fail, indicating the bug:

The hostprovider parses all entries and builds a hash. When building
the recordhash all comments are discarded. When puppet has to update at
least one entry it uses the to_line function to convert the record hash
back to a file. Because the comments are not stored in the hash, they
cannot be written back to the file.
2010-11-17 15:55:24 -08:00
Paul Berry e6ec6468c4 Merge commit '2.6.3' into next
Resolved conflicts manually:
	spec/integration/indirector/bucket_file/rest_spec.rb
	spec/integration/indirector/certificate_revocation_list/rest_spec.rb
2010-11-17 15:19:15 -08:00
Jesse Wolfe 178c2a6282 Fix test failures that fixing #4726 exposed.
The patch for #4726 causes old unit tests of the rrd reporting
infrastructure to run on my machine. These tests were calling the old
report api, which does not succeed.
Also, the rrd settings had unintentionally been moved out of the
:metrics section, making it possible that the rrd report directory would
fail to get created during testing.
2010-11-16 12:22:04 -08:00
Markus Roberts b15231df58 Fix for #4299 -- Don't require which
We already had an internal implementation of which hiding under an assumed
name (Puppet::Util.binary); this commit calls it out of hiding and uses it
consisantly.
2010-11-12 15:02:00 +11:00
Markus Roberts cc5224c191 Maint. fix for test broken by 00eedac5
As per Nigel, this fixes the test broken by commit 00eedac5 in which a :combine
was added in lib but the corresponding change was not made in the test.
2010-11-10 20:56:42 -08:00
Jesse Wolfe 6acfdba87b Partial merge to 2.6.2rc1 : Merge commits 'd057b90' and '6dd1930' into next
This commit merges in d057b90 with the addition of commit 6dd1930 to fix
some tests that are confined to machines where rrd is installed.
2010-10-04 15:37:23 -07:00
Jesse Wolfe 6dd1930ff6 Fix test failures that fixing #4726 exposed.
The patch for #4726 causes old unit tests of the rrd reporting
infrastructure to run on my machine. These tests were calling the old
report api, which does not succeed.
Also, the rrd settings had unintentionally been moved out of the
:metrics section, making it possible that the rrd report directory would
fail to get created during testing.
2010-10-04 15:35:41 -07:00
Jesse Wolfe 1a00c07971 Partial merge to 2.6.2rc1 : Merge commit '66cf3a9' into next
There are test failures in commits following this one.
2010-10-04 12:22:47 -07:00
Jacob Helwig d54352a0cc Port Puppet::SSLCertificates::CA test to rspec
Signed-off-by: Jacob Helwig <jacob@puppetlabs.com>
2010-09-28 15:36:23 -07:00
Jesse Wolfe 9e66daa27c Merge commit '2.6.1' into next 2010-09-13 23:34:06 -07:00
Jesse Wolfe 9e72ccd8ff Merge commit '2.6.1rc4' into next 2010-09-13 23:00:35 -07:00
James Cammarata 9bdfe694bc Fix for Bug #4756 - Providers no longer respect missing features
Restored deleted lines from type.rb and reinstated unit tests
2010-09-14 09:22:19 +10:00
Jesse Wolfe 6860594c4d Merge remote branch 'paul/ticket/next/4638' into next 2010-09-09 16:20:26 -07:00
Matt Robinson 07d0be4684 [#4308] Remove puppettest from specs
The less stuff being done in the spec_helper the better for reasoning
about what's happening in the tests.  puppettest.rb does a lot of things
that aren't necessary for the specs, so this patch gets those things out
of the spec_helper.

Reviewed by: Jesse Wolfe
2010-09-03 02:53:01 +10:00
Paul Berry 1ba536eb53 [3782] Test isolation problem in test/ral/providers/cron/crontab.rb
The test in question (test_parse_line) was nondeterministic because it
was relying on the sort order of a Hash whose keys were symbols.  When
the sort order caused a blank line to appear at the end of the file
under test, the blank line was elided by the crontab parser, causing a
failure.

Modified the test to execute in a deterministic order that doesn't
place the blank line at the end.
2010-08-31 11:46:36 -07:00
Paul Berry df088c9ba1 [4638] Cleanup of plurals and inheritance relationships in AST
Changed the grammar so that the following "plural" constructs always
parse as an ASTArray:

- funcvalues
- rvalues
- resourceinstances
- anyparams
- params
- caseopts
- casevalues

And the following "singluar" construct never parses as an ASTArray:

- statement

The previous behavior was for these constructs to parse as a scalar
when they represented a single item and an ASTArray when they
contained zero or multiple items.  ("Statement" could sometimes
represent a single item because a single resource declaration could
represent multiple resources).  This complicated other grammar rules
and caused ambiguous handling of nested arrays.

Also made these changes to the AST class hierarchy:

- ResourceInstance no longer derives from ASTArray.  This relationship
  was not meaningful because a ResourceInstance is a (title,
  parameters) pair, not an array, and it produced complications when
  we wanted to represent an array of ResourceInstance objects.

- Resource no longer derives from ResourceReference.  No significant
  functionality was being inherited and the relationship doesn't make
  sense in an AST context.

- ResourceOverride no longer derives from Resource.  No significant
  functionality was being inherited and the relationship doesn't make
  sense in an AST context.

- Resource can now represent a compound resource instance such as
  "notify { foo: ; bar: }".  This saves the parser from having to
  use represent a statement as an array of objects.

- ASTArray's evaluate method never flattens out arrays of arrays.
2010-08-27 10:29:23 -07:00
Jesse Wolfe 16f701edd8 Merge remote branch 'paul/4472-4483-4496-4521-4522'
a.k.a. "make_taller_trees"
2010-08-17 12:25:37 -07:00
Paul Berry 4da88fb4cd [#4496]+[#4521]+[#4522] Add structures to the AST to represent type definitions (classes, definitions, and nodes).
Previously, type definitions were not represented directly in the AST.
Instead, the parser would instantiate types and insert them into
known_resource_types as soon as they were parsed.  This made it
difficult to distinguish which types had come from the file that was
just parsed and which types had been loaded previously, which led to
bug 4496.

A side-effect of this change is that the user is no longer allowed to
define types inside of conditional constructs (such as if/else).  This
was allowed before but had unexpected semantics (bugs 4521 and 4522).

It is still possible, however, to place an "include" statement inside
a conditional construct, and have that "include" statement trigger the
autoloading of a file that instantiates types.
2010-08-13 15:54:26 -07:00
Markus Roberts 47005aa201 Maint -- tests need to respect RFC-952
We had a test that assumed hostnames would only consist of letters; by RFC-952
they are also allowed to contain digits and '-'s.  The test failed on such
machines.
2010-08-04 17:49:11 -07:00
Paul Berry 00ebf01227 [#4344] Fix for failing templates when module name matches file in local dir.
When the name of a module matches the name of a file in the local
directory, puppet agent would sometimes try to read that file and
interpret it as puppet code.  This happened because files.rb was
unintentionally permitting puppet files without an extension.  Fixed
by changing the glob pattern to only permit ".pp" and ".rb"
extensions.
2010-08-03 15:19:31 -07:00
Markus Roberts 3180b9d9b2 Code smell: Two space indentation
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
2010-07-09 18:12:17 -07:00
Markus Roberts 5432259702 Code smell: Avoid needless decorations
* 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
2010-07-09 18:07:15 -07:00
Markus Roberts 8f15707251 Code smell: Don't restate results directly after assignment
Replaced 33 occurances of

        ([$@]?\w+)( +[|&+-]{0,2}= .+)
        \1
    end

with

3 Examples:

    The code:
            @sync ||= Sync.new
            @sync
        end
    becomes:
            @sync ||= Sync.new
        end
    The code:
            str += "\n"
            str
        end
    becomes:
            str += "\n"
        end
    The code:
            @indirection = Puppet::Indirector::Indirection.new(self, indirection,  options)
            @indirection
        end
    becomes:
            @indirection = Puppet::Indirector::Indirection.new(self, indirection,  options)
        end
2010-07-09 18:06:58 -07:00
Markus Roberts 42a5390612 Code smell: Use ||= for conditional initialization
Replaced 55 occurances of

    ([$@]?\w+) += +(.*) +(if +\1.nil\?|if +! *\1|unless +\1|unless +defined\?\(\1\))$

with

    \1 ||= \2

3 Examples:

    The code:
        @sync
    becomes:
        @sync
    The code:

    becomes:

    The code:
        if @yydebug
    becomes:
        if @yydebug
2010-07-09 18:06:48 -07:00
Markus Roberts a07bbe2e71 Code smell: Omit needless checks on defined
* Replaced 53 occurances of

      defined\?\((.+?)\) (?:and|&&) \1( |$)

  with

      \1\2

  In code like:

     unless defined? @foo and @foo and bar("baz")

  "defined? @foo and @foo" can safely be replaced with "@foo":

     unless @foo and bar("baz")

  Because:

   * Both evaluate to false/nil when @foo is not defined
   * Both evaluate to @foo when @foo is defined

  3 Examples:

      The code:
          @sync = Sync.new unless defined?(@sync) and @sync
      becomes:
          @sync = Sync.new unless @sync
      The code:
          unless defined?(@content) and @content
      becomes:
          unless @content
      The code:
          raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if defined?(@indirection) and @indirection
      becomes:
          raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if @indirection

* Replaced 2 occurances of

      defined\?\((.+?)\) (?:and|&&) ! *\1.nil\?

  with

      !\1.nil?

  In code like:

     while defined? @foo and ! @foo.nil? ...

  "defined? @foo and ! @foo.nil?" can safely be replaced with "! @foo.nil?":

     while ! @foo.nil? ...

  Because:

   * Both evaluate to false/nil when @foo is not defined
   * Both evaluate to "! @foo.nil?" when @foo is defined

  2 Examples:

      The code:
          !!(defined?(@value) and ! @value.nil?)
      becomes:
          !!(!@value.nil?)
      The code:
          self.init unless defined?(@@state) and ! @@state.nil?
      becomes:
          self.init unless !@@state.nil?
2010-07-09 18:06:38 -07:00
Markus Roberts 07b15bf6fa Code smell: Avoid unneeded blocks
Replaced 45 occurances of

    (DEF)
        begin
            (LINES)
        rescue(.*)
            (LINES)
        end
    end

with

3 Examples:

    The code:
        def find(name)
            begin
                self.const_get(name.to_s.capitalize)
            rescue
                puts "Unable to find application '#{name.to_s}'."
                Kernel::exit(1)
            end
        end
    becomes:
        def find(name)
                self.const_get(name.to_s.capitalize)
        rescue
                puts "Unable to find application '#{name.to_s}'."
                Kernel::exit(1)
        end
    The code:
        def exit_on_fail(message, code = 1)
            begin
                yield
            rescue RuntimeError, NotImplementedError => detail
                puts detail.backtrace if Puppet[:trace]
                $stderr.puts "Could not #{message}: #{detail}"
                exit(code)
            end
        end
    becomes:
        def exit_on_fail(message, code = 1)
                yield
        rescue RuntimeError, NotImplementedError => detail
                puts detail.backtrace if Puppet[:trace]
                $stderr.puts "Could not #{message}: #{detail}"
                exit(code)
        end
    The code:
        def start
            begin
                case ssl
                when :tls
                    @connection = LDAP::SSLConn.new(host, port, true)
                when true
                    @connection = LDAP::SSLConn.new(host, port)
                else
                    @connection = LDAP::Conn.new(host, port)
                end
                @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
                @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON)
                @connection.simple_bind(user, password)
            rescue => detail
                raise Puppet::Error, "Could not connect to LDAP: #{detail}"
            end
        end
    becomes:
        def start
                case ssl
                when :tls
                    @connection = LDAP::SSLConn.new(host, port, true)
                when true
                    @connection = LDAP::SSLConn.new(host, port)
                else
                    @connection = LDAP::Conn.new(host, port)
                end
                @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
                @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON)
                @connection.simple_bind(user, password)
        rescue => detail
                raise Puppet::Error, "Could not connect to LDAP: #{detail}"
        end
2010-07-09 18:06:37 -07:00
Markus Roberts 8d1fbe4586 Code smell: Avoid explicit returns
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
2010-07-09 18:06:33 -07:00
Markus Roberts 889158ad57 Code smell: Booleans are first class values.
* Replaced 2 occurances of

      def (.*)
          begin
              (.*) = Integer\((.*)\)
              return \2
          rescue ArgumentError
              \2 = nil
          end
          if \2 = (.*)
              return \2
          else
              return false
          end
      end

  with

  2 Examples:

      The code:
          def validuser?(value)
              begin
                  number = Integer(value)
                  return number
              rescue ArgumentError
                  number = nil
              end
              if number = uid(value)
                  return number
              else
                  return false
              end
          end
      becomes:
          def validuser?(value)
              Integer(value) rescue uid(value) || false
          end
      The code:
          def validgroup?(value)
              begin
                  number = Integer(value)
                  return number
              rescue ArgumentError
                  number = nil
              end
              if number = gid(value)
                  return number
              else
                  return false
              end
          end
      becomes:
          def validgroup?(value)
              Integer(value) rescue gid(value) || false
          end

* Replaced 28 occurances of

      return (.*?) if (.*)
      return (.*)

  with

  3 Examples:

      The code:
          return send(options[:mode]) if [:rdoc, :trac, :markdown].include?(options[:mode])
          return other
      becomes:
          return[:rdoc, :trac, :markdown].include?(options[:mode]) ? send(options[:mode]) : other
      The code:
          return true if known_resource_types.definition(name)
          return false
      becomes:
          return(known_resource_types.definition(name) ? true : false)
      The code:
          return :rest if request.protocol == 'https'
          return Puppet::FileBucket::File.indirection.terminus_class
      becomes:
          return(request.protocol == 'https' ? :rest : Puppet::FileBucket::File.indirection.terminus_class)

* Replaced no occurances of

      return (.*?) unless (.*)
      return (.*)

  with

* Replaced 7 occurances of

      if (.*)
          (.*[^:])false
      else
          \2true
      end

  with

  3 Examples:

      The code:
          if RUBY_PLATFORM == "i386-mswin32"
              InstallOptions.ri  = false
          else
              InstallOptions.ri  = true
          end
      becomes:
          InstallOptions.ri  = RUBY_PLATFORM != "i386-mswin32"
      The code:
          if options[:references].length > 1
              with_contents = false
          else
              with_contents = true
          end
      becomes:
          with_contents = options[:references].length <= 1
      The code:
          if value == false or value == "" or value == :undef
              return false
          else
              return true
          end
      becomes:
          return (value != false and value != "" and value != :undef)

* Replaced 19 occurances of

      if (.*)
          (.*[^:])true
      else
          \2false
      end

  with

  3 Examples:

      The code:
          if Puppet::Util::Log.level == :debug
              return true
          else
              return false
          end
      becomes:
          return Puppet::Util::Log.level == :debug
      The code:
          if satisfies?(*features)
              return true
          else
              return false
          end
      becomes:
          return !!satisfies?(*features)
      The code:
          if self.class.parsed_auth_db.has_key?(resource[:name])
              return true
          else
              return false
          end
      becomes:
          return !!self.class.parsed_auth_db.has_key?(resource[:name])

* Replaced 1 occurance of

      if ([a-z_]) = (.*)
          (.*[^:])\1
      else
          \3(.*)
      end

  with

  1 Example:

      The code:
          if c = self.send(@subclassname, method)
              return c
          else
              return nil
          end
      becomes:
          return self.send(@subclassname, method) || nil

* Replaced 2 occurances of

      if (.*)
          (.*[^:])\1
      else
          \2false
      end

  with

  2 Examples:

      The code:
          if hash[:Local]
              @local = hash[:Local]
          else
              @local = false
          end
      becomes:
          @local = hash[:Local]
      The code:
          if hash[:Local]
              @local = hash[:Local]
          else
              @local = false
          end
      becomes:
          @local = hash[:Local]

* Replaced 10 occurances of

      if (.*)
          (.*[^:])(.*)
      else
          \2false
      end

  with

  3 Examples:

      The code:
          if defined?(@isnamevar)
              return @isnamevar
          else
              return false
          end
      becomes:
          return defined?(@isnamevar) && @isnamevar
      The code:
          if defined?(@required)
              return @required
          else
              return false
          end
      becomes:
          return defined?(@required) && @required
      The code:
          if number = uid(value)
              return number
          else
              return false
          end
      becomes:
          return (number = uid(value)) && number

* Replaced no occurances of

      if (.*)
          (.*[^:])nil
      else
          \2(true)
      end

  with

* Replaced no occurances of

      if (.*)
          (.*[^:])true
      else
          \2nil
      end

  with

* Replaced no occurances of

      if (.*)
          (.*[^:])\1
      else
          \2nil
      end

  with

* Replaced 23 occurances of

      if (.*)
          (.*[^:])(.*)
      else
          \2nil
      end

  with

  3 Examples:

      The code:
          if node = Puppet::Node.find(hostname)
              env = node.environment
          else
              env = nil
          end
      becomes:
          env = (node = Puppet::Node.find(hostname)) ? node.environment : nil
      The code:
          if mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?
              return @mounts[MODULES].copy(mod.name, mod.file_directory)
          else
              return nil
          end
      becomes:
          return (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil
      The code:
          if hash.include?(:CA) and hash[:CA]
              @ca = Puppet::SSLCertificates::CA.new()
          else
              @ca = nil
          end
      becomes:
          @ca = (hash.include?(:CA) and hash[:CA]) ? Puppet::SSLCertificates::CA.new() : nil
2010-07-09 18:06:12 -07:00
Markus Roberts 81e283b28c Code smell: Line modifiers are preferred to one-line blocks.
* 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]
2010-07-09 18:06:06 -07:00
Markus Roberts e8cf06336b Code smell: Use string interpolation
* 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
2010-07-09 18:05:55 -07:00
Markus Roberts eefccf2525 Code smell: English names for special globals rather than line-noise
* Replaced 36 occurances of [$][?] with $CHILD_STATUS

  3 Examples:

      The code:
          print "%s finished with exit code %s\n" % [host, $?.exitstatus]
      becomes:
          print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus]
      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, $CHILD_STATUS.exitstatus]
      The code:
          unless $? == 0
      becomes:
          unless $CHILD_STATUS == 0

* Replaced 3 occurances of [$][$] with $PID

  3 Examples:

      The code:
          Process.kill(:HUP, $$) if restart_requested?
      becomes:
          Process.kill(:HUP, $PID) if restart_requested?
      The code:
          if pid == $$
      becomes:
          if pid == $PID
      The code:
          host[:name] = "!invalid.hostname.$$$"
      becomes:
          host[:name] = "!invalid.hostname.$PID$"

* Replaced 7 occurances of [$]& with $MATCH

  3 Examples:

      The code:
          work.slice!(0, $&.length)
      becomes:
          work.slice!(0, $MATCH.length)
      The code:
          if $&
      becomes:
          if $MATCH
      The code:
          if $&
      becomes:
          if $MATCH

* Replaced 28 occurances of [$]:(?!:) with $LOAD_PATH

  3 Examples:

      The code:
          sitelibdir = $:.find { |x| x =~ /site_ruby/ }
      becomes:
          sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
      The code:
          $:.unshift "lib"
      becomes:
          $LOAD_PATH.unshift "lib"
      The code:
          $:.shift
      becomes:
          $LOAD_PATH.shift

* Replaced 3 occurances of [$]! with $ERROR_INFO

  3 Examples:

      The code:
          $LOG.fatal("Problem reading #{filepath}: #{$!}")
      becomes:
          $LOG.fatal("Problem reading #{filepath}: #{$ERROR_INFO}")
      The code:
          $stderr.puts "Couldn't build man pages: " + $!
      becomes:
          $stderr.puts "Couldn't build man pages: " + $ERROR_INFO
      The code:
          $stderr.puts $!.message
      becomes:
          $stderr.puts $ERROR_INFO.message

* Replaced 3 occurances of ^(.*)[$]" with \1$LOADED_FEATURES

  3 Examples:

      The code:
          unless $".index 'racc/parser.rb'
      becomes:
          unless $LOADED_FEATURES.index 'racc/parser.rb'
      The code:
          $".push 'racc/parser.rb'
      becomes:
          $LOADED_FEATURES.push 'racc/parser.rb'
      The code:
          $".should be_include("tmp/myfile.rb")
      becomes:
          $LOADED_FEATURES.should be_include("tmp/myfile.rb")
2010-07-09 18:05:08 -07:00
Markus Roberts 9ee56f2e67 Code smell: Inconsistent indentation and related formatting issues
* 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|
2010-07-09 18:05:04 -07:00
Matt Robinson cdd43825ce [#4114] Fix failures in the unit tests
The initial commit changed the name of a method (close -> close_all) and
changed the way the array log destination worked before we saw that the
unit tests were using it differently.
2010-07-07 11:51:54 -07:00
Jesse Wolfe 4b00c6af91 [#4110] Wrap Type#retrieve calls for backwards compatibility
This patch introduces Type#retrieve_resource as a wrapper for
Type#resource, to coerce the return value from legacy types from Hash to
Resource.

Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-07-07 11:14:51 -07:00
Matt Robinson 174e02a2b7 [#4090] Change how RunMode instances are created so that an object for each RunMode is only created once instead of every time it's called
Got lots of unpredictable test failures, presumably because a new
RunMode was being created every time we accessed the RunMode.
2010-07-01 13:48:03 -07:00
Matt Robinson 62e3b611e6 [#4090] Fix last few tests and renames of mode to run_mode 2010-07-01 13:48:03 -07:00
Jesse Wolfe af41beb05c Remove an old test that had been unintentionally reintroduced by a mistake in a conflict resolution 2010-06-25 18:35:26 -07:00
Jesse Wolfe 6a8e6feb0a Tweak an old test due to new error handling. 2010-06-25 18:27:39 -07:00
Jesse Wolfe e5478d4ff0 Simplify the newattr method by removing a level violation
and update the specs that were testing it.
2010-06-25 18:14:58 -07:00
Markus Roberts db44a32695 Tweak for fix for #1175 to fix test failures
Tests that weren't managing the environment but were still expecting to have
functions defined in it were appalled when the functions/environments binding
actually started working.  This patch fixes those tests.
2010-06-24 15:59:11 -07:00
Matt Robinson 3bd6f11085 maint: Fixing a test typo s/stub/stubs/ 2010-06-24 15:59:11 -07:00
Rein Henrichs af8bd77a9f [#4064] Modify confine to also allow a message and a block containing the test.
This way the test can be evaluated lazily when needed. Adds tests and
documentation.
2010-02-17 06:50:53 -08:00
Nick Lewis 8b127b1851 [#3388] Setting host_aliases from [] to [] no longer results in any changes
The message was "host_aliases changed from 'absent' to ''". When reading from
the hosts file, a host without aliases was considered to have "absent"
host_aliases. The host_aliases list is now considered to be present but empty
if it is absent.
2010-02-17 06:50:53 -08:00
Luke Kanies d6407f46f1 Working #3139 - removing obsolete checking in Storage
We were type-checking the use of Storage for no good reason.

I've removed all of that, so we can use either resources
or their Refs for caching.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-02-17 06:50:53 -08:00
Luke Kanies 0b95a8528e Working #3139 - scheduling moved to resource harness
We previously had the schedule checking code in Puppet::Type,
but it's more of a transactional function, and in order to
do proper auditing in the transactional area, we need the
cache checking done there.  Scheduling is one
of the few functions that actually uses cached data currently.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-02-17 06:50:53 -08:00
Jesse Wolfe 7c6b883645 [#1621] Composite keys for resources
This patch implements the fundamental pieces of the move to composite
keys:
    * Instead of having a single namevar, we have a non-empty collection
      of them, and two resources are the same if and only if all of them
      match.  Note that the present situation is a special case of this,
      where the collection always has exactly one member.
    * As currently, namevar is determined by the type.
    * Instead just of inferring the single namevar from the title we let
      types decompose the title into values for several (perhaps all) of
      the namevar components; note that the present situation is again a
      special case of this.

Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-06-21 14:15:25 -07:00
Markus Roberts 2396ebac90 Use the 'root' feature rather than directly checking the uid
Jesse fixed all these but David and others moved them and introduced some more so...
2010-02-17 06:50:53 -08:00
Jesse Wolfe d1b86ec961 Behavior change for //UNC_Paths broke an old test 2010-02-17 06:50:53 -08:00
Matt Robinson b5f14c6eea {#3866] Rename the method metaclass to singleton_class to avoid the deprecation warnings from Rails ActiveSupport
The metaid.rb file came straight from why the lucky stiff's "seeing
metaclasses clearly" article.  Rails used this too, but they recently
deprecated the name metaclass in favor of singleton_class to match what
ruby-core decided to do.  meta, eigen and singlton class were all
suggested and in the end singleton was agreed upon.

http://redmine.ruby-lang.org/issues/show/1082
2010-02-17 06:50:53 -08:00
Jesse Wolfe b7d387e3e7 Feature #2935 Puppet[:mode] and Puppet[:name] are read-only
Historically, the Puppet[:name] setting has been settable, but the
results of chaning it are poorly defined.
The switch to modes instead of executable names seems like a good time
to disable this complexity.

Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-02-17 06:50:53 -08:00
Jesse Wolfe fc2904955c feature #2276 Single Executable: use new names for settings sections
The puppet-internal settings sections aren't actually exposed to the
user, but to reduce confusion I've renamed them to be consistent with
the single-executable application names.

Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-02-17 06:50:53 -08:00
Luke Kanies e9627a0606 Fixing #2658 - adding backward compatibility for 0.24
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>
2010-02-17 06:50:53 -08:00
Jesse Wolfe 63e2e56d31 feature #2276 Single Executable: subcommand method
Extract the logic to determine the subcommand name into a method.

Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-02-17 06:50:53 -08:00
Luke Kanies d61a69a0e5 Fixing #3668 - fixed autoloading classes from modules
This involved essentially moving all of the importing and loading
code out of the Parser and into a new 'TypeLoader' class.

The parser and the ResourceTypeCollection classes now delegate
to that class for all file handling.  Most of the code paths are
also now much cleaner, and a bit of redundancy was removed.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-02-17 06:50:53 -08:00
Markus Roberts 7c59acfaef Renamed all references to Reductive Labs to Puppet Labs
Find and replace to the rescue...
2010-02-17 06:50:53 -08:00
Luke Kanies ee0cc07544 Fixing #3533 - Removing all transaction cleanup
It's really slow and has no actual functionality
any more, since we just remove the catalogs from memory
anyway.

This should be a good speed boost for very little effort.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-02-17 06:50:53 -08:00
Luke Kanies 8c31ebe7f2 Removing obsolete tests
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 15:09:58 -07:00
Luke Kanies aee9c29403 Fixing a warning in the aix package provider
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 15:02:44 -07:00
Luke Kanies 232ad8fa31 Removing tests for code that was removed in the REST refactor
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 14:59:48 -07:00
Luke Kanies 94fddbc8f7 Fixing and porting Transaction Report tests
There are still a few unported tests, but it's at least
better now.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 14:56:09 -07:00
Jesse Wolfe 66858ef73a Fix test in parser.rb due to API change
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-04-12 13:37:31 -07:00
Luke Kanies 1821187f21 Porting/removing group test/unit tests
Most of it was just complicated, and the rest
useless.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 11:31:32 -07:00
Luke Kanies 03532e0879 Porting a simple set of tests from test/unit
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 11:17:52 -07:00
Luke Kanies 006e6afd6e Removing obsolete test
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-12 11:14:05 -07:00
Jesse Wolfe e31fe8ce42 Fix a failure in new FileBucket where it was impossible to read from a
bucket with a non-default path.

Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
2010-04-09 19:18:56 -07:00
Luke Kanies b643413da5 Removing any mentions of :casesensitive setting
It is a setting that was added years ago as a backward
compatibility option and even if it still works, which
is questionable, it has no purpose any longer.

It just complicated the code and didn't do much, so it's gone
now.

Also simplified the interface of Leaf#evaluate_match, since it
was now using none of the passed-in options.

Finally, removed/migrated the last of the Selector/CaseStatement
test/unit tests.

Signed-off-by: Luke Kanies <luke@puppetlabs.com>
2010-04-09 16:02:32 -07:00
Luke Kanies 0d704686b9 Finishing renaming :params to :parameters internally
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>
2010-02-17 06:50:53 -08:00
Luke Kanies 6e4db8261a Fixing type/title resource resolution
This code is impressively difficult, because
sometimes resource types act like resources (classes
and nodes are singletons) and sometimes like resource
types (defined and builtin resources).

So, to get nodes to show as Node[foo] and classes as
Class[Foo::Bar], but defined resources to show up as
Foo::Bar[baz], we have to do some silliness.

Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00
Luke Kanies 9c867e6d79 Fixing most of the broken tests in test/
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>
2010-02-17 06:50:53 -08:00
Luke Kanies 7089446697 Removing Resource::Reference classes
This commit is hopefully less messy than it
first appears, but it's certainly cross-cutting.

The reason for all of this is that we previously only
looked up builtin resource types from outside the parser,
but now that the defined resource types are available globally
via environments, we can push that lookup code to Resource.

Once we do that, however, we have to have environment and
namespace information in every resource.

Here I remove the Resource::Reference classes (except
the AST class), and use Resource instances instead. I
did this because the shared code between the two classes
got incredibly complicated, such that they should have had
a hierarchical relationship disallowed by their constants.
This complexity convinced me just to get rid of References
entirely.

I also make Puppet::Parser::Resource a subclass
of Puppet::Resource.

There are still broken tests in test/, but this was a big
enough commit I wanted to get it in.

Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00
Luke Kanies 2fa0a489e2 Adding parameter validation to Puppet::Resource
This will allow us to remove all of the parameter
validation from the other Resource classes.

This is possible because resource types defined
in the language are visible outside of the parser,
via the environment.

This will enable lots of code removal and simplication.

Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00
Jesse Wolfe 1603f73637 Feature #3394 REST Runner, preparation
Rename Puppet::Agent::Runner to Puppet::Run, for consistency
2010-02-17 06:50:53 -08:00
Jesse Wolfe e5a78009f6 Feature #3347 REST-ified FileBucket
FileBucket Files have been reimplemented as an indirector terminus so that
they can be transmitted over REST.
The old Network::Client.dipper has been replaced with a compatibility later
in FileBucket::Dipper that uses the indirector to access filebucket termini.

Slightly revised patch:
* No longer allows nil contents in FileBucket outside of initialization
* Uses File.exist? instead of the deprecated File.exists?
* Tweaks JSON serialization and de-serialization to include "path"

Deferred issues:
* Feature #3371 "FileBucket should not keep files in memory".
* Feature #3372 "Replace FileBucket Dipper with more idiomatic calls"
2010-02-17 06:50:53 -08:00
Markus Roberts 7504f1ede9 Resolving conflicts with ??? 2010-02-17 06:50:53 -08:00
Luke Kanies d0389f4d16 Renaming Parser::ResourceType to Resource::Type
Basically, these classes (ResourceType and ResourceTypeCollection)
don't really belong in Parser, so I'm moving them to the
Resource namespace.  This will be where anything RAL-related goes
from now on, and as we migrate functionality out of Puppet::Type,
it should go here.

Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00
Luke Kanies 201889bd30 Renaming LoadedCode to ResourceTypeCollection
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00
Luke Kanies 6bf1953271 Removing old, never-used DSL code
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00
Jesse Wolfe ce944a5d9a Fix unit tests in file/target.rb 2010-02-17 06:50:53 -08:00
Jesse Wolfe 481ddb845c Name change of event in ral/type/exec.rb 2010-02-17 06:50:53 -08:00
Jesse Wolfe 1ebc91e1bd Use a helper function to evaluate a resource since the API has changed 2010-02-17 06:50:53 -08:00
Jesse Wolfe bfb1fa5ebc Allow skipped resources to process events 2010-02-17 06:50:53 -08:00
Jesse Wolfe 50ed75b5c2 Remove test that tests internal class structures which have changed. 2010-02-17 06:50:53 -08:00
Jesse Wolfe 177907935b Remove stale set_trigger
Delete tests that are superceded by specs in "Changing Transaction to
use the new ResourceHarness"
2010-02-17 06:50:53 -08:00
Jesse Wolfe 2a2ab75967 Fix test failures due to name changes of event symbols 2010-02-17 06:50:53 -08:00
Jesse Wolfe 0a72a98c16 Remove rollback test, since rollback was removed. 2010-02-17 06:50:53 -08:00
Luke Kanies 0f768ed335 Removing now-obsolete user tests
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
2010-02-17 06:50:53 -08:00