dopi 0.17.0

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.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +322 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +102 -0
  8. data/LICENSE.txt +177 -0
  9. data/README.md +309 -0
  10. data/Rakefile +44 -0
  11. data/Vagrantfile +64 -0
  12. data/bin/dopi +4 -0
  13. data/doc/getting_started.md +247 -0
  14. data/doc/getting_started_examples/001_hello_world.yaml +17 -0
  15. data/doc/getting_started_examples/002_connecting_over_ssh.yaml +35 -0
  16. data/doc/plugins/custom.md +88 -0
  17. data/doc/plugins/mco/rpc.md +82 -0
  18. data/doc/plugins/ssh/custom.md +141 -0
  19. data/doc/plugins/ssh/file_contains.md +37 -0
  20. data/doc/plugins/ssh/file_deploy.md +52 -0
  21. data/doc/plugins/ssh/file_exists.md +31 -0
  22. data/doc/plugins/ssh/file_replace.md +37 -0
  23. data/doc/plugins/ssh/puppet_agent_run.md +50 -0
  24. data/doc/plugins/ssh/reboot.md +22 -0
  25. data/doc/plugins/ssh/wait_for_login.md +53 -0
  26. data/doc/plugins/winrm/cmd.md +161 -0
  27. data/doc/plugins/winrm/file_contains.md +39 -0
  28. data/doc/plugins/winrm/file_exists.md +31 -0
  29. data/doc/plugins/winrm/powershell.md +27 -0
  30. data/doc/plugins/winrm/puppet_agent_run.md +49 -0
  31. data/doc/plugins/winrm/reboot.md +17 -0
  32. data/doc/plugins/winrm/wait_for_login.md +55 -0
  33. data/dopi.gemspec +42 -0
  34. data/lib/dopi/cli/command_add.rb +35 -0
  35. data/lib/dopi/cli/command_list.rb +19 -0
  36. data/lib/dopi/cli/command_remove.rb +31 -0
  37. data/lib/dopi/cli/command_reset.rb +27 -0
  38. data/lib/dopi/cli/command_run.rb +68 -0
  39. data/lib/dopi/cli/command_show.rb +109 -0
  40. data/lib/dopi/cli/command_update.rb +37 -0
  41. data/lib/dopi/cli/command_validate.rb +27 -0
  42. data/lib/dopi/cli/global_options.rb +55 -0
  43. data/lib/dopi/cli/log.rb +33 -0
  44. data/lib/dopi/cli.rb +57 -0
  45. data/lib/dopi/command/custom.rb +52 -0
  46. data/lib/dopi/command/dummy.rb +27 -0
  47. data/lib/dopi/command/mco/rpc.rb +158 -0
  48. data/lib/dopi/command/ssh/custom.rb +48 -0
  49. data/lib/dopi/command/ssh/file_contains.rb +70 -0
  50. data/lib/dopi/command/ssh/file_deploy.rb +71 -0
  51. data/lib/dopi/command/ssh/file_exists.rb +54 -0
  52. data/lib/dopi/command/ssh/file_replace.rb +96 -0
  53. data/lib/dopi/command/ssh/puppet_agent_run.rb +63 -0
  54. data/lib/dopi/command/ssh/reboot.rb +50 -0
  55. data/lib/dopi/command/ssh/wait_for_login.rb +68 -0
  56. data/lib/dopi/command/winrm/cmd.rb +44 -0
  57. data/lib/dopi/command/winrm/file_contains.rb +66 -0
  58. data/lib/dopi/command/winrm/file_exists.rb +51 -0
  59. data/lib/dopi/command/winrm/powershell.rb +16 -0
  60. data/lib/dopi/command/winrm/puppet_agent_run.rb +61 -0
  61. data/lib/dopi/command/winrm/reboot.rb +33 -0
  62. data/lib/dopi/command/winrm/wait_for_login.rb +49 -0
  63. data/lib/dopi/command.rb +239 -0
  64. data/lib/dopi/command_parser/arguments.rb +38 -0
  65. data/lib/dopi/command_parser/credentials.rb +59 -0
  66. data/lib/dopi/command_parser/env.rb +37 -0
  67. data/lib/dopi/command_parser/exec.rb +27 -0
  68. data/lib/dopi/command_parser/exit_code.rb +73 -0
  69. data/lib/dopi/command_parser/output.rb +126 -0
  70. data/lib/dopi/command_set.rb +66 -0
  71. data/lib/dopi/connector/local.rb +77 -0
  72. data/lib/dopi/connector/ssh.rb +170 -0
  73. data/lib/dopi/connector/winrm.rb +167 -0
  74. data/lib/dopi/error.rb +43 -0
  75. data/lib/dopi/log.rb +18 -0
  76. data/lib/dopi/node.rb +70 -0
  77. data/lib/dopi/plan.rb +99 -0
  78. data/lib/dopi/pluginmanager.rb +62 -0
  79. data/lib/dopi/state.rb +226 -0
  80. data/lib/dopi/state_store.rb +155 -0
  81. data/lib/dopi/step.rb +227 -0
  82. data/lib/dopi/step_set.rb +70 -0
  83. data/lib/dopi/version.rb +3 -0
  84. data/lib/dopi.rb +165 -0
  85. data/spec/command_helper.rb +11 -0
  86. data/spec/fixtures/mco_client.cfg +26 -0
  87. data/spec/fixtures/plans/fail_on_timeout.yaml +20 -0
  88. data/spec/fixtures/plans/hello_world.yaml +34 -0
  89. data/spec/fixtures/plans/non_existing_node.yaml +26 -0
  90. data/spec/fixtures/plans/test_role_variable.yaml +29 -0
  91. data/spec/fixtures/puppet/Puppetfile +8 -0
  92. data/spec/fixtures/puppet/Puppetfile.lock +57 -0
  93. data/spec/fixtures/puppet/hiera.yaml +6 -0
  94. data/spec/fixtures/puppet/manifests/site.pp +52 -0
  95. data/spec/fixtures/test_configuration.yaml +54 -0
  96. data/spec/fixtures/test_credentials.yaml +11 -0
  97. data/spec/fixtures/test_deloyed_file.txt +5 -0
  98. data/spec/fixtures/test_infrastructure.yaml +12 -0
  99. data/spec/fixtures/test_nodes.yaml +45 -0
  100. data/spec/fixtures/testenv_plan.yaml +159 -0
  101. data/spec/integration/dopi/addrun_spec.rb +31 -0
  102. data/spec/integration/dopi/cli/command_run_spec.rb +38 -0
  103. data/spec/integration/dopi/cli/global_options_spec.rb +128 -0
  104. data/spec/integration/dopi/command_spec.rb +66 -0
  105. data/spec/integration/dopi/fail_check_plans/file_exists_fails.yaml +38 -0
  106. data/spec/integration/dopi/fail_check_plans/output_parser.yaml +39 -0
  107. data/spec/integration/dopi/fail_check_plans/powershell_fail.yaml +25 -0
  108. data/spec/integration/dopi/fail_check_plans/timeout.yaml +29 -0
  109. data/spec/integration/dopi/fail_check_plans/verify_commands.yaml +33 -0
  110. data/spec/integration/dopi/failplan.rb +27 -0
  111. data/spec/integration/dopi/plan.rb +27 -0
  112. data/spec/integration/dopi/plans/dummy.yaml +29 -0
  113. data/spec/integration/dopi/plans/max_per_role.yaml +55 -0
  114. data/spec/integration/dopi/plans/no_timeout.yaml +29 -0
  115. data/spec/integration/dopi/plans/node_and_role_patterns.yaml +58 -0
  116. data/spec/integration/dopi/plans/node_by_config.yaml +116 -0
  117. data/spec/integration/dopi/plans/plugin_defaults.yaml +86 -0
  118. data/spec/integration/dopi/plans/plugins/mco/rpc.yaml +33 -0
  119. data/spec/integration/dopi/plans/plugins/ssh/custom.yaml +97 -0
  120. data/spec/integration/dopi/plans/plugins/ssh/file_contains.yaml +51 -0
  121. data/spec/integration/dopi/plans/plugins/ssh/file_deploy.yaml +82 -0
  122. data/spec/integration/dopi/plans/plugins/ssh/file_exists.yaml +69 -0
  123. data/spec/integration/dopi/plans/plugins/ssh/file_replace.yaml +55 -0
  124. data/spec/integration/dopi/plans/plugins/ssh/puppet_agent_run.yaml +45 -0
  125. data/spec/integration/dopi/plans/plugins/ssh/reboot.yaml +43 -0
  126. data/spec/integration/dopi/plans/plugins/ssh/wait_for_login.yaml +45 -0
  127. data/spec/integration/dopi/plans/plugins/winrm/cmd.yaml +39 -0
  128. data/spec/integration/dopi/plans/plugins/winrm/file_contains.yaml +51 -0
  129. data/spec/integration/dopi/plans/plugins/winrm/file_exists.yaml +69 -0
  130. data/spec/integration/dopi/plans/plugins/winrm/reboot.yaml +31 -0
  131. data/spec/integration/dopi/plans/resolve_roles_on_validate.yaml +23 -0
  132. data/spec/integration/dopi/plans/ssh_parallel.yaml +37 -0
  133. data/spec/integration/dopi/plans/verify_commands.yaml +49 -0
  134. data/spec/spec_helper.rb +104 -0
  135. data/spec/unit/dopi/command/custom_spec.rb +58 -0
  136. data/spec/unit/dopi/command/mco/rpc_spec.rb +157 -0
  137. data/spec/unit/dopi/command/ssh/custom_spec.rb +30 -0
  138. data/spec/unit/dopi/command/ssh/file_deploy_spec.rb +42 -0
  139. data/spec/unit/dopi/command/ssh/file_replace_spec.rb +35 -0
  140. data/spec/unit/dopi/command_parser/credentials_spec.rb +53 -0
  141. data/spec/unit/dopi/command_parser/exit_code_spec.rb +63 -0
  142. data/spec/unit/dopi/command_parser/output_spec.rb +129 -0
  143. data/spec/unit/dopi/command_spec.rb +14 -0
  144. data/spec/unit/dopi/connector/winrm_spec.rb +111 -0
  145. data/spec/unit/dopi/node_spec.rb +24 -0
  146. data/spec/unit/dopi/plan_spec.rb +31 -0
  147. data/spec/unit/dopi/state_spec.rb +109 -0
  148. data/spec/unit/dopi/step_spec.rb +13 -0
  149. metadata +448 -0
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dopi::Command do
4
+
5
+ describe '#create_plugin_instance' do
6
+ it 'takes a plugin name, a node and a command parser and returns a command plugin' do
7
+ command = create_command('dummy')
8
+ expect(command).to be_a_kind_of Dopi::Command
9
+ command = create_command({:plugin => 'dummy'})
10
+ expect(command).to be_a_kind_of Dopi::Command
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ class WinrmTestKlass
4
+ include Dopi::Connector::Winrm
5
+ attr_accessor :hash, :plugin_timeout
6
+ end
7
+
8
+ describe Dopi::Connector::Winrm do
9
+ before :each do
10
+ @winrm = WinrmTestKlass.new
11
+ end
12
+
13
+ describe '#port' do
14
+ it 'should return the default port if not specified' do
15
+ expect(@winrm.port).to eq(5985)
16
+ end
17
+ it 'should return the port if it is specified' do
18
+ @winrm.hash = {:port => 42}
19
+ expect(@winrm.port).to eq(42)
20
+ end
21
+ it 'will raise and error if the port is not specified as a number' do
22
+ @winrm.hash = {:port => '42'}
23
+ expect{@winrm.port}.to raise_error Dopi::CommandParsingError
24
+ end
25
+ it 'will raise and error if the port is smaller than 1' do
26
+ @winrm.hash = {:port => 0}
27
+ expect{@winrm.port}.to raise_error Dopi::CommandParsingError
28
+ end
29
+ it 'will raise and error if the port is bigger than 65535' do
30
+ @winrm.hash = {:port => 10000000}
31
+ expect{@winrm.port}.to raise_error Dopi::CommandParsingError
32
+ end
33
+ end
34
+
35
+ describe '#ssl' do
36
+ it 'should return false if specified as false' do
37
+ @winrm.hash = {:ssl => false}
38
+ expect(@winrm.ssl).to be false
39
+ end
40
+ it 'should return true if not specified' do
41
+ expect(@winrm.ssl).to be true
42
+ end
43
+ it 'will raise and error if specified wrong' do
44
+ @winrm.hash = {:ssl => 'foo'}
45
+ expect{@winrm.ssl}.to raise_error Dopi::CommandParsingError
46
+ end
47
+ end
48
+
49
+ describe '#ca_trust_path' do
50
+ it 'should return the path if specified' do
51
+ @winrm.hash = {:ca_trust_path => 'spec/unit'}
52
+ expect(@winrm.ca_trust_path).to eq('spec/unit')
53
+ end
54
+ it 'should return nil if not specified' do
55
+ @winrm.hash = {:plugin => 'winrm'}
56
+ expect(@winrm.ca_trust_path).to be nil
57
+ end
58
+ it 'will raise and error if specified wrong' do
59
+ @winrm.hash = {:ca_trust_path => 'foo'}
60
+ expect{@winrm.ca_trust_path}.to raise_error Dopi::CommandParsingError
61
+ end
62
+ end
63
+
64
+ describe '#disable_sspi' do
65
+ it 'should return false if specified as false' do
66
+ @winrm.hash = {:disable_sspi => true}
67
+ expect(@winrm.disable_sspi).to be true
68
+ end
69
+ it 'should return true if not specified' do
70
+ expect(@winrm.disable_sspi).to be nil
71
+ end
72
+ it 'will raise and error if specified wrong' do
73
+ @winrm.hash = {:disable_sspi => 'foo'}
74
+ expect{@winrm.disable_sspi}.to raise_error Dopi::CommandParsingError
75
+ end
76
+ end
77
+
78
+ describe '#basic_auth_only' do
79
+ it 'should return false if specified as false' do
80
+ @winrm.hash = {:basic_auth_only => true}
81
+ expect(@winrm.basic_auth_only).to be true
82
+ end
83
+ it 'should return true if not specified' do
84
+ expect(@winrm.basic_auth_only).to be nil
85
+ end
86
+ it 'will raise and error if specified wrong' do
87
+ @winrm.hash = {:basic_auth_only => 'foo'}
88
+ expect{@winrm.basic_auth_only}.to raise_error Dopi::CommandParsingError
89
+ end
90
+ end
91
+
92
+ describe '#operation_timeout' do
93
+ it 'should return plugin_timeout - 5s if not specified' do
94
+ @winrm.plugin_timeout = 65
95
+ expect(@winrm.operation_timeout).to eq(60)
96
+ end
97
+ it 'should return 120 if specified as 120' do
98
+ @winrm.hash = {:operation_timeout => 120}
99
+ expect(@winrm.operation_timeout).to eq(120)
100
+ end
101
+ it 'will raise and error if it is not a number' do
102
+ @winrm.hash = {:operation_timeout => 'foo'}
103
+ expect{@winrm.operation_timeout}.to raise_error Dopi::CommandParsingError
104
+ end
105
+ it 'will raise and error if it is not a positive number' do
106
+ @winrm.hash = {:operation_timeout => -20}
107
+ expect{@winrm.operation_timeout}.to raise_error Dopi::CommandParsingError
108
+ end
109
+ end
110
+
111
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dopi::Node do
4
+
5
+ before :all do
6
+ end
7
+
8
+ before :each do
9
+ end
10
+
11
+ describe '#new' do
12
+ pending
13
+ end
14
+
15
+ describe '#role' do
16
+ pending
17
+ end
18
+
19
+ describe '#ssh_root_pass' do
20
+ pending
21
+ end
22
+
23
+ end
24
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe Dopi::Plan do
5
+
6
+ before :each do
7
+ plan_file = 'spec/integration/dopi/plans/ssh_parallel.yaml'
8
+ plan_parser = DopCommon::Plan.new(YAML.load_file(plan_file))
9
+ @plan = Dopi::Plan.new(plan_parser)
10
+ end
11
+
12
+ describe '#new' do
13
+ it 'should create a plan object' do
14
+ expect(@plan).to be_a Dopi::Plan
15
+ end
16
+ end
17
+
18
+ describe '#nodes' do
19
+ it 'creates 3 nodes' do
20
+ expect(@plan.nodes.length).to be 3
21
+ end
22
+ end
23
+
24
+ describe '#step_sets' do
25
+ it 'creates 1 step set' do
26
+ expect(@plan.step_sets.length).to be 1
27
+ end
28
+ end
29
+
30
+ end
31
+
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ class StateTestKlass
4
+ include Dopi::State
5
+ def name; "dummy"; end
6
+ end
7
+
8
+ describe Dopi::State do
9
+
10
+ before :each do
11
+ @child_state1 = StateTestKlass.new
12
+ @child_state2 = StateTestKlass.new
13
+ @state = StateTestKlass.new
14
+ @state2 = StateTestKlass.new
15
+ @state2.state_add_child(@child_state1)
16
+ @state2.state_add_child(@child_state2)
17
+ end
18
+
19
+ describe '#new' do
20
+ it 'creates a new state in condition ready' do
21
+ expect(@state.state_ready?).to eq true
22
+ end
23
+ end
24
+
25
+ describe 'valid_state_changes' do
26
+
27
+ it 'can run and finish a task' do
28
+ @state.state_auto_evaluate_children = false
29
+
30
+ # First state transition to running
31
+ expect{@state.state_fail}.to raise_error Dopi::StateTransitionError
32
+ expect{@state.state_finish}.to raise_error Dopi::StateTransitionError
33
+ expect{@state.state_reset}.to_not raise_error
34
+ expect{@state.state_run}.to_not raise_error
35
+ expect(@state.state_running?).to eq true
36
+
37
+ # First state transition to done
38
+ expect{@state.state_reset}.to raise_error Dopi::StateTransitionError
39
+ expect{@state.state_run}.to_not raise_error
40
+ expect{@state.state_finish}.to_not raise_error
41
+ expect(@state.state_done?).to eq true
42
+
43
+ # No more state transitions possible (except finish)
44
+ expect{@state.state_fail}.to raise_error Dopi::StateTransitionError
45
+ expect{@state.state_reset}.to raise_error Dopi::StateTransitionError
46
+ expect{@state.state_run}.to raise_error Dopi::StateTransitionError
47
+ expect{@state.state_finish}.to_not raise_error
48
+ end
49
+
50
+ it 'can run, fail a task and reset it again' do
51
+ @state.state_auto_evaluate_children = false
52
+
53
+ # First state transition to running
54
+ expect{@state.state_fail}.to raise_error Dopi::StateTransitionError
55
+ expect{@state.state_finish}.to raise_error Dopi::StateTransitionError
56
+ expect{@state.state_reset}.to_not raise_error
57
+ expect{@state.state_run}.to_not raise_error
58
+ expect(@state.state_running?).to eq true
59
+
60
+ # First state transition to failed
61
+ expect{@state.state_reset}.to raise_error Dopi::StateTransitionError
62
+ expect{@state.state_run}.to_not raise_error
63
+ expect{@state.state_fail}.to_not raise_error
64
+ expect(@state.state_failed?).to eq true
65
+
66
+ # Reset the state to ready
67
+ expect{@state.state_finish}.to raise_error Dopi::StateTransitionError
68
+ expect{@state.state_run}.to raise_error Dopi::StateTransitionError
69
+ expect{@state.state_fail}.to_not raise_error
70
+ expect{@state.state_reset}.to_not raise_error
71
+ expect(@state.state_ready?).to eq true
72
+ end
73
+
74
+ it 'can run a task in noop and go back to ready again' do
75
+ @state.state_auto_evaluate_children = false
76
+
77
+ # First state transition to running
78
+ expect{@state.state_fail}.to raise_error Dopi::StateTransitionError
79
+ expect{@state.state_finish}.to raise_error Dopi::StateTransitionError
80
+ expect{@state.state_run_noop}.to_not raise_error
81
+ expect(@state.state_running_noop?).to eq true
82
+ expect{@state.state_fail}.to raise_error Dopi::StateTransitionError
83
+ expect{@state.state_finish}.to raise_error Dopi::StateTransitionError
84
+ expect{@state.state_ready}.to_not raise_error
85
+ expect(@state.state_ready?).to eq true
86
+ end
87
+
88
+ end
89
+
90
+ describe "state changes evaluated from children" do
91
+
92
+ it "will fail if one of the children is failed" do
93
+ @child_state1.state_run
94
+ @child_state1.state_fail
95
+ expect(@state2.state_failed?).to eq true
96
+ end
97
+
98
+ it "will be done if all of the children are done" do
99
+ @child_state1.state_run
100
+ @child_state1.state_finish
101
+ @child_state2.state_run
102
+ @child_state2.state_finish
103
+ expect(@state2.state_done?).to eq true
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dopi::Step do
4
+
5
+ describe '#new' do
6
+ pending
7
+ end
8
+
9
+ describe '#run' do
10
+ pending
11
+ end
12
+
13
+ end