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.
[Potentially Breaking] Provisioners responsible for converge action.
Potentially Breaking Notes ========================== This is potentially breaking to Driver authors if all of the following are true: * Your Driver currently directly inherits from `Kitchen::Driver::Base` * Your Driver implements/overrides the `#converge` method Put another way, your Driver may have issues if it looks like the following: module Kitchen module Driver class MyDriver < Kitchen::Driver::Base def conerge(state) # custom converge work end end end end For the vast majority (well over 90%) of OSS Drivers in the wild, current behavior is maintained as they all inherit from `Kitchen::Driver::SSHBase`. This class has been cemented to preserve its current behavior, and Test Kitchen will invoke the `#converge` method for these Drivers. **Note:** upgrade path and instructions for Driver authors will be written, but backwards compatibility is being taken seriously. A future deprecation process may remove the `SSHBase` backwards compatibility, but not without plenty of lead time and warning. Due to the constraints of SemVer, by definition, this wouldn't occur before a 2.x codebase release. Self-Aware Provisioners ======================= As of this commit a `#call(state)` method exists in `Kitchen::Provisioner::Base` which will be invoked by Test Kitchen when the converge action is performed. For backwards compatibility, the same convergence "template" is used, relying on a small number of public methods that return command strings and 3 methods responsible for sandbox creation and cleanup. The high-level description of the default `#call(state)` method is as follows: 1. Create the temporary sandbox on the workstation with "stuff" to transfer to the remote instance. 2. Run the `#install_command` on the remote instance, if it is implemented. 3. Run the `#init_command` on the remote instance, if it is implemented. 4. Transfer all files in the sandbox path to the remote instance's configured `:root_path`. 5. Run the `#prepare_command` on the remote instance, if it is implemented. 6. Run the `#run_command` on the remote instance, if it is implemented. As a Provisioner author, you may elect to overwrite or partially re-implement the `#call(state)` method to do whatever you need in whatever order makes sense. This key difference allows Provisioner authors to entirely own the `kitchen converge` action and not also rely on the Driver used to manage the instances.
- Loading branch information
Showing
14 changed files
with
558 additions
and
86 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
module Kitchen | ||
|
||
# A driver is responsible for carrying out the lifecycle activities of an | ||
# instance, such as creating, converging, and destroying an instance. | ||
# instance, such as creating and destroying an instance. | ||
# | ||
# @author Fletcher Nichol <[email protected]> | ||
module Driver | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,54 @@ module Kitchen | |
|
||
module Provisioner | ||
|
||
# Dummy provisioner for Kitchen. This driver does nothing but report what | ||
# would happen if this provisioner did anything of consequence. As a result | ||
# it may be a useful provisioner to use when debugging or developing new | ||
# features or plugins. | ||
# | ||
# @author Fletcher Nichol <[email protected]> | ||
class Dummy < Kitchen::Provisioner::Base | ||
|
||
default_config :sleep, 0 | ||
default_config :random_failure, false | ||
|
||
# (see Base#call) | ||
def call(state) | ||
info("[#{name}] Converge on instance=#{instance} with state=#{state}") | ||
sleep_if_set | ||
failure_if_set | ||
debug("[#{name}] Converge completed (#{config[:sleep]}s).") | ||
end | ||
|
||
private | ||
|
||
# Sleep for a period of time, if a value is set in the config. | ||
# | ||
# @api private | ||
def sleep_if_set | ||
sleep(config[:sleep].to_f) if config[:sleep].to_f > 0.0 | ||
end | ||
|
||
# Simulate a failure in an action, if set in the config. | ||
# | ||
# @api private | ||
def failure_if_set | ||
if config[:"fail"] | ||
debug("Failure for Provisioner #{name}.") | ||
raise ActionFailed, "Action #converge failed for #{instance.to_str}." | ||
elsif config[:random_failure] && randomly_fail? | ||
debug("Random failure for Provisioner #{name}.") | ||
raise ActionFailed, "Action #converge failed for #{instance.to_str}." | ||
end | ||
end | ||
|
||
# Determine whether or not to randomly fail. | ||
# | ||
# @return [true, false] | ||
# @api private | ||
def randomly_fail? | ||
[true, false].sample | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.