Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5809

ClassInformationService.classes_per_environment returns classes as array rather than nested in hash



    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • PUP 4.4.0
    • None
    • None
    • Not Needed
    • this is a change in an enabler/service for Puppet Server/NC.


      In the original description of the classes_per_environment method in PUP-4819, the sample aggregrated result looked like this:

      'environment' => {
        'filename' => {
          :error     => 'errormessage',
          :classes => [
            { :name => 'classname',
              :params => [
                { :name => 'paramname',
                  :type => 'puppettype',
                  :default_source => '....',
                  :default_literal => <OBJECT>
               # next param
            # next class
        # next file
      # next env

      When I use the classes_per_environment method, a successful parse includes the classes as an array rather than as the value of a key named :classes in the hash.

      For example, I used the following code...

      require 'puppet'
      require 'puppet/info_service'
      files_to_parse = { "production" => [ "./parse.pp" ] }
      puts Puppet::InfoService::ClassInformationService.new.classes_per_environment(files_to_parse)

      ... to parse the following "./parse.pp" file:

      class myclass (String $string_with_single_quotes = "$::osfamily",
                     String $string_with_double_quotes = "string with double quotes",
                     Fubar $foo = "bar"

      The output from the Ruby code is...

      {"production"=>{"./parse.pp"=>[{:name=>"myclass", :params=>[{:name=>"string_with_single_quotes", :type=>"String", :default_source=>"\"$::osfamily\""}, {:name=>"string_with_double_quotes", :type=>"String", :default_literal=>"string with double quotes", :default_source=>"\"string with double quotes\""}, {:name=>"foo", :type=>"Fubar", :default_literal=>"bar", :default_source=>"\"bar\""}]}]}}

      ... whereas I was thinking that the "classes" array would be wrapped in a hash like this ...

      {"production"=>{"./parse.pp"=>{:classes=>[{:name=>"myclass", :params=>[{:name=>"string_with_single_quotes", :type=>"String", :default_source=>"\"$::osfamily\""}, {:name=>"string_with_double_quotes", :type=>"String", :default_literal=>"string with double quotes", :default_source=>"\"string with double quotes\""}, {:name=>"foo", :type=>"Fubar", :default_literal=>"bar", :default_source=>"\"bar\""}]}]}}}

      When an :error is returned instead of the "classes" array, it is wrapped in a subordinate hash, like this:

      {"production"=>{"./parse.pp"=>{:error=>"This Name has no effect. A value was produced and then forgotten (one or more preceding expressions may have the wrong form) at ./parse.pp:1:1"}}}

      I think for consistency and for future expansion of the data structure - e.g., if we ever want to add more per-file metadata in the response than just "classes" - that it would be good to wrap the "classes" array in a Hash under the :classes key, as the description in PUP-5807 originally called for.


        Issue Links



              Unassigned Unassigned
              jeremy.barlow Jeremy Barlow
              0 Vote for this issue
              3 Start watching this issue



                Zendesk Support