loom-core 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +31 -0
  3. data/Gemfile.lock +19 -1
  4. data/Rakefile +2 -0
  5. data/bin/loom +3 -0
  6. data/docs/architecture.jpg +0 -0
  7. data/gentags.sh +2 -0
  8. data/lib/loom/all.rb +1 -1
  9. data/lib/loom/config.rb +1 -1
  10. data/lib/loom/mods/mod_loader.rb +7 -2
  11. data/lib/loom/pattern/all.rb +1 -0
  12. data/lib/loom/pattern/definition_context.rb +4 -4
  13. data/lib/loom/pattern/dsl.rb +176 -119
  14. data/lib/loom/pattern/expanding_reference.rb +88 -6
  15. data/lib/loom/pattern/loader.rb +1 -17
  16. data/lib/loom/pattern/pattern.rb +52 -0
  17. data/lib/loom/pattern/reference.rb +17 -13
  18. data/lib/loom/pattern/reference_set.rb +71 -50
  19. data/lib/loom/runner.rb +46 -33
  20. data/lib/loom/runner/all.rb +2 -0
  21. data/lib/loom/runner/execution_context.rb +9 -0
  22. data/lib/loom/{dsl.rb → runner/sshkit_connector.rb} +5 -7
  23. data/lib/loom/shell.rb +4 -2
  24. data/lib/loom/shell/core.rb +16 -16
  25. data/lib/loom/version.rb +1 -1
  26. data/lib/loomext/coremods/exec.rb +1 -0
  27. data/loom.TAGS +797 -0
  28. data/loom.gemspec +1 -0
  29. data/spec/.loom/error_handling.loom +1 -0
  30. data/spec/.loom/fail.loom +27 -13
  31. data/spec/.loom/files.loom +1 -0
  32. data/spec/.loom/inventory.yml +3 -0
  33. data/spec/.loom/net.loom +1 -0
  34. data/spec/.loom/pattern_context.loom +1 -0
  35. data/spec/.loom/pkg.loom +1 -0
  36. data/spec/.loom/shell.loom +1 -0
  37. data/spec/.loom/test.loom +17 -4
  38. data/spec/.loom/user.loom +1 -0
  39. data/spec/.loom/vms.loom +1 -0
  40. data/spec/loom/pattern/dsl_spec.rb +3 -2
  41. data/spec/shared/loom_internals_helper.rb +1 -1
  42. data/spec/test_loom_spec.rb +102 -42
  43. data/test +15 -0
  44. metadata +25 -3
@@ -41,4 +41,5 @@ Gem::Specification.new do |s|
41
41
  s.add_development_dependency 'guard-rspec', '~> 4.7'
42
42
  s.add_development_dependency 'pry', '~> 0.10'
43
43
  s.add_development_dependency 'pry-byebug'
44
+ s.add_development_dependency 'rubocop'
44
45
  end
@@ -1,4 +1,5 @@
1
1
  # !!! NOTE: This will reboot the host it runs on!!!
2
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:error_handling.loom
2
3
  module ErrorHandling
3
4
  include Loom::Pattern
4
5
 
@@ -1,20 +1,34 @@
1
1
  # All patterns are expected to fail
2
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:fail.loom
3
+ module ExpectedFailures
4
+ include Loom::Pattern
2
5
 
3
- desc "Always fails due to return code."
4
- pattern :fail_soft do |loom, facts|
5
- unless loom << :false
6
- loom.x :echo, "i am false"
6
+ before do
7
+ Loom.log.warn <<EOS
8
+
9
+ !!!
10
+ !!! The next case is expected to fail !!!
11
+ !!!
12
+ EOS
7
13
  end
8
- end
9
14
 
10
- desc "Always fails due to a hard failure"
11
- pattern :fail_hard do |loom, facts|
12
- loom.fail "Fail big or not at all"
13
- end
14
15
 
15
- desc "Expected to fail: Check timeout commands"
16
- pattern :timeout_fail do |loom, facts|
17
- loom.timeout(:timeout => 1) do
18
- loom.x :sleep, 2
16
+ desc "Always fails due to return code."
17
+ pattern :fail_soft do |loom, facts|
18
+ unless loom.x :false
19
+ loom.x :echo, "i fail soft, because ALL examples are expected to succeed"
20
+ end
21
+ end
22
+
23
+ desc "Expect `loom.fail` to throw and error out"
24
+ pattern :fail_hard do |loom, facts|
25
+ loom.fail "`loom.fail`: Fail big or not at all"
26
+ end
27
+
28
+ desc "Expected to fail: Check timeout commands"
29
+ pattern :timeout_fail do |loom, facts|
30
+ loom.timeout(:timeout => 1) do
31
+ loom.x :sleep, 2
32
+ end
19
33
  end
20
34
  end
