Skip to content

Commit

Permalink
Enabled Busser with Transport shell logic.
Browse files Browse the repository at this point in the history
Added default_port and default max_threads parameters.
Modified chef_omnibus functions with a nice progress bar.
Deleted old winrm.rb and winrm_base.rb from project.
  • Loading branch information
afiune authored and fnichol committed Jan 20, 2015
1 parent 2db85d8 commit 5489c67
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 654 deletions.
2 changes: 0 additions & 2 deletions lib/kitchen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
require "kitchen/driver"
require "kitchen/driver/base"
require "kitchen/driver/ssh_base"
require "kitchen/driver/winrm_base"
require "kitchen/driver/proxy"
require "kitchen/instance"
require "kitchen/transport"
Expand All @@ -46,7 +45,6 @@
require "kitchen/platform"
require "kitchen/state_file"
require "kitchen/ssh"
require "kitchen/winrm"
require "kitchen/suite"
require "kitchen/version"

Expand Down
189 changes: 97 additions & 92 deletions lib/kitchen/busser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module Kitchen
# @author Fletcher Nichol <[email protected]>
class Busser

include Configurable
include Logging

# Constructs a new Busser command generator, given a suite name.
#
# @param [String] suite_name name of suite on which to operate
Expand Down Expand Up @@ -96,40 +99,38 @@ def diagnose
# work needs to be performed
def setup_cmd
return if local_suite_files.empty?

ruby = "#{config[:ruby_bindir]}/ruby"
gem = sudo("#{config[:ruby_bindir]}/gem")
busser = sudo(config[:busser_bin])

cmd = <<-CMD.gsub(/^ {8}/, "")
#{busser_setup_env}
gem_bindir=`#{ruby} -rrubygems -e "puts Gem.bindir"`
if ! #{gem} list busser -i >/dev/null; then
#{gem} install #{gem_install_args}
fi
#{sudo("${gem_bindir}")}/busser setup
#{busser} plugin install #{plugins.join(" ")}
CMD
Util.wrap_command(cmd)
end

# Return a command string just like setup_cmd but in PowerShell
#
# @author Salim Afiune <[email protected]>
def setup_cmd_posh
@setup_cmd_posh ||= if local_suite_files.empty?
nil

case shell
when 'bourne'

cmd = <<-CMD.gsub(/^ {10}/, "")
#{busser_setup_env}
gem_bindir=`#{ruby} -rrubygems -e "puts Gem.bindir"`
if ! #{gem} list busser -i >/dev/null; then
#{gem} install #{gem_install_args}
fi
#{sudo("${gem_bindir}")}/busser setup
#{busser} plugin install #{plugins.join(" ")}
CMD
when 'powershell'
cmd = <<-CMD.gsub(/^ {10}/, "")
#{busser_setup_env}
if ((gem list busser -i) -eq \"false\") {
gem install #{gem_install_args}
}
# We have to modify Busser::Setup to work with PowerShell
# busser setup
#{busser} plugin install #{plugins.join(" ")}
CMD
else
setup_cmd_posh = []
setup_cmd_posh << busser_setup_env_posh
setup_cmd_posh << "If ((gem list busser -i) -eq \"false\") {
gem install #{gem_install_args} }"
# We have to modify Busser::Setup to work with PowerShell
# setup_cmd_posh << "&\"$env:SYSTEMDRIVE/tmp/busser/gems/bin/busser\" setup"
setup_cmd_posh << "#{config[:busser_bin]} plugin install #{plugins.join(" ")}"
setup_cmd_posh.join("; ")
raise "[#{self}] Unsupported shell: #{shell}"
end
Util.wrap_command(cmd, shell)
end

# Returns a command string which transfers all suite test files to the
Expand All @@ -149,36 +150,15 @@ def sync_cmd
#{sudo(config[:busser_bin])} suite cleanup
CMD

local_suite_files.each do |f|
cmd << stream_file(f, remote_file(f, config[:suite_name])).concat("\n")
end
helper_files.each do |f|
cmd << stream_file(f, remote_file(f, "helpers")).concat("\n")
end

Util.wrap_command(cmd)
end

# Return a command string just like sync_cmd but in PowerShell
#
# @author Salim Afiune <[email protected]>
def sync_cmd_posh
return if local_suite_files.empty?

cmd = <<-CMD.gsub(/^ {8}/, "")
#{busser_setup_env_posh}
#{config[:busser_bin]} suite cleanup
CMD
local_suite_files.each do |f|
cmd << stream_file(f, remote_file_posh(f, config[:suite_name])).concat("\n")
end
helper_files.each do |f|
cmd << stream_file(f, remote_file_posh(f, "helpers")).concat("\n")
end

cmd
Util.wrap_command(cmd, shell)
end

# Returns a command string which runs all Busser suite tests for the suite.
Expand All @@ -197,27 +177,41 @@ def run_cmd
#{sudo(config[:busser_bin])} test
CMD

Util.wrap_command(cmd)
Util.wrap_command(cmd, shell)
end

# Return a command string just like run_cmd but in PowerShell
# Performs any final configuration required to do its work.
# A reference to an Instance is required as configuration dependant
# data may need access through an Instance. This also acts as a hook
# point where the object may wish to perform other last minute checks,
# valiations, or configuration expansions.
#
# @author Salim Afiune <[email protected]>
def run_cmd_posh
return if local_suite_files.empty?
cmd = <<-CMD.gsub(/^ {8}/, "")
#{busser_setup_env_posh}
#{config[:busser_bin]} test
CMD
cmd
# @param instance [Instance] an associated instance
# @return [self] itself, used for chaining
# @raise [ClientError] if instance parameter is nil
def finalize_config!(instance)
super
load_needed_dependencies!
# Overwrite the sudo configuration comming from the Transport
config[:sudo] = instance.transport.sudo
# Smart way to do this?
config[:busser_bin] = "busser" if shell.eql?("powershell")
self
end

