lib/onceover/testconfig.rb in onceover-3.2.8 vs lib/onceover/testconfig.rb in onceover-3.3.0

- old
+ new

@@ -26,11 +26,11 @@ attr_accessor :skip_r10k attr_accessor :strict_variables def initialize(file, opts = {}) begin - config = YAML.load(File.read(file)) + config = YAML.safe_load(File.read(file)) rescue Errno::ENOENT raise "Could not find #{file}" rescue Psych::SyntaxError raise "Could not parse #{file}, check that it is valid YAML and that the encoding is correct" end @@ -151,11 +151,11 @@ puppetcode = [] Dir["#{spec_dir}/pre_conditions/*.pp"].each do |condition_file| logger.debug "Reading pre_conditions from #{condition_file}" puppetcode << File.read(condition_file) end - return nil if puppetcode.count == 0 + return nil if puppetcode.count.zero? puppetcode.join("\n") end def deploy_local(repo = Onceover::Controlrepo.new, opts = {}) require 'onceover/controlrepo' @@ -201,9 +201,25 @@ logger.debug "Copying files to #{temp_controlrepo}" files_to_copy.each do |file| FileUtils.cp(file,"#{temp_controlrepo}/#{(Pathname(file).relative_path_from(Pathname(repo.root))).to_s}") end + + # When using puppetfile vs deploy with r10k, we want to respect the :control_branch + # located in the Puppetfile. To accomplish that, we use git and find the current + # branch name, then replace strings within the staged puppetfile, prior to copying. + + logger.debug "Checking current working branch" + git_branch = `git rev-parse --abbrev-ref HEAD`.chomp + + logger.debug "found #{git_branch} as current working branch" + puppetfile_contents = File.read("#{temp_controlrepo}/Puppetfile") + + logger.debug "replacing :control_branch mentions in the Puppetfile with #{git_branch}" + new_puppetfile_contents = puppetfile_contents.gsub(/:control_branch/, "'#{git_branch}'") + File.write("#{temp_controlrepo}/Puppetfile", new_puppetfile_contents) + + FileUtils.mkdir_p("#{repo.tempdir}/#{repo.environmentpath}/production") logger.debug "Copying #{temp_controlrepo} to #{repo.tempdir}/#{repo.environmentpath}/production" FileUtils.cp_r(Dir["#{temp_controlrepo}/*"], "#{repo.tempdir}/#{repo.environmentpath}/production") FileUtils.rm_rf(temp_controlrepo)