Ask Your Question
0

beaker simulate puppet agent -t

asked 2017-10-27 08:11:38 -0600

louis gravatar image

I started using beaker rspec and would like to simulate a puppet agent -t in order to run some module testing.

default.yaml

HOSTS:
  ubuntu-1404-x64-master:
    roles:
      - agent
      - default
      - master
      - dashboard
      - database
    platform: ubuntu-14.04-amd64
    hypervisor: vagrant
    vagrant_memsize: 4096
    box: puppetlabs/ubuntu-14.04-64-nocm
CONFIG:
  type: foss
  consoleport: 443

spechelperacceptance.rb

require 'beaker-rspec'
#require 'beaker-rspec/spec_helper'
#require 'beaker-rspec/helpers/serverspec'
require 'beaker/puppet_install_helper'
#require 'beaker/module_install_helper'

# Install Puppet on all hosts
install_puppet_agent_on(hosts, options)
run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no'

RSpec.configure do |c|
  module_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))

  c.formatter = :documentation

  c.before :suite do
    # Install module to all hosts
    hosts.each do |host|
      install_dev_puppet_module_on(host, :source => module_root, :module_name => 'lm3corp_rsyslog',
          :target_module_path => '/etc/puppetlabs/code/environments/production/modules')
      # Install dependencies
      on(host, puppet('module', 'install', 'puppetlabs-stdlib'))
      on(host, puppet('module', 'install', 'saz-rsyslog'))
      # Add more setup code as needed
    end
  end
end

test_spec.rb

require 'spec_helper_acceptance'

apply_manifests_opts = {
  :catch_failures => true,
  :modulepath     => '/etc/puppetlabs/code/environments/production/modules',
  :debug          => true
}

describe 'my_wrapper_class::client class' do
  pp = <<-EOS
    class { 'my_wrapper_class::client': }
  EOS


  it 'should run without errors' do
    result = apply_manifest(pp, apply_manifests_opts )
    expect(result.exit_code).to eq 2
  end

  #TODO: after creating a server and a client a file on the server should contain some sort of logging from the client
  #

end

In the output I can see that beaker executed the manifest with puppet apply. Is there a way to set the command to

puppet agent -t

 puppet apply --debug --detailed-exitcodes --modulepath=/etc/puppetlabs/code/environments/production/modules /tmp/apply_manifest.pp.mZvSN6
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-11-09 15:27:57 -0600

updated 2017-11-09 15:29:48 -0600

Try setting the environment variable BEAKER_debug="true" for showing the full beaker run.

When using apply_manifest, the full list of options are here:

http://www.rubydoc.info/gems/beaker/2.4.1/Beaker/DSL/Helpers#applymanifeston-instance_method

Every flag that's available from a puppet run should be there.

What you're trying to achieve, could look something like this:

require 'spec_helper_acceptance'

describe 'foo', unless: UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
    it 'should run without any errors' do
      pp = <<-EOS
        include foo
      EOS
      apply_manifest(pp, :catch_failures => true)
      expect(apply_manifest(
        pp,
        :modulepath     => '/etc/puppetlabs/code/modules',
        :debug               => true,
        :catch_failures => true).exit_code).to be_zero
    end 
end
edit flag offensive delete link more
0

answered 2017-11-02 03:58:35 -0600

David Schmitt gravatar image

Have a look at beaker-testmode_switcher's code on how to inject the test manifest into the master, and run apply instead of the usual apply_manifest

require 'master_manipulator'
include MasterManipulator::Site
environment_base_path = on(master, puppet('config', 'print', 'environmentpath')).stdout.rstrip
prod_env_site_pp_path = File.join(environment_base_path, 'production', 'manifests', 'site.pp')
site_pp = create_site_pp(master, manifest: manifest)
inject_site_pp(master, prod_env_site_pp_path, site_pp)

on(hosts, puppet('agent', '--test', '--environment production', '--detailed-exitcodes'), ...
edit flag offensive delete link more

Comments

I definitely need to try this approach.

louis gravatar imagelouis ( 2017-11-02 18:42:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-10-27 08:11:38 -0600

Seen: 104 times

Last updated: Nov 09