private

DEFAULT_RUBY_BINDIR = "/opt/chef/embedded/bin".freeze
DEFAULT_ROOT_PATH = "/tmp/busser".freeze

# Loads any needed dependencies
#
# @raise [ClientError] if any library loading fails or any of the
# dependency requirements cannot be satisfied
# @api private
def load_needed_dependencies!
end

# @return [Hash] a configuration hash
# @api private
attr_reader :config
Expand Down Expand Up @@ -297,15 +291,18 @@ def helper_files
# @api private
def remote_file(file, dir)
local_prefix = File.join(config[:test_base_path], dir)
"`#{sudo(config[:busser_bin])} suite path`/".
concat(file.sub(%r{^#{local_prefix}/}, ""))
case shell
when 'bourne'
"`#{sudo(config[:busser_bin])} suite path`/".
concat(file.sub(%r{^#{local_prefix}/}, ""))
when 'powershell'
"$env:BUSSER_SUITE_PATH/".
concat(file.sub(%r{^#{local_prefix}/}, ""))
else
raise "[#{self}] Unsupported shell: #{shell}"
end
end

def remote_file_posh(file, dir)
local_prefix = File.join(config[:test_base_path], dir)
"$env:BUSSER_SUITE_PATH/".
concat(file.sub(%r{^#{local_prefix}/}, ""))
end
# Returns a command string that will, once evaluated, result in the copying
# of a local file to a remote instance.
#
Expand Down Expand Up @@ -341,34 +338,42 @@ def sudo(command)
config[:sudo] ? "sudo -E #{command}" : command
end

# @return [Transport.shell] the transport desired shell for this instance
# This would help us know which commands to use. Bourne, Powershell, etc.
#
# @api private
def shell
instance.transport.shell
end

# Returns a command string that sets appropriate environment variables for
# busser commands.
#
# @return [String] command string
# @api private
def busser_setup_env
[
%{BUSSER_ROOT="#{config[:root_path]}"},
%{GEM_HOME="#{config[:root_path]}/gems"},
%{GEM_PATH="#{config[:root_path]}/gems"},
%{GEM_CACHE="#{config[:root_path]}/gems/cache"},
%{\nexport BUSSER_ROOT GEM_HOME GEM_PATH GEM_CACHE}
].join(" ")
end

# Return a command string just like busser_setup_env but in PowerShell
#
# @author Salim Afiune <[email protected]>
def busser_setup_env_posh
[
%{$env:BUSSER_ROOT="#{config[:root_path]}";},
%{$env:GEM_HOME="#{config[:root_path]}/gems";},
%{$env:GEM_PATH="#{config[:root_path]}/gems";},
%{$env:PATH="$env:PATH;$env:GEM_PATH/bin";},
%{try { $env:BUSSER_SUITE_PATH=@(#{config[:busser_bin]} suite path) }},
%{catch { $env:BUSSER_SUITE_PATH="" };},
%{$env:GEM_CACHE="#{config[:root_path]}/gems/cache"}
].join(" ")
case shell
when 'bourne'
[
%{BUSSER_ROOT="#{config[:root_path]}"},
%{GEM_HOME="#{config[:root_path]}/gems"},
%{GEM_PATH="#{config[:root_path]}/gems"},
%{GEM_CACHE="#{config[:root_path]}/gems/cache"},
%{\nexport BUSSER_ROOT GEM_HOME GEM_PATH GEM_CACHE}
].join(" ")
when 'powershell'
[
%{$env:BUSSER_ROOT="#{config[:root_path]}";},
%{$env:GEM_HOME="#{config[:root_path]}/gems";},
%{$env:GEM_PATH="#{config[:root_path]}/gems";},
%{$env:PATH="$env:PATH;$env:GEM_PATH/bin";},
%{try { $env:BUSSER_SUITE_PATH=@(#{@config[:busser_bin]} suite path) }},
%{catch { $env:BUSSER_SUITE_PATH="" };},
%{$env:GEM_CACHE="#{config[:root_path]}/gems/cache"}
].join(" ")
else
raise "[#{self}] Unsupported shell: #{shell}"
end
end

# Returns arguments to a `gem install` command, suitable to install the
Expand Down
11 changes: 0 additions & 11 deletions lib/kitchen/data_munger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def busser_data_for(suite, platform)
set_kitchen_config_at!(bdata, :kitchen_root)
set_kitchen_config_at!(bdata, :test_base_path)
set_kitchen_config_at!(bdata, :log_level)
override_busser_guest_param!(bdata, driver_data_for(suite, platform))
end
end

Expand Down Expand Up @@ -134,16 +133,6 @@ def suite_data
# @api private
attr_reader :kitchen_config

def override_busser_guest_param!(root, driver)
if driver.key?(:guest)
case driver.fetch(:guest)
when ":windows"
root[:sudo] = false
root[:busser_bin] = "busser"
end
end
end

def combine_arrays!(root, key, *namespaces)
if root.key?(key)
root[key] = namespaces.
Expand Down
Loading

0 comments on commit 5489c67

Please sign in to comment.