Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puppet user type fails using rspec-puppet-augeas #18

Open
gtjwilkicki opened this issue Feb 3, 2016 · 0 comments
Open

Puppet user type fails using rspec-puppet-augeas #18

gtjwilkicki opened this issue Feb 3, 2016 · 0 comments

Comments

@gtjwilkicki
Copy link

I have written an rspec for an augeas resource I want to test and I'm getting an error when I try to run the test:

Failure/Error: should execute.with_change
    NoMethodError:
      Could not create resources for managing Puppet's files and directories in sections [:main]: undefined method `exists?' for nil:NilClass
      undefined method `exists?' for nil:NilClass
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/type/user.rb:382:in `exists?'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings.rb:800:in >`service_user_available?'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings/file_setting.rb:52:in `safe_to_use_settings_value?'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings/file_setting.rb:43:in `value'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings/file_setting.rb:106:in `owner'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings/file_setting.rb:160:in `to_resource'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings.rb:916:in `block in to_catalog'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings.rb:912:in `each'
   # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings.rb:912:in `to_catalog'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/settings.rb:982:in `use'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/util/storage.rb:45:in `load'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/resource/catalog.rb:163:in `apply'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/rspec-puppet-augeas-0.4.0/lib/rspec-puppet-augeas/fixtures.rb:61:in `apply'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/rspec-puppet-augeas-0.4.0/lib/rspec-puppet-augeas/resource.rb:17:in `initialize'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/rspec-puppet-augeas-0.4.0/lib/rspec-puppet-augeas/example/run_augeas_example_group.rb:69:in `new'
    # /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/rspec-puppet-augeas-0.4.0/lib/rspec-puppet-augeas/example/run_augeas_example_group.rb:69:in `subject'
    # ./spec/classes/system_spec.rb:26:in `block (3 levels) in '
    # ------------------
    # --- Caused by: ---
    # NoMethodError:
    #   undefined method `exists?' for nil:NilClass
    #   /home/jwilkicki/.rvm/gems/ruby-2.1.5/gems/puppet-3.8.3/lib/puppet/type/user.rb:382:in > `exists?'

My spec_helper looks like this:

require 'rubygems'
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-augeas'

# Create temporary config file
require 'erb'
require 'fileutils'
require 'tempfile'
require 'tmpdir'

tempdir = Dir.mktmpdir("my-spec")
parentdir = File.dirname(File.expand_path(__FILE__))
config_template = File.join(parentdir,'fixtures','puppet','puppet.conf.erb')

renderer = ERB.new(File.read(config_template))

user = Etc.getpwuid(Process.uid).name

temp_conf_name = File.join(tempdir,"puppet.conf")
temp_conf = File.open(temp_conf_name,"w+")

begin
  temp_conf.puts(renderer.result(binding))
ensure
  temp_conf.close
end

RSpec.configure do |c|
   c.config = temp_conf_name
   c.module_path = File.join(parentdir, 'fixtures', 'modules')
   c.manifest_dir = File.join(parentdir, 'fixtures', 'manifests')
  c.augeas_fixtures = File.join(parentdir,'fixtures','augeas')

  c.after(:all) do
    FileUtils.remove_entry_secure(tempdir,true)
  end
end

The code with the temp file is my attempt to provide a custom puppet.conf that forces the user to be the process owner, since issue 15 seemed to indicate that Puppet might not like running as a non-root user. I've also tried without a custom puppet.conf, per the example in the README file.

My spec is pretty basic:

require 'spec_helper'

describe 'my::class' do

   describe 'has augeas resource' do
          it {
              should contain_augeas('my attrs')
         }
  end
end

Puppet version is 3.8.3 and I'm using rspec 3.4.0 with rspec-puppet-augeas 0.4.0 on Ruby 2.1.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant