Add multiple module path support and test tasks

Change-Id: Ie582146053185809b43b6483346993f0ec7eded5
This commit is contained in:
Dmitry Ilyin 2016-07-08 12:16:26 -05:00
parent 10c3599d22
commit 7ce9a11467
20 changed files with 117 additions and 33 deletions

10
demo.rb Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require_relative './noop_tests'
ENV['SPEC_SPEC_DIR'] = './spec/demo-hosts'
if $0 == __FILE__
manager = Noop::Manager.new
manager.main
end

View File

@ -326,7 +326,9 @@ Paths related:
it but it should be at the *spec/hosts* from the root folder or the
rpsec-puppet will break.
- **SPEC_MODULE_PATH** or **SPEC_MODULEPATH** Set the path to the modules
library.
library. It can be either a path to a single directory with Puppet
modules or a string with colon-separated paths to several module
directories.
- **SPEC_TASK_DIR** Set the path to the task manifests folder.
- **SPEC_DEPLOYMENT_DIR** Set the path to the *deployment* directory. It's
actually use only to find the scripts to update and reset modules.

View File

@ -50,16 +50,12 @@ module Noop
end
end
# @return [Pathname]
def self.dir_path_modules_local
return @dir_path_modules_local if @dir_path_modules_local
@dir_path_modules_local = Noop::Utils.path_from_env 'SPEC_MODULEPATH', 'SPEC_MODULE_PATH'
@dir_path_modules_local = dir_path_root + 'modules' unless @dir_path_modules_local
begin
@dir_path_modules_local = @dir_path_modules_local.realpath
rescue
@dir_path_modules_local
end
# @return [Array<Pathname>]
def self.list_path_modules
return @list_path_modules if @list_path_modules
@list_path_modules = Noop::Utils.path_list_from_env 'SPEC_MODULEPATH', 'SPEC_MODULE_PATH'
return @list_path_modules if @list_path_modules.any?
@list_path_modules = [dir_path_root + 'modules']
end
# @return [Pathname]

View File

@ -82,18 +82,20 @@ module Noop
def task_graph_metadata
return @task_graph_metadata if @task_graph_metadata
@task_graph_metadata = {}
error "No #{Noop::Config.dir_path_modules_local} directory!" unless Noop::Config.dir_path_modules_local.directory?
Noop::Config.dir_path_modules_local.find do |task_file|
next unless task_file.file?
next unless task_file.to_s.end_with? 'tasks.yaml'
begin
tasks = YAML.load_file task_file
rescue
next
end
tasks.each do |task|
id = task['id']
@task_graph_metadata[id] = task
Noop::Config.list_path_modules.each do |path|
next unless path.directory?
path.find do |task_file|
next unless task_file.file?
next unless task_file.to_s.end_with? 'tasks.yaml'
begin
tasks = YAML.load_file task_file
rescue
next
end
tasks.each do |task|
id = task['id']
@task_graph_metadata[id] = task
end
end
end

View File

@ -117,7 +117,7 @@ module Noop
opts.on('--dir_task_files DIR', 'Path to the folder with task manifest files') do |dir|
ENV['SPEC_TASK_DIR'] = dir
end
opts.on('--dir_puppet_modules DIR', 'Path to the puppet modules') do |dir|
opts.on('--module_path DIR', 'Path to the puppet modules. Can consist of several dirs separated by a colon.') do |dir|
ENV['SPEC_MODULE_PATH'] = dir
end

View File

@ -207,7 +207,6 @@ Total tasks to run: <%= task_list.count.to_s.colorize :yellow %>
:dir_path_root,
:dir_path_task_root,
:dir_path_task_spec,
:dir_path_modules_local,
:dir_path_tasks_local,
:dir_path_deployment,
:dir_path_workspace,
@ -217,12 +216,17 @@ Total tasks to run: <%= task_list.count.to_s.colorize :yellow %>
:dir_path_facts_override,
:dir_path_globals,
:dir_path_reports,
:list_path_modules,
]
max_length = paths.map { |p| p.to_s.length }.max
paths.each do |path|
directory = Noop::Config.send path
output "#{directory_check_status_string directory} #{path.to_s.ljust max_length} #{directory}"
directory = [directory] unless directory.is_a? Array
directory.each do |element|
output "#{directory_check_status_string element} #{path.to_s.ljust max_length} #{element}"
end
end
end

View File

