rundock 0.4.15 → 0.4.16

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 940c942d94419b9a6eb11d29669d6a35c8da0fe4
4
- data.tar.gz: d7eb5f064af783640f66a0aac77eee6fe4e8cd01
3
+ metadata.gz: 24c0aa8f73630ca0f4fcab31e3db5fe9d6c56e4a
4
+ data.tar.gz: 93a2cabce87a681f76f5a344b4d36135365a85ba
5
5
  SHA512:
6
- metadata.gz: 6de9ad7cf3cf83a341a60eba88db15ac38893772c457ff6c41d432eee49c9da31181c195634a054f4f884e90e88acce73c395495a985ad29d5a869f4df5ef837
7
- data.tar.gz: 41d324f0e916f2375d1bd687a5ee2fcbe39e7afd70f6b828efd1a0dfd3efe002bbcc094b601c54d37802be79fd6ec8904be71fd2e6f14d9774ca84d4d635b0aa
6
+ metadata.gz: cf3d9806d2389fbf71c5eb34523e9d3bc9f3c6dbfb7a2b6a9060d77c86840f3bb22bbdf65c570d119159efa4a1cca77a97758ffa89d6ab5d113609c4611eeb84
7
+ data.tar.gz: d6c254e1e05c9c836b9f2bba9166c4119cfd2aac76113306acc79b72d791dc01c5bde8d9d865d6503a45091ed3bcfd784538f814837d4255b5ae3dc91a918a06
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.4.16
2
+
3
+ Update
4
+
5
+ - Support hooks define in scenario file
6
+
1
7
  ## v0.4.15
2
8
 
3
9
  Update
data/Rakefile CHANGED
@@ -73,7 +73,7 @@ def do_rundock_scenarios(platform)
73
73
  default_ssh_opt = ''
74
74
  end
75
75
 
76
- if scenario =~ %r{^*scenarios/(.*_hooks)_scenario.yml$}
76
+ if scenario =~ %r{^*scenarios/(.*_hooks_by_option)_scenario.yml$}
77
77
  hooks_opt = " -k ./spec/integration/hooks/#{Regexp.last_match(1)}.yml"
78
78
  else
79
79
  hooks_opt = ''
@@ -5,8 +5,8 @@ module Rundock
5
5
  attr_accessor :nodeinfo
6
6
  attr_accessor :task_info
7
7
  attr_accessor :errexit
8
- attr_accessor :enable_hooks
9
8
  attr_accessor :dry_run
9
+ attr_accessor :hooks
10
10
 
