forked from test-kitchen/test-kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mix Configurable into Busser to use default_config.
Now Busser uses the same intialization as Drivers, Provisioners, and Transports (using `#finalize_config!`). The suite_name is now provided by asking `instance.suite.name`.
- Loading branch information
Showing
6 changed files
with
64 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,62 +28,37 @@ module Kitchen | |
# @author Fletcher Nichol <[email protected]> | ||
class Busser | ||
|
||
# Constructs a new Busser command generator, given a suite name. | ||
# | ||
# @param [String] suite_name name of suite on which to operate | ||
# (**Required**) | ||
# @param [Hash] opts optional configuration | ||
# @option opts [String] :kitchen_root local path to the root of the project | ||
# @option opts [String] :instance_ruby_bindir path to the directory | ||
# containing the Ruby binary on the remote instance | ||
# @option opts [TrueClass, FalseClass] :sudo whether or not to invoke | ||
# sudo before commands requiring root access (default: `true`) | ||
def initialize(suite_name, opts = {}) | ||
validate_options(suite_name) | ||
|
||
kitchen_root = opts.fetch(:kitchen_root) { Dir.pwd } | ||
test_base_path = opts.fetch(:test_base_path, Kitchen::DEFAULT_TEST_DIR) | ||
|
||
@config = Hash.new | ||
@config[:kitchen_root] = kitchen_root | ||
@config[:test_base_path] = File.expand_path(test_base_path, kitchen_root) | ||
@config[:suite_name] = suite_name | ||
@config[:sudo] = opts.fetch(:sudo, true) | ||
@config[:ruby_bindir] = opts.fetch(:ruby_bindir, DEFAULT_RUBY_BINDIR) | ||
@config[:root_path] = opts.fetch(:root_path, DEFAULT_ROOT_PATH) | ||
@config[:version] = opts.fetch(:version, "busser") | ||
@config[:busser_bin] = opts.fetch(:busser_bin, File.join(@config[:root_path], "bin/busser")) | ||
end | ||
include Configurable | ||
|
||
# Returns the name of this busser, suitable for display in a CLI. | ||
# | ||
# @return [String] name of this busser | ||
def name | ||
config[:suite_name] | ||
default_config :busser_bin do |busser| | ||
File.join(busser[:root_path], %W[bin busser]) | ||
end | ||
|
||
# Returns an array of configuration keys. | ||
# | ||
# @return [Array] array of configuration keys | ||
def config_keys | ||
config.keys | ||
end | ||
default_config :root_path, "/tmp/busser" | ||
|
||
default_config :ruby_bindir, "/opt/chef/embedded/bin" | ||
|
||
default_config :sudo, true | ||
|
||
default_config(:suite_name) { |busser| busser.instance.suite.name } | ||
|
||
default_config :version, "busser" | ||
|
||
expand_path_for :test_base_path | ||
|
||
# Provides hash-like access to configuration keys. | ||
# Creates a new Busser object using the provided configuration data | ||
# which will be merged with any default configuration. | ||
# | ||
# @param attr [Object] configuration key | ||
# @return [Object] value at configuration key | ||
def [](attr) | ||
config[attr] | ||
# @param config [Hash] provided driver configuration | ||
def initialize(config = {}) | ||
init_config(config) | ||
end | ||
|
||
# Returns a Hash of configuration and other useful diagnostic information. | ||
# Returns the name of this busser, suitable for display in a CLI. | ||
# | ||
# @return [Hash] a diagnostic hash | ||
def diagnose | ||
result = Hash.new | ||
config_keys.sort.each { |k| result[k] = config[k] } | ||
result | ||
# @return [String] name of this busser | ||
def name | ||
config[:suite_name] | ||
end | ||
|
||
# Returns a command string which installs Busser, and installs all | ||
|
@@ -162,31 +137,6 @@ def run_cmd | |
|
||
private | ||
|
||
DEFAULT_RUBY_BINDIR = "/opt/chef/embedded/bin".freeze | ||
DEFAULT_ROOT_PATH = "/tmp/busser".freeze | ||
|
||
# @return [Hash] a configuration hash | ||
# @api private | ||
attr_reader :config | ||
|
||
# Ensures that the object is internally consistent and otherwise raising | ||
# an exception. | ||
# | ||
# @param suite_name [String] the suite name | ||
# @raise [ClientError] if a suite name is missing | ||
# @raise [UserError] if the suite name is invalid | ||
# @api private | ||
def validate_options(suite_name) | ||
if suite_name.nil? | ||
raise ClientError, "Busser#new requires a suite_name" | ||
end | ||
|
||
if suite_name == "helper" | ||
raise UserError, | ||
"Suite name invalid: 'helper' is a reserved directory name." | ||
end | ||
end | ||
|
||
# Returns a uniquely sorted Array of Busser plugin gems that need to | ||
# be installed for the related suite. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters