class Kitchen::Verifier::Busser
Command string generator to interface with Busser. The commands that are generated are safe to pass to an SSH command or as an unix command argument (escaped in single quotes).
@author Fletcher Nichol <fnichol@nichol.ca>
Public Class Methods
Creates a new Busser object using the provided configuration data which will be merged with any default configuration.
@param config [Hash] provided driver configuration
# File lib/kitchen/verifier/busser.rb, line 57 def initialize(config = {}) init_config(config) end
Public Instance Methods
(see Base#create_sandbox)
Kitchen::Verifier::Base#create_sandbox
# File lib/kitchen/verifier/busser.rb, line 62 def create_sandbox super prepare_helpers prepare_suites end
(see Base#init_command)
# File lib/kitchen/verifier/busser.rb, line 69 def init_command return if local_suite_files.empty? cmd = sudo(config[:busser_bin]).dup .tap { |str| str.insert(0, "& ") if powershell_shell? } prefix_command(wrap_shell_code(Util.outdent!(<<-CMD))) #{busser_env} #{cmd} suite cleanup CMD end
(see Base#install_command)
# File lib/kitchen/verifier/busser.rb, line 83 def install_command return if local_suite_files.empty? vars = install_command_vars prefix_command(shell_code_from_file(vars, "busser_install_command")) end
(see Base#run_command)
# File lib/kitchen/verifier/busser.rb, line 92 def run_command return if local_suite_files.empty? cmd = sudo(config[:busser_bin]).dup .tap { |str| str.insert(0, "& ") if powershell_shell? } prefix_command(wrap_shell_code(Util.outdent!(<<-CMD))) #{busser_env} #{cmd} test #{plugins.join(" ").gsub!("busser-", "")} CMD end
Legacy method stub for ‘#sync_cmd`.
@deprecated When backwards compatibility for old Busser methods is
removed, this method will no longer be available. Use `transport#upload` to transfer test files in its place.
# File lib/kitchen/verifier/busser.rb, line 126 def sync_cmd warn("Legacy call to #sync_cmd cannot be preserved, meaning that " \ "test files will not be uploaded. " \ "Code that calls #sync_cmd can now use the transport#upload " \ "method to transfer files.") end
Private Instance Methods
Returns a command string that sets appropriate environment variables for busser commands.
@return [String] command string @api private
# File lib/kitchen/verifier/busser.rb, line 140 def busser_env root = config[:root_path] gem_home = gem_path = remote_path_join(root, "gems") gem_cache = remote_path_join(gem_home, "cache") [ shell_env_var("BUSSER_ROOT", root), shell_env_var("GEM_HOME", gem_home), shell_env_var("GEM_PATH", gem_path), shell_env_var("GEM_CACHE", gem_cache), ].join("\n") .tap { |str| str.insert(0, reload_ps1_path) if windows_os? } end
Determines whether or not a local workstation file exists under a Chef-related directory.
@return [truthy,falsey] whether or not a given file is some kind of
Chef-related file
@api private
# File lib/kitchen/verifier/busser.rb, line 160 def chef_data_dir?(base, file) file =~ %r{^#{base}/(data|data_bags|environments|nodes|roles)/} end
Returns arguments to a ‘gem install` command, suitable to install the Busser gem.
@return [String] arguments string @api private
# File lib/kitchen/verifier/busser.rb, line 169 def gem_install_args gem, version = config[:version].split("@") if /^\d+\.\d+\.\d+/.match?(gem) version = gem gem = "busser" end root = config[:root_path] gem_bin = remote_path_join(root, "bin") # We don't want the gems to be installed in the home directory, # this will force the bindir and the gem install location both # to be under /tmp/verifier args = gem args += " --version #{version}" if version args += " --no-document --no-format-executable -n #{gem_bin}" args += " --no-user-install" args end
Returns an Array of common helper filenames currently residing on the local workstation.
@return [Array<String>] array of helper files @api private
# File lib/kitchen/verifier/busser.rb, line 194 def helper_files glob = File.join("helpers", "*/**/*") Util.safe_glob(config[:test_base_path], glob).reject { |f| File.directory?(f) } end
# File lib/kitchen/verifier/busser.rb, line 199 def install_command_vars ruby = remote_path_join(config[:ruby_bindir], "ruby") .tap { |path| path.concat(".exe") if windows_os? } gem = remote_path_join(config[:ruby_bindir], "gem") [ busser_env, shell_var("ruby", ruby), shell_var("gem", gem), shell_var("version", config[:version]), shell_var("gem_install_args", gem_install_args), shell_var("busser", sudo(config[:busser_bin])), shell_var("plugins", plugins.join(" ")), ].join("\n") end
Returns an Array of test suite filenames for the related suite currently residing on the local workstation. Any special provisioner-specific directories (such as a Chef roles/ directory) are excluded.
@return [Array<String>] array of suite files @api private
# File lib/kitchen/verifier/busser.rb, line 221 def local_suite_files base = File.join(config[:test_base_path], config[:suite_name]) Util.safe_glob(base, "*/**/*").reject do |f| chef_data_dir?(base, f) || File.directory?(f) end end
Returns a uniquely sorted Array of Busser plugin gems that need to be installed for the related suite.
@return [Array<String>] a lexically sorted, unique item array of Busser
plugin gem names
@api private
# File lib/kitchen/verifier/busser.rb, line 234 def plugins non_suite_dirs = %w{data data_bags environments nodes roles} Util.list_directory(File.join(config[:test_base_path], config[:suite_name])).reject do |d| !File.directory?(d) || non_suite_dirs.include?(File.basename(d)) end.map { |d| "busser-#{File.basename(d)}" }.sort.uniq end
Copies all common testing helper files into the suites directory in the sandbox.
@api private
# File lib/kitchen/verifier/busser.rb, line 245 def prepare_helpers base = File.join(config[:test_base_path], "helpers") helper_files.each do |src| dest = File.join(sandbox_suites_dir, src.sub("#{base}/", "")) FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp(src, dest, preserve: true) end end
Copies all test suite files into the suites directory in the sandbox.
@api private
# File lib/kitchen/verifier/busser.rb, line 258 def prepare_suites base = File.join(config[:test_base_path], config[:suite_name]) local_suite_files.each do |src| dest = File.join(sandbox_suites_dir, src.sub("#{base}/", "")) FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp(src, dest, preserve: true) end end
@return [String] path to suites directory under sandbox path @api private
# File lib/kitchen/verifier/busser.rb, line 270 def sandbox_suites_dir File.join(sandbox_path, "suites") end