11
11
  AVAIL_TAKE_OVERS = [
12
12
  :task_info,
@@ -6,11 +6,18 @@ module Rundock
6
6
  DEFAULT_HOOKS_FILE_PATH = './hooks.yml'
7
7
  HookStructureError = Class.new(NotImplementedError)
8
8
 
9
- def build(enables)
9
+ attr_accessor :enable_hooks
10
+
11
+ def initialize(options)
12
+ super(options)
13
+ @enable_hooks = {}
14
+ end
15
+
16
+ def build(enables, hook_attributes)
10
17
  if enables.blank?
11
18
  Logger.info('Empty hook is specified.')
12
19
  return []
13
- elsif @options[:hooks]
20
+ elsif hook_attributes.nil? && @options[:hooks]
14
21
  if FileTest.exist?(@options[:hooks])
15
22
  hooks_file = @options[:hooks]
16
23
  Logger.info("hooks file is #{hooks_file}")
@@ -18,36 +25,44 @@ module Rundock
18
25
  Logger.warn("hooks file is not found. use #{DEFAULT_HOOKS_FILE_PATH}")
19
26
  hooks_file = DEFAULT_HOOKS_FILE_PATH
20
27
  end
21
- else
28
+ elsif hook_attributes.nil?
29
+ Logger.warn("Hook source is not found. (enables:#{enables.join(',')})") unless enables.empty?
22
30
  return []
23
31
  end
24
32
 
25
- build_from_file(hooks_file, enables)
33
+ if hooks_file
34
+ build_from_attributes(YAML.load_file(hooks_file).deep_symbolize_keys, enables)
35
+ else
36
+ build_from_attributes(hook_attributes, enables)
37
+ end
26
38
  end
27
39
 
28
- def build_from_attributes(attributes)
29
- return [] unless attributes.key?(:enable_hooks)
30
- build_from_file(attributes[:hooks], attributes[:enable_hooks])
40
+ def rebuild(node_attributes)
41
+ hooks = []
42
+
43
+ node_attributes.each do |k, v|
44
+ hooks = Rundock::HookFactory.instance(v[:hook_type]).create(k.to_s, v)
45
+ end
46
+
47
+ hooks
31
48
  end
32
49
 
33
50
  private
34
51
 
35
- def build_from_file(file, enables)
52
+ def build_from_attributes(attributes, enables)
36
53
  hooks = []
54
+
37
55
  allow_all = enables.include?('all')
38
56
 
39
- File.open(file) do |f|
40
- YAML.load_documents(f) do |y|
41
- y.each do |k, v|
42
- raise HookStructureError if !v.is_a?(Hash) || !v.key?('hook_type')
43
- next if !allow_all && !enables.include?(k)
44
- hook = Rundock::HookFactory.instance(v['hook_type']).create(k, v.deep_symbolize_keys)
45
- hooks << hook
46
- end
47
- end
57
+ attributes.each do |k, v|
58
+ raise HookStructureError unless v.is_a?(Hash)
59
+ next if !allow_all && !enables.include?(k.to_s)
60
+ @enable_hooks[k] = v
61
+ hooks << Rundock::HookFactory.instance(v[:hook_type]).create(k.to_s, v)
48
62
  end
49
63
 
50
64
  Logger.warn('Empty hook is detected. Please verity hooks file and scenario file.') if hooks.empty?
65
+
51
66
  hooks
52
67
  end
53
68
  end
@@ -1,7 +1,7 @@
1
1
  module Rundock
2
2
  module Builder
3
3
  class OperationBuilder < Base
4
- def build_first(scenario, node_info, tasks)
4
+ def build_first(scenario, node_info, tasks, hooks)
5
5
  if @options[:hostgroup] && !@options[:command]
6
6
  raise CommandArgNotFoundError, %("--command or -c" option is required if hostgroup specified.)
7
7
  end
@@ -32,8 +32,11 @@ module Rundock
32
32
  node.add_operation(build_cli_command_operation(@options[:command], node_attribute, @options))
33
33
  end
34
34
  elsif k == :hook
35
- node_attribute.enable_hooks = Array(v)
36
- node.hooks = HookBuilder.new(@options).build(Array(v)) if node
35
+ hooks_builder = HookBuilder.new(@options)
36
+ if node
37
+ node.hooks = hooks_builder.build(Array(v), hooks)
38
+ node_attribute.hooks = hooks_builder.enable_hooks
39
+ end
37
40
  else
38
41
 
39
42
  next unless node
@@ -50,7 +53,6 @@ module Rundock
50
53
 
51
54
  def build_task(tasks, backend, node_attribute)
52
55
  node = Node.new(node_attribute.nodename, backend)
53
- node.hooks = HookBuilder.new(nil).build_from_attributes(node_attribute.nodeinfo)
54
56
  scen = Scenario.new
55
57
 
56
58
  tasks.each do |k, v|
@@ -68,7 +70,7 @@ module Rundock
68
70
  @options[:host].split(',').each do |host|
69
71
  backend = BackendBuilder.new(@options, host, nil).build
70
72
  node = Node.new(host, backend)
71
- node.hooks = HookBuilder.new(@options).build(['all'])
73
+ node.hooks = HookBuilder.new(@options).build(['all'], nil)
72
74
  node.add_operation(
73
75
  build_cli_command_operation(@options[:command], Rundock::Attribute::NodeAttribute.new, @options))
74
76
  scen.nodes.push(node)
@@ -37,7 +37,7 @@ module Rundock
37
37
  def build_scenario_with_file
38
38
  if @scenario_file
39
39
 
40
- type = [:main, :node_info, :tasks]
40
+ type = [:main, :node_info, :tasks, :hooks]
41
41
  scenario_data = {}
42
42
 
43
43
  YAML.load_documents(@scenario_file).each_with_index do |data, idx|
@@ -51,7 +51,10 @@ module Rundock
51
51
 
52
52
  ope = OperationBuilder.new(@options)
53
53
  ope.build_first(
54
- scenario_data[:main], scenario_data[:node_info], scenario_data[:tasks])
54
+ scenario_data[:main],
55
+ scenario_data[:node_info],
56
+ scenario_data[:tasks],
57
+ scenario_data[:hooks])
55
58
  end
