barking_iguana-compound 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ module BarkingIguana
2
+ module Compound
3
+ class TestSuite
4
+ def define_rake_tasks
5
+ Rake::Task.define_task name do
6
+ run
7
+ end.add_description "Run #{name} suite"
8
+
9
+ tests.each do |test|
10
+ Rake::Task.define_task "#{name}:#{test.name}" do
11
+ test.run
12
+ end.add_description "Run #{test.name} test from #{name} suite"
13
+
14
+ Rake::Task.define_task "#{name}:#{test.name}:destroy" do
15
+ test.teardown
16
+ end.add_description "Tear down #{test.name} test from #{name} suite"
17
+
18
+ test.stages.each do |stage|
19
+ stage.actions.each do |action|
20
+ Rake::Task.define_task "#{name}:#{test.name}:#{action}" do
21
+ stage.public_send action
22
+ end.add_description "Run action #{action} of the #{test.name} test from #{name} suite"
23
+ end
24
+ end if test.simple_test?
25
+
26
+ test.stages.each do |stage|
27
+ Rake::Task.define_task "#{name}:#{test.name}:#{stage.name}" do
28
+ stage.run
29
+ end.add_description "Run stage #{stage.name} of the #{test.name} test from #{name} suite"
30
+
31
+ stage.actions.each do |action|
32
+ Rake::Task.define_task "#{name}:#{test.name}:#{stage.name}:#{action}" do
33
+ stage.public_send action
34
+ end.add_description "Run action #{action} of stage #{stage.name} of the #{test.name} test from #{name} suite"
35
+ end
36
+ end unless test.simple_test?
37
+ end
38
+ end
39
+
40
+ attr_accessor :control_directory
41
+ private :control_directory=
42
+
43
+ attr_accessor :directory
44
+ private :directory=
45
+
46
+ def initialize directory, control_directory
47
+ self.directory = directory
48
+ self.control_directory = control_directory
49
+ end
50
+
51
+ def tests
52
+ test_directories.map { |d| Test.new self, d }
53
+ end
54
+
55
+ def name
56
+ File.basename directory
57
+ end
58
+
59
+ include BarkingIguana::Logging::Helper
60
+ include BarkingIguana::Benchmark
61
+
62
+ def run
63
+ benchmark name do
64
+ tests.each &:run
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def test_directories
71
+ Dir.glob("#{directory}/*").select { |d| File.directory? d }
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,79 @@
1
+ class Vagrant
2
+ attr_accessor :manager
3
+ private :manager=, :manager
4
+
5
+ attr_accessor :vagrant_file_template_path
6
+ private :vagrant_file_template_path=, :vagrant_file_template_path
7
+
8
+ attr_accessor :root
9
+ private :root=, :root
10
+
11
+ attr_accessor :environment
12
+ private :environment=, :environment
13
+
14
+ def initialize manager, options = {}
15
+ self.manager = manager
16
+ self.vagrant_file_template_path = options[:vagrant_file_template_path] || File.expand_path('../../../../resources/Vagrantfile.erb', __FILE__)
17
+ self.root = options[:root] || Dir.pwd
18
+ self.environment = options[:environment] || {}
19
+ end
20
+
21
+ include BarkingIguana::Logging::Helper
22
+ include BarkingIguana::Benchmark
23
+
24
+ {
25
+ up: "",
26
+ status: "",
27
+ halt: "-f",
28
+ destroy: "-f"
29
+ }.each_pair do |command, always_args|
30
+ define_method command do |*passed_args|
31
+ logger.debug { "COMMAND: #{command.inspect}, PASSED_ARGS: #{passed_args.inspect}, ALWAYS_ARGS: #{always_args.inspect}" }
32
+ merged_args = ([always_args] + passed_args).flatten.join(' ').strip
33
+ logger.debug { "MERGED ARGS: #{merged_args.inspect}" }
34
+ command_line = "/usr/local/bin/vagrant #{command} #{merged_args}".strip
35
+ logger.debug { "COMMAND LINE: #{command_line.inspect}" }
36
+ c = Mixlib::ShellOut.new command_line, cwd: root, env: environment, live_stream: logger
37
+ benchmark "running command #{command_line.inspect} in #{root.inspect} with env #{environment.inspect}" do
38
+ c.run_command
39
+ end
40
+ c.error!
41
+ c.stdout
42
+ end
43
+ end
44
+
45
+ def write_file
46
+ logger.debug { "Writing Vagrantfile to #{vagrant_file_path}" }
47
+ File.open vagrant_file_path, 'w' do |f|
48
+ f.puts vagrant_file_content
49
+ end
50
+ end
51
+ alias_method :prepare, :write_file
52
+
53
+ def vagrant_file_content
54
+ ERB.new(vagrant_file_template).result binding
55
+ end
56
+
57
+ def vagrant_file_template
58
+ File.read vagrant_file_template_path
59
+ end
60
+
61
+ def vagrant_file_path
62
+ File.join root, 'Vagrantfile'
63
+ end
64
+
65
+ def refresh_status
66
+ current_status = status.split(/\n/)
67
+ hosts.each do |host|
68
+ current_status.each do |line|
69
+ if line =~ /^#{host.name}\b/
70
+ host.state = line.sub(host.name, '').sub('(virtualbox)', '').strip
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def hosts
77
+ manager.hosts
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module BarkingIguana
2
+ module Compound
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ Vagrant.configure(2) do |config|
2
+ config.vm.box = "bento/ubuntu-16.10"
3
+ config.vm.box_check_update = false
4
+ config.vm.provider "virtualbox" do |vb|
5
+ vb.memory = "512"
6
+ end
7
+
8
+ <% hosts.each do |host| %>
9
+ config.vm.define "<%= host.name %>" do |this|
10
+ this.vm.hostname = "<%= host.name %>"
11
+ this.vm.network "private_network", ip: "<%= host.uri %>"
12
+ end
13
+ <% end %>
14
+
15
+ config.ssh.username = "vagrant"
16
+ config.ssh.password = "vagrant"
17
+ config.ssh.insert_key = false
18
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barking_iguana-compound
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Craig R Webster
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: barking_iguana-logging
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: barking_iguana-benchmark
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mixlib-shellout
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-wait
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ansible_spec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: colorize
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: hostlist_expression
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: oj
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Compound testing of Ansible playbooks
168
+ email:
169
+ - craig@barkingiguana.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - Gemfile
177
+ - README.md
178
+ - Rakefile
179
+ - barking_iguana-compound.gemspec
180
+ - bin/console
181
+ - bin/setup
182
+ - lib/barking_iguana/compound.rb
183
+ - lib/barking_iguana/compound/ansible.rb
184
+ - lib/barking_iguana/compound/ansible/inventory.rb
185
+ - lib/barking_iguana/compound/ansible/inventory_parser.rb
186
+ - lib/barking_iguana/compound/ansible/playbook.rb
187
+ - lib/barking_iguana/compound/host.rb
188
+ - lib/barking_iguana/compound/host_manager.rb
189
+ - lib/barking_iguana/compound/server_spec.rb
190
+ - lib/barking_iguana/compound/spec_helper.rb
191
+ - lib/barking_iguana/compound/test.rb
192
+ - lib/barking_iguana/compound/test_stage.rb
193
+ - lib/barking_iguana/compound/test_suite.rb
194
+ - lib/barking_iguana/compound/vagrant.rb
195
+ - lib/barking_iguana/compound/version.rb
196
+ - resources/Vagrantfile.erb
197
+ homepage: https://github.com/barkingiguana/compound
198
+ licenses: []
199
+ metadata:
200
+ allowed_push_host: https://rubygems.org
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.4.5.1
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: Compound testing of Ansible playbooks
221
+ test_files: []