kitchen-static 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -0
- data/lib/kitchen/driver/queueing/base.rb +87 -0
- data/lib/kitchen/driver/queueing/json.rb +37 -0
- data/lib/kitchen/driver/queueing/script.rb +49 -0
- data/lib/kitchen/driver/static.rb +85 -2
- data/lib/kitchen/driver/static_version.rb +1 -1
- metadata +68 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fadfee7e8df80d6580498dc4c93c42bb7e4bf1cad8b8d71136dd03687da8a5f
|
4
|
+
data.tar.gz: 96d2a5be8ab420ac58d66ec1391d0edb00e4135fc9ed702c99325d1e11d1eb55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 893fb9091522ebf53e78112449f87e6134986a8b2806d05ffcf3d95567b02a7099f3bfb2587a2aaa0a013503ec17463bdf2aa298fa1b8d24764516bdc13aa7f5
|
7
|
+
data.tar.gz: 3762dc3b7e91d9324f3ffed0dfd7729e42a8ed8ec968cbe355181bdf446e8284cec459a1d6ad184f99194e7efff85bc0380821e4207919da00cf274258c4db2d
|
data/LICENSE
CHANGED
File without changes
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Kitchen::Driver
|
2
|
+
class Static
|
3
|
+
module Queueing
|
4
|
+
class Base
|
5
|
+
@options = {}
|
6
|
+
@request_options = {}
|
7
|
+
@release_options = {}
|
8
|
+
|
9
|
+
@hostname = nil
|
10
|
+
@banner = nil
|
11
|
+
|
12
|
+
@env_vars = {}
|
13
|
+
|
14
|
+
attr_reader :options, :request_options, :release_options, :env_vars, :banner
|
15
|
+
|
16
|
+
def initialize(options)
|
17
|
+
@options = {
|
18
|
+
queueing_timeout: 3600,
|
19
|
+
}
|
20
|
+
|
21
|
+
@request_options = {}
|
22
|
+
@release_options = {}
|
23
|
+
|
24
|
+
setup(options)
|
25
|
+
|
26
|
+
process_kitchen_options(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def request(state)
|
30
|
+
handle_request(state)
|
31
|
+
end
|
32
|
+
|
33
|
+
def release(state)
|
34
|
+
@env_vars = {
|
35
|
+
STATIC_HOSTNAME: state[:hostname],
|
36
|
+
}
|
37
|
+
|
38
|
+
handle_release(state)
|
39
|
+
end
|
40
|
+
|
41
|
+
def banner?
|
42
|
+
! @banner.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.descendants
|
46
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def setup(_options)
|
52
|
+
# Add setup and defaults in specific handler
|
53
|
+
end
|
54
|
+
|
55
|
+
def handle_request(_state)
|
56
|
+
raise "Implement request handler"
|
57
|
+
end
|
58
|
+
|
59
|
+
def handle_release(_state)
|
60
|
+
raise "Implement release handler"
|
61
|
+
end
|
62
|
+
|
63
|
+
def default_request_options(options = {})
|
64
|
+
@request_options.merge!(options)
|
65
|
+
end
|
66
|
+
|
67
|
+
def default_release_options(options = {})
|
68
|
+
@release_options.merge!(options)
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_kitchen_options(kitchen_options)
|
72
|
+
@options = kitchen_options
|
73
|
+
|
74
|
+
@request_options.merge!(options[:request])
|
75
|
+
@options.delete(:request)
|
76
|
+
|
77
|
+
@release_options.merge!(options[:release])
|
78
|
+
@options.delete(:release)
|
79
|
+
end
|
80
|
+
|
81
|
+
def timeout
|
82
|
+
options[:queueing_timeout]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'base.rb'
|
2
|
+
|
3
|
+
module Kitchen::Driver
|
4
|
+
class Static
|
5
|
+
module Queueing
|
6
|
+
class Json < Base
|
7
|
+
def initialize(options = {})
|
8
|
+
super
|
9
|
+
|
10
|
+
default_handler_options({
|
11
|
+
mode: :wait, # :wait, :repeat, ?
|
12
|
+
method: :get, # :get, :post
|
13
|
+
data: '',
|
14
|
+
query: {},
|
15
|
+
map: {}
|
16
|
+
})
|
17
|
+
|
18
|
+
kitchen_handler_options options
|
19
|
+
end
|
20
|
+
|
21
|
+
def request
|
22
|
+
super
|
23
|
+
|
24
|
+
# TODO
|
25
|
+
end
|
26
|
+
|
27
|
+
def release
|
28
|
+
super
|
29
|
+
|
30
|
+
# TODO
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "mixlib/shellout"
|
2
|
+
|
3
|
+
require_relative "base.rb"
|
4
|
+
|
5
|
+
module Kitchen::Driver
|
6
|
+
class Static
|
7
|
+
module Queueing
|
8
|
+
class Script < Base
|
9
|
+
def setup(_kitchen_options)
|
10
|
+
default_request_options({
|
11
|
+
match_hostname: "^(.*)$",
|
12
|
+
match_banner: nil,
|
13
|
+
})
|
14
|
+
|
15
|
+
default_release_options({})
|
16
|
+
end
|
17
|
+
|
18
|
+
def handle_request(_state)
|
19
|
+
stdout = execute(request_options[:execute])
|
20
|
+
|
21
|
+
matched = stdout.match(request_options[:match_hostname])
|
22
|
+
raise format("Could not extract hostname from '%s' with regular expression /%s/", stdout, request_options[:match_hostname]) unless matched
|
23
|
+
|
24
|
+
# Allow additional feedback from command
|
25
|
+
@banner = stdout.match(request_options[:match_banner])&.captures&.first if request_options[:match_banner]
|
26
|
+
|
27
|
+
matched.captures.first
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_release(_state)
|
31
|
+
execute(release_options[:execute])
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def execute(command)
|
37
|
+
raise format("Received empty command") if command.nil? || command.empty?
|
38
|
+
|
39
|
+
cmd = Mixlib::ShellOut.new(command, environment: env_vars, timeout: timeout)
|
40
|
+
cmd.run_command
|
41
|
+
|
42
|
+
raise format("Error executing `%s`: %s", command, cmd.stderr) if cmd.status != 0
|
43
|
+
|
44
|
+
cmd.stdout.strip
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "kitchen"
|
2
|
+
|
2
3
|
require_relative "static_version"
|
3
4
|
|
4
5
|
module Kitchen
|
@@ -12,16 +13,98 @@ module Kitchen
|
|
12
13
|
|
13
14
|
plugin_version Kitchen::Driver::STATIC_VERSION
|
14
15
|
|
15
|
-
|
16
|
+
default_config :host, nil
|
17
|
+
|
18
|
+
default_config :queueing, false
|
19
|
+
default_config :queueing_timeout, 3600
|
20
|
+
default_config :queueing_handlers, []
|
21
|
+
default_config :request, {}
|
22
|
+
default_config :release, {}
|
23
|
+
|
24
|
+
BANNER_FORMAT = "[kitchen-static] >>> %s <<<".freeze
|
16
25
|
|
17
26
|
def create(state)
|
18
|
-
|
27
|
+
print_version
|
28
|
+
|
29
|
+
state[:hostname] = queueing? ? request(state) : config[:host]
|
30
|
+
|
31
|
+
if queueing?
|
32
|
+
info format("[kitchen-static] Received %s for testing", state[:hostname])
|
33
|
+
info format(BANNER_FORMAT, queueing_handler.banner) if queueing_handler.banner?
|
34
|
+
end
|
19
35
|
end
|
20
36
|
|
21
37
|
def destroy(state)
|
38
|
+
print_version
|
22
39
|
return if state[:hostname].nil?
|
40
|
+
|
41
|
+
release(state) if queueing?
|
42
|
+
info format("[kitchen-static] Released %s from testing", state[:hostname]) if queueing?
|
43
|
+
|
23
44
|
state.delete(:hostname)
|
24
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def request(state)
|
50
|
+
info format("[kitchen-static] Queueing request via %s handler", queueing_type)
|
51
|
+
|
52
|
+
queueing_handler.request(state)
|
53
|
+
end
|
54
|
+
|
55
|
+
def release(state)
|
56
|
+
info format("[kitchen-static] Queueing release via %s handler", queueing_type)
|
57
|
+
|
58
|
+
queueing_handler.release(state)
|
59
|
+
end
|
60
|
+
|
61
|
+
def queueing?
|
62
|
+
config[:queueing] === true
|
63
|
+
end
|
64
|
+
|
65
|
+
def queueing_handler
|
66
|
+
@queueing_handler ||= queueing_registry[queueing_type].new(config)
|
67
|
+
end
|
68
|
+
|
69
|
+
def queueing_type
|
70
|
+
return unless queueing?
|
71
|
+
|
72
|
+
config.fetch(:type, "script")
|
73
|
+
end
|
74
|
+
|
75
|
+
def queueing_registry
|
76
|
+
return unless queueing?
|
77
|
+
|
78
|
+
@queueing_registry unless @queueing_registry.nil? || @queueing_registry.empty?
|
79
|
+
@queueing_registry = {}
|
80
|
+
|
81
|
+
bundled_handlers = File.join(__dir__, "queueing", "*.rb")
|
82
|
+
require_queueing_handlers(bundled_handlers)
|
83
|
+
|
84
|
+
additional_handlers = config[:queueing_handlers]
|
85
|
+
additional_handlers.each { |glob| require_queueing_handlers(glob) }
|
86
|
+
|
87
|
+
Queueing::Base.descendants.each do |handler_class|
|
88
|
+
type = queueing_type_from_class(handler_class)
|
89
|
+
@queueing_registry[type] = handler_class
|
90
|
+
|
91
|
+
debug format("[kitchen-static] Added queueing handler: %s", type)
|
92
|
+
end
|
93
|
+
|
94
|
+
@queueing_registry
|
95
|
+
end
|
96
|
+
|
97
|
+
def require_queueing_handlers(glob)
|
98
|
+
Dir.glob(glob).each { |file| require file }
|
99
|
+
end
|
100
|
+
|
101
|
+
def queueing_type_from_class(handler_class)
|
102
|
+
handler_class.to_s.split("::").last.downcase
|
103
|
+
end
|
104
|
+
|
105
|
+
def print_version
|
106
|
+
debug format("Starting kitchen-static %s", Kitchen::Driver::STATIC_VERSION)
|
107
|
+
end
|
25
108
|
end
|
26
109
|
end
|
27
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-static
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Heinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -30,34 +30,90 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mixlib-shellout
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: bundler
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
36
50
|
requirements:
|
37
51
|
- - ">="
|
38
52
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
53
|
+
version: '1.16'
|
40
54
|
type: :development
|
41
55
|
prerelease: false
|
42
56
|
version_requirements: !ruby/object:Gem::Requirement
|
43
57
|
requirements:
|
44
58
|
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
60
|
+
version: '1.16'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: guard
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.16'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.16'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: guard-rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.0'
|
47
89
|
- !ruby/object:Gem::Dependency
|
48
90
|
name: rake
|
49
91
|
requirement: !ruby/object:Gem::Requirement
|
50
92
|
requirements:
|
51
|
-
- - "
|
93
|
+
- - "~>"
|
52
94
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
95
|
+
version: '12.0'
|
54
96
|
type: :development
|
55
97
|
prerelease: false
|
56
98
|
version_requirements: !ruby/object:Gem::Requirement
|
57
99
|
requirements:
|
58
|
-
- - "
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '12.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: yard
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.9'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
59
115
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
116
|
+
version: '0.9'
|
61
117
|
description: Test Kitchen driver for static hosts
|
62
118
|
email:
|
63
119
|
- theinen@tecracer.de
|
@@ -66,6 +122,9 @@ extensions: []
|
|
66
122
|
extra_rdoc_files: []
|
67
123
|
files:
|
68
124
|
- LICENSE
|
125
|
+
- lib/kitchen/driver/queueing/base.rb
|
126
|
+
- lib/kitchen/driver/queueing/json.rb
|
127
|
+
- lib/kitchen/driver/queueing/script.rb
|
69
128
|
- lib/kitchen/driver/static.rb
|
70
129
|
- lib/kitchen/driver/static_version.rb
|
71
130
|
homepage: https://github.com/tecracer-theinen/kitchen-static
|
@@ -87,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
146
|
- !ruby/object:Gem::Version
|
88
147
|
version: '0'
|
89
148
|
requirements: []
|
90
|
-
|
91
|
-
rubygems_version: 2.7.6
|
149
|
+
rubygems_version: 3.0.3
|
92
150
|
signing_key:
|
93
151
|
specification_version: 4
|
94
152
|
summary: Test Kitchen driver for static hosts
|