From cd00c6d3a30036ab2ec5cdad8e8cbb0981ec14e0 Mon Sep 17 00:00:00 2001 From: Jason Antman Date: Wed, 26 Aug 2015 21:22:58 -0400 Subject: [PATCH] issue #22 - first batch of pullreview.com fixes --- .pullreview.yml | 2 ++ lib/vagrant-r10k/action/base.rb | 3 +++ lib/vagrant-r10k/action/deploy.rb | 11 +++++++---- lib/vagrant-r10k/action/validate.rb | 8 +++++--- lib/vagrant-r10k/config.rb | 9 ++++++--- lib/vagrant-r10k/helpers.rb | 8 +++++++- lib/vagrant-r10k/version.rb | 1 + 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/.pullreview.yml b/.pullreview.yml index 0074fd1..0523875 100644 --- a/.pullreview.yml +++ b/.pullreview.yml @@ -2,3 +2,5 @@ notifications: pullrequest: comment: verbose +excludes: + - spec/* diff --git a/lib/vagrant-r10k/action/base.rb b/lib/vagrant-r10k/action/base.rb index 8cc026f..353e24e 100644 --- a/lib/vagrant-r10k/action/base.rb +++ b/lib/vagrant-r10k/action/base.rb @@ -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 diff --git a/lib/vagrant-r10k/action/deploy.rb b/lib/vagrant-r10k/action/deploy.rb index 8d0dfba..843c29a 100644 --- a/lib/vagrant-r10k/action/deploy.rb +++ b/lib/vagrant-r10k/action/deploy.rb @@ -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 @@ -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' @@ -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 @@ -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 diff --git a/lib/vagrant-r10k/action/validate.rb b/lib/vagrant-r10k/action/validate.rb index 2d015ee..5db2813 100644 --- a/lib/vagrant-r10k/action/validate.rb +++ b/lib/vagrant-r10k/action/validate.rb @@ -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 @@ -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 diff --git a/lib/vagrant-r10k/config.rb b/lib/vagrant-r10k/config.rb index 6e6b457..85b59ef 100644 --- a/lib/vagrant-r10k/config.rb +++ b/lib/vagrant-r10k/config.rb @@ -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 @@ -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 @@ -27,7 +30,7 @@ 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" @@ -35,11 +38,11 @@ def validate(machine) 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") diff --git a/lib/vagrant-r10k/helpers.rb b/lib/vagrant-r10k/helpers.rb index 725ab62..d12cebb 100644 --- a/lib/vagrant-r10k/helpers.rb +++ b/lib/vagrant-r10k/helpers.rb @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/lib/vagrant-r10k/version.rb b/lib/vagrant-r10k/version.rb index 9a81fc2..6502ce7 100644 --- a/lib/vagrant-r10k/version.rb +++ b/lib/vagrant-r10k/version.rb @@ -1,4 +1,5 @@ module VagrantPlugins + # hold version number constant module R10k VERSION = "0.2.0" end