56
59
  end
57
60
  end
@@ -33,18 +33,19 @@ module Rundock
33
33
  attr_accessor :show_header
34
34
  attr_accessor :short_header
35
35
  attr_accessor :date_header
36
- attr_accessor :onrec
37
36
  attr_accessor :buffer
38
37
 
39
38
  def initialize(*args)
40
39
  super
41
40
  @indent_depth = 0
42
41
  @buffer = []
42
+ @rec = false
43
+ @lock = false
43
44
  end
44
45
 
45
46
  def call(severity, datetime, progname, msg)
46
47
  out = formatted_message(severity, datetime, progname, msg)
47
- @buffer << LogEntity.new(severity, datetime, progname, msg, indent_depth, self)
48
+ @buffer << LogEntity.new(severity, datetime, progname, msg, indent_depth, self) if @rec
48
49
 
49
50
  if colored
50
51
  colorize(out, severity)
@@ -77,11 +78,28 @@ module Rundock
77
78
  end
78
79
 
79
80
  def flush
81
+ return nil if @lock
80
82
  ret = @buffer.dup
81
83
  @buffer.clear
82
84
  ret
83
85
  end
84
86
 
87
+ def on_rec
88
+ @rec = true unless @lock
89
+ end
90
+
91
+ def off_rec
92
+ @rec = false unless @lock
93
+ end
94
+
95
+ def rec_lock
96
+ @lock = true
97
+ end
98
+
99
+ def rec_unlock
100
+ @lock = false
101
+ end
102
+
85
103
  def formatted_message(severity, datetime, progname, msg)
86
104
  if !@show_header
87
105
  out = "%s\n" % [msg2str(msg)]
data/lib/rundock/node.rb CHANGED
@@ -20,7 +20,7 @@ module Rundock
20
20
  end
21
21
 
22
22
  def run
23
- Logger.formatter.onrec = true
23
+ Logger.formatter.on_rec
24
24
  Logger.debug("run node: #{@name}")
25
25
  Logger.warn("no operation running: #{@name}") if @operations.blank?
26
26
 
@@ -39,7 +39,7 @@ module Rundock
39
39
  h.hook(node_attributes, log_buffer)
40
40
  end
41
41
 
42
- Logger.formatter.onrec = false
42
+ Logger.formatter.off_rec
43
43
  end
44
44
  end
45
45
  end
@@ -12,7 +12,11 @@ module Rundock
12
12
  attributes[:task_info][i.to_sym], backend, Rundock::Attribute::NodeAttribute.new(attributes))
13
13
 
14
14
  Logger.info("start task: #{i}")
15
+
16
+ Logger.formatter.rec_lock
17
+
15
18
  scenario.run
19
+ Logger.formatter.rec_unlock
16
20
  end
17
21
  end
18
22
  end
@@ -1,3 +1,3 @@
1
1
  module Rundock
2
- VERSION = '0.4.15'
2
+ VERSION = '0.4.16'
3
3
  end
@@ -0,0 +1,23 @@
1
+ - node: localhost
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_file_hook_innner_one_scenario"
4
+ hook: file_hook_one
5
+ - node: anyhost-01
6
+ task:
7
+ - remove_task
8
+ hook:
9
+ - file_hook_two
10
+ ---
11
+ anyhost-01:
12
+ host: localhost
13
+ ---
14
+ remove_task:
15
+ command:
16
+ - "rm -f /var/tmp/hello_rundock_from_file_hook_inner_two_scenario"
17
+ ---
18
+ file_hook_one:
19
+ hook_type: file
20
+ filepath: /var/tmp/hello_rundock_from_file_hook_inner_one_scenario
21
+ file_hook_two:
22
+ hook_type: file
23
+ filepath: /var/tmp/hello_rundock_from_file_hook_inner_two_scenario
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe file('/var/tmp/hello_rundock_from_file_hook_one_scenario') do
4
+ it { should be_file }
5
+ its(:content) { should match(/hookname:file_one /) }
6
+ its(:content) { should match(/DEBUG/) }
7
+ end
8
+
9
+ describe file('/var/tmp/hello_rundock_from_file_hook_array_1_scenario') do
10
+ it { should be_file }
11
+ its(:content) { should match(/anyhost-01/) }
12
+ its(:content) { should match(/hookname:file_array_1 /) }
13
+ its(:content) { should match(/DEBUG/) }
14
+ end
15
+
16
+ describe file('/var/tmp/hello_rundock_from_file_hook_array_2_scenario') do
17
+ it { should be_file }
18
+ its(:content) { should match(/anyhost-01/) }
19
+ its(:content) { should match(/hookname:file_array_2 /) }
20
+ its(:content) { should match(/DEBUG/) }
21
+ end
22
+
23
+ describe file('/var/tmp/hello_rundock_from_file_hook_all_1_scenario') do
24
+ it { should be_file }
25
+ its(:content) { should match(/hookname:file_all_1 /) }
26
+ its(:content) { should match(/DEBUG/) }
27
+ end
28
+
29
+ describe file('/var/tmp/hello_rundock_from_file_hook_all_2_scenario') do
30
+ it { should be_file }
31
+ its(:content) { should match(/hookname:file_all_2 /) }
32
+ its(:content) { should match(/DEBUG/) }
33
+ end
@@ -1,28 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe file('/var/tmp/hello_rundock_from_file_hook_one_scenario') do
3
+ describe file('/var/tmp/hello_rundock_from_file_hook_inner_one_scenario') do
4
4
  it { should be_file }
