Skip to content

Commit 08c0069

Browse files
committed
(CONT-812) Update acceptance test setup
1 parent 7c8580e commit 08c0069

File tree

3 files changed

+8
-137
lines changed

3 files changed

+8
-137
lines changed

Diff for: .fixtures.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ fixtures:
33
facts: 'https://github.com/puppetlabs/puppetlabs-facts.git'
44
provision: 'https://github.com/puppetlabs/provision.git'
55
puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git'
6-
symlinks: []
6+
symlinks:
7+
test: "#{source_dir}/spec/fixtures/acceptance/modules/test"

Diff for: Rakefile

+5-135
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ RSpec::Core::RakeTask.new(:spec) do |t|
1515
t.exclude_pattern = "spec/acceptance/**/*.rb"
1616
end
1717

18+
RSpec::Core::RakeTask.new(:acceptance) do |t|
19+
t.pattern = "spec/unit/**/*.rb"
20+
end
21+
1822
task :spec => :spec_clean
23+
task :acceptance => :spec_prep
1924

2025
# Add our own tasks
2126
require 'puppet-strings/tasks'
@@ -32,138 +37,3 @@ task :validate do
3237
sh "erb -P -x -T '-' #{template} | ruby -c"
3338
end
3439
end
35-
36-
namespace :litmus do
37-
def install_remote_gem(gem_name, target_nodes, inventory_hash)
38-
# TODO: Currently this is Linux only
39-
install_command = "/opt/puppetlabs/puppet/bin/gem install #{gem_name}"
40-
result = run_command(install_command, target_nodes, config: nil, inventory: inventory_hash)
41-
if result.is_a?(Array)
42-
result.each do |node|
43-
puts "#{node['target']} failed: '#{node['value']}'" if node['status'] != 'success'
44-
end
45-
else
46-
raise "Failed trying to run '#{install_command}' against inventory."
47-
end
48-
end
49-
50-
def install_build_tools(target_nodes, inventory_hash)
51-
puts 'Installing build tools...'
52-
install_build_command = "yum -y group install 'Development Tools'"
53-
result = run_command(install_build_command, target_nodes, config: nil, inventory: inventory_hash)
54-
if result.is_a?(Array)
55-
result.each do |node|
56-
puts "#{node['target']} failed: '#{node['value']}'" if node['status'] != 'success'
57-
end
58-
else
59-
raise "Failed trying to run '#{install_build_command}' against inventory."
60-
end
61-
end
62-
63-
# Install the gem under test and required fixture on a collection of nodes
64-
#
65-
# @param :target_node_name [Array] nodes on which to install a puppet module for testing.
66-
desc 'install_gems - build and install module fixtures'
67-
task :install_gems, [:target_node_name] do |_task, args|
68-
inventory_hash = inventory_hash_from_inventory_file
69-
target_nodes = find_targets(inventory_hash, args[:target_node_name])
70-
if target_nodes.empty?
71-
puts 'No targets found'
72-
exit 0
73-
end
74-
require 'bolt_spec/run'
75-
include BoltSpec::Run
76-
77-
# Build the gem
78-
puts 'Building gem...'
79-
`gem build puppet-strings.gemspec --quiet`
80-
result = $CHILD_STATUS
81-
raise "Unable to build the puppet-strings gem. Returned exit code #{result.exitstatus}" unless result.exitstatus.zero?
82-
83-
# Find the gem build artifact
84-
gem_tar = Dir.glob('puppet-strings-*.gem').max_by { |f| File.mtime(f) }
85-
raise "Unable to find package in 'puppet-strings-*.gem'" if gem_tar.nil?
86-
87-
gem_tar = File.expand_path(gem_tar)
88-
89-
target_string = if args[:target_node_name].nil?
90-
'all'
91-
else
92-
args[:target_node_name]
93-
end
94-
puts 'Copying gem to targets...'
95-
upload_file(gem_tar, File.basename(gem_tar), target_string, inventory: inventory_hash)
96-
97-
install_build_tools(target_nodes, inventory_hash)
98-
99-
# Install dependent gems
100-
puts 'Installing yard gem...'
101-
install_remote_gem('yard', target_nodes, inventory_hash)
102-
puts 'Installing rgen gem...'
103-
install_remote_gem('rgen', target_nodes, inventory_hash)
104-
# Install puppet-strings
105-
puts 'Installing puppet-strings gem...'
106-
install_remote_gem(File.basename(gem_tar), target_nodes, inventory_hash)
107-
puts 'Installed'
108-
end
109-
end
110-
111-
#### CHANGELOG ####
112-
begin
113-
require 'github_changelog_generator/task'
114-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
115-
require 'puppet-strings/version'
116-
config.future_release = "v#{PuppetStrings::VERSION}"
117-
config.header = "# Changelog\n\n" \
118-
"All significant changes to this repo will be summarized in this file.\n"
119-
config.configure_sections = {
120-
added: {
121-
prefix: "Added",
122-
labels: ["enhancement"]
123-
},
124-
fixed: {
125-
prefix: "Fixed",
126-
labels: ["bugfix"]
127-
},
128-
breaking: {
129-
prefix: "Changed",
130-
labels: ["backwards-incompatible"]
131-
}
132-
}
133-
config.exclude_labels = ['maintenance','incomplete']
134-
config.user = 'puppetlabs'
135-
config.project = 'puppet-strings'
136-
end
137-
rescue LoadError
138-
desc 'Install github_changelog_generator to get access to automatic changelog generation'
139-
task :changelog do
140-
raise 'Install github_changelog_generator to get access to automatic changelog generation'
141-
end
142-
end
143-
144-
desc 'Run acceptance tests'
145-
task :acceptance do
146-
147-
begin
148-
if ENV['MATRIX_TARGET']
149-
agent_version = ENV['MATRIX_TARGET'].chomp
150-
else
151-
agent_version = 'puppet7'
152-
end
153-
154-
Rake::Task['litmus:provision'].invoke('docker', 'litmusimage/centos:7')
155-
156-
Rake::Task['litmus:install_agent'].invoke(agent_version.to_s)
157-
158-
Rake::Task['litmus:install_modules_from_directory'].invoke('./spec/fixtures/acceptance/modules')
159-
160-
Rake::Task['litmus:install_gems'].invoke
161-
162-
Rake::Task['litmus:acceptance:parallel'].invoke
163-
164-
rescue StandardError => e
165-
puts e.message
166-
raise e
167-
end
168-
169-
end

Diff for: spec/spec_helper_acceptance_local.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
def sut_module_path(module_regex)
4-
modules = JSON.parse(run_shell('puppet module list --render-as json').stdout)
4+
modules = JSON.parse(run_shell('bundle exec puppet module list --modulepath spec/fixtures/modules --render-as json').stdout)
55
test_module_info = modules['modules_by_path'].values.flatten.find { |mod_info| mod_info =~ module_regex }
66
test_module_info.match(%r{\(([^)]*)\)})[1]
77
end

0 commit comments

Comments
 (0)