@@ -1,4 +1,5 @@
1
1
  # Tests for LoomExt::CoreMods::Package
2
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:files.loom
2
3
  module Files
3
4
  include Loom::Pattern
4
5
 
@@ -0,0 +1,3 @@
1
+ ---
2
+ - a.host.to.check
3
+ - my.other.host
@@ -1,3 +1,4 @@
1
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:net.loom
1
2
  module Net
2
3
  include Loom::Pattern
3
4
 
@@ -1,5 +1,6 @@
1
1
  # Tests patterns nested at deeper module levels with contextual let, before, and
2
2
  # after hooks. Verifies hook order and contexts are set correctly.
3
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:pattern_context.loom
3
4
  module PatternContext
4
5
  module Parent
5
6
  include Loom::Pattern
@@ -1,4 +1,5 @@
1
1
  # Tests for LoomExt::CoreMods::Package
2
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:pkg.loom
2
3
  module Package
3
4
  include Loom::Pattern
4
5
 
@@ -1,3 +1,4 @@
1
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:shell.loom
1
2
  module Shell
2
3
  include Loom::Pattern
3
4
 
@@ -1,12 +1,24 @@
1
1
  # TODO: add in test verifications that these tests are actually doing what
2
2
  # they're supposed to do.
3
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:test.loom
4
+ weave :smoke, [
5
+ :"test:*",
6
+ ]
3
7
 
4
- module Smoke
8
+ module Test
5
9
  include Loom::Pattern
6
10
 
7
- desc "Prints some known facts"
8
- report :three_facts do |loom, facts|
9
- facts
11
+ with_facts { |f| f.merge a_fact: :or_fiction? }
12
+ let(:a_fact_len) { |f| f[:a_fact].size }
13
+
14
+ desc "inspects the facts"
15
+ report :the_facts do |loom, facts|
16
+ loom.fail "this should not happen: #{a_fact_len}" unless a_fact_len == 11
17
+ end
18
+
19
+ desc "expects cli provided :param_facts"
20
+ pattern :param_facts do |loom, facts|
21
+ loom.fail "expected :param_facts" unless facts[:param_facts] == "from args"
10
22
  end
11
23
 
12
24
  desc "Reports `uptime` status"
@@ -28,6 +40,7 @@ module Smoke
28
40
  pattern :wrap_returns do |loom, facts|
29
41
  # using loom.time as a proxy for Shell::Core#wrap here
30
42
  loom.time do
43
+ # TODO: this should be loom.fail
31
44
  raise "wrapped true is not true" unless loom.test :true
32
45
  raise "wrapped false is not false" if loom.test :false
33
46
  end
@@ -1,4 +1,5 @@
1
1
  # Tests for LoomExt::CoreMods::User
2
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:user.loom
2
3
  module User
3
4
  include Loom::Pattern
4
5
 
@@ -1,5 +1,6 @@
1
1
  # Tests for LoomExt::CoreMods::Vbox.
2
2
  # Currently disabled
3
+ # $ bx rspec spec/test_loom_spec.rb -f d -t file:vms.loom
3
4
  module VMs
4
5
  include Loom::Pattern
5
6
 
@@ -3,6 +3,7 @@ require "loom/pattern"
3
3
  require "loom/shell"
4
4
 
5
5
  describe Loom::Pattern::DSL do
6
+ extend LoomSpec::LoomInternalsHelper
6
7
 
7
8
  # Fake API for tests. This object should raise an error on any command
8
9
  # execution.
@@ -18,8 +19,8 @@ describe Loom::Pattern::DSL do
18
19
  config.log_device = @logger_io
19
20
  end
20
21
 
21
- @reference_set = Loom::Pattern::ReferenceSet::Builder
22
- .create(loom_file, ':loom_file')
22
+ @reference_set =
23
+ Loom::Pattern::ReferenceSet.builder(loom_file, ':loom_file').build
23
24
  end
24
25
 
25
26
  let(:pattern_under_test) { @reference_set['pattern_under_test'] }
@@ -15,7 +15,7 @@ module LoomSpec
15
15
 
16
16
  def create_reference_set(loom_file_src=nil, path: 'loom/file/path')
17
17
  loom_file_src ||= File.read(path)
18
- Loom::Pattern::ReferenceSet::Builder.create(loom_file_src, path)
18
+ Loom::Pattern::ReferenceSet::builder(loom_file_src, path).build
19
19
  end
20
20
 
21
21
  def capture_logs_to_io
@@ -15,6 +15,10 @@ describe "spec .loom files" do
15
15
  }
16
16
 
17
17
  EXPECTED_EXIT_CODE = {
18
+ # 100 to indicate failing patterns
19
+ # + 3 failed patterns
20
+ # ---
21
+ # 103 expected exit code
18
22
  "fail.loom" => 103
19
23
  }
