rundock 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2edc8af21fef25b6da99b4b109b52e5bc706211
4
- data.tar.gz: 737f981e31b4507c83d4c9727694465e8e8aa65f
3
+ metadata.gz: 3d00dfb1b4e328b253c9a566e2ba01043018c993
4
+ data.tar.gz: d76ebd204fa24b34db93c347f092cba6016dda66
5
5
  SHA512:
6
- metadata.gz: 0adfd065978317da2da25ee3a4301556496ab7cbe164854440e3c96d2c4a631da974c069d34603a1292b06cb0a9ea998a81b1db825614d3964df2bc382835a35
7
- data.tar.gz: cefbc63aacef98bdd97015735b0caa6e7256a84bbe917f8b8e312047f8a786fc82c7373a0036e5936be4c01c2c17fb21dbe14bf4d5e2be6003be80a321333d2c
6
+ metadata.gz: e4942411fc3dfb1419da7cbddf5434f627c1f6a94d925f6c643ce1305585a7fc98b168a2aec70340f2d738676123d3bc8b923ef8c85e6f4ceeafca5b57cfc8c7
7
+ data.tar.gz: 07f54fb15feb55d8de8aef4e3241d6341d841cc2ae520283d2cc58ba0600f0457226cac957817ce98baf23b90b5c87af7025965ad38bdb36873c2e60a41dafff
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v0.5.2
2
+
3
+ Update
4
+
5
+ - Support deploy ERB Template file
6
+
7
+ ## v0.5.1
8
+
9
+ Update
10
+
11
+ - Support target group in scenario section
12
+
1
13
  ## v0.5.0
2
14
 
3
15
  Update
@@ -87,7 +99,7 @@ Fix
87
99
 
88
100
  Improvements
89
101
 
90
- - Add running operation to other node infomation
102
+ - Add running operation to other node information
91
103
 
92
104
  Fix
93
105
 
@@ -14,7 +14,7 @@ module Rundock
14
14
  :dry_run
15
15
  ]
16
16
 
17
- def next
17
+ def init_except_take_over_state
18
18
  list.each do |k, _v|
19
19
  define_attr(k, nil) unless AVAIL_TAKE_OVERS.include?(k)
20
20
  end
@@ -43,6 +43,10 @@ module Rundock
43
43
  end
44
44
  end
45
45
 
46
+ def specinfra_run_command(command)
47
+ @backend.run_command(command)
48
+ end
49
+
46
50
  private
47
51
 
48
52
  def run_command(cmd, exec_options = {})
@@ -19,9 +19,6 @@ module Rundock
19
19
  # update ssh options for node from node_info
20
20
  @parsed_options.merge!(@node_info[@nodename.to_sym][:ssh_opts])
21
21
 
22
- # delete trash ssh_options(node[host::ssh_options])
23
- @node_info[@nodename.to_sym].delete(:ssh_opts)
24
-
25
22
  # add any attributes for host from node_info
26
23
  @parsed_options.merge!(@node_info[@nodename.to_sym])
27
24
 
@@ -6,53 +6,55 @@ module Rundock
6
6
  raise CommandArgNotFoundError, %("--command or -c" option is required if targetgroup specified.)
7
7
  end
8
8
 
9
- node = nil
10
- node_attribute = nil
9
+ parsing_node_attribute = nil
11
10
  scen = Scenario.new
12
11
  scen.tasks = tasks
13
12
 
14
- # use scenario file
15
- scenario.each do |n|
16
- scen.nodes.push(node) if node
13
+ scenario.each do |sn|
14
+ nodes = []
15
+ operations = []
16
+ hook_contents = []
17
17
 
18
- n.deep_symbolize_keys.each do |sk, sv|
18
+ sn.deep_symbolize_keys.each do |sk, sv|
19
19
  if sk == :target
20
20
  target_builder = TargetBuilder.new(@options)
21
21
  target = target_builder.build(sv, targets)
22
22
 
23
23
  if target.is_a?(Node)
24
- if node_attribute.nil?
25
- node_attribute = Rundock::Attribute::NodeAttribute.new(task_info: {})
26
- else
27
- node_attribute.next
28
- end
29
-
30
- node_attribute.nodename = sv
31
- node = target
32
- tasks.each { |k, v| node_attribute.task_info[k] = v } if tasks
33
- scen.node_info[sv.to_sym] = node_attribute.nodeinfo = target_builder.parsed_options
24
+ nodes = Array(target)
25
+ parsing_node_attribute = build_node_attribute(scen, sv, parsing_node_attribute, tasks, target_builder.parsed_node_options[sv.to_sym])
26
+ operations = Array(build_cli_command_operation(@options[:command], parsing_node_attribute, @options)) if @options[:command]
34
27
  end
