Skip to content

Commit

Permalink
issue #22 - first batch of pullreview.com fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Aug 27, 2015
1 parent 168f841 commit cd00c6d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .pullreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
notifications:
pullrequest:
comment: verbose
excludes:
- spec/*
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
8 changes: 7 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,8 @@ 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 +98,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

0 comments on commit cd00c6d

Please sign in to comment.