To do a beaker run, you run the following command:
AnnouncementI have released my new course on Udemy, Kubernetes By Example. Sign up now to get free lifetime access!
bundle install bundle exec rspec spec/acceptance
By default the test will run on whichever nodeset that’s called “default”. Hence a file called default.yml needs to exists. which we’ll cover later.
Create the “acceptance” and “nodesets” folder
In your modules folder, all your beaker stuff resides in a new folder called “acceptance” which resides under spec:
[sher@puppetmaster demo_module]$ mkdir spec/acceptance [sher@puppetmaster demo_module]$ mkdir spec/acceptance/nodsets [sher@puppetmaster demo_module]$ tree . ├── Gemfile ├── Gemfile.lock ├── manifests │ └── init.pp ├── metadata.json ├── orig-Gemfile ├── Rakefile ├── README.md ├── spec │ ├── acceptance # Here's the new "acceptance"folder. │ │ └── nodsets # Here's the new "nodesets"folder. │ ├── classes │ │ └── init_spec.rb │ ├── defines │ ├── fixtures │ ├── functions │ ├── hosts │ └── spec_helper.rb └── tests └── init.pp
The acceptance folder will house all our beaker tests.
The nodesets folder will house one or more yml file. Each of these yml files will contain information about the testbed environment that beaker will need to provision and run the tests on.
Install the necessary Gems
To run beaker tests you need to install a few gems, They are:
As discussed earlier, we can install these gems from the command line using “gem install gem-name”. But it is better to take the bundler approach, and get these added to your gemfile.
Also you should add these gems to the gemfile that you created when you used for rspec testing, hence your gemfile should now look like:
[sher@puppetmaster demo_module]$ cat Gemfile source 'https://rubygems.org' gem 'puppet', :require => false gem 'puppetlabs_spec_helper', :require => false gem 'rspec-puppet', :require => false gem 'rake', '~>10.4.2', :require => false # beaker related gems gem 'beaker-rspec', :require => false gem 'serverspec', :require => false [sher@puppetmaster demo_module]$
Note: In most gemfiles like the apache puppet module’s gemfile, the beaker gem isn’t explicitly declared, that’s because the beaker gem is a dependency of the beaker-rspec gem. Hence beaker will get installed/used as part of the “bundle install” and “bundle exec…” commands.
Create the “spec_helper_acceptance.rb” file
- Gemfile – it includes the beaker gems. The main beaker specific gems are beaker, beaker-rspec, and
- spec/acceptance/ – all beaker _spec.rbv files are placed here.
- spec/acceptance/nodesets/* – list of files for each target testbed vm. one vm per file.
- spec/spec_helper_acceptance.rb – this mainly is unchanged but