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

data-in-modules: missing facts during building of the hierarchy fails the lookup completely and silently

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.7.0, PUP 4.8.0
    • Fix Version/s: PUP 4.9.0
    • Component/s: None
    • Labels:
      None
    • Template:
    • Team:
      Puppet Developer Experience
    • Story Points:
      1
    • Sprint:
      PDS 2016-11-16, PDS 2016-11-30
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      when using certain types of puppet variables data in modules could fail silently to lookup values interpolated from these variables.
    • QA Risk Assessment:
      No Action
    • QA Risk Assessment Reason:
      improvement of error messaging; covered well by unit tests.

      Description

      When building the hierarchy for looking up data in modules, lib/puppet/data_providers/hiera_config.rb the interpolation around https://github.com/puppetlabs/puppet/blob/4.7.0/lib/puppet/data_providers/hiera_config.rb#L101 does weird things causing the whole lookup to fail, instead of

      • ignoring that hierarchy level
      • reporting a specific error

      This can easily be reproduced by adding the following code to spec/classes/test_spec.rb into https://github.com/puppetlabs/puppetlabs-ntp/tree/c4f586c8eabc879837942febbb70d30dc4d614ac and running

      bundle install --without system_tests
      bundle exec rake spec_prep
      bundle exec rspec spec/classes/test_spec.rb
      

      require 'spec_helper'
       
      describe 'ntp' do
        before :each do
          Puppet[:trace]= true
        end
        context "false negatives" do
          context 'without facts' do
            # "restrict" is the only reqired parameter with only OS defaults.
            it { is_expected.to compile.and_raise_error(/expects a value for parameter 'restrict' at line 1/) }
          end
       
          context 'with only the required fact' do
            # hiera.yaml uses os.family to locate data/Debian.yaml,
            # which contains a ntp::restrict value
            let :facts do
              {
                os: {
                  family: 'Debian',
                }
              }
            end
       
            it { is_expected.to compile }
          end
        end
       
        context "passing tests" do
          context 'with any facts' do
            # these facts do not match any of the existing data files
            # only common.yaml is used
            let :facts do
              {
                os: {
                  name: 'foo',
                  family: 'foo',
                  release: { major: 'foo', full: 'foo' }
                },
                operatingsystem: 'foo'
              }
            end
       
            it { is_expected.to compile.and_raise_error(/expects a value for parameter 'restrict' at line 1/) }
          end
       
          context 'with full facts' do
            # all facts provided
            let :facts do
              {
                os: {
                  name: 'Debian',
                  family: 'Debian',
                  release: { major: 'stretch/sid', full: 'stretch/sid' }
                },
                operatingsystem: 'foo'
              }
            end
       
            it { is_expected.to compile }
          end
        end
      end
      

      Expected Outcome: all these tests pass.

      Actual outcome:

      david@zion:~/git/puppetlabs-ntp$ bundle exec rspec spec/classes/test_spec.rb 
       
      ntp
        false negatives
          without facts
            should fail to compile and raise an error matching /expects a value for parameter 'restrict' at line 1/ (FAILED - 1)
          with only the required fact
            should compile into a catalogue without dependency cycles (FAILED - 2)
        passing tests
          with any facts
            should fail to compile and raise an error matching /expects a value for parameter 'restrict' at line 1/
          with full facts
            should compile into a catalogue without dependency cycles
       
      Failures:
       
        1) ntp false negatives without facts should fail to compile and raise an error matching /expects a value for parameter 'restrict' at line 1/
           Failure/Error: it { is_expected.to compile.and_raise_error(/expects a value for parameter 'restrict' at line 1/) }
           
             error during compilation: Evaluation Error: Error while evaluating a Function Call, Class[Ntp]:
               expects a value for parameter 'broadcastclient'
               expects a value for parameter 'config'
               expects a value for parameter 'config_dir'
               expects a value for parameter 'config_file_mode'
               expects a value for parameter 'config_epp'
               expects a value for parameter 'config_template'
               expects a value for parameter 'disable_auth'
               expects a value for parameter 'disable_dhclient'
               expects a value for parameter 'disable_kernel'
               expects a value for parameter 'disable_monitor'
               expects a value for parameter 'fudge'
               expects a value for parameter 'driftfile'
               expects a value for parameter 'leapfile'
               expects a value for parameter 'logfile'
               expects a value for parameter 'iburst_enable'
               expects a value for parameter 'keys'
               expects a value for parameter 'keys_enable'
               expects a value for parameter 'keys_file'
               expects a value for parameter 'keys_controlkey'
               expects a value for parameter 'keys_requestkey'
               expects a value for parameter 'keys_trusted'
               expects a value for parameter 'minpoll'
               expects a value for parameter 'maxpoll'
               expects a value for parameter 'package_ensure'
               expects a value for parameter 'package_manage'
               expects a value for parameter 'package_name'
               expects a value for parameter 'panic'
               expects a value for parameter 'peers'
               expects a value for parameter 'preferred_servers'
               expects a value for parameter 'restrict'
               expects a value for parameter 'interfaces'
               expects a value for parameter 'interfaces_ignore'
               expects a value for parameter 'servers'
               expects a value for parameter 'service_enable'
               expects a value for parameter 'service_ensure'
               expects a value for parameter 'service_manage'
               expects a value for parameter 'service_name'
               expects a value for parameter 'service_provider'
               expects a value for parameter 'stepout'
               expects a value for parameter 'step_tickers_file'
               expects a value for parameter 'step_tickers_epp'
               expects a value for parameter 'step_tickers_template'
               expects a value for parameter 'tinker'
               expects a value for parameter 'tos'
               expects a value for parameter 'tos_minclock'
               expects a value for parameter 'tos_minsane'
               expects a value for parameter 'tos_floor'
               expects a value for parameter 'tos_ceiling'
               expects a value for parameter 'tos_cohort'
               expects a value for parameter 'udlc'
               expects a value for parameter 'udlc_stratum'
               expects a value for parameter 'ntpsigndsocket'
               expects a value for parameter 'authprov' at line 1:1 on node zion.black.co.at
           # ./spec/classes/test_spec.rb:10:in `block (4 levels) in <top (required)>'
       
        2) ntp false negatives with only the required fact should compile into a catalogue without dependency cycles
           Failure/Error: it { is_expected.to compile }
           
             error during compilation: Evaluation Error: Error while evaluating a Function Call, Class[Ntp]:
               expects a value for parameter 'broadcastclient'
               expects a value for parameter 'config'
               expects a value for parameter 'config_dir'
               expects a value for parameter 'config_file_mode'
               expects a value for parameter 'config_epp'
               expects a value for parameter 'config_template'
               expects a value for parameter 'disable_auth'
               expects a value for parameter 'disable_dhclient'
               expects a value for parameter 'disable_kernel'
               expects a value for parameter 'disable_monitor'
               expects a value for parameter 'fudge'
               expects a value for parameter 'driftfile'
               expects a value for parameter 'leapfile'
               expects a value for parameter 'logfile'
               expects a value for parameter 'iburst_enable'
               expects a value for parameter 'keys'
               expects a value for parameter 'keys_enable'
               expects a value for parameter 'keys_file'
               expects a value for parameter 'keys_controlkey'
               expects a value for parameter 'keys_requestkey'
               expects a value for parameter 'keys_trusted'
               expects a value for parameter 'minpoll'
               expects a value for parameter 'maxpoll'
               expects a value for parameter 'package_ensure'
               expects a value for parameter 'package_manage'
               expects a value for parameter 'package_name'
               expects a value for parameter 'panic'
               expects a value for parameter 'peers'
               expects a value for parameter 'preferred_servers'
               expects a value for parameter 'restrict'
               expects a value for parameter 'interfaces'
               expects a value for parameter 'interfaces_ignore'
               expects a value for parameter 'servers'
               expects a value for parameter 'service_enable'
               expects a value for parameter 'service_ensure'
               expects a value for parameter 'service_manage'
               expects a value for parameter 'service_name'
               expects a value for parameter 'service_provider'
               expects a value for parameter 'stepout'
               expects a value for parameter 'step_tickers_file'
               expects a value for parameter 'step_tickers_epp'
               expects a value for parameter 'step_tickers_template'
               expects a value for parameter 'tinker'
               expects a value for parameter 'tos'
               expects a value for parameter 'tos_minclock'
               expects a value for parameter 'tos_minsane'
               expects a value for parameter 'tos_floor'
               expects a value for parameter 'tos_ceiling'
               expects a value for parameter 'tos_cohort'
               expects a value for parameter 'udlc'
               expects a value for parameter 'udlc_stratum'
               expects a value for parameter 'ntpsigndsocket'
               expects a value for parameter 'authprov' at line 1:1 on node zion.black.co.at
           # ./spec/classes/test_spec.rb:24:in `block (4 levels) in <top (required)>'
       
      Finished in 2.14 seconds (files took 0.719 seconds to load)
      4 examples, 2 failures
       
      Failed examples:
       
      rspec ./spec/classes/test_spec.rb:10 # ntp false negatives without facts should fail to compile and raise an error matching /expects a value for parameter 'restrict' at line 1/
      rspec ./spec/classes/test_spec.rb:24 # ntp false negatives with only the required fact should compile into a catalogue without dependency cycles
       
      david@zion:~/git/puppetlabs-ntp$ 
      

      The first two tests ("without facts", and "with only the required fact") fail with none of the values with default values in common.yaml being applied. The "with full facts" one has all the facts for the hierarchy and suddenly works, although only the os.family should be required. The last one ("with any facts") shows that even specifying nonsensical values is sufficient to make the tests pass.

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  david.schmitt David Schmitt
                  QA Contact:
                  Eric Thompson
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Zendesk Support