20
24
 
@@ -25,53 +29,109 @@ describe "spec .loom files" do
25
29
 
26
30
  let(:host) { "rp0" }
27
31
  let(:patterns) { ref_set.slugs }
28
- let(:command) {[
29
- "bin/loom weave #{patterns.join " "}",
30
- "-t",
31
- "-l #{loom_file}",
32
- "-X log_level=info",
33
- "-H #{host}",
34
- "-V",
35
- "-X sshkit_log_level=warn",
36
- "-X log_device=stderr",
37
- "-X run_failure_strategy=cowboy",
38
- ]}
39
-
40
- # bundle exec rspec --tag smoke
41
- context "test.loom" do
42
- let(:loom_file) { LOOM_FILES.select { |p| p.match?(/test.loom/) }.first }
43
- let(:ref_set) { create_reference_set(path: loom_file) }
44
- let(:patterns) { ref_set.slugs.select { |s| s.match?(/^smoke:/) } }
45
- let(:host) { "localhost" }
46
-
47
- it "should pass a few tests quickly", :smoke => true do
48
- exec = command.join(' ')
49
- output = `#{exec}`
50
- expect($?.exitstatus).to eq 0
32
+ let(:command) { nil }
33
+
34
+ let(:executor) { lambda do |*cmd_parts|
35
+ cmd_exec = cmd_parts.join ' '
36
+ output = `#{cmd_exec} 2>&1`
37
+ OpenStruct.new({
38
+ cmd_exec: cmd_exec,
39
+ stdout: output,
40
+ rc: $?.exitstatus,
41
+ })
42
+ end }
43
+ let(:exec_result) { executor.call(*command) }
44
+
45
+ context "$ loom inventory", smoke: true do
46
+ let(:command) {[
47
+ "bin/loom inventory",
48
+ "-X loom_search_paths=./spec/.loom"
49
+ ]}
50
+
51
+ it "should list all hosts in inventory.yml" do
52
+ result = exec_result
53
+
54
+ ["a.host.to.check", "my.other.host"].each do |h|
55
+ expect(result.stdout).to match(/#{h}/), result.to_yaml
56
+ end
57
+ expect(result.rc).to eql 0
51
58
  end
52
59
  end
53
60
 
54
- # bundle exec rspec --tag integration
55
- LOOM_FILES.each do |loom_file|
56
- context File.basename loom_file do
57
- let(:loom_file) { loom_file }
61
+ context "$ loom pattern", smoke: true do
62
+ let(:command) {[
63
+ "bin/loom patterns",
64
+ "-l #{LOOM_FILES.join ','}"
65
+ ]}
66
+
67
+ it "should list all patterns to stdout" do
68
+ result = exec_result
69
+
70
+ # some expected pattern slug namespaces
71
+ ["pkg", "shell", "expectedfailures", "test"].each do |ns|
72
+ expect(result.stdout).to match(/^\s*#{ns}:.+/), result.to_yaml
73
+ end
74
+ expect(result.rc).to eql 0
75
+ end
76
+ end
77
+
78
+ context "$ loom weave" do
79
+
80
+ # Tests important command line flags
81
+ let(:command) {[
82
+ "bin/loom weave #{patterns.join " "}",
83
+ "-t",
84
+ "-l #{loom_file}",
85
+ "-X log_level=info",
86
+ "-H #{host}",
87
+ "-V",
88
+ "-X sshkit_log_level=warn",
89
+ "-X log_device=stderr",
90
+ "-X run_failure_strategy=cowboy",
91
+ "-F param_facts='from args'"
92
+ ]}
93
+
94
+ # bundle exec rspec --tag smoke
95
+ context "test.loom" do
96
+ let(:loom_file) { LOOM_FILES.select { |p| p.match?(/#{subject}/) }.first }
58
97
  let(:ref_set) { create_reference_set(path: loom_file) }
98
+ let(:patterns) { [:smoke] }
99
+ let(:host) { "localhost" }
100
+
101
+ it "should pass the smoke tests quickly", :smoke => true do
102
+ result = exec_result
103
+ unless result.rc == 0
104
+ puts "loom output:\n#{output}"
105
+ end
106
+ expect(result.rc).to eq 0
107
+ end
108
+ end
59
109
 
60
- if XFILE_SET[File.basename(loom_file)]
61
- xit "should pass all the tests",
62
- SPEC_TAGS.merge(:file => File.basename(loom_file)) {}
63
- else
64
- it "should pass all tests",
65
- SPEC_TAGS.merge(:file => File.basename(loom_file)) do
66
- exec = command.join(' ')
67
- puts exec
68
- # TODO pattern match the commands on STDOUT (see comment in
69
- # .loom/test.loom)
70
- output = `#{exec}`
71
-
72
- basename = File.basename(loom_file)
73
- expected_exit_code = EXPECTED_EXIT_CODE[basename] || 0
74
- expect($?.exitstatus).to eq expected_exit_code
110
+ # bundle exec rspec --tag integration
111
+ LOOM_FILES.each do |loom_file|
112
+ context File.basename loom_file do
113
+ let(:loom_file) { loom_file }
114
+ let(:ref_set) { create_reference_set(path: loom_file) }
115
+
116
+ if XFILE_SET[File.basename(loom_file)]
117
+ xit "should pass all the tests",
118
+ SPEC_TAGS.merge(:file => File.basename(loom_file)) {}
119
+ else
120
+ it "should pass all tests",
121
+ SPEC_TAGS.merge(:file => File.basename(loom_file)) do
122
+ exec = command.join(' ')
123
+ puts <<EOS
124
+ executing command:
125
+ $ #{exec}
126
+ EOS
127
+ # TODO pattern match the commands on STDOUT (see comment in
128
+ # .loom/test.loom)
129
+ output = `#{exec}`
130
+
131
+ basename = File.basename(loom_file)
132
+ expected_exit_code = EXPECTED_EXIT_CODE[basename] || 0
133
+ expect($?.exitstatus).to eq expected_exit_code
134
+ end
75
135
  end
76
136
  end
77
137
  end
data/test CHANGED
@@ -1,2 +1,17 @@
1
1
  #!/bin/sh
2
+ echo "running unit and smoke tests"
2
3
  bundle exec rspec --tag ~integration
4
+ rc=$?
5
+ if [ $rc -ne 0 ]; then
6
+ exit $rc
7
+ fi
8
+
9
+ y_or_Y="${1}"
10
+ if [ "${y_or_Y}" == "" ];then
11
+ read -p "run integration tests (y/n)?" y_or_Y
12
+ fi
13
+
14
+ case "$y_or_Y" in
15
+ y|Y ) bundle exec rspec --tag integration;;
16
+ * ) exit $rc;;
17
+ esac
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loom-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-26 00:00:00.000000000 Z
11
+ date: 2018-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sshkit
@@ -190,6 +190,20 @@ dependencies:
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
+ - !ruby/object:Gem::Dependency
194
+ name: rubocop
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ type: :development
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
193
207
  description: Repeatable management of remote hosts over SSH
194
208
  email: ejohnson82@gmail.com
195
209
  executables:
@@ -199,17 +213,19 @@ extra_rdoc_files: []
199
213
  files:
200
214
  - ".gitignore"
201
215
  - ".rspec"
216
+ - ".rubocop.yml"
202
217
  - Gemfile
203
218
  - Gemfile.lock
204
219
  - Guardfile
205
220
  - Rakefile
206
221
  - bin/loom
222
+ - docs/architecture.jpg
223
+ - gentags.sh
207
224
  - lib/env/development.rb
208
225
  - lib/loom.rb
209
226
  - lib/loom/all.rb
210
227
  - lib/loom/config.rb
211
228
  - lib/loom/core_ext.rb
212
- - lib/loom/dsl.rb
213
229
  - lib/loom/facts.rb
214
230
  - lib/loom/facts/all.rb
215
231
  - lib/loom/facts/fact_file_provider.rb
@@ -231,10 +247,14 @@ files:
231
247
  - lib/loom/pattern/expanding_reference.rb
232
248
  - lib/loom/pattern/hook.rb
233
249
  - lib/loom/pattern/loader.rb
250
+ - lib/loom/pattern/pattern.rb
234
251
  - lib/loom/pattern/reference.rb
235
252
  - lib/loom/pattern/reference_set.rb
236
253
  - lib/loom/pattern/result_reporter.rb
237
254
  - lib/loom/runner.rb
255
+ - lib/loom/runner/all.rb
256
+ - lib/loom/runner/execution_context.rb
257
+ - lib/loom/runner/sshkit_connector.rb
238
258
  - lib/loom/shell.rb
239
259
  - lib/loom/shell/all.rb
240
260
  - lib/loom/shell/api.rb
@@ -268,12 +288,14 @@ files:
268
288
  - lib/loomext/coremods/vm.rb
269
289
  - lib/loomext/coremods/vm/all.rb
270
290
  - lib/loomext/coremods/vm/vbox.rb
291
+ - loom.TAGS
271
292
  - loom.gemspec
272
293
  - loom/inventory.yml
273
294
  - scripts/harness.sh
274
295
  - spec/.loom/error_handling.loom
275
296
  - spec/.loom/fail.loom
276
297
  - spec/.loom/files.loom
298
+ - spec/.loom/inventory.yml
277
299
  - spec/.loom/net.loom
278
300
  - spec/.loom/pattern_context.loom
279
301
  - spec/.loom/pkg.loom