Skip to content

Commit

Permalink
Refactor puppetserver container tests
Browse files Browse the repository at this point in the history
This updates the puppetserver tests to use `docker-compose` instead of
`docker-run`. This also updates the tests to use the shared testing
gem from github.com/puppetlabs/pupperware.

This also includes a move from the puppet-agent-alpine to
puppet-agent-ubuntu for testing. We were seeing a lot of intermittent
network failures with the alpine container on windows (LCOW). See
moby/libnetwork#2371 and
microsoft/opengcs#303 have more information on
this issue. This should hopefully clear up the intermittent name
resolution failures we were seeing.
  • Loading branch information
Morgan Rhodes committed May 3, 2019
1 parent 8ab5f04 commit 6abbd06
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 110 deletions.
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
32 changes: 32 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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:-}
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
dns_search: '.test'
networks:
puppetserver_test:
aliases:
- compiler.test

networks:
puppetserver_test:
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
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
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.

0 comments on commit 6abbd06

Please sign in to comment.