35
-
36
- if @options[:command]
37
- node.add_operation(build_cli_command_operation(@options[:command], node_attribute, @options))
28
+ elsif sk == :target_group
29
+ target_builder = TargetBuilder.new(@options)
30
+ nodes = target_builder.build_group(sv, targets)
31
+ nodes.each do |n|
32
+ if n.is_a?(Node)
33
+ parsing_node_attribute = build_node_attribute(scen, n.name, parsing_node_attribute, tasks, target_builder.parsed_node_options[n.name.to_sym])
34
+ operations = Array(build_cli_command_operation(@options[:command], parsing_node_attribute, @options)) if @options[:command]
35
+ end
38
36
  end
39
37
  elsif sk == :hook
40
38
  hooks_builder = HookBuilder.new(@options)
41
- if node
42
- node.hooks = hooks_builder.build(Array(sv), hooks)
43
- node_attribute.hooks = hooks_builder.enable_hooks
44
- end
39
+ hook_contents = hooks_builder.build(Array(sv), hooks)
40
+ parsing_node_attribute.hooks = hooks_builder.enable_hooks
45
41
  else
42
+ ope = build_operations(sk, Array(sv), parsing_node_attribute, @options, false)
43
+ operations << ope if ope
44
+ end
45
+ end
46
46
 
47
- next unless node
48
-
49
- ope = build_operations(sk, Array(sv), node_attribute, @options, false)
50
- node.add_operation(ope) if ope
47
+ nodes.each do |n|
48
+ operations.each do |o|
49
+ n.add_operation(o)
51
50
  end
51
+
52
+ n.hooks = hook_contents
52
53
  end
54
+
55
+ scen.nodes.concat(nodes)
53
56
  end
54
57
 
55
- scen.nodes.push(node) if node
56
58
  scen
57
59
  end
58
60
 
@@ -86,8 +88,22 @@ module Rundock
86
88
 
87
89
  private
88
90
 
91
+ def build_node_attribute(scenario, nodename, node_attribute, tasks, parsed_options)
92
+ if node_attribute.nil?
93
+ node_attribute = Rundock::Attribute::NodeAttribute.new(task_info: {})
94
+ else
95
+ node_attribute.init_except_take_over_state
96
+ end
97
+
98
+ node_attribute.nodename = nodename
99
+ tasks.each { |k, v| node_attribute.task_info[k] = v } if tasks
100
+ scenario.node_info[nodename.to_sym] = node_attribute.nodeinfo = parsed_options
101
+
102
+ node_attribute
103
+ end
104
+
89
105
  def build_cli_command_operation(command, node_attributes, cli_options)
90
- node_attributes.nodename = @options[:host]
106
+ node_attributes.nodename = @options[:host] unless node_attributes.nodename
91
107
  node_attributes.errexit = !cli_options[:run_anyway]
92
108
  node_attributes.dry_run = cli_options[:dry_run] ? true : false
93
109
  Rundock::OperationFactory.instance(:command).create(Array(command), node_attributes.list)
@@ -2,10 +2,12 @@ module Rundock
2
2
  module Builder
3
3
  class TargetBuilder < Base
4
4
  TargetNoSupportError = Class.new(NotImplementedError)
5
+ TargetGroupNotFoundError = Class.new(StandardError)
5
6
 
6
- attr_accessor :parsed_options
7
+ attr_accessor :parsed_node_options
7
8
 
8
9
  def build(target_name, target_info)
10
+ # host type specified if target not found.
9
11
  if target_info.nil? ||
10
12
  !target_info.key?(target_name.to_sym) ||
11
13
  !target_info[target_name.to_sym].key?(:target_type) ||
@@ -13,13 +15,38 @@ module Rundock
13
15
 
14
16
  backend_builder = BackendBuilder.new(@options, target_name, target_info)
15
17
  backend = backend_builder.build
16
- @parsed_options = backend_builder.parsed_options
18
+ @parsed_node_options = { target_name.to_sym => backend_builder.parsed_options }
17
19
 
18
20
  return Node.new(target_name, backend)
19
21
  else
20
22
  raise TargetNoSupportError
21
23
  end
22
24
  end
