inprovise 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjkyZDI4ZDcwMWQzZTM3NTJiYzJiYmNjNDI2N2U2NmZkNWI1Y2M3MQ==
4
+ MmU0MTAwMDZmYzQzNTQxYzA2ZGU5MTNmNzA4ZDJkNDg2ZTU0ZTRjOQ==
5
5
  data.tar.gz: !binary |-
6
- Zjk2ZmQ3YWFhYjE2ZTk2NzdlOTUyMDkyNDU3MDNiNDgwZTc5MmM3Mg==
6
+ MzAzNWE4NTY0ZmMwNDgzZDRkMTY3MTJkNDBhOTM2N2FmOGY0YzIzYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzNjNzJhZDgyMjNjMjNiZjYzMjEzZjI0NmU0NTFkYmY4ZmY1MWI0NGY1MWM4
10
- NjUwMTNmODA4NjYwNjQ3NzYwYTUyMjQyOWExOTJlM2I0ZjU0ODE1NDc5ODJi
11
- OWM5NDIxMDkxYWE4YjAyYmQ5NmZiMDIzMjE1MWI0MTBjMmVjMTE=
9
+ ZDMwYzRiZGU2YzE2ZTZiZGYwYjRkMjJkMzExMGE0MDdkMTI1NTllMjQxNzY0
10
+ MTRhYjBjZmYyNDk0ODAzZDAzNDIwNWU3YThjYWFmYWYzY2EzZDQyZjliNWY3
11
+ ZWVhYzgxZDEyZWEzMWU5YTgzZjkxOGU2YTc4MThiOTdiNDk0MzI=
12
12
  data.tar.gz: !binary |-
13
- MWY0Y2M5ZWQ0YTQ3ZWNlZTljM2I0NmYwYjBkNDc5OTcwN2YxODcyYWM4YWY1
14
- NjliYmZmZmMxYzE3YjJhOGQ1MDBkNTAwMDU0MDMyN2RhYTgxYTBiNWI2YWQw
15
- MWE0YjgzZWM5OWVhNzZmYzBlNDY3Y2YwNTc4MzhlZjIxODMzZmM=
13
+ NWM0ZmUxMzZlYzllYTM3NjY3MjNhNWY5YjZjMTdlNWM5M2Y4YjFmZGY2NGI3
14
+ MTAyODMxMjVlMTA3NDdjZDFiYmE3MjJkMGQ0ZWFmZjc2YzIwM2JiM2RjZDI1
15
+ NjI1YWFjMDNkNmFiMDg4MjM4ZDM5OWNlY2M1MzE5Y2FlNWVlMzg=
@@ -7,7 +7,7 @@ require 'open3'
7
7
 
8
8
  class Inprovise::ExecutionContext
9
9
 
10
- class DSL
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 node
20
- @context.node
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 trigger(action_ref, *args)
209
- action_name, pkg_name = *action_ref.split(':', 2).reverse
210
- pkg = @script
211
- pkg = @index.get(pkg_name) if pkg_name
212
- action = pkg.actions[action_name] if pkg
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 = pkg
217
- @script.update_configuration(self)
230
+ @script = scr
218
231
  begin
219
232
  exec(action, *args)
220
233
  ensure
@@ -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 do |script|
39
- execute_configuration(script, context)
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 execute_configuration(script, context)
55
- script.update_configuration(context)
56
- exec(script, :configure, context)
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).trigger(@action_ref, *@args)
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::MockExecutionContext.new(@node, @log, @index, config).trigger(@action_ref, *@args)
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
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Inprovise
7
7
 
8
- VERSION = '0.2.11'
8
+ VERSION = '0.2.12'
9
9
 
10
10
  end
@@ -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).twice
104
- .with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context && (cmd == :configure || cmd == :apply) }
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).twice
139
- .with() { |script, cmd, context| script.name.must_equal('validate') && Inprovise::ExecutionContext === context && (cmd == :configure || cmd == :revert) }
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.11
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-13 00:00:00.000000000 Z
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored