I need some help here. I have a simple augeas resource that changes a line in the /etc/sysconfig/iptables-config file. I am trying to write an rspec test for this and it's not working.
Â
RHEL7, pdk 1.10. I do not have any augeas packages installed, only using what is bundled with pdk 1.10.
Â
If my augeas resource specifies the incl and lens attributes, the test doesn't work at all, complaining that Shellvars.lns cannot be found.
Â
If my augeas resource specifies the context attribute and does not specify a lens (augeas uses Shellvars for this file by default anyway), the execute.with_change fails, but verifying the changes via aug_get and checking execute.idempotently both succeed.
Â
Below I have the four combinations of the above and the output generated. At the very bottom is my spec_helper.rb file.
The IPTABLES_MODULES value is "" in the iptables-config file in the spec/fixtures/augeas/etc/sysconfig directory.
Â
Â
Augeas resource:
 augeas { 'set_iptables_modules':  incl  => '/etc/sysconfig/iptables-config',  lens  => 'Shellvars.lns',  changes => [   "set IPTABLES_MODULES '\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\"'"  ] }
Â
Â
Spec test:
 describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do  it 'specifies the kernel modules to load in the iptables configuration' do   is_expected.to execute.with_change   expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"'   is_expected.to execute.idempotently  end end
Â
Â
Output:
bsirinek@mydevhost $ pdk test unitpdk (INFO): Using Ruby 2.4.5pdk (INFO): Using Puppet 5.5.12[✔] Preparing to run the unit tests.
[✖] Running unit tests.
Run options: exclude {:bolt=>true} Evaluated 18 tests in 9.488949739 seconds: 1 failures, 0 pending.failed: rspec: ./spec/classes/init_spec.rb:29: Augeas[set_iptables_modules] fails when executing:debug: Opening augeas with root /tmp/rspec-puppet-augeas20190625-14571-apd4ov, lens path , flags 64debug: Augeas version 1.8.1 is installedwarning: Loading failed for one or more files, see debug for /augeas//error outputdebug: /augeas/load/Xfm/error = Can not find lens Shellvars.lnsdebug: Will attempt to save and only run if files changeddebug: sending command 'set' with params ["/files/etc/sysconfig/iptables-config/IPTABLES_MODULES", "\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\""]debug: Closed the augeas connectionerr: Could not evaluate: Saving failed, see debug sebastion Augeas[set_iptables_modules] specifies the kernel modules to load in the iptables configuration Failure/Error:   describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do   it 'specifies the kernel modules to load in the iptables configuration' do    is_expected.to execute.with_change    expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"' Total resources:  13Touched resources: 13Resource coverage: 100.00%
Â
Â
Â
Â
Â
Â
Augeas resource:
 augeas { 'set_iptables_modules':  context => '/files/etc/sysconfig/iptables-config',  changes => [   "set IPTABLES_MODULES '\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\"'"  ] }
Â
Â
Spec test:
 describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do  it 'specifies the kernel modules to load in the iptables configuration' do   is_expected.to execute.with_change   expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"'   is_expected.to execute.idempotently  end end
Â
Â
Output:
bsirinek@mydevhost $ pdk test unitpdk (INFO): Using Ruby 2.4.5pdk (INFO): Using Puppet 5.5.12[✔] Preparing to run the unit tests.
[✖] Running unit tests.
Run options: exclude {:bolt=>true} Evaluated 18 tests in 9.104591825 seconds: 1 failures, 0 pending.failed: rspec: ./spec/classes/init_spec.rb:29: Augeas[set_iptables_modules] doesn't change when executed:debug: Opening augeas with root /tmp/rspec-puppet-augeas20190625-16038-6r286s, lens path , flags 32debug: Augeas version 1.8.1 is installeddebug: Will attempt to save and only run if files changeddebug: sending command 'set' with params ["/etc/sysconfig/iptables-config/IPTABLES_MODULES", "\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\""]debug: Skipping because no files were changeddebug: Closed the augeas connection sebastion Augeas[set_iptables_modules] specifies the kernel modules to load in the iptables configuration Failure/Error:   describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do   it 'specifies the kernel modules to load in the iptables configuration' do    is_expected.to execute.with_change    expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"' Total resources:  13Touched resources: 13Resource coverage: 100.00%
Â
Â
Â
Augeas resource:
 augeas { 'set_iptables_modules':  incl  => '/etc/sysconfig/iptables-config',  lens  => 'Shellvars.lns',  changes => [   "set IPTABLES_MODULES '\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\"'"  ] }