25
+
26
+ def build_group(target_group_name, target_info)
27
+ if !target_info.nil? &&
28
+ target_info.key?(target_group_name.to_sym) &&
29
+ target_info[target_group_name.to_sym][:target_type] == 'group' &&
30
+ target_info[target_group_name.to_sym].key?(:targets) &&
31
+ target_info[target_group_name.to_sym][:targets].is_a?(Array)
32
+
33
+ targets = target_info[target_group_name.to_sym][:targets]
34
+ nodes = []
35
+ @parsed_node_options = {}
36
+
37
+ targets.each do |n|
38
+ backend_builder = BackendBuilder.new(@options, n, target_info)
39
+ backend = backend_builder.build
40
+
41
+ @parsed_node_options[n.to_sym] = backend_builder.parsed_options
42
+ nodes << Node.new(n, backend)
43
+ end
44
+
45
+ nodes
46
+ else
47
+ raise TargetGroupNotFoundError
48
+ end
49
+ end
23
50
  end
24
51
  end
25
52
  end
@@ -1,4 +1,7 @@
1
1
  require 'rundock/operation/base'
2
+ require 'erb'
3
+ require 'tempfile'
4
+ require 'ostruct'
2
5
 
3
6
  module Rundock
4
7
  module Operation
@@ -16,6 +19,17 @@ module Rundock
16
19
  # dst: /tmp/deploy_dest_remote_file
17
20
  # - src: /tmp/deploy_from_local_dir
18
21
  # dst: /tmp/deploy_dest_remote_dir
22
+ # - src: /tmp/deploy_from_local_erb_bile
23
+ # dst: /tmp/deploy_dest_remote_file
24
+ # erb: true
25
+ # trim_mode: '-'
26
+ # binding:
27
+ # hostname:
28
+ # type: command
29
+ # value: 'hostname'
30
+ # memtotal:
31
+ # type: command
32
+ # value: "cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'"
19
33
  # ---
20
34
  # anyhost-01:
21
35
  # host: 192.168.1.11
@@ -25,16 +39,75 @@ module Rundock
25
39
  # key: ~/.ssh/id_rsa
26
40
  # ---
27
41
  class Deploy < Base
42
+ DEFAULT_TRIM_MODE = '-'
43
+ DEFAULT_BINDING_TYPE = 'command'
44
+
28
45
  def run(backend, attributes)
29
46
  options = attributes[:deploy]
30
47
 
31
- options.each do |path|
32
- Logger.error('src: options not found.') if !path[:src] || path[:src].blank?
33
- Logger.error('dst: options not found.') if !path[:dst] || path[:dst].blank?
34
- Logger.info("deploy localhost:#{path[:src]} remote:#{attributes[:nodeinfo][:host]}:#{path[:dst]}")
35
- backend.send_file(path[:src], path[:dst])
48
+ options.each do |opt|
49
+ Logger.error('src: options not found.') if !opt.key?(:src) || opt[:src].blank?
50
+ Logger.error('dst: options not found.') if !opt.key?(:dst) || opt[:dst].blank?
51
+
52
+ is_erb = opt.key?(:erb) && opt[:erb]
53
+
54
+ if opt.key?(:trim_mode)
55
+ trim_mode = opt[:trim_mode]
56
+ else
57
+ trim_mode = DEFAULT_TRIM_MODE
58
+ end
59
+
60
+ erb_options = ''
61
+ erb_options = " erb: true trim_mode: #{trim_mode}" if is_erb
62
+
63
+ Logger.info("deploy localhost: #{opt[:src]} remote:#{attributes[:nodeinfo][:host]}:#{opt[:dst]}#{erb_options}")
64
+ Logger.debug("deploy erb binding: #{opt[:binding]}") if is_erb
65
+
66
+ if is_erb
67
+ val_binding = extract_map(backend, opt[:binding])
68
+ else
69
+ val_binding = {}
70
+ end
71
+
72
+ if is_erb
73
+ erb_content = conv_erb(opt[:src], trim_mode, val_binding)
74
+
75
+ tempfile = Tempfile.new('', Dir.tmpdir)
76
+ begin
77
+ tempfile.write(erb_content)
78
+ tempfile.rewind
79
+ backend.send_file(tempfile.path, opt[:dst])
80
+ ensure
81
+ tempfile.close
82
+ end
83
+ else
84
+ backend.send_file(opt[:src], opt[:dst])
85
+ end
36
86
  end
37
87
  end
