Class: Kitchen::Driver::Localhost
- Inherits:
-
Base
- Object
- Base
- Kitchen::Driver::Localhost
- Defined in:
- lib/kitchen/driver/localhost.rb
Overview
Localhost driver for Kitchen.
Class Method Summary collapse
-
.lock ⇒ Mutex
Define a Mutex at the class level so we can prevent instances using this driver from colliding.
-
.lock! ⇒ Object
Lock the class-level Mutex, whatever state it’s in currently.
-
.unlock! ⇒ Object
Unlock the class-level Mutex, whatever state it’s in currently.
Instance Method Summary collapse
-
#create(state) ⇒ Object
Create the temp dirs on the local filesystem for Kitchen.
-
#destroy(_) ⇒ Object
Clean up the temp dirs left behind.
Class Method Details
.lock ⇒ Mutex
Define a Mutex at the class level so we can prevent instances using this driver from colliding.
42 43 44 |
# File 'lib/kitchen/driver/localhost.rb', line 42 def self.lock @lock ||= Mutex.new end |
.lock! ⇒ Object
Lock the class-level Mutex, whatever state it’s in currently.
49 50 51 |
# File 'lib/kitchen/driver/localhost.rb', line 49 def self.lock! lock.lock end |
.unlock! ⇒ Object
Unlock the class-level Mutex, whatever state it’s in currently.
56 57 58 59 60 61 62 |
# File 'lib/kitchen/driver/localhost.rb', line 56 def self.unlock! # Mutex#unlock raises an exception if lock is owned by another thread # and Mutex#owned? isn't available in Ruby 1.9. lock.unlock if lock.locked? rescue ThreadError nil end |
Instance Method Details
#create(state) ⇒ Object
Create the temp dirs on the local filesystem for Kitchen.
(see Base#create)
68 69 70 71 72 |
# File 'lib/kitchen/driver/localhost.rb', line 68 def create(state) self.class.lock! state[:hostname] = Socket.gethostname logger.info("[Localhost] Instance #{instance} ready.") end |
#destroy(_) ⇒ Object
Clean up the temp dirs left behind
(see Base#destroy)
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kitchen/driver/localhost.rb', line 79 def destroy(_) paths = [ instance.provisioner[:root_path], instance.verifier[:root_path] ] paths.each do |p| FileUtils.rm_rf(p) logger.info("[Localhost] Deleted temp dir '#{p}'.") end self.class.unlock! end |