-
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.
Merge pull request #1 from tecracer-theinen/theinen/queueing
Implementation of script-based host queueing
- Loading branch information
Showing
10 changed files
with
326 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Offense count: 36 | ||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. | ||
# URISchemes: http, https | ||
AllCops: | ||
TargetRubyVersion: 2.6 | ||
Exclude: | ||
- Guardfile | ||
- Rakefile | ||
|
||
Metrics/LineLength: | ||
Max: 147 | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
notification :terminal_title, display_message: true | ||
|
||
guard :shell do | ||
watch(/\.rb$/) { `rake install:local` } | ||
guard 'rake', task: 'install:local' do | ||
watch(/\.rb$/) | ||
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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
module Kitchen::Driver | ||
class Static | ||
module Queueing | ||
class Base | ||
@options = {} | ||
@request_options = {} | ||
@release_options = {} | ||
|
||
@hostname = nil | ||
@banner = nil | ||
|
||
@env_vars = {} | ||
|
||
attr_reader :options, :request_options, :release_options, :env_vars, :banner | ||
|
||
def initialize(options) | ||
@options = { | ||
queueing_timeout: 3600, | ||
} | ||
|
||
@request_options = {} | ||
@release_options = {} | ||
|
||
setup(options) | ||
|
||
process_kitchen_options(options) | ||
end | ||
|
||
def request(state) | ||
handle_request(state) | ||
end | ||
|
||
def release(state) | ||
@env_vars = { | ||
STATIC_HOSTNAME: state[:hostname], | ||
} | ||
|
||
handle_release(state) | ||
end | ||
|
||
def banner? | ||
! @banner.nil? | ||
end | ||
|
||
def self.descendants | ||
ObjectSpace.each_object(Class).select { |klass| klass < self } | ||
end | ||
|
||
private | ||
|
||
def setup(_options) | ||
# Add setup and defaults in specific handler | ||
end | ||
|
||
def handle_request(_state) | ||
raise "Implement request handler" | ||
end | ||
|
||
def handle_release(_state) | ||
raise "Implement release handler" | ||
end | ||
|
||
def default_request_options(options = {}) | ||
@request_options.merge!(options) | ||
end | ||
|
||
def default_release_options(options = {}) | ||
@release_options.merge!(options) | ||
end | ||
|
||
def process_kitchen_options(kitchen_options) | ||
@options = kitchen_options | ||
|
||
@request_options.merge!(options[:request]) | ||
@options.delete(:request) | ||
|
||
@release_options.merge!(options[:release]) | ||
@options.delete(:release) | ||
end | ||
|
||
def timeout | ||
options[:queueing_timeout] | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "mixlib/shellout" | ||
|
||
require_relative "base.rb" | ||
|
||
module Kitchen::Driver | ||
class Static | ||
module Queueing | ||
class Script < Base | ||
def setup(_kitchen_options) | ||
default_request_options({ | ||
match_hostname: "^(.*)$", | ||
match_banner: nil, | ||
}) | ||
|
||
default_release_options({}) | ||
end | ||
|
||
def handle_request(_state) | ||
stdout = execute(request_options[:execute]) | ||
|
||
matched = stdout.match(request_options[:match_hostname]) | ||
raise format("Could not extract hostname from '%s' with regular expression /%s/", stdout, request_options[:match_hostname]) unless matched | ||
|
||
# Allow additional feedback from command | ||
@banner = stdout.match(request_options[:match_banner])&.captures&.first if request_options[:match_banner] | ||
|
||
matched.captures.first | ||
end | ||
|
||
def handle_release(_state) | ||
execute(release_options[:execute]) | ||
end | ||
|
||
private | ||
|
||
def execute(command) | ||
raise format("Received empty command") if command.nil? || command.empty? | ||
|
||
cmd = Mixlib::ShellOut.new(command, environment: env_vars, timeout: timeout) | ||
cmd.run_command | ||
|
||
raise format("Error executing `%s`: %s", command, cmd.stderr) if cmd.status != 0 | ||
|
||
cmd.stdout.strip | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.