88
+
89
+ private
90
+
91
+ def conv_erb(src, trim_mode, mapping)
92
+ srcfile = ::File.open(src, &:read)
93
+
94
+ begin
95
+ ERB.new(srcfile, nil, trim_mode).tap do |erb|
96
+ erb.filename = src
97
+ end.result(OpenStruct.new(mapping).instance_eval { binding })
98
+ rescue => ex
99
+ Logger.error("ERB Error: #{ex.message}")
100
+ end
101
+ end
102
+
103
+ def extract_map(backend, binding)
104
+ map = {}
105
+ binding.each do |k, v|
106
+ map[k] = backend.specinfra_run_command(v[:value]).stdout.strip if v.key?(:value)
107
+ end
108
+
109
+ map
110
+ end
38
111
  end
39
112
  end
40
113
  end
@@ -1,3 +1,3 @@
1
1
  module Rundock
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.2'
3
3
  end
data/scenario_sample.yml CHANGED
@@ -5,10 +5,12 @@
5
5
  # ### scenario section ###
6
6
  # - target: <target_name>
7
7
  # <operation_name>:
8
- # - <operation_detail>
9
- # - :
8
+ # <operation_content>
10
9
  # <operation_name>:
11
10
  # :
11
+ # hook:
12
+ # - <hook_name>
13
+ # :
12
14
  # - target: <target_name>
13
15
  # :
14
16
  # ---
@@ -0,0 +1,17 @@
1
+ - target: localhost
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario"
4
+ - "rm -f /var/tmp/hello_rundock_from_deploy_erb_dst_file_scenario"
5
+ - "echo 'Hello Rundock from deploy erb <%= erb_val_1 %> Scenario.' > /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario"
6
+ - "echo '<%= erb_val_2 %>' >> /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario"
7
+ deploy:
8
+ - src: /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario
9
+ dst: /var/tmp/hello_rundock_from_deploy_erb_dst_file_scenario
10
+ erb: true
11
+ binding:
12
+ erb_val_1:
13
+ type: command
14
+ value: 'echo "runrunrundock"'
15
+ erb_val_2:
16
+ type: command
17
+ value: 'uname'
@@ -0,0 +1,30 @@
1
+ - target_group: target_group_01
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_target_group_1_scenario"
4
+ task: write_echo_01
5
+ - target_group: target_group_02
6
+ command:
7
+ - "rm -f /var/tmp/hello_rundock_from_target_group_2_scenario"
8
+ task: write_echo_02
9
+ ---
10
+ target_group_01:
11
+ target_type: group
12
+ targets:
13
+ - anyhost-01
14
+ - anyhost-02
15
+ target_group_02:
16
+ target_type: group
17
+ targets:
18
+ - anyhost-01
19
+ - anyhost-02
20
+ anyhost-01:
21
+ host: localhost
22
+ anyhost-02:
23
+ host: 127.0.0.1
24
+ ---
25
+ write_echo_01:
26
+ command:
27
+ - "echo 'Hello Rundock from target group 1 Scenario.' | tee /var/tmp/hello_rundock_from_target_group_1_scenario"
28
+ write_echo_02:
29
+ command:
30
+ - "echo 'Hello Rundock from target group 2 Scenario.' | tee /var/tmp/hello_rundock_from_target_group_2_scenario"
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe file('/var/tmp/hello_rundock_from_deploy_erb_dst_file_scenario') do
4
+ it { should be_file }
5
+ its(:content) { should match(/Hello Rundock from deploy erb runrunrundock Scenario./) }
6
+ its(:content) { should match(/Linux/) }
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe file('/var/tmp/hello_rundock_from_target_group_1_scenario') do
4
+ it { should be_file }
5
+ its(:content) { should match(/Hello Rundock from target group 1 Scenario./) }
6
+ end
7
+
8
+ describe file('/var/tmp/hello_rundock_from_target_group_2_scenario') do
9
+ it { should be_file }
10
+ its(:content) { should match(/Hello Rundock from target group 2 Scenario./) }
11
+ end
@@ -0,0 +1,29 @@
1
+ - target: localhost
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario"
4
+ - "echo 'Hello Rundock from deploy erb <%= erb_val_1 %> Scenario.' > /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario"
5
+ - "echo '<%= erb_val_2 %>' >> /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario"
6
+ - target: anyhost-01
7
+ task:
8
+ - deploy_task
9
+ ---
10
+ anyhost-01:
11
+ host: 172.17.42.1
12
+ ssh_opts:
13
+ port: 22222
14
+ user: tester
15
+ key: "<replaced_by_platforms>"
16
+ ---
17
+ deploy_task:
18
+ command:
19
+ - "rm -f /var/tmp/hello_rundock_from_deploy_erb_dst_file_scenario"
20
+ deploy:
21
+ - src: /var/tmp/hello_rundock_from_deploy_erb_src_file_scenario
22
+ dst: /var/tmp/hello_rundock_from_deploy_erb_dst_file_scenario
23
+ erb: true
24
+ binding:
25
+ erb_val_1:
26
+ type: command
27
+ value: "echo 'runrunrundock'"
28
+ erb_val_2:
29
+ value: 'uname'
@@ -0,0 +1,40 @@
1
+ - target_group: target_group_01
2
+ command:
3
+ - "rm -f /var/tmp/hello_rundock_from_target_group_1_scenario"
4
+ task: write_echo_01
5
+ - target_group: target_group_02
6
+ command:
7
+ - "rm -f /var/tmp/hello_rundock_from_target_group_2_scenario"
8
+ task: write_echo_02
9
+ ---
10
+ target_group_01:
11
+ target_type: group
12
+ targets:
13
+ - anyhost-01
14
+ - anyhost-02
15
+ target_group_02:
16
+ target_type: group
17
+ targets:
18
+ - anyhost-01
19
+ - anyhost-02
20
+ anyhost-01:
21
+ target_type: host
22
+ host: 172.17.42.1
23
+ ssh_opts:
24
+ port: 22222
25
+ user: tester
26
+ key: "<replaced_by_platforms>"
27
+ anyhost-02:
28
+ target_type: host
29
+ host: "172.17.42.1"
30
+ ssh_opts:
31
+ port: 22222
32
+ user: tester
33
+ keys: ["<replaced_by_platforms>"]
34
+ ---
35
+ write_echo_01:
36
+ command:
37
+ - "echo 'Hello Rundock from target group 1 Scenario.' | tee /var/tmp/hello_rundock_from_target_group_1_scenario"
38
+ write_echo_02:
39
+ command:
40
+ - "echo 'Hello Rundock from target group 2 Scenario.' | tee /var/tmp/hello_rundock_from_target_group_2_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.5.0
4
+ version: 0.5.2
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-08 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,25 +188,31 @@ files:
188
188
  - spec/integration/platforms/centos6/Dockerfile
