Automated Acceptance Testing | Puppet
Recommended by 0 users
Automating Acceptance Testing
Our module has passed the first hurdle by passing unit testing! Now we need to do further testing to ensure that the module will actually compile and that it will do what we think it will do without breaking any past functionality. The way to test this is by automated acceptance testing. We need to actually install the module on an agent and run some tests that will tell us if the modules meet these requirements or not. Luckily, PuppetLabs had thought of this and has developed Beaker to help us achieve these goals.
Configuring Docker to be our Beaker Provider
The first thing we need to do on our Jenkins server is get Docker installed and available for the Jenkins user to run. Installation of Docker varies by distribution, so follow the instructions on the Docker website https://www.docker.com/ to get Docker installed. Make sure to run the following command to give your Jenkins user permissions to run Docker
$ sudo usermod -aG docker Jenkins
Login as the root user, then login as the Jenkins user using the following command:
# su - jenkins
This is necessary because there is no password for the Jenkins user. You can now test that Docker is working correctly by running the hello-world container as the Jenkins user:
$ docker run hello-world
You should see the container run successfully.
You may have to edit the permissions of the /var/run/docker.sock file so that the Jenkins user can run Docker from a script. This will be the case if you can run our test as the Jenkins user from the workspace directory successfully, but it won’t run when automated by Jenkins. To fix, edit the docker config file with the following values:
Restart the Docker daemon and you should be good to run Docker from Jenkins build scripts.
Configuring Jenkins to run Beaker Testing
Our automated acceptance tests come after a successful unit test Jenkins build. We need to create a separate Jenkins job for our acceptance testing. Create a new freestyle Jenkins job named ‘puppet-acceptance-testing.’ Configure the following options for your job:
Add a build step to execute a shell script with the following contents:
You will need to install the EnvInject Jenkins plugin in order for us to use our BEAKER_color option to disable beaker outputting color and clogging our output with escape characters. Another plugin we will need for our next step is the ‘Parameterized Trigger plugin.’
Next, configure your cd-sample job to run our acceptance-test job upon a successful build. Add a ‘Trigger parameterized build on other projects’ post build step with the following settings:
Save the job.
You are now ready to test your updates. Like before, let’s make a change to the metadata.json file by incrementing the point release another version, committing our change and pushing to git. You see both jobs fire, showing that our module passes the automated acceptance testing.
As you can see beaker setup a Docker container with puppet then used that puppet agent to install our module twice to make sure that it would run without errors and that it was idempotent. Now, we know that our module passes unit testing and automated acceptance testing. We need to deploy it to our nonprod puppet environment so that we can perform user acceptance testing before promoting our module to production.