summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Ilyin <dilyin@mirantis.com>2016-07-08 12:16:26 -0500
committerDmitry Ilyin <dilyin@mirantis.com>2016-07-14 14:33:53 -0500
commit7ce9a11467f0857fddf635e03c36c0a6d919498c (patch)
treed3491d398d0572361873ab932ea4aae82a9ddb88
parent10c3599d227d4510f77da06bf1dff0e6d37e1c63 (diff)
Add multiple module path support and test tasks
Notes
Notes (review): Verified+1: Fuel CI <fuel-ci-bot@mirantis.com> Code-Review+2: Dmitry Ilyin <dilyin@mirantis.com> Workflow+1: Dmitry Ilyin <dilyin@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 18 Jul 2016 16:22:27 +0000 Reviewed-on: https://review.openstack.org/339750 Project: openstack/fuel-noop-fixtures Branch: refs/heads/master
-rw-r--r--demo.rb10
-rw-r--r--doc/usage.rst4
-rw-r--r--lib/noop/config/base.rb16
-rw-r--r--lib/noop/manager/library.rb26
-rw-r--r--lib/noop/manager/options.rb2
-rw-r--r--lib/noop/manager/report.rb8
-rw-r--r--lib/noop/task/overrides.rb2
-rw-r--r--lib/noop/task/report.rb1
-rw-r--r--lib/noop/task/run.rb2
-rw-r--r--lib/noop/utils.rb15
-rw-r--r--spec/demo-hosts/test/compute_spec.rb10
-rw-r--r--spec/demo-hosts/test/controller_spec.rb10
-rw-r--r--spec/demo-hosts/test/fail_spec.rb10
-rw-r--r--spec/demo-hosts/test/master_spec.rb10
-rw-r--r--spec/lib/config_spec.rb6
-rw-r--r--spec/spec_helper.rb6
-rw-r--r--tasks/test/compute.pp3
-rw-r--r--tasks/test/controller.pp3
-rw-r--r--tasks/test/fail.pp3
-rw-r--r--tasks/test/master.pp3
20 files changed, 117 insertions, 33 deletions
diff --git a/demo.rb b/demo.rb
new file mode 100644
index 0000000..66ebe8e
--- /dev/null
+++ b/demo.rb
@@ -0,0 +1,10 @@
1#!/usr/bin/env ruby
2
3require_relative './noop_tests'
4
5ENV['SPEC_SPEC_DIR'] = './spec/demo-hosts'
6
7if $0 == __FILE__
8 manager = Noop::Manager.new
9 manager.main
10end
diff --git a/doc/usage.rst b/doc/usage.rst
index 3055d25..76a6d31 100644
--- a/doc/usage.rst
+++ b/doc/usage.rst
@@ -326,7 +326,9 @@ Paths related:
326 it but it should be at the *spec/hosts* from the root folder or the 326 it but it should be at the *spec/hosts* from the root folder or the
327 rpsec-puppet will break. 327 rpsec-puppet will break.
328- **SPEC_MODULE_PATH** or **SPEC_MODULEPATH** Set the path to the modules 328- **SPEC_MODULE_PATH** or **SPEC_MODULEPATH** Set the path to the modules
329 library. 329 library. It can be either a path to a single directory with Puppet
330 modules or a string with colon-separated paths to several module
331 directories.
330- **SPEC_TASK_DIR** Set the path to the task manifests folder. 332- **SPEC_TASK_DIR** Set the path to the task manifests folder.
331- **SPEC_DEPLOYMENT_DIR** Set the path to the *deployment* directory. It's 333- **SPEC_DEPLOYMENT_DIR** Set the path to the *deployment* directory. It's
332 actually use only to find the scripts to update and reset modules. 334 actually use only to find the scripts to update and reset modules.
diff --git a/lib/noop/config/base.rb b/lib/noop/config/base.rb
index cf493e3..430c3aa 100644
--- a/lib/noop/config/base.rb
+++ b/lib/noop/config/base.rb
@@ -50,16 +50,12 @@ module Noop
50 end 50 end
51 end 51 end
52 52
53 # @return [Pathname] 53 # @return [Array<Pathname>]
54 def self.dir_path_modules_local 54 def self.list_path_modules
55 return @dir_path_modules_local if @dir_path_modules_local 55 return @list_path_modules if @list_path_modules
56 @dir_path_modules_local = Noop::Utils.path_from_env 'SPEC_MODULEPATH', 'SPEC_MODULE_PATH' 56 @list_path_modules = Noop::Utils.path_list_from_env 'SPEC_MODULEPATH', 'SPEC_MODULE_PATH'
57 @dir_path_modules_local = dir_path_root + 'modules' unless @dir_path_modules_local 57 return @list_path_modules if @list_path_modules.any?
58 begin 58 @list_path_modules = [dir_path_root + 'modules']
59 @dir_path_modules_local = @dir_path_modules_local.realpath
60 rescue
61 @dir_path_modules_local
62 end
63 end 59 end
64 60
65 # @return [Pathname] 61 # @return [Pathname]
diff --git a/lib/noop/manager/library.rb b/lib/noop/manager/library.rb
index 99c0fbb..e88f92f 100644
--- a/lib/noop/manager/library.rb
+++ b/lib/noop/manager/library.rb
@@ -82,18 +82,20 @@ module Noop
82 def task_graph_metadata 82 def task_graph_metadata
83 return @task_graph_metadata if @task_graph_metadata 83 return @task_graph_metadata if @task_graph_metadata
84 @task_graph_metadata = {} 84 @task_graph_metadata = {}
85 error "No #{Noop::Config.dir_path_modules_local} directory!" unless Noop::Config.dir_path_modules_local.directory? 85 Noop::Config.list_path_modules.each do |path|
86 Noop::Config.dir_path_modules_local.find do |task_file| 86 next unless path.directory?
87 next unless task_file.file? 87 path.find do |task_file|
88 next unless task_file.to_s.end_with? 'tasks.yaml' 88 next unless task_file.file?
89 begin 89 next unless task_file.to_s.end_with? 'tasks.yaml'
90 tasks = YAML.load_file task_file 90 begin
91 rescue 91 tasks = YAML.load_file task_file
92 next 92 rescue
93 end 93 next
94 tasks.each do |task| 94 end
95 id = task['id'] 95 tasks.each do |task|
96 @task_graph_metadata[id] = task 96 id = task['id']
97 @task_graph_metadata[id] = task
98 end
97 end 99 end
98 end 100 end
99 101
diff --git a/lib/noop/manager/options.rb b/lib/noop/manager/options.rb
index 5db9504..65950d2 100644
--- a/lib/noop/manager/options.rb
+++ b/lib/noop/manager/options.rb
@@ -117,7 +117,7 @@ module Noop
117 opts.on('--dir_task_files DIR', 'Path to the folder with task manifest files') do |dir| 117 opts.on('--dir_task_files DIR', 'Path to the folder with task manifest files') do |dir|
118 ENV['SPEC_TASK_DIR'] = dir 118 ENV['SPEC_TASK_DIR'] = dir
119 end 119 end
120 opts.on('--dir_puppet_modules DIR', 'Path to the puppet modules') do |dir| 120 opts.on('--module_path DIR', 'Path to the puppet modules. Can consist of several dirs separated by a colon.') do |dir|
121 ENV['SPEC_MODULE_PATH'] = dir 121 ENV['SPEC_MODULE_PATH'] = dir
122 end 122 end
123 123
diff --git a/lib/noop/manager/report.rb b/lib/noop/manager/report.rb
index 7978f42..69b4f42 100644
--- a/lib/noop/manager/report.rb
+++ b/lib/noop/manager/report.rb
@@ -207,7 +207,6 @@ Total tasks to run: <%= task_list.count.to_s.colorize :yellow %>
207 :dir_path_root, 207 :dir_path_root,
208 :dir_path_task_root, 208 :dir_path_task_root,
209 :dir_path_task_spec, 209 :dir_path_task_spec,
210 :dir_path_modules_local,
211 :dir_path_tasks_local, 210 :dir_path_tasks_local,
212 :dir_path_deployment, 211 :dir_path_deployment,
213 :dir_path_workspace, 212 :dir_path_workspace,
@@ -217,12 +216,17 @@ Total tasks to run: <%= task_list.count.to_s.colorize :yellow %>
217 :dir_path_facts_override, 216 :dir_path_facts_override,
218 :dir_path_globals, 217 :dir_path_globals,
219 :dir_path_reports, 218 :dir_path_reports,
219
220 :list_path_modules,
220 ] 221 ]
221 max_length = paths.map { |p| p.to_s.length }.max 222 max_length = paths.map { |p| p.to_s.length }.max
222 223
223 paths.each do |path| 224 paths.each do |path|
224 directory = Noop::Config.send path 225 directory = Noop::Config.send path
225 output "#{directory_check_status_string directory} #{path.to_s.ljust max_length} #{directory}" 226 directory = [directory] unless directory.is_a? Array
227 directory.each do |element|
228 output "#{directory_check_status_string element} #{path.to_s.ljust max_length} #{element}"
229 end
226 end 230 end
227 end 231 end
228 232
diff --git a/lib/noop/task/overrides.rb b/lib/noop/task/overrides.rb
index d650efa..cb13dae 100644
--- a/lib/noop/task/overrides.rb
+++ b/lib/noop/task/overrides.rb
@@ -15,7 +15,7 @@ module Noop
15 # to run in this RSpec session 15 # to run in this RSpec session
16 def setup_manifest 16 def setup_manifest
17 RSpec.configuration.manifest = file_path_manifest.to_s 17 RSpec.configuration.manifest = file_path_manifest.to_s
18 RSpec.configuration.module_path = Noop::Config.dir_path_modules_local.to_s 18 RSpec.configuration.module_path = Noop::Config.list_path_modules.join ':'
19 RSpec.configuration.manifest_dir = Noop::Config.dir_path_tasks_local.to_s 19 RSpec.configuration.manifest_dir = Noop::Config.dir_path_tasks_local.to_s
20 20
21 # FIXME: kludge to support calling Puppet function outside of the test context 21 # FIXME: kludge to support calling Puppet function outside of the test context
diff --git a/lib/noop/task/report.rb b/lib/noop/task/report.rb
index e5a0648..96bf852 100644
--- a/lib/noop/task/report.rb
+++ b/lib/noop/task/report.rb
@@ -10,6 +10,7 @@ module Noop
10Facts: <%= task.file_path_facts %> 10Facts: <%= task.file_path_facts %>
11Hiera: <%= task.file_path_hiera %> 11Hiera: <%= task.file_path_hiera %>
12Spec: <%= task.file_path_spec %> 12Spec: <%= task.file_path_spec %>
13Modules: <%= Noop::Config.list_path_modules.join(':') %>
13Manifest: <%= task.file_path_manifest %> 14Manifest: <%= task.file_path_manifest %>
14 15
15Node: <%= task.hiera_lookup 'fqdn' or '?' %> 16Node: <%= task.hiera_lookup 'fqdn' or '?' %>
diff --git a/lib/noop/task/run.rb b/lib/noop/task/run.rb
index 7acea0e..015b242 100644
--- a/lib/noop/task/run.rb
+++ b/lib/noop/task/run.rb
@@ -68,7 +68,7 @@ module Noop
68 'SPEC_REPORTS_DIR' => Noop::Config.dir_path_reports.to_s, 68 'SPEC_REPORTS_DIR' => Noop::Config.dir_path_reports.to_s,
69 'SPEC_SPEC_DIR' => Noop::Config.dir_path_task_spec.to_s, 69 'SPEC_SPEC_DIR' => Noop::Config.dir_path_task_spec.to_s,
70 'SPEC_TASK_DIR' => Noop::Config.dir_path_tasks_local.to_s, 70 'SPEC_TASK_DIR' => Noop::Config.dir_path_tasks_local.to_s,
71 'SPEC_MODULE_PATH' => Noop::Config.dir_path_modules_local.to_s, 71 'SPEC_MODULE_PATH' => Noop::Config.list_path_modules.join(':'),
72 } 72 }
73 command = "rspec #{file_path_spec.to_s} #{rspec_options} --format json --out #{file_path_report_json.to_s}" 73 command = "rspec #{file_path_spec.to_s} #{rspec_options} --format json --out #{file_path_report_json.to_s}"
74 command = "bundle exec #{command}" if ENV['SPEC_BUNDLE_EXEC'] 74 command = "bundle exec #{command}" if ENV['SPEC_BUNDLE_EXEC']
diff --git a/lib/noop/utils.rb b/lib/noop/utils.rb
index c924fdb..463e537 100644
--- a/lib/noop/utils.rb
+++ b/lib/noop/utils.rb
@@ -10,6 +10,21 @@ module Noop
10 nil 10 nil
11 end 11 end
12 12
13 def self.path_list_from_env(*names)
14 paths = []
15 names.each do |name|
16 name = name.to_s
17 next unless ENV[name]
18 list = ENV[name].split(':')
19 list.each do |path|
20 path = convert_to_path path
21 path = path.realpath if path.exist?
22 paths << path
23 end
24 end
25 paths
26 end
27
13 # @param [Object] value 28 # @param [Object] value
14 # @return [Pathname] 29 # @return [Pathname]
15 def self.convert_to_path(value) 30 def self.convert_to_path(value)
diff --git a/spec/demo-hosts/test/compute_spec.rb b/spec/demo-hosts/test/compute_spec.rb
new file mode 100644
index 0000000..3d28c33
--- /dev/null
+++ b/spec/demo-hosts/test/compute_spec.rb
@@ -0,0 +1,10 @@
1require 'spec_helper'
2require 'shared-examples'
3
4# ROLE: compute
5
6manifest = 'test/compute.pp'
7
8describe manifest, :type => :host do
9 run_test manifest
10end
diff --git a/spec/demo-hosts/test/controller_spec.rb b/spec/demo-hosts/test/controller_spec.rb
new file mode 100644
index 0000000..5be3726
--- /dev/null
+++ b/spec/demo-hosts/test/controller_spec.rb
@@ -0,0 +1,10 @@
1require 'spec_helper'
2require 'shared-examples'
3
4# ROLE: controller
5
6manifest = 'test/controller.pp'
7
8describe manifest, :type => :host do
9 run_test manifest
10end
diff --git a/spec/demo-hosts/test/fail_spec.rb b/spec/demo-hosts/test/fail_spec.rb
new file mode 100644
index 0000000..6bc3181
--- /dev/null
+++ b/spec/demo-hosts/test/fail_spec.rb
@@ -0,0 +1,10 @@
1require 'spec_helper'
2require 'shared-examples'
3
4# HIERA: master
5
6manifest = 'test/fail.pp'
7
8describe manifest, :type => :host do
9 run_test manifest
10end
diff --git a/spec/demo-hosts/test/master_spec.rb b/spec/demo-hosts/test/master_spec.rb
new file mode 100644
index 0000000..6c3befd
--- /dev/null
+++ b/spec/demo-hosts/test/master_spec.rb
@@ -0,0 +1,10 @@
1require 'spec_helper'
2require 'shared-examples'
3
4# HIERA: master
5
6manifest = 'test/master.pp'
7
8describe manifest, :type => :host do
9 run_test manifest
10end
diff --git a/spec/lib/config_spec.rb b/spec/lib/config_spec.rb
index 77a8d16..6f5301a 100644
--- a/spec/lib/config_spec.rb
+++ b/spec/lib/config_spec.rb
@@ -22,9 +22,9 @@ describe Noop::Config do
22 expect(subject.dir_path_task_spec.to_s).to eq "#{root}/spec/hosts" 22 expect(subject.dir_path_task_spec.to_s).to eq "#{root}/spec/hosts"
23 end 23 end
24 24
25 it 'dir_path_modules_local' do 25 it 'list_path_modules' do
26 expect(subject.dir_path_modules_local).to be_a Pathname 26 expect(subject.list_path_modules).to be_a Array
27 expect(subject.dir_path_modules_local.to_s).to eq "#{root}/modules" 27 expect(subject.list_path_modules.first.to_s).to eq "#{root}/modules"
28 end 28 end
29 29
30 it 'dir_path_tasks_local' do 30 it 'dir_path_tasks_local' do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 5e41275..3e20689 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -9,8 +9,10 @@ require_relative '../lib/noop'
9 9
10# Add fixture lib dirs to LOAD_PATH. Work-around for PUP-3336 10# Add fixture lib dirs to LOAD_PATH. Work-around for PUP-3336
11if Puppet.version < '4.0.0' 11if Puppet.version < '4.0.0'
12 Dir["#{Noop::Config.dir_path_modules_local}/*/lib"].entries.each do |lib_dir| 12 Noop::Config.list_path_modules.each do |path|
13 $LOAD_PATH << lib_dir 13 Dir["#{path}/*/lib"].entries.each do |lib_dir|
14 $LOAD_PATH << lib_dir
15 end
14 end 16 end
15end 17end
16 18
diff --git a/tasks/test/compute.pp b/tasks/test/compute.pp
new file mode 100644
index 0000000..5369eec
--- /dev/null
+++ b/tasks/test/compute.pp
@@ -0,0 +1,3 @@
1notice("MODULAR: test/compute")
2
3notify { 'test/compute' :}
diff --git a/tasks/test/controller.pp b/tasks/test/controller.pp
new file mode 100644
index 0000000..178b2cf
--- /dev/null
+++ b/tasks/test/controller.pp
@@ -0,0 +1,3 @@
1notice("MODULAR: test/controller")
2
3notify { 'test/controller' :}
diff --git a/tasks/test/fail.pp b/tasks/test/fail.pp
new file mode 100644
index 0000000..a7e4fcd
--- /dev/null
+++ b/tasks/test/fail.pp
@@ -0,0 +1,3 @@
1notice("MODULAR: test/fail")
2
3fail('some error') \ No newline at end of file
diff --git a/tasks/test/master.pp b/tasks/test/master.pp
new file mode 100644
index 0000000..9cca2be
--- /dev/null
+++ b/tasks/test/master.pp
@@ -0,0 +1,3 @@
1notice("MODULAR: test/master")
2
3notify { 'test/master' :}