189
189
  - spec/integration/platforms/centos6/setup.sh
190
190
  - spec/integration/platforms/localhost/scenarios/all_file_hooks_by_option_scenario.yml
191
+ - spec/integration/platforms/localhost/scenarios/deploy_erb_scenario.yml
191
192
  - spec/integration/platforms/localhost/scenarios/deploy_scenario.yml
192
193
  - spec/integration/platforms/localhost/scenarios/file_hooks_by_option_scenario.yml
193
194
  - spec/integration/platforms/localhost/scenarios/file_hooks_scenario.yml
194
195
  - spec/integration/platforms/localhost/scenarios/run_anyway_scenario.yml
195
196
  - spec/integration/platforms/localhost/scenarios/simple_echo_scenario.yml
196
197
  - spec/integration/platforms/localhost/scenarios/simple_plugin_scenario.yml
198
+ - spec/integration/platforms/localhost/scenarios/target_group_scenario.yml
197
199
  - spec/integration/platforms/localhost/scenarios/use_default_ssh_scenario.yml
200
+ - spec/integration/recipes/deploy_erb_spec.rb
198
201
  - spec/integration/recipes/deploy_spec.rb
199
202
  - spec/integration/recipes/file_hook_by_option_spec.rb
200
203
  - spec/integration/recipes/file_hook_spec.rb
201
204
  - spec/integration/recipes/simple_echo_scenario_spec.rb
202
205
  - spec/integration/recipes/simple_echo_spec.rb
203
206
  - spec/integration/recipes/simple_plugin_scenario_spec.rb
207
+ - spec/integration/recipes/tareget_group_scenario_spec.rb
204
208
  - spec/integration/scenarios/all_file_hooks_by_option_scenario.yml
209
+ - spec/integration/scenarios/deploy_erb_scenario.yml
205
210
  - spec/integration/scenarios/deploy_scenario.yml
206
211
  - spec/integration/scenarios/file_hooks_by_option_scenario.yml
207
212
  - spec/integration/scenarios/file_hooks_scenario.yml
208
213
  - spec/integration/scenarios/simple_echo_scenario.yml
209
214
  - spec/integration/scenarios/simple_plugin_scenario.yml
215
+ - spec/integration/scenarios/target_group_scenario.yml
210
216
  - spec/integration/scenarios/use_default_ssh_scenario.yml
211
217
  - spec/integration/spec_helper.rb
212
218
  homepage: https://github.com/hiracy/rundock