diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8a2971a5..f5f9c96b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,7 +2,7 @@ pool: # self-hosted agent on Windows 10 1709 environment # includes newer Docker engine with LCOW enabled, new build of LCOW image # includes Ruby 2.5, Go 1.10, Node.js 10.10, hadolint - name: Default + name: Internal LCOW variables: COMPOSE_PROJECT_NAME: pupperware diff --git a/docker-compose.yml b/docker-compose.yml index ec0f38b0..7faf80dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,7 @@ services: - ${VOLUME_ROOT:-.}/volumes/code:/etc/puppetlabs/code/ - ${VOLUME_ROOT:-.}/volumes/puppet:/etc/puppetlabs/puppet/ - ${VOLUME_ROOT:-.}/volumes/serverdata:/opt/puppetlabs/server/data/puppetserver/ - dns_search: '.local' + dns_search: local networks: default: aliases: @@ -38,7 +38,7 @@ services: volumes: - ${VOLUME_ROOT:-.}/volumes/puppetdb-postgres/data:/var/lib/postgresql/data - ./postgres-custom:/docker-entrypoint-initdb.d - dns_search: '.local' + dns_search: local networks: default: aliases: @@ -62,7 +62,7 @@ services: - puppet volumes: - ${VOLUME_ROOT:-.}/volumes/puppetdb/ssl:/etc/puppetlabs/puppet/ssl/ - dns_search: '.local' + dns_search: local networks: default: aliases: diff --git a/gem/lib/pupperware/spec_helper.rb b/gem/lib/pupperware/spec_helper.rb index b00baab1..48f1835b 100644 --- a/gem/lib/pupperware/spec_helper.rb +++ b/gem/lib/pupperware/spec_helper.rb @@ -137,6 +137,11 @@ def get_container_hostname(container) return fqdn || inspect_container(container, '{{.Config.Hostname}}') end + # this only works when a container has a single network + def get_container_ip(container) + inspect_container(container, '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}') + end + def emit_log(container) container_name = get_container_name(container) STDOUT.puts("#{'*' * 80}\nContainer logs for #{container_name} / #{container}\n#{'*' * 80}\n") @@ -236,11 +241,13 @@ def clean_certificate(agent_name) # Puppet Agent Helpers ###################################################################### - def run_agent(agent_name, network, server = get_container_hostname(get_service_container('puppet'))) + def run_agent(agent_name, network, server = get_container_hostname(get_service_container('puppet')), hosts = {}) # setting up a Windows TTY is difficult, so we don't # allocating a TTY will show container pull output on Linux, but that's not good for tests STDOUT.puts("running agent #{agent_name} in network #{network} against #{server}") - result = run_command("docker run --rm --network #{network} --name #{agent_name} --hostname #{agent_name} puppet/puppet-agent-alpine agent --verbose --onetime --no-daemonize --summarize --server #{server}") + host_map = hosts.map { |k, v| "--add-host=\"#{k}:#{v}\"" }.join(' ') + STDOUT.puts("adding hosts #{host_map} to agents /etc/hosts") unless host_map.nil? + result = run_command("docker run --rm --network #{network} #{host_map} --name #{agent_name} --hostname #{agent_name} puppet/puppet-agent-alpine agent --verbose --onetime --no-daemonize --summarize --server #{server}") return result[:status].exitstatus end diff --git a/spec/examples/running_cluster.rb b/spec/examples/running_cluster.rb index ada64fc3..f5ee23e5 100644 --- a/spec/examples/running_cluster.rb +++ b/spec/examples/running_cluster.rb @@ -33,7 +33,11 @@ end it 'should be able to run an agent' do - status = run_agent(@test_agent, 'pupperware_default') + # to workaround DNS resolution problems, add a /etc/hosts entry + puppetserver_container = get_service_container('puppet') + puppetserver_hostname = get_container_hostname(puppetserver_container) + hosts = { puppetserver_hostname => get_container_ip(puppetserver_container) } + status = run_agent(@test_agent, 'pupperware_default', puppetserver_hostname, hosts) expect(status).to eq(0) end