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

Refactor puppetserver container tests #2062

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ lein: 2.8.1
dist: trusty
# see https://www.deps.co/guides/travis-ci-latest-java/ certificate issues
sudo: required

services:
- docker

script:
- ./ext/travisci/test.sh
- $TRAVIS_BUILD_DIR/ext/travisci/secscan.sh "$TRAVIS_BUILD_DIR/src/clj" "clj"
Expand All @@ -13,9 +17,23 @@ matrix:
- stage: puppetserver tests
jdk: openjdk8
- stage: puppetserver container tests
language: generic
language: ruby
rvm: 2.5.5
env:
- DOCKER_COMPOSE_VERSION=1.24.0
script:
- cd docker && make lint && make build && make test
- |
set -ex
sudo rm /usr/local/bin/docker-compose
curl --location https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname --kernel-name`-`uname --machine` > docker-compose
chmod +x docker-compose
sudo mv docker-compose /usr/local/bin
cd docker
make lint
make build
make test
set +x

notifications:
email: false
hipchat:
Expand Down
4 changes: 4 additions & 0 deletions docker/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ end

gem 'rspec'
gem 'rspec_junit_formatter'
gem 'pupperware',
:git => 'https://github.com/puppetlabs/pupperware.git',
:ref => 'master',
:glob => 'gem/*.gemspec'
12 changes: 9 additions & 3 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ build_date := $(shell date -u +%FT%T)
hadolint_available := $(shell hadolint --help > /dev/null 2>&1; echo $$?)
hadolint_command := hadolint --ignore DL3008 --ignore DL3018 --ignore DL4000 --ignore DL4001
hadolint_container := hadolint/hadolint:latest
pwd := $(shell pwd)
export BUNDLE_PATH = $(pwd)/.bundle/gems
export BUNDLE_BIN = $(pwd)/.bundle/bin
export GEMFILE = $(pwd)/Gemfile

version = $(shell echo $(git_describe) | sed 's/-.*//')
dockerfile := Dockerfile
Expand Down Expand Up @@ -53,11 +57,13 @@ ifeq ($(IS_LATEST),true)
endif

test: prep
@bundle install --path .bundle/gems
@bundle install --path $$BUNDLE_PATH --gemfile $$GEMFILE
@PUPPET_TEST_DOCKER_IMAGE=$(NAMESPACE)/puppetserver-standalone:$(version) \
bundle exec rspec --options puppetserver-standalone/.rspec spec
bundle exec --gemfile $$GEMFILE \
rspec --options puppetserver-standalone/.rspec spec
@PUPPET_TEST_DOCKER_IMAGE=$(NAMESPACE)/puppetserver:$(version) \
bundle exec rspec --options puppetserver/.rspec spec
bundle exec --gemfile $$GEMFILE \
rspec --options puppetserver/.rspec spec

push-image: prep
@docker push puppet/puppetserver-standalone:$(version)
Expand Down
36 changes: 36 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.5'

services:
puppet:
hostname: puppet.test
image: ${PUPPET_TEST_DOCKER_IMAGE:-puppet/puppetserver-standalone}
environment:
- PUPPETSERVER_HOSTNAME=puppet.test
- PUPPERWARE_ANALYTICS_ENABLED=${PUPPERWARE_ANALYTICS_ENABLED:-false}
- DNS_ALT_NAMES=puppet,puppet.test,${DNS_ALT_NAMES:-}
- PUPPET_STORECONFIGS=false
- PUPPET_REPORTS=log
dns_search: '.test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting that this works, because I thought what I discovered in my experiments was that this is actually supposed to be:

dns_search: test

networks:
puppetserver_test:
aliases:
- puppet.test

compiler:
hostname: compiler.test
image: ${PUPPET_TEST_DOCKER_IMAGE:-puppet/puppetserver-standalone}
environment:
- PUPPERWARE_ANALYTICS_ENABLED=${PUPPERWARE_ANALYTICS_ENABLED:-false}
- CA_ENABLED=false
- CA_HOSTNAME=puppet.test
- PUPPET_STORECONFIGS=false
- PUPPET_REPORTS=log
dns_search: '.test'
networks:
puppetserver_test:
aliases:
- compiler.test

networks:
puppetserver_test:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Even though this adds more to the file, we should probably make this explicit it in other compose files so we have better control of the name.

name: puppetserver_test
1 change: 0 additions & 1 deletion docker/puppetserver-standalone/.rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--require spec_helper
--format RspecJunitFormatter
--out puppetserver-standalone/TEST-rspec.xml
--format documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

if [ -n "$PUPPET_STORECONFIGS_BACKEND" ]; then
puppet config set storeconfigs_backend $PUPPET_STORECONFIGS_BACKEND --section master
fi

if [ -n "$PUPPET_STORECONFIGS" ]; then
puppet config set storeconfigs $PUPPET_STORECONFIGS --section master
fi

if [ -n "$PUPPET_REPORTS" ]; then
puppet config set reports $PUPPET_REPORTS --section master
fi
1 change: 0 additions & 1 deletion docker/puppetserver/.rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--require spec_helper
--format RspecJunitFormatter
--out puppetserver/TEST-rspec.xml
--format documentation
3 changes: 3 additions & 0 deletions docker/puppetserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ENV PUPPERWARE_ANALYTICS_STREAM="$pupperware_analytics_stream"
ENV PUPPERWARE_ANALYTICS_TRACKING_ID="UA-132486246-3"
ENV PUPPERWARE_ANALYTICS_APP_NAME="puppetserver"
ENV PUPPERWARE_ANALYTICS_ENABLED=false
ENV PUPPET_STORECONFIGS_BACKEND="puppetdb"
ENV PUPPET_STORECONFIGS=true
ENV PUPPET_REPORTS="puppetdb"

LABEL org.label-schema.maintainer="Puppet Release Team <[email protected]>" \
org.label-schema.vendor="Puppet" \
Expand Down
12 changes: 12 additions & 0 deletions docker/puppetserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ The following environment variables are supported:

If consul is enabled, the port to access consul at. Defaults to '8500'.

- `PUPPET_REPORTS`

Sets `reports` in puppet.conf. Defaults to 'puppetdb'.

- `PUPPET_STORECONFIGS`

Sets `storeconfigs` in puppet.conf. Defaults to true.

- `PUPPET_STORECONFIGS_BACKEND`

Sets `storeconfigs_backend` in puppet.conf. Defaults to 'puppetdb'.

- `PUPPETDB_SERVER_URLS`

The `server_urls` to set in /etc/puppetlabs/puppet/puppetdb.conf. Defaults to 'https://puppetdb:8081'.
Expand Down
103 changes: 22 additions & 81 deletions docker/spec/puppetserver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,56 @@

require 'rspec/core'
require 'open3'
require 'pupperware/spec_helper'

describe 'puppetserver container' do
include Helpers

def puppetserver_health_check(container)
empty_response_counter = 0
status = ''

# We intermittently get an empty response from the `docker inspect`
# but we don't want this to run forever if the container failed, so
# assume that 5 empty responses in a row is a failure case
while status.empty? && empty_response_counter < 5
result = run_command("docker inspect \"#{container}\" --format '{{.State.Health.Status}}'")
status = result[:stdout].chomp
if status.empty?
empty_response_counter += 1
sleep 1
end
STDOUT.puts "queried health status of #{container}: #{status}"
end

return status
end
include Pupperware::SpecHelpers

before(:all) do
run_command('docker pull puppet/puppet-agent-alpine:latest')
@image = ENV['PUPPET_TEST_DOCKER_IMAGE']
if @image.nil?
run_command('docker pull puppet/puppet-agent-ubuntu:latest')
if ENV['PUPPET_TEST_DOCKER_IMAGE'].nil?
fail <<-MSG
error_message = <<-MSG
* * * * *
* * * * *
PUPPET_TEST_DOCKER_IMAGE environment variable must be set so we
know which image to test against!
* * * * *
* * * * *
MSG
fail error_message
end
end

# Windows doesn't have the default 'bridge' network driver
network_opt = File::ALT_SEPARATOR.nil? ? '' : '--driver=nat'

result = run_command("docker network create #{network_opt} puppetserver_test_network")
fail 'Failed to create network' unless result[:status].exitstatus == 0
@network = result[:stdout].chomp
status = run_command('docker-compose --no-ansi version')[:status]
if status.exitstatus != 0
fail "`docker-compose` must be installed and available in your PATH"
end

result = run_command("docker run --rm --detach \
--env DNS_ALT_NAMES=puppet \
--env PUPPERWARE_ANALYTICS_ENABLED=false \
--name puppet.test \
--network #{@network} \
--hostname puppet.test \
#{@image}")
fail 'Failed to create puppet.test' unless result[:status].exitstatus == 0
@container = result[:stdout].chomp
teardown_cluster()

result = run_command("docker run --rm --detach \
--env DNS_ALT_NAMES=puppet \
--env PUPPERWARE_ANALYTICS_ENABLED=false \
--env CA_ENABLED=false \
--env CA_HOSTNAME=puppet.test \
--network #{@network} \
--name puppet-compiler.test \
--hostname puppet-compiler.test \
#{@image}")
fail 'Failed to create compiler' unless result[:status].exitstatus == 0
@compiler = result[:stdout].chomp
run_command('docker-compose --no-ansi up --detach')
end

after(:all) do
run_command("docker container kill #{@container}") unless @container.nil?
run_command("docker container kill #{@compiler}") unless @compiler.nil?
run_command("docker network rm #{@network}") unless @network.nil?
emit_logs()
teardown_cluster()
end

it 'should start puppetserver successfully' do
status = puppetserver_health_check(@container)
while (status == 'starting' || status == "'starting'")
sleep(1)
status = puppetserver_health_check(@container)
end
if status !~ /\'?healthy\'?/
run_command("docker logs #{@container}")
end
expect(status).to match(/\'?healthy\'?/)
expect(wait_on_puppetserver_status()).to eq ('healthy')
end

it 'should be able to run a puppet agent against the puppetserver' do
result = run_command("docker run --rm --name puppet-agent.test --hostname puppet-agent.test --network #{@network} puppet/puppet-agent-alpine:latest agent --test --server puppet.test")
expect(result[:status].exitstatus).to eq(0)
expect(run_agent('puppet-agent.test', 'puppetserver_test')).to eq(0)
end

it 'should be able to start a compile master' do
status = puppetserver_health_check(@compiler)
while (status == 'starting' || status == "'starting'")
sleep(1)
status = puppetserver_health_check(@compiler)
end
if status !~ /\'?healthy\'?/
run_command("docker logs #{@compiler}")
end
expect(status).to match(/\'?healthy\'?/)
end
expect(wait_on_puppetserver_status(180, 'compiler')).to eq ('healthy')
end

it 'should be able to run an agent against the compile master' do
result = run_command("docker run --rm --name puppet-agent-compiler.test --hostname puppet-agent-compiler.test --network #{@network} puppet/puppet-agent-alpine:latest agent --test --server puppet-compiler.test --ca_server puppet.test")
expect(result[:status].exitstatus).to eq(0)
expect(run_agent('compiler-agent.test', 'puppetserver_test', get_container_hostname(get_service_container('compiler')), get_container_hostname(get_service_container('puppet')))).to eq(0)
end

it 'should have r10k available' do
result = run_command('docker exec puppet.test r10k --help')
result = run_command('docker-compose exec -T puppet r10k --help')
expect(result[:status].exitstatus).to eq(0)
end
end
22 changes: 0 additions & 22 deletions docker/spec/spec_helper.rb

This file was deleted.