Module: Kitchen

Defined in:
lib/kitchen.rb,
lib/kitchen/cli.rb,
lib/kitchen/ssh.rb,
lib/kitchen/util.rb,
lib/kitchen/color.rb,
lib/kitchen/suite.rb,
lib/kitchen/busser.rb,
lib/kitchen/config.rb,
lib/kitchen/driver.rb,
lib/kitchen/errors.rb,
lib/kitchen/logger.rb,
lib/kitchen/command.rb,
lib/kitchen/logging.rb,
lib/kitchen/version.rb,
lib/kitchen/instance.rb,
lib/kitchen/platform.rb,
lib/kitchen/lazy_hash.rb,
lib/kitchen/shell_out.rb,
lib/kitchen/collection.rb,
lib/kitchen/diagnostic.rb,
lib/kitchen/rake_tasks.rb,
lib/kitchen/state_file.rb,
lib/kitchen/thor_tasks.rb,
lib/kitchen/data_munger.rb,
lib/kitchen/driver/base.rb,
lib/kitchen/loader/yaml.rb,
lib/kitchen/provisioner.rb,
lib/kitchen/command/exec.rb,
lib/kitchen/command/list.rb,
lib/kitchen/command/sink.rb,
lib/kitchen/command/test.rb,
lib/kitchen/configurable.rb,
lib/kitchen/driver/dummy.rb,
lib/kitchen/driver/proxy.rb,
lib/kitchen/base64_stream.rb,
lib/kitchen/command/login.rb,
lib/kitchen/login_command.rb,
lib/kitchen/command/action.rb,
lib/kitchen/generator/init.rb,
lib/kitchen/command/console.rb,
lib/kitchen/driver/ssh_base.rb,
lib/kitchen/command/diagnose.rb,
lib/kitchen/metadata_chopper.rb,
lib/kitchen/provisioner/base.rb,
lib/kitchen/provisioner/dummy.rb,
lib/kitchen/provisioner/shell.rb,
lib/kitchen/provisioner/chef_base.rb,
lib/kitchen/provisioner/chef_solo.rb,
lib/kitchen/provisioner/chef_zero.rb,
lib/kitchen/command/driver_discover.rb,
lib/kitchen/generator/driver_create.rb,
lib/kitchen/provisioner/chef/berkshelf.rb,
lib/kitchen/provisioner/chef/librarian.rb

Overview

Author:: Fletcher Nichol ([email protected])

Copyright (C) 2013, Fletcher Nichol

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: Base64Stream, Color, Command, Configurable, Driver, Error, Generator, Loader, Logging, Provisioner, ShellOut, Util Classes: ActionFailed, Busser, CLI, ClientError, Collection, Config, DataMunger, Diagnostic, Instance, InstanceFailure, LazyHash, Logger, LoginCommand, MetadataChopper, Platform, RakeTasks, SSH, SSHFailed, StandardError, StateFile, StateFileLoadError, Suite, ThorTasks, TransientFailure, UserError

Constant Summary collapse

DEFAULT_LOG_LEVEL =

Default log level verbosity

:info
DEFAULT_TEST_DIR =

Default base directory for integration tests, fixtures, etc.

"test/integration".freeze
DEFAULT_LOG_DIR =

Default base directory for instance and common log files

".kitchen/logs".freeze
VERSION =
"1.3.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerLogger

Returns the common Kitchen logger.

Returns:

  • (Logger)

    the common Kitchen logger



57
58
59
# File 'lib/kitchen.rb', line 57

def logger
  @logger
end

.mutexMutex

Returns a common mutex for global coordination.

Returns:

  • (Mutex)

    a common mutex for global coordination



60
61
62
# File 'lib/kitchen.rb', line 60

def mutex
  @mutex
end

Class Method Details

.default_file_loggerLogger

Returns a default file logger which emits on standard output and to a log file.

Returns:



80
81
82
83
# File 'lib/kitchen.rb', line 80

def default_file_logger
  logfile = File.expand_path(File.join(".kitchen", "logs", "kitchen.log"))
  Logger.new(:stdout => $stdout, :logdev => logfile, :level => env_log)
end

.default_loggerLogger

Returns a default logger which emits on standard output.

Returns:



72
73
74
# File 'lib/kitchen.rb', line 72

def default_logger
  Logger.new(:stdout => $stdout, :level => env_log)
end

.source_rootPathname

Returns the root path of the Kitchen gem source code.

Returns:

  • (Pathname)

    root path of gem



65
66
67
# File 'lib/kitchen.rb', line 65

def source_root
  @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
end

.tty?true, false

Returns whether or not standard output is associated with a terminal device (tty).

Returns:

  • (true, false)

    is there a tty?



89
90
91
# File 'lib/kitchen.rb', line 89

def tty?
  $stdout.tty?
end

.with_friendly_errorsObject

Yields to a code block in order to consistently emit a useful crash/error message and exit appropriately. There are two primary failure conditions: an expected instance failure, and any other unexpected failures.

Note This method may call Kernel.exit so may not return if the yielded code block raises an exception.

Instance Failure

This is an expected failure scenario which could happen if an instance couldn't be created, a Chef run didn't successfully converge, a post-convergence test suite failed, etc. In other words, you can count on encountering these failures all the time--this is Kitchen's worldview: crash early and often. In this case a cleanly formatted exception is written to STDERR and the exception message is written to the common Kitchen file logger.

Unexpected Failure

All other forms of Kitchen::Error exceptions are considered unexpected or unplanned exceptions, typically from user configuration errors, driver or provisioner coding issues or bugs, or internal code issues. Given a stable release of Kitchen and a solid set of drivers and provisioners, the most likely cause of this is user configuration error originating in the .kitchen.yml setup. For this reason, the exception is written to STDERR, a full formatted exception trace is written to the common Kitchen file logger, and a message is displayed on STDERR to the user informing them to check the log files and check their configuration with the kitchen diagnose subcommand.

Raises:

  • (SystemExit)

    if an exception is raised in the yielded block



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/kitchen/errors.rb', line 153

def self.with_friendly_errors
  yield
rescue Kitchen::InstanceFailure => e
  Kitchen.mutex.synchronize do
    handle_instance_failure(e)
  end
  exit 10
rescue Kitchen::Error => e
  Kitchen.mutex.synchronize do
    handle_error(e)
  end
  exit 20
end