Class: Kitchen::Instance
- Inherits:
-
Object
- Object
- Kitchen::Instance
- Defined in:
- lib/kitchen/instance_patch.rb
Overview
Monkey patch the Kitchen::Instance class with the default configs for the Localhost driver/transport.
Class Method Summary collapse
-
.lock ⇒ Mutex
Define a Mutex at the class level so we can prevent instances using the Localhost driver from colliding.
Instance Method Summary collapse
- #old_setup_transport ⇒ Object
- #old_test ⇒ Object
-
#platform ⇒ Object
If using the Localhost driver, use the custom Platform class to figure out whether we need to use PowerShell or not.
-
#setup_transport ⇒ Object
If using the Localhost driver, force usage of the Localhost transport.
-
#test(destroy_node = :passing) ⇒ Object
If using the Localhost driver, don’t start the test phase until we can get a lock on the class-level Mutex.
Class Method Details
.lock ⇒ Mutex
Define a Mutex at the class level so we can prevent instances using the Localhost driver from colliding.
39 40 41 |
# File 'lib/kitchen/instance_patch.rb', line 39 def lock @lock ||= Mutex.new end |
Instance Method Details
#old_setup_transport ⇒ Object
65 |
# File 'lib/kitchen/instance_patch.rb', line 65 alias_method :old_setup_transport, :setup_transport |
#old_test ⇒ Object
44 |
# File 'lib/kitchen/instance_patch.rb', line 44 alias_method :old_test, :test |
#platform ⇒ Object
If using the Localhost driver, use the custom Platform class to figure out whether we need to use PowerShell or not.
(see Instance#platform)
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kitchen/instance_patch.rb', line 85 def platform if driver.class == Kitchen::Driver::Localhost && \ @platform.class != Kitchen::Platform::Localhost @platform = Kitchen::Platform::Localhost.new( name: @platform.name, os_type: @platform.os_type, shell_type: @platform.shell_type ) end @platform end |
#setup_transport ⇒ Object
If using the Localhost driver, force usage of the Localhost transport.
(see Instance#setup_transport)
72 73 74 75 76 77 |
# File 'lib/kitchen/instance_patch.rb', line 72 def setup_transport if driver.class == Kitchen::Driver::Localhost @transport = Kitchen::Transport::Localhost.new end old_setup_transport end |
#test(destroy_node = :passing) ⇒ Object
If using the Localhost driver, don’t start the test phase until we can get a lock on the class-level Mutex.
(see Instance#test)
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kitchen/instance_patch.rb', line 52 def test(destroy_node = :passing) if driver.class == Kitchen::Driver::Localhost debug("[Localhost] Waiting for a lock before #{to_str} can proceed...") self.class.lock.synchronize do debug("[Localhost] Lock obtained for #{to_str}; proceeding...") old_test(destroy_node) debug("[Localhost] Test complete for #{to_str}; releasing lock...") end else old_test(destroy_node) end end |