5
- its(:content) { should match(/hookname:file_one /) }
5
+ its(:content) { should match(/hookname:file_hook_one /) }
6
+ its(:content) { should match(/DEBUG/) }
6
7
  end
7
8
 
8
- describe file('/var/tmp/hello_rundock_from_file_hook_array_1_scenario') do
9
+ describe file('/var/tmp/hello_rundock_from_file_hook_inner_two_scenario') do
9
10
  it { should be_file }
10
- its(:content) { should match(/anyhost-01/) }
11
- its(:content) { should match(/hookname:file_array_1 /) }
12
- end
13
-
14
- describe file('/var/tmp/hello_rundock_from_file_hook_array_2_scenario') do
15
- it { should be_file }
16
- its(:content) { should match(/anyhost-01/) }
17
- its(:content) { should match(/hookname:file_array_2 /) }
18
- end
19
-
20
- describe file('/var/tmp/hello_rundock_from_file_hook_all_1_scenario') do
21
- it { should be_file }
22
- its(:content) { should match(/hookname:file_all_1 /) }
23
- end
24
-
25
- describe file('/var/tmp/hello_rundock_from_file_hook_all_2_scenario') do
26
- it { should be_file }
27
- its(:content) { should match(/hookname:file_all_2 /) }
11
+ its(:content) { should match(/hookname:file_hook_two /) }
12
+ its(:content) { should match(/DEBUG/) }
28
13
  end
@@ -1,7 +1,9 @@
1
1
  - node: anyhost-01
2
2
  command:
3
3
  - "echo 'hookname:file_all_1 ' > /var/tmp/hello_rundock_from_file_hook_all_1_scenario"
4
+ - "echo '[DEBUG:] dummy log' >> /var/tmp/hello_rundock_from_file_hook_all_1_scenario"
4
5
  - "echo 'hookname:file_all_2 ' > /var/tmp/hello_rundock_from_file_hook_all_2_scenario"
6
+ - "echo '[DEBUG:] dummy log' >> /var/tmp/hello_rundock_from_file_hook_all_2_scenario"
5
7
  hook: all
6
8
  ---
7
9
  anyhost-01:
@@ -1,10 +1,13 @@
1
1
  - node: anyhost-01
2
2
  command:
3
3
  - "echo 'hookname:file_one ' > /var/tmp/hello_rundock_from_file_hook_one_scenario"
4
+ - "echo '[DEBUG:] dumy log' >> /var/tmp/hello_rundock_from_file_hook_one_scenario"
4
5
  - "echo 'anyhost-01' > /var/tmp/hello_rundock_from_file_hook_array_1_scenario"
5
6
  - "echo 'anyhost-01' > /var/tmp/hello_rundock_from_file_hook_array_2_scenario"
6
7
  - "echo 'hookname:file_array_1 ' >> /var/tmp/hello_rundock_from_file_hook_array_1_scenario"
7
8
  - "echo 'hookname:file_array_2 ' >> /var/tmp/hello_rundock_from_file_hook_array_2_scenario"
