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/22 pullreview #26

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions lib/vagrant-r10k/action/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
module VagrantPlugins
module R10k
module Action
# base class for vagrant-r10k hook actions
class Base

include R10K::Logging

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

# r10k deploy hook
def self.deploy
Vagrant::Action::Builder.new.tap do |b|
b.use Action::Validate
Expand Down
11 changes: 7 additions & 4 deletions lib/vagrant-r10k/action/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
module VagrantPlugins
module R10k
module Action
# run r10k deploy
class Deploy < Base

# determine if we should run, and get config
def call(env)
@logger.debug "vagrant::r10k::deploy called"

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

if !provision_enabled?(env)
unless provision_enabled?(env)
env[:ui].info "provisioning disabled; skipping vagrant-r10k"
return @app.call(env)
end
Expand All @@ -36,6 +38,7 @@ def call(env)
@app.call(env)
end

# run the actual r10k deploy
def deploy(env, config)
@logger.debug("vagrant::r10k::deploy.deploy called")
require 'r10k/task_runner'
Expand All @@ -49,7 +52,7 @@ def deploy(env, config)
R10K::Logging.level = 3
end

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

Expand All @@ -68,7 +71,7 @@ def deploy(env, config)
@env[:ui].error "Invalid syntax in Puppetfile at #{config[:puppetfile_path]}"
raise ErrorWrapper.new(ex)
end
if !runner.succeeded?
unless runner.succeeded?
runner.get_errors().each do |error|
raise ErrorWrapper.new(RuntimeError.new(error[1]))
end
Expand Down
8 changes: 5 additions & 3 deletions lib/vagrant-r10k/action/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
module VagrantPlugins
module R10k
module Action
# action to validate config pre-deploy
class Validate < Base

# validate configuration pre-deploy
def call(env)
@logger.debug "vagrant::r10k::validate called"

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

if !provision_enabled?(env)
unless provision_enabled?(env)
env[:ui].info "provisioning disabled; skipping vagrant-r10k"
return @app.call(env)
end
Expand All @@ -30,7 +32,7 @@ def call(env)
@logger.debug "vagrant::r10k::validate: validating Puppetfile at #{config[:puppetfile_path]}"
begin
puppetfile.load
rescue Exception => ex
rescue StandardError => ex
@logger.error "ERROR: Puppetfile bad syntax"
raise ErrorWrapper.new(RuntimeError.new(ex))
end
Expand Down
9 changes: 6 additions & 3 deletions lib/vagrant-r10k/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

module VagrantPlugins
module R10k
# vagrant-r10k plugin configuration
class Config < Vagrant.plugin('2', :config)
attr_accessor :puppet_dir
attr_accessor :puppetfile_path
attr_accessor :module_path

# initialize config
def initialize
@puppet_dir = UNSET_VALUE
@puppetfile_path = UNSET_VALUE
Expand All @@ -15,6 +17,7 @@ def initialize
@logger.debug("vagrant-r10k-config: initialize")
end

# validate configuration
def validate(machine)
@logger.debug("vagrant-r10k-config: validate")
errors = _detected_errors
Expand All @@ -27,19 +30,19 @@ def validate(machine)
end

puppet_dir_path = File.join(machine.env.root_path, puppet_dir)
errors << "puppet_dir directory '#{puppet_dir_path}' does not exist" if !File.directory?(puppet_dir_path)
errors << "puppet_dir directory '#{puppet_dir_path}' does not exist" unless File.directory?(puppet_dir_path)

if puppetfile_path == UNSET_VALUE
errors << "config.r10k.puppetfile_path must be set"
return { "vagrant-r10k" => errors }
end

puppetfile = File.join(machine.env.root_path, puppetfile_path)
errors << "puppetfile '#{puppetfile}' does not exist" if !File.file?(puppetfile)
errors << "puppetfile '#{puppetfile}' does not exist" unless File.file?(puppetfile)

if module_path != UNSET_VALUE
module_path_path = File.join(machine.env.root_path, module_path)
errors << "module_path directory '#{module_path_path}' does not exist" if !File.directory?(module_path_path)
errors << "module_path directory '#{module_path_path}' does not exist" unless File.directory?(module_path_path)
end

@logger.debug("vagrant-r10k-config: END validate")
Expand Down
7 changes: 6 additions & 1 deletion lib/vagrant-r10k/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# this is an ugly monkeypatch, since we're running inside of Vagrant,
# which has already defined logger but not with the debug1 and debug2 custom levels
module Log4r
# this is an ugly monkeypatch, since we're running inside of Vagrant,
# which has already defined logger but not with the debug1 and debug2 custom levels
class Logger

def debug1(msg)
self.debug(msg)
end

def debug2(msg)
self.debug(msg)
end
Expand All @@ -17,6 +20,7 @@ def debug2(msg)

# patch this so we can get programmatic access to the errors
module R10K
# patch this so we can get programmatic access to the errors
class TaskRunner
def get_errors
@errors
Expand All @@ -26,6 +30,7 @@ def get_errors

module VagrantPlugins
module R10k
# General-use vagrant-r10k helper methosd
module Helpers

# Determine if r10k.puppet_dir and r10k.puppetfile_path are in config
Expand Down Expand Up @@ -92,7 +97,7 @@ def puppet_provisioner(env)
#
# @return [Hash]
def r10k_config(env)
ret = {:manifests => nil, :module_path => nil, :manifest_file => nil}
ret = { :manifests => nil, :module_path => nil, :manifest_file => nil }
ret[:env_dir_path] = env_dir(env)
ret[:puppetfile_path] = puppetfile_path(env)
prov = puppet_provisioner(env)
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant-r10k/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module VagrantPlugins
# hold version number constant
module R10k
VERSION = "0.2.0"
end
Expand Down