puppetlabs / puppet_litmus

Providing a simple command line tool for puppet content creators, to enable simple and complex test deployments.
Apache License 2.0
88 stars 56 forks source link

Argument mismatch between ServerSpec @runner.run_command and BoltSpec::Run::run_command #227

Closed baron1405 closed 4 years ago

baron1405 commented 4 years ago

Describe the Bug

Attempting to call linux_kernel_parameter from my Litmus acceptance tests results in:

> Error while executing command: rake
  pdk (INFO): Using Ruby 2.5.7
  pdk (INFO): Using Puppet 6.11.1
  ================
  localhost:2222, waffleimage/centos7
  .F

  Failures:

    1) inotify Configure kernel inotify parameters Linux kernel parameter "fs.inotify.max_user_instances" value 
       On host `localhost:2222'
       Failure/Error: its(:value) { is_expected.to eq(256) }
       ArgumentError:
         wrong number of arguments (given 1, expected 2)

       # /opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/bolt-1.42.0/lib/bolt_spec/run.rb:51:in `run_command'
       # /opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/serverspec-2.41.5/lib/serverspec/type/linux_kernel_parameter.rb:4:in `value'
       # ./spec/acceptance/inotify_spec.rb:14:in `block (4 levels) in <top (required)>'

Looking at the code identified in the stack trace we find that the ServerSpec linux_kernel_parameter code call run_command on line 4 as:

module Serverspec::Type
  class LinuxKernelParameter < Base
    def value
      ret = @runner.run_command("/sbin/sysctl -q -n #{@name}")
      val = ret.stdout.strip
      val = val.to_i if val.match(/^\d+$/)
      val
    end
  end
end

However, this results in a call to BoltSpec::Run's run_command which is defined as:


    def run_command(command, targets, options: {}, config: nil, inventory: nil)
      if config.nil? && defined?(bolt_config)
        config = bolt_config
      end

      if inventory.nil? && defined?(bolt_inventory)
        inventory = bolt_inventory
      end

      result = BoltRunner.with_runner(config, inventory) do |runner|
        runner.run_command(command, targets, options)
      end
      result = result.to_a
      Bolt::Util.walk_keys(result, &:to_s)
    end

So ServerSpec passes a single argument but BoltSpec expects two arguments.

This problem appears to effect all ServerSpec types that call run_command.

Expected Behavior

Successful call to linux_kernel_parameter.

Steps to Reproduce

Here is the relevant portion of my acceptance test:

    context linux_kernel_parameter('fs.inotify.max_user_instances') do
      its(:value) { is_expected.to eq(256) }
    end

Environment

DavidS commented 4 years ago

Thanks for your report. I think the issue you're experiencing is fixed by https://github.com/puppetlabs/puppet_litmus/pull/226 . Can you confirm that current master fixes this for you?

baron1405 commented 4 years ago

@DavidS I'd be happy to try this but can you tell me what to put where to ensure I am testing against the current master. Thanks!

DavidS commented 4 years ago

You can use the git source in the Gemfile of your module to point to this repository and use master (or any other repo and branch).

Since we did a number of releases since then, you can now also upgrade to the newest PDK instead and use the version shipped there.

Feel free to re-open this, or file a new issue if this is still a problem for you.

shaun-rutherford commented 4 years ago

Hi @DavidS I'm still seeing this issue despite being on the latest PDK: pdk --version 1.18.1

Error Message:

08:12:23   1) user and configuration validation Command "/sbin/sssctl config-check" exit_status 
08:12:23      On host `127.0.0.1:2201'
08:12:23      Failure/Error: its(:exit_status) { is_expected.to eq(0) }
08:12:23      ArgumentError:
08:12:23        wrong number of arguments (given 1, expected 2)
08:12:23        
08:12:23      # /root/.pdk/cache/ruby/2.5.0/gems/bolt-2.19.0/lib/bolt_spec/run.rb:51:in `run_command'
08:12:23      # /opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/serverspec-2.41.5/lib/serverspec/type/command.rb:23:in `command_result'
08:12:23      # /opt/puppetlabs/pdk/share/cache/ruby/2.5.0/gems/serverspec-2.41.5/lib/serverspec/type/command.rb:18:in `exit_status'
08:12:23      # ./spec/acceptance/validation_spec.rb:40:in `block (3 levels) in <top (required)>'

Code Ran:

  describe command('/sbin/sssctl config-check') do
    its(:exit_status) { is_expected.to eq(0) }
  end

Could you please advise?