@ -15,7 +15,7 @@ module Noop
# to run in this RSpec session
def setup_manifest
RSpec.configuration.manifest = file_path_manifest.to_s
RSpec.configuration.module_path = Noop::Config.dir_path_modules_local.to_s
RSpec.configuration.module_path = Noop::Config.list_path_modules.join ':'
RSpec.configuration.manifest_dir = Noop::Config.dir_path_tasks_local.to_s
# FIXME: kludge to support calling Puppet function outside of the test context

View File

@ -10,6 +10,7 @@ module Noop
Facts: <%= task.file_path_facts %>
Hiera: <%= task.file_path_hiera %>
Spec: <%= task.file_path_spec %>
Modules: <%= Noop::Config.list_path_modules.join(':') %>
Manifest: <%= task.file_path_manifest %>
Node: <%= task.hiera_lookup 'fqdn' or '?' %>

View File

@ -68,7 +68,7 @@ module Noop
'SPEC_REPORTS_DIR' => Noop::Config.dir_path_reports.to_s,
'SPEC_SPEC_DIR' => Noop::Config.dir_path_task_spec.to_s,
'SPEC_TASK_DIR' => Noop::Config.dir_path_tasks_local.to_s,
'SPEC_MODULE_PATH' => Noop::Config.dir_path_modules_local.to_s,
'SPEC_MODULE_PATH' => Noop::Config.list_path_modules.join(':'),
}
command = "rspec #{file_path_spec.to_s} #{rspec_options} --format json --out #{file_path_report_json.to_s}"
command = "bundle exec #{command}" if ENV['SPEC_BUNDLE_EXEC']

View File

@ -10,6 +10,21 @@ module Noop
nil
end
def self.path_list_from_env(*names)
paths = []
names.each do |name|
name = name.to_s
next unless ENV[name]
list = ENV[name].split(':')
list.each do |path|
path = convert_to_path path
path = path.realpath if path.exist?
paths << path
end
end
paths
end
# @param [Object] value
# @return [Pathname]
def self.convert_to_path(value)

View File

@ -0,0 +1,10 @@
require 'spec_helper'
require 'shared-examples'
# ROLE: compute
manifest = 'test/compute.pp'
describe manifest, :type => :host do
run_test manifest
end

View File

@ -0,0 +1,10 @@
require 'spec_helper'
require 'shared-examples'
# ROLE: controller
manifest = 'test/controller.pp'
describe manifest, :type => :host do
run_test manifest
end

View File

@ -0,0 +1,10 @@
require 'spec_helper'
require 'shared-examples'
# HIERA: master
manifest = 'test/fail.pp'
describe manifest, :type => :host do
run_test manifest
end

View File

@ -0,0 +1,10 @@
require 'spec_helper'
require 'shared-examples'
# HIERA: master
manifest = 'test/master.pp'
describe manifest, :type => :host do
run_test manifest
end

View File

@ -22,9 +22,9 @@ describe Noop::Config do
expect(subject.dir_path_task_spec.to_s).to eq "#{root}/spec/hosts"
end
it 'dir_path_modules_local' do
expect(subject.dir_path_modules_local).to be_a Pathname
expect(subject.dir_path_modules_local.to_s).to eq "#{root}/modules"
it 'list_path_modules' do
expect(subject.list_path_modules).to be_a Array
expect(subject.list_path_modules.first.to_s).to eq "#{root}/modules"
end
it 'dir_path_tasks_local' do

View File

@ -9,8 +9,10 @@ require_relative '../lib/noop'
# Add fixture lib dirs to LOAD_PATH. Work-around for PUP-3336
if Puppet.version < '4.0.0'
Dir["#{Noop::Config.dir_path_modules_local}/*/lib"].entries.each do |lib_dir|
$LOAD_PATH << lib_dir
Noop::Config.list_path_modules.each do |path|
Dir["#{path}/*/lib"].entries.each do |lib_dir|
$LOAD_PATH << lib_dir
end
end
end

3
tasks/test/compute.pp Normal file
View File

@ -0,0 +1,3 @@
notice("MODULAR: test/compute")
notify { 'test/compute' :}

3
tasks/test/controller.pp Normal file
View File

@ -0,0 +1,3 @@
notice("MODULAR: test/controller")
notify { 'test/controller' :}

3
tasks/test/fail.pp Normal file
View File

@ -0,0 +1,3 @@
notice("MODULAR: test/fail")
fail('some error')

3
tasks/test/master.pp Normal file
View File

@ -0,0 +1,3 @@
notice("MODULAR: test/master")
notify { 'test/master' :}