9
+ - "echo '[DEBUG:] dummy log' >> /var/tmp/hello_rundock_from_file_hook_array_1_scenario"
10
+ - "echo '[DEBUG:] dummy log' >> /var/tmp/hello_rundock_from_file_hook_array_2_scenario"
8
11
  hook:
9
12
  - file_one
10
13
  - file_array_1
@@ -0,0 +1,24 @@
1
+ - node: anyhost-01
2
+ command:
3
+ - "echo 'hookname:file_hook_one ' > /var/tmp/hello_rundock_from_file_hook_inner_one_scenario"
4
+ - "echo '[DEBUG:] dummy log' >> /var/tmp/hello_rundock_from_file_hook_inner_one_scenario"
5
+ - "echo 'hookname:file_hook_two ' > /var/tmp/hello_rundock_from_file_hook_inner_two_scenario"
6
+ - "echo '[DEBUG:] dummy log' >> /var/tmp/hello_rundock_from_file_hook_inner_two_scenario"
7
+ hook:
8
+ - file_hook_one
9
+ - file_hook_two
10
+ ---
11
+ anyhost-01:
12
+ host: 172.17.42.1
13
+ ssh_opts:
14
+ port: 22222
15
+ user: tester
16
+ key: "<replaced_by_platforms>"
17
+ ---
18
+ ---
19
+ file_hook_one:
20
+ hook_type: file
21
+ filepath: /var/tmp/hello_rundock_from_file_hook_inner_one_scenario
22
+ file_hook_two:
23
+ hook_type: file
24
+ filepath: /var/tmp/hello_rundock_from_file_hook_inner_two_scenario
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rundock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.15
4
+ version: 0.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - hiracy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-01 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -182,26 +182,29 @@ files:
182
182
  - rundock.gemspec
183
183
  - scenario_sample.yml
184
184
  - spec/integration/groups/simple_host_group.yml
185
- - spec/integration/hooks/all_file_hooks.yml
186
- - spec/integration/hooks/simple_file_hooks.yml
185
+ - spec/integration/hooks/all_file_hooks_by_option.yml
186
+ - spec/integration/hooks/file_hooks_by_option.yml
187
187
  - spec/integration/platforms/centos6/Dockerfile
188
188
  - spec/integration/platforms/centos6/setup.sh
189
- - spec/integration/platforms/localhost/scenarios/all_file_hooks_scenario.yml
189
+ - spec/integration/platforms/localhost/scenarios/all_file_hooks_by_option_scenario.yml
190
190
  - spec/integration/platforms/localhost/scenarios/deploy_scenario.yml
191
+ - spec/integration/platforms/localhost/scenarios/file_hooks_by_option_scenario.yml
192
+ - spec/integration/platforms/localhost/scenarios/file_hooks_scenario.yml
191
193
  - spec/integration/platforms/localhost/scenarios/run_anyway_scenario.yml
192
194
  - spec/integration/platforms/localhost/scenarios/simple_echo_scenario.yml
193
- - spec/integration/platforms/localhost/scenarios/simple_file_hooks_scenario.yml
194
195
  - spec/integration/platforms/localhost/scenarios/simple_plugin_scenario.yml
195
196
  - spec/integration/platforms/localhost/scenarios/use_default_ssh_scenario.yml
196
197
  - spec/integration/recipes/deploy_spec.rb
198
+ - spec/integration/recipes/file_hook_by_option_spec.rb
197
199
  - spec/integration/recipes/file_hook_spec.rb
198
200
  - spec/integration/recipes/simple_echo_scenario_spec.rb
199
201
  - spec/integration/recipes/simple_echo_spec.rb
200
202
  - spec/integration/recipes/simple_plugin_scenario_spec.rb
201
- - spec/integration/scenarios/all_file_hooks_scenario.yml
203
+ - spec/integration/scenarios/all_file_hooks_by_option_scenario.yml
202
204
  - spec/integration/scenarios/deploy_scenario.yml
205
+ - spec/integration/scenarios/file_hooks_by_option_scenario.yml
206
+ - spec/integration/scenarios/file_hooks_scenario.yml
203
207
  - spec/integration/scenarios/simple_echo_scenario.yml
204
- - spec/integration/scenarios/simple_file_hooks_scenario.yml
205
208
  - spec/integration/scenarios/simple_plugin_scenario.yml
206
209
  - spec/integration/scenarios/use_default_ssh_scenario.yml
207
210
  - spec/integration/spec_helper.rb