Â
Â
Spec test:
 describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do  it 'specifies the kernel modules to load in the iptables configuration' do   #is_expected.to execute.with_change   expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"'   is_expected.to execute.idempotently  end end
Â
Â
Output:
bsirinek@mydevhost $ pdk test unitpdk (INFO): Using Ruby 2.4.5pdk (INFO): Using Puppet 5.5.12[✔] Preparing to run the unit tests.
[✖] Running unit tests.
Run options: exclude {:bolt=>true} Evaluated 18 tests in 8.827282266 seconds: 1 failures, 0 pending.failed: rspec: ./spec/classes/init_spec.rb:29: Augeas[set_iptables_modules] fails when executing:debug: Opening augeas with root /tmp/rspec-puppet-augeas20190625-18357-10z5g08, lens path , flags 64debug: Augeas version 1.8.1 is installedwarning: Loading failed for one or more files, see debug for /augeas//error outputdebug: /augeas/load/Xfm/error = Can not find lens Shellvars.lnsdebug: Will attempt to save and only run if files changeddebug: sending command 'set' with params ["/files/etc/sysconfig/iptables-config/IPTABLES_MODULES", "\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\""]debug: Closed the augeas connectionerr: Could not evaluate: Saving failed, see debug sebastion Augeas[set_iptables_modules] specifies the kernel modules to load in the iptables configuration Failure/Error:   describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do   it 'specifies the kernel modules to load in the iptables configuration' do    #is_expected.to execute.with_change    expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"' Total resources:  13Touched resources: 13Resource coverage: 100.00%
Â
Â
Â
Augeas resource: augeas { 'set_iptables_modules':  context => '/files/etc/sysconfig/iptables-config',  changes => [   "set IPTABLES_MODULES '\"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4\"'"  ] }
Â
Â
Spec test:
 describe_augeas 'set_iptables_modules', :lens => 'Shellvars', :target => 'etc/sysconfig/iptables-config' do  it 'specifies the kernel modules to load in the iptables configuration' do   #is_expected.to execute.with_change   expect(aug_get('IPTABLES_MODULES')) == '"iptable_nat ip_conntrack nf_nat_tftp nf_conntrack_ipv4"'   is_expected.to execute.idempotently  end end
Â
Â
Output:
bsirinek@mydevhost $ pdk test unitpdk (INFO): Using Ruby 2.4.5pdk (INFO): Using Puppet 5.5.12[✔] Preparing to run the unit tests.
[✔] Running unit tests.
Run options: exclude {:bolt=>true} Evaluated 18 tests in 9.325532779 seconds: 0 failures, 0 pending. Total resources:  13Touched resources: 13Resource coverage: 100.00%
Â
Â
RSpec.configure do |c| c.mock_with :rspecend require 'puppetlabs_spec_helper/module_spec_helper'require 'rspec-puppet-facts' require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) include RspecPuppetFacts default_facts = { puppetversion: Puppet.version, facterversion: Facter.version,} default_fact_files = [ File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')),] default_fact_files.each do |f| next unless File.exist?(f) && File.readable?(f) && File.size?(f)  begin  default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) rescue => e  RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" endend RSpec.configure do |c| c.default_facts = default_facts c.hiera_config = 'spec/fixtures/hiera/hiera.yaml' c.before :each do  # set to strictest setting for testing  # by default Puppet runs at warning level  Puppet.settings[:strict] = :warning end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do  RSpec::Puppet::Coverage.report!(0) endend def ensure_module_defined(module_name) module_name.split('::').reduce(Object) do |last_module, next_module|  last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false)  last_module.const_get(next_module, false) endend # 'spec_overrides' from sync.yml will appear below this linerequire 'rspec-puppet-augeas'require 'octofacts'RSpec.configure do |c|c.default_formatter = 'doc'c.augeas_fixtures = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures', 'augeas')endrequire 'puppetlabs_spec_helper/module_spec_helper'ENV["OCTOFACTS_FIXTURE_PATH"] ||= File.expand_path("fixtures/facts/octofacts", File.dirname(__FILE__))ENV["OCTOFACTS_INDEX_PATH"]  ||= File.expand_path("fixtures/facts/octofacts-index.yaml", File.dirname(__FILE__))
Â
ENV['AUGEAS_LENS_LIB']='/opt/puppetlabs/puppet/share/augeas/lenses/dist'
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d7c413e7-aaea-4871-884a-d6565d36910b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.