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

Issues/9 #23

Merged
merged 15 commits into from
Aug 26, 2015
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ vendor
coverage
results.xml
spec/boxes
acceptance.out
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ the first time the VMWare provider is run in a given installation, it will
present an interactive sudo prompt in order to be able to interact with
VMWare.

Running Virtualbox acceptance tests:

bundle exec rake acceptance:virtualbox

When tests fail, they leave Virtualbox ``hostonlyif``s around; this can quickly clutter up the
system and cause other problems. As a result, after the virtualbox tests, we invoke the Vagrant
VirtualBox Provider's [delete_unused_host_only_networks](https://github.com/mitchellh/vagrant/blob/b118ab10c8e0f8e62a547249805f05240e6e4ee9/plugins/providers/virtualbox/driver/version_5_0.rb#L69)
method. This can also be manually run via ``bundle exec rake clean_vbox``.

These tests may generate a _lot_ of output; since there's no nice standalone junit XML viewer,
it may be helpful to run the tests as:

bundle exec rake acceptance:virtualbox 2>&1 | tee acceptance.out

And then examine ``acceptance.out`` as needed.


__Note__ that the vmware-workstation provider acceptance tests are not currently
functional; I've only been able to get the VirtualBox acceptance tests working.
If many users report vmware-specific problems, I'll give the tests another try.
Expand All @@ -173,6 +190,10 @@ I had these working at some point, but have been unable to get them working sinc
it seems that (a bit painfully and ironically), mitchellh's [vagrant-spec](https://github.com/mitchellh/vagrant-spec/)
doesn't seem to work cleanly with Hashicorp's paid/licensed Vagrant providers.

Running (currently broken) VMWare Workstation acceptance tests:

bundle exec rake acceptance:vmware_workstation

### Manually Testing Vagrant

For manual testing:
Expand Down
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ task :help do
system("rake -T")
end

desc "Cleanup VirtualBox hostonlyifs"
task :clean_vbox do
puts "Initializing Vagrant ProviderVirtualBox plugin"
require 'vagrant'
dm = VagrantPlugins::ProviderVirtualBox::Driver::Meta.new
puts "Deleting unused VirtualBox host-only networks"
dm.delete_unused_host_only_networks
end

namespace :acceptance do
providers = ['virtualbox', 'vmware_workstation']

Expand All @@ -111,6 +120,9 @@ namespace :acceptance do
system_or_die("VS_PROVIDER=#{provider} VS_BOX_PATH=#{box_path} TMPDIR=#{tmp_dir_path} bundle exec vagrant-spec test")
system("rm -Rf #{tmp_dir_path}/*")
fix_results_xml()
if provider == 'virtualbox'
Rake::Task['clean_vbox'].invoke
end
end
end
end
41 changes: 41 additions & 0 deletions lib/vagrant-r10k/action/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'vagrant/action'
require_relative '../helpers'

module VagrantPlugins
module R10k
module Action
class Base

include R10K::Logging

def self.validate
Vagrant::Action::Builder.new.tap do |b|
b.use Action::Validate
end
end

def self.deploy
Vagrant::Action::Builder.new.tap do |b|
b.use Action::Validate
b.use Action::Deploy
end
end

include VagrantPlugins::R10k::Helpers

def initialize(app, env)
@app = app
@env = env
klass = self.class.name.downcase.split('::').last
@logger = Log4r::Logger.new("vagrant::r10k::#{klass}")
if ENV["VAGRANT_LOG"] == "debug"
R10K::Logging.level = 0
@logger.level = 0
else
R10K::Logging.level = 3
end
end
end
end
end
end
82 changes: 82 additions & 0 deletions lib/vagrant-r10k/action/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require_relative 'base'

module VagrantPlugins
module R10k
module Action
class Deploy < Base

def call(env)
@logger.debug "vagrant::r10k::deploy called"

if !r10k_enabled?(env)
env[:ui].info "vagrant-r10k not configured; skipping"
return @app.call(env)
end

