Skip to content

Commit

Permalink
Merge pull request #30 from /issues/16
Browse files Browse the repository at this point in the history
fixes #16 - message for 'Could not resolve host' failure
  • Loading branch information
jantman committed Sep 4, 2015
2 parents 0977bd6 + 358a9b0 commit d08f8ac
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/vagrant-r10k/action/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def deploy(env, config)
end
unless runner.succeeded?
runner.get_errors().each do |error|
raise ErrorWrapper.new(RuntimeError.new(error[1]))
if error[1].message.include?("fatal: unable to access") and error[1].message.include?("Could not resolve host")
# if we can't resolve the host, the error should include how to skip provisioning
@logger.debug("vagrant-r10k: caught 'Could not resolve host' error")
raise ErrorWrapper.new(RuntimeError.new(error[1].message + "\n\nIf you don't have connectivity to the host, running 'vagrant up --no-provision' will skip r10k deploy and all provisioning."))
else
raise ErrorWrapper.new(RuntimeError.new(error[1]))
end
end
end
@env[:ui].info "vagrant-r10k: Deploy finished"
Expand Down
21 changes: 21 additions & 0 deletions spec/acceptance/skeletons/could_not_resolve_host/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

#require 'vagrant-vmware-workstation'
puts ENV

Vagrant.configure("2") do |config|
config.vm.box = "vagrantr10kspec"
config.vm.network "private_network", type: "dhcp"

# r10k plugin to deploy puppet modules
config.r10k.puppet_dir = "puppet"
config.r10k.puppetfile_path = "puppet/Puppetfile"

# Provision the machine with the appliction
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "puppet/modules"
end
end
20 changes: 20 additions & 0 deletions spec/acceptance/skeletons/could_not_resolve_host/gitcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# helper script to determine if a git clone is checked out to a
# PR, tag, or branch, and then output some information about the status
if [ $# -gt 0 ]; then
cd $1
fi
origin=$(git remote show -n origin | grep 'Fetch URL:' | awk '{print $3}')
if tmp=$(git status | grep "refs/pull/origin"); then
foo=$(echo "$tmp" | awk '{print $4}' | awk -F / '{print $4}')
echo "PR: ${foo} @ $(git rev-parse HEAD) (origin: ${origin})"
elif tagname=$(git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null); then
echo "tag: ${tagname} @ $(git rev-parse HEAD) (origin: ${origin})"
elif git symbolic-ref -q HEAD &>/dev/null; then
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
echo "branch: ${branch_name} @ $(git rev-parse HEAD) (origin: ${origin})"
else
echo "sha: $(git rev-parse HEAD) (origin: ${origin})"
fi
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is currently a noop but will be supported in the future.
forge 'forge.puppetlabs.com'

# v1.0.1 -> cdb8d7a186846b49326cec1cfb4623bd77529b04
mod 'reviewboard',
:git => 'https://invalidhost.jasonantman.com/jantman/puppet-reviewboard.git',
:ref => 'v1.0.1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is currently a noop but will be supported in the future.
forge 'forge.puppetlabs.com'

# v1.0.1 -> cdb8d7a186846b49326cec1cfb4623bd77529b04
mod 'reviewboard',
:git => 'https://github.com/jantman/puppet-reviewboard.git',
:ref => 'v1.0.1'

# 0.1.0 -> 3a504b5f66ebe1853bda4ee065fce18118958d84
mod 'nodemeister',
:git => 'https://github.com/jantman/puppet-nodemeister.git',
:ref => '0.1.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
notify {'vagrant-r10k puppet run': }
Empty file.
17 changes: 17 additions & 0 deletions spec/acceptance/vagrant-r10k/vagrant-r10k_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@
end
end

describe 'could not resolve git host' do
before do
setup_before('could_not_resolve_host', options)
end
after do
assert_execute("vagrant", "destroy", "--force")
end

it 'fails with error including how to skip provisioning' do
status("Test: vagrant up")
up_result = execute('vagrant', 'up', "--provider=#{provider}", '--debug')
expect(up_result).to exit_with(1)
expect(up_result.stderr).to match(%r"RuntimeError: Couldn't update git cache for https://invalidhost\.jasonantman\.com/jantman/puppet-reviewboard\.git: \"fatal: unable to access 'https://invalidhost\.jasonantman\.com/jantman/puppet-reviewboard\.git/': Could not resolve host: invalidhost\.jasonantman\.com\"\n\nIf you don't have connectivity to the host, running 'vagrant up --no-provision' will skip r10k deploy and all provisioning")
ensure_puppet_didnt_run(up_result)
end
end

# setup skeleton, add box
def setup_before(skel_name, options)
environment.skeleton(skel_name)
Expand Down
62 changes: 62 additions & 0 deletions spec/unit/action_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,68 @@
end
end

describe 'Could not resolve host' do
include_context 'unit' do
let(:vagrantfile) { <<-EOF
Vagrant.configure('2') do |config|
config.vm.define :test
# r10k plugin to deploy puppet modules
# config.r10k.puppet_dir = 'puppet'
# config.r10k.puppetfile_path = 'puppet/Puppetfile'
# Provision the machine with the appliction
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "puppet/modules"
end
end
EOF
}
end
let(:puppetfile_dbl) { double }
before do
allow_any_instance_of(VagrantPlugins::R10k::Helpers).to receive(:get_puppetfile).and_return(puppetfile_dbl)
allow_any_instance_of(R10K::Logging).to receive(:level=)
end
it 'raises an error' do
# stubs and doubles
with_temp_env("VAGRANT_LOG" => "foo") do
File.stub(:file?).with('puppetfile/path').and_return(true)
runner_dbl = double
sync_dbl = double
allow(runner_dbl).to receive(:append_task).with(sync_dbl)
allow(runner_dbl).to receive(:succeeded?).and_return(false)
allow(runner_dbl).to receive(:get_errors).and_return(
[[
sync_dbl,
R10K::Git::GitError.new("Couldn't update git cache for https://foo.com/jantman/bar.git: \"fatal: unable to access 'https://foo.com/jantman/bar.git/': Could not resolve host: foo.com\"")
]])
allow(sync_dbl).to receive(:new).with(puppetfile_dbl)
R10K::TaskRunner.stub(:new) { runner_dbl }
R10K::Task::Puppetfile::Sync.stub(:new) { sync_dbl }
# expectations
expect(R10K::Logging).to receive(:level=).with(3).twice
expect(ui).to receive(:info).with("vagrant-r10k: Beginning r10k deploy of puppet modules into module/path using puppetfile/path")
logger = subject.instance_variable_get(:@logger)
expect(logger).to receive(:debug).once.ordered.with("vagrant::r10k::deploy.deploy called")
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: creating Puppetfile::Sync task")
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: appending task to runner queue")
expect(runner_dbl).to receive(:append_task).with(sync_dbl).once
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: running sync task")
expect(runner_dbl).to receive(:run).once
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: sync task complete")
expect(logger).to receive(:debug).once.ordered.with("vagrant-r10k: caught 'Could not resolve host' error")
expect(runner_dbl).to receive(:succeeded?).once
# negative expectations
expect(ui).to_not receive(:info).with("vagrant-r10k: Deploy finished")
expect(app).to_not receive(:call)
# run
expect { subject.deploy(env, config) }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /Could not resolve host: foo\.com.*If you don't have connectivity to the host, running 'vagrant up --no-provision' will skip r10k deploy and all provisioning/m)
end
end
end

describe 'puppetfile syntax error' do
include_context 'unit' do
let(:vagrantfile) { <<-EOF
Expand Down

0 comments on commit d08f8ac

Please sign in to comment.