inprovise 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/inprovise/execution_context.rb +24 -11
- data/lib/inprovise/script.rb +1 -1
- data/lib/inprovise/script_runner.rb +15 -6
- data/lib/inprovise/trigger_runner.rb +17 -2
- data/lib/inprovise/version.rb +1 -1
- data/test/script_runner_test.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmU0MTAwMDZmYzQzNTQxYzA2ZGU5MTNmNzA4ZDJkNDg2ZTU0ZTRjOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzAzNWE4NTY0ZmMwNDgzZDRkMTY3MTJkNDBhOTM2N2FmOGY0YzIzYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDMwYzRiZGU2YzE2ZTZiZGYwYjRkMjJkMzExMGE0MDdkMTI1NTllMjQxNzY0
|
10
|
+
MTRhYjBjZmYyNDk0ODAzZDAzNDIwNWU3YThjYWFmYWYzY2EzZDQyZjliNWY3
|
11
|
+
ZWVhYzgxZDEyZWEzMWU5YTgzZjkxOGU2YTc4MThiOTdiNDk0MzI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWM0ZmUxMzZlYzllYTM3NjY3MjNhNWY5YjZjMTdlNWM5M2Y4YjFmZGY2NGI3
|
14
|
+
MTAyODMxMjVlMTA3NDdjZDFiYmE3MjJkMGQ0ZWFmZjc2YzIwM2JiM2RjZDI1
|
15
|
+
NjI1YWFjMDNkNmFiMDg4MjM4ZDM5OWNlY2M1MzE5Y2FlNWVlMzg=
|
@@ -7,7 +7,7 @@ require 'open3'
|
|
7
7
|
|
8
8
|
class Inprovise::ExecutionContext
|
9
9
|
|
10
|
-
class
|
10
|
+
class ConfigDSL
|
11
11
|
def initialize(context)
|
12
12
|
@context = context
|
13
13
|
end
|
@@ -16,13 +16,19 @@ class Inprovise::ExecutionContext
|
|
16
16
|
@context.config.send(meth, *args)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@context.
|
19
|
+
def script
|
20
|
+
@context.script ? @context.script.name : ''
|
21
21
|
end
|
22
22
|
|
23
23
|
def config
|
24
24
|
@context.config
|
25
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class DSL < ConfigDSL
|
29
|
+
def node
|
30
|
+
@context.node
|
31
|
+
end
|
26
32
|
|
27
33
|
def as(user, &blk)
|
28
34
|
@context.as(user, &blk)
|
@@ -81,7 +87,7 @@ class Inprovise::ExecutionContext
|
|
81
87
|
end
|
82
88
|
|
83
89
|
def trigger(action_ref, *args)
|
84
|
-
@context.trigger(action_ref, *args)
|
90
|
+
@context.trigger(*@context.resolve_action_ref(action_ref), *args)
|
85
91
|
end
|
86
92
|
|
87
93
|
def binary_exists?(binary)
|
@@ -101,6 +107,10 @@ class Inprovise::ExecutionContext
|
|
101
107
|
@script = nil
|
102
108
|
end
|
103
109
|
|
110
|
+
def exec_config(blk)
|
111
|
+
ConfigDSL.new(self).instance_eval(&blk)
|
112
|
+
end
|
113
|
+
|
104
114
|
def exec(blk, *args)
|
105
115
|
if args.empty?
|
106
116
|
DSL.new(self).instance_eval(&blk)
|
@@ -205,16 +215,19 @@ class Inprovise::ExecutionContext
|
|
205
215
|
Inprovise::Template.new(path, self)
|
206
216
|
end
|
207
217
|
|
208
|
-
def
|
209
|
-
action_name,
|
210
|
-
|
211
|
-
|
212
|
-
action =
|
218
|
+
def resolve_action_ref(action_ref)
|
219
|
+
action_name, scr_name = *action_ref.split(':', 2).reverse
|
220
|
+
scr = @script
|
221
|
+
scr = @index.get(scr_name) if scr_name
|
222
|
+
action = scr ? scr.actions[action_name] : nil
|
213
223
|
raise Inprovise::MissingActionError.new(action_ref) unless action
|
224
|
+
[scr, action]
|
225
|
+
end
|
226
|
+
|
227
|
+
def trigger(scr, action, *args)
|
214
228
|
curtask = @node.log.set_task(action_ref)
|
215
229
|
curscript = @script
|
216
|
-
@script =
|
217
|
-
@script.update_configuration(self)
|
230
|
+
@script = scr
|
218
231
|
begin
|
219
232
|
exec(action, *args)
|
220
233
|
ensure
|
data/lib/inprovise/script.rb
CHANGED
@@ -80,8 +80,8 @@ class Inprovise::Script
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def update_configuration(context)
|
83
|
+
context.config[self.name.to_sym] ||= Inprovise::Config.new
|
83
84
|
if @configuration
|
84
|
-
context.config[self.name.to_sym] ||= Inprovise::Config.new
|
85
85
|
context.config[self.name.to_sym].update!(@configuration)
|
86
86
|
end
|
87
87
|
end
|
@@ -35,9 +35,8 @@ class Inprovise::ScriptRunner
|
|
35
35
|
scrs = scripts
|
36
36
|
context = @perform ? Inprovise::ExecutionContext.new(@node, @log, @index, config) : Inprovise::MockExecutionContext.new(@node, @log, @index, config)
|
37
37
|
context.config.command = command_name.to_sym
|
38
|
-
scrs.each
|
39
|
-
|
40
|
-
end
|
38
|
+
scrs.each { |script| script.update_configuration(context) }
|
39
|
+
scrs.each { |script| setup_configuration(script, context) }
|
41
40
|
scrs.reverse! if command_name.to_sym == :revert
|
42
41
|
@log.say(scrs.map(&:name).join(', '), :yellow) if Inprovise.verbosity > 0
|
43
42
|
scrs.each do |script|
|
@@ -51,25 +50,31 @@ class Inprovise::ScriptRunner
|
|
51
50
|
@perform = true
|
52
51
|
end
|
53
52
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
53
|
+
def setup_configuration(script, context)
|
54
|
+
context.log.set_task(script)
|
55
|
+
context.log.command(:configure)
|
56
|
+
context.script = script
|
57
|
+
script.command(:configure).each {|cmd| context.exec_config(cmd) }
|
57
58
|
end
|
59
|
+
private :setup_configuration
|
58
60
|
|
59
61
|
def execute_apply(script, context)
|
60
62
|
return unless should_run?(script, :apply, context)
|
61
63
|
exec(script, :apply, context)
|
62
64
|
validate!(script, context)
|
63
65
|
end
|
66
|
+
private :execute_apply
|
64
67
|
|
65
68
|
def execute_revert(script, context)
|
66
69
|
return unless should_run?(script, :revert, context)
|
67
70
|
exec(script, :revert, context)
|
68
71
|
end
|
72
|
+
private :execute_revert
|
69
73
|
|
70
74
|
def execute_validate(script, context)
|
71
75
|
validate!(script, context)
|
72
76
|
end
|
77
|
+
private :execute_validate
|
73
78
|
|
74
79
|
def should_run?(script, command_name, context)
|
75
80
|
return false unless script.provides_command?(command_name)
|
@@ -80,6 +85,7 @@ class Inprovise::ScriptRunner
|
|
80
85
|
return !is_present if command_name == :apply
|
81
86
|
is_present
|
82
87
|
end
|
88
|
+
private :should_run?
|
83
89
|
|
84
90
|
def validate!(script, context)
|
85
91
|
return true unless @perform
|
@@ -87,6 +93,7 @@ class Inprovise::ScriptRunner
|
|
87
93
|
return if is_valid?(script, context)
|
88
94
|
raise ValidationFailureError.new(@node, script)
|
89
95
|
end
|
96
|
+
private :validate!
|
90
97
|
|
91
98
|
def is_valid?(script, context)
|
92
99
|
results = exec(script, :validate, context)
|
@@ -94,6 +101,7 @@ class Inprovise::ScriptRunner
|
|
94
101
|
context.log.command("validate -> #{rc}") if Inprovise.verbosity > 0
|
95
102
|
rc
|
96
103
|
end
|
104
|
+
private :is_valid?
|
97
105
|
|
98
106
|
def exec(script, command_name, context)
|
99
107
|
cmds = script.command(command_name)
|
@@ -103,6 +111,7 @@ class Inprovise::ScriptRunner
|
|
103
111
|
context.script = script
|
104
112
|
cmds.map {|cmd| context.exec(cmd) }
|
105
113
|
end
|
114
|
+
private :exec
|
106
115
|
|
107
116
|
class ValidationFailureError < StandardError
|
108
117
|
def initialize(node, script)
|
@@ -17,15 +17,30 @@ class Inprovise::TriggerRunner
|
|
17
17
|
|
18
18
|
def execute(_, config=nil)
|
19
19
|
Inprovise.log.local("Triggering #{@action_ref} for #{@node.to_s}")
|
20
|
-
Inprovise::ExecutionContext.new(@node, @log, @index, config)
|
20
|
+
context = Inprovise::ExecutionContext.new(@node, @log, @index, config)
|
21
|
+
scr, action = context.resolve_action_ref(@action_ref)
|
22
|
+
setup_configuration(scr, context)
|
23
|
+
context.trigger(scr, action, *@args)
|
21
24
|
end
|
22
25
|
|
23
26
|
def demonstrate(_, config=nil)
|
24
|
-
Inprovise
|
27
|
+
Inprovise.log.local("Demonstrating trigger #{@action_ref} for #{@node.to_s}")
|
28
|
+
context = Inprovise::MockExecutionContext.new(@node, @log, @index, config)
|
29
|
+
scr, action = context.resolve_action_ref(@action_ref)
|
30
|
+
setup_configuration(scr, context)
|
31
|
+
context.trigger(scr, action, *@args)
|
25
32
|
end
|
26
33
|
|
27
34
|
private
|
28
35
|
|
36
|
+
def setup_configuration(script, context)
|
37
|
+
script.update_configuration(context)
|
38
|
+
context.log.set_task(script)
|
39
|
+
context.log.command(:configure)
|
40
|
+
context.script = script
|
41
|
+
script.command(:configure).each {|cmd| context.exec_config(cmd) }
|
42
|
+
end
|
43
|
+
|
29
44
|
def parse_action_ref(action_ref_with_args)
|
30
45
|
matches = action_ref_with_args.match(/([\w\-\:]+?)(\[([\w\-\,]+?)\])/)
|
31
46
|
return [action_ref_with_args,[]] unless matches
|
data/lib/inprovise/version.rb
CHANGED
data/test/script_runner_test.rb
CHANGED
@@ -100,8 +100,8 @@ describe Inprovise::ScriptRunner do
|
|
100
100
|
|
101
101
|
it 'validates before and after applying a script' do
|
102
102
|
@runner = Inprovise::ScriptRunner.new(@node, 'validate')
|
103
|
-
@runner.expects(:exec).
|
104
|
-
.with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context &&
|
103
|
+
@runner.expects(:exec).once
|
104
|
+
.with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context && cmd == :apply }
|
105
105
|
@runner.expects(:is_valid?).twice
|
106
106
|
.with() { |script, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context }
|
107
107
|
.returns(false, true)
|
@@ -135,8 +135,8 @@ describe Inprovise::ScriptRunner do
|
|
135
135
|
|
136
136
|
it 'validates before reverting a script' do
|
137
137
|
@runner = Inprovise::ScriptRunner.new(@node, 'validate')
|
138
|
-
@runner.expects(:exec).
|
139
|
-
.with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context &&
|
138
|
+
@runner.expects(:exec).once
|
139
|
+
.with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context && cmd == :revert }
|
140
140
|
@runner.expects(:is_valid?).once
|
141
141
|
.with() { |script, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context }
|
142
142
|
.returns(true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inprovise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Corino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|