if !provision_enabled?(env)
env[:ui].info "provisioning disabled; skipping vagrant-r10k"
return @app.call(env)
end

# get our config
config = r10k_config(env)
if config.nil?
@logger.info "vagrant::r10k::deploy got nil configuration"
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k configuration error; cannot continue"))
end
@logger.debug("vagrant::r10k::deploy: env_dir_path=#{config[:env_dir_path]}")
@logger.debug("vagrant::r10k::deploy: puppetfile_path=#{config[:puppetfile_path]}")
@logger.debug("vagrant::r10k::deploy: module_path=#{config[:module_path]}")
@logger.debug("vagrant::r10k::deploy: manifests=#{config[:manifests]}")
@logger.debug("vagrant::r10k::deploy: manifest_file=#{config[:manifest_file]}")
@logger.debug("vagrant::r10k::deploy: puppet_dir=#{config[:puppet_dir]}")

deploy(env, config)

@app.call(env)
end

def deploy(env, config)
@logger.debug("vagrant::r10k::deploy.deploy called")
require 'r10k/task_runner'
require 'r10k/task/puppetfile'

env[:ui].info "vagrant-r10k: Beginning r10k deploy of puppet modules into #{config[:module_path]} using #{config[:puppetfile_path]}"

if ENV["VAGRANT_LOG"] == "debug"
R10K::Logging.level = 0
else
R10K::Logging.level = 3
end

if !File.file?(config[:puppetfile_path])
raise ErrorWrapper.new(RuntimeError.new("Puppetfile at #{config[:puppetfile_path]} does not exist."))
end

# do the actual module buildout
runner = R10K::TaskRunner.new([])
begin
puppetfile = get_puppetfile(config)
@logger.debug("vagrant-r10k: creating Puppetfile::Sync task")
task = R10K::Task::Puppetfile::Sync.new(puppetfile)
@logger.debug("vagrant-r10k: appending task to runner queue")
runner.append_task task
@logger.debug("vagrant-r10k: running sync task")
runner.run
@logger.debug("vagrant-r10k: sync task complete")
rescue SyntaxError => ex
@env[:ui].error "Invalid syntax in Puppetfile at #{config[:puppetfile_path]}"
raise ErrorWrapper.new(ex)
end
if !runner.succeeded?
runner.get_errors().each do |error|
raise ErrorWrapper.new(RuntimeError.new(error[1]))
end
end
@env[:ui].info "vagrant-r10k: Deploy finished"
@app.call(env)
end
end
end
end
end
44 changes: 44 additions & 0 deletions lib/vagrant-r10k/action/validate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_relative 'base'

module VagrantPlugins
module R10k
module Action
class Validate < Base

def call(env)
@logger.debug "vagrant::r10k::validate called"

if !r10k_enabled?(env)
env[:ui].info "vagrant-r10k not configured; skipping"
return @app.call(env)
end

if !provision_enabled?(env)
env[:ui].info "provisioning disabled; skipping vagrant-r10k"
return @app.call(env)
end

config = r10k_config(env)
if config.nil?
@logger.info "vagrant::r10k::deploy got nil configuration"
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k configuration error; cannot continue"))
end

puppetfile = get_puppetfile(config)

# validate puppetfile
@logger.debug "vagrant::r10k::validate: validating Puppetfile at #{config[:puppetfile_path]}"
begin
puppetfile.load
rescue Exception => ex
@logger.error "ERROR: Puppetfile bad syntax"
raise ErrorWrapper.new(RuntimeError.new(ex))
end

@app.call(env)
end

end
end
end
end
2 changes: 1 addition & 1 deletion lib/vagrant-r10k/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize
@puppet_dir = UNSET_VALUE
@puppetfile_path = UNSET_VALUE
@module_path = UNSET_VALUE
@logger = Log4r::Logger.new("vagrant::r10k::modulegetter")
@logger = Log4r::Logger.new("vagrant::r10k::config")
@logger.debug("vagrant-r10k-config: initialize")
end

Expand Down
Loading