From 90a75c5256d09d81f35f14eb91f0449a60877693 Mon Sep 17 00:00:00 2001 From: Iristyle Date: Wed, 24 Apr 2019 16:28:37 -0700 Subject: [PATCH] WIP - rekick - remove after this commit passes * --- azure-pipelines.yml | 2 +- gem/lib/pupperware/spec_helper.rb | 11 +++++++++-- spec/examples/running_cluster.rb | 6 +++++- 3 files changed, 15 insertions(+), 4 deletions(-) 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/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