Class: Kitchen::Verifier::Base
- Inherits:
-
Plugin::Base
- Object
- Plugin::Base
- Kitchen::Verifier::Base
- Includes:
- Configurable, Logging
- Defined in:
- lib/kitchen/verifier/base.rb
Overview
Base class for a verifier.
Instance Attribute Summary
Attributes included from Configurable
Class Method Summary collapse
-
.kitchen_verifier_api_version(version) ⇒ Object
Sets the API version for this verifier.
Instance Method Summary collapse
-
#call(state) ⇒ Object
Runs the verifier on the instance.
-
#cleanup_sandbox ⇒ Object
Deletes the sandbox path.
-
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which verifier related files and directories can be copied or created.
-
#doctor(state) ⇒ Object
Check system and configuration for common errors.
-
#init_command ⇒ String
Generates a command string which will perform any data initialization or configuration required after the verifier software is installed but before the sandbox has been transferred to the instance.
-
#initialize(config = {}) ⇒ Base
constructor
Creates a new Verifier object using the provided configuration data which will be merged with any default configuration.
-
#install_command ⇒ String
Generates a command string which will install and configure the verifier software on an instance.
-
#prepare_command ⇒ String
Generates a command string which will perform any commands or configuration required just before the main verifier run command but after the sandbox has been transferred to the instance.
-
#run_command ⇒ String
Generates a command string which will invoke the main verifier command on the prepared instance.
-
#sandbox_dirs ⇒ String
Returns the list of items in the sandbox directory.
-
#sandbox_path ⇒ String
Returns the absolute path to the sandbox directory or raises an exception if
#create_sandboxhas not yet been called.
Methods included from Logging
#banner, #debug, #error, #fatal, #info, #warn
Methods included from Configurable
#[], #bourne_shell?, #calculate_path, #config_keys, #diagnose, #diagnose_plugin, #finalize_config!, included, #name, #powershell_shell?, #remote_path_join, #unix_os?, #verify_dependencies, #windows_os?
Constructor Details
#initialize(config = {}) ⇒ Base
Creates a new Verifier object using the provided configuration data which will be merged with any default configuration.
58 59 60 |
# File 'lib/kitchen/verifier/base.rb', line 58 def initialize(config = {}) init_config(config) end |
Class Method Details
.kitchen_verifier_api_version(version) ⇒ Object
Sets the API version for this verifier. If the verifier does not set
this value, then nil will be used and reported.
Sets the API version for this verifier
217 218 219 |
# File 'lib/kitchen/verifier/base.rb', line 217 def self.kitchen_verifier_api_version(version) @api_version = version end |
Instance Method Details
#call(state) ⇒ Object
Runs the verifier on the instance.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/kitchen/verifier/base.rb', line 66 def call(state) create_sandbox instance.transport.connection(state) do |conn| conn.execute(install_command) conn.execute(init_command) info("Transferring files to #{instance.to_str}") conn.upload(sandbox_dirs, config[:root_path]) debug("Transfer complete") conn.execute(prepare_command) begin conn.execute(run_command) ensure # Retrieval is best-effort: a file we could not fetch must not # fail an otherwise successful verify, and must never replace # an error already in flight from the run command. A transport # that cannot download at all is a bug, not a missing file, so # it still raises when there is no verify error to protect. run_error = $! begin info("Downloading files from #{instance.to_str}") config[:downloads].to_h.each do |remotes, local| debug("Downloading #{Array(remotes).join(", ")} to #{local}") conn.download(remotes, local) end debug("Download complete") rescue => ex raise unless run_error || ex.is_a?(Kitchen::Transport::TransportFailed) warn("Failed to download files from #{instance.to_str}: #{ex.}") end end end rescue Kitchen::Transport::TransportFailed => ex raise ActionFailed, ex. ensure cleanup_sandbox end |
#cleanup_sandbox ⇒ Object
Deletes the sandbox path. Without calling this method, the sandbox path will persist after the process terminates. In other words, cleanup is explicit. This method is safe to call multiple times.
117 118 119 120 121 122 |
# File 'lib/kitchen/verifier/base.rb', line 117 def cleanup_sandbox return if sandbox_path.nil? debug("Cleaning up local sandbox in #{sandbox_path}") FileUtils.rmtree(sandbox_path) end |
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which verifier related files and directories can be copied or created. The contents of this directory will be copied over to the instance before invoking the verifier's run command. After this method completes, it is expected that the contents of the sandbox is complete and ready for copy to the remote instance.
Note: any subclasses would be well advised to call super first when overriding this method, for example:
142 143 144 145 146 147 |
# File 'lib/kitchen/verifier/base.rb', line 142 def create_sandbox @sandbox_path = Dir.mktmpdir("#{instance.name}-sandbox-") File.chmod(0755, sandbox_path) info("Preparing files for transfer") debug("Creating local sandbox in #{sandbox_path}") end |
#doctor(state) ⇒ Object
Check system and configuration for common errors.
110 111 112 |
# File 'lib/kitchen/verifier/base.rb', line 110 def doctor(state) false end |
#init_command ⇒ String
Generates a command string which will perform any data initialization
or configuration required after the verifier software is installed
but before the sandbox has been transferred to the instance. If no work
is required, then nil will be returned.
162 |
# File 'lib/kitchen/verifier/base.rb', line 162 def init_command; end |
#install_command ⇒ String
Generates a command string which will install and configure the
verifier software on an instance. If no work is required, then nil
will be returned.
154 |
# File 'lib/kitchen/verifier/base.rb', line 154 def install_command; end |
#prepare_command ⇒ String
Generates a command string which will perform any commands or
configuration required just before the main verifier run command but
after the sandbox has been transferred to the instance. If no work is
required, then nil will be returned.
170 |
# File 'lib/kitchen/verifier/base.rb', line 170 def prepare_command; end |
#run_command ⇒ String
Generates a command string which will invoke the main verifier
command on the prepared instance. If no work is required, then nil
will be returned.
177 |
# File 'lib/kitchen/verifier/base.rb', line 177 def run_command; end |
#sandbox_dirs ⇒ String
Returns the list of items in the sandbox directory
194 195 196 |
# File 'lib/kitchen/verifier/base.rb', line 194 def sandbox_dirs Util.list_directory(sandbox_path) end |
#sandbox_path ⇒ String
Returns the absolute path to the sandbox directory or raises an
exception if #create_sandbox has not yet been called.
185 186 187 188 189 |
# File 'lib/kitchen/verifier/base.rb', line 185 def sandbox_path @sandbox_path ||= raise ClientError, "Sandbox directory has not yet " \ "been created. Please run #{self.class}#create_sandox before " \ "trying to access the path." end |