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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.4.0
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      1
    • Sprint:
      Language 2016-02-10
    • Release Notes:
      Not Needed
    • Release Notes Summary:
      this is a change in an enabler/service for Puppet Server/NC.

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeremy.barlow Jeremy Barlow
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support