Skip to content

Commit a9fcee6

Browse files
authored
Merge pull request #364 from puppetlabs/CONT-237-clean_up_deprecations
(CONT-237) Deprecation and legacy version support removal
2 parents c142acf + c542e01 commit a9fcee6

File tree

13 files changed

+16
-235
lines changed

13 files changed

+16
-235
lines changed

.noexec.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,31 +141,17 @@ A number of the Puppet parser features, controlled via configuration during a
141141
normal puppet run, can be controlled by exporting specific environment
142142
variables for the spec run. These are:
143143

144-
* ``STRICT_VARIABLES`` - set to "yes" to enable set to strict variable checking when using Puppet versions between 3.5 and 4.0;
145-
set to "no" to disable strict variable checking on Puppet versions 4.0, and later.
146-
See [strict_variables](http://docs.puppetlabs.com/references/latest/configuration.html#strictvariables)
147-
in puppet.conf for details.
144+
* ``STRICT_VARIABLES`` - Set to "no" to disable strict variable checking.
145+
See [strict_variables](http://docs.puppetlabs.com/references/latest/configuration.html#strictvariables) in puppet.conf for details.
148146
* ``ORDERING`` - set to the desired ordering method ("title-hash", "manifest", or "random")
149147
to set the order of unrelated resources when applying a catalog. Leave unset for the default
150148
behavior, currently "random". This is equivalent to setting [ordering](http://docs.puppetlabs.com/references/latest/configuration.html#ordering)
151149
in puppet.conf.
152-
* The following options only affect Puppet 3.x:
153-
* ``FUTURE_PARSER`` _(Puppet 3.x, starting with 3.2)_ - set to "yes" to enable the [future parser](https://docs.puppet.com/puppet/3/experiments_future.html),
154-
the equivalent of setting [parser=future](https://puppet.com/docs/puppet/3.8/configuration.html#parser)
155-
in puppet.conf.
156-
* ``TRUSTED_NODE_DATA`` _(Puppet 3.x, starting with 3.4)_ - set to "yes" to enable [the $facts hash and trusted node data](https://puppet.com/docs/puppet/3.8/lang_facts_and_builtin_vars.html#trusted-facts),
157-
which enabled ``$facts`` and ``$trusted`` hashes. This is equivalent to setting
158-
[trusted_node_data=true](https://puppet.com/docs/puppet/3.8/configuration.html#trustednodedata)
159-
in puppet.conf.
160-
* ``STRINGIFY_FACTS`` _(Puppet 3.x, starting with 3.5)_ - set to "no" to enable [structured facts](http://docs.puppetlabs.com/facter/2.0/fact_overview.html#writing-structured-facts),
161-
otherwise leave unset to retain the current default behavior. This is equivalent to setting
162-
[stringify_facts=false](https://puppet.com/docs/puppet/3.8/configuration.html#stringifyfacts)
163-
in puppet.conf.
164-
165-
As an example, to run spec tests with the future parser, strict variable checking,
150+
151+
As an example, to run spec tests with the future parser, strict variable checking,
166152
and manifest ordering, you would:
167153

168-
FUTURE_PARSER=yes STRICT_VARIABLES=yes ORDERING=manifest rake spec
154+
ORDERING=manifest rake spec
169155

170156

171157
Using Utility Classes

lib/puppetlabs_spec_helper/module_spec_helper.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ def verify_contents(subject, title, expected_lines)
6666
c.formatter = 'RSpec::Github::Formatter'
6767
end
6868

69-
c.environmentpath = spec_path if Puppet.version.to_f >= 4.0
69+
c.environmentpath = spec_path
7070
c.module_path = module_path
7171
c.manifest_dir = File.join(fixture_path, 'manifests')
72-
c.parser = 'future' if ENV['FUTURE_PARSER'] == 'yes'
7372

7473
c.before :each do
7574
if c.mock_framework.framework_name == :rspec
@@ -78,12 +77,7 @@ def verify_contents(subject, title, expected_lines)
7877
Puppet.features.stubs(:root?).returns(true)
7978
end
8079

81-
# stringify_facts and trusted_node_data were removed in puppet4
82-
if Puppet.version.to_f < 4.0
83-
Puppet.settings[:stringify_facts] = false if ENV['STRINGIFY_FACTS'] == 'no'
84-
Puppet.settings[:trusted_node_data] = true if ENV['TRUSTED_NODE_DATA'] == 'yes'
85-
end
86-
Puppet.settings[:strict_variables] = true if ENV['STRICT_VARIABLES'] == 'yes' || (Puppet.version.to_f >= 4.0 && ENV['STRICT_VARIABLES'] != 'no')
80+
Puppet.settings[:strict_variables] = true if ENV['STRICT_VARIABLES'] == 'yes' || ENV['STRICT_VARIABLES'] != 'no'
8781
Puppet.settings[:ordering] = ENV['ORDERING'] if ENV['ORDERING']
8882
end
8983
end

lib/puppetlabs_spec_helper/puppet_spec_helper.rb

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -51,99 +51,14 @@
5151
# Continue gracefully
5252
end
5353

54-
# This is just a utility class to allow us to isolate the various version-specific
55-
# branches of initialization logic into methods without polluting the global namespace.#
56-
class Puppet::PuppetSpecInitializer
57-
# This method is for initializing puppet state for testing for older versions
58-
# of puppet that do not support the new TestHelper API. As you can see,
59-
# this involves explicitly modifying global variables, directly manipulating
60-
# Puppet's Settings singleton object, and other fun implementation details
61-
# that code external to puppet should really never know about.
62-
def self.initialize_via_fallback_compatibility(config)
63-
warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
64-
config.before :all do
65-
# nothing to do for now
66-
end
67-
68-
config.after :all do
69-
# nothing to do for now
70-
end
71-
72-
config.before :each do
73-
# these globals are set by Application
74-
$puppet_application_mode = nil # rubocop:disable Style/GlobalVars
75-
$puppet_application_name = nil # rubocop:disable Style/GlobalVars
76-
77-
# REVISIT: I think this conceals other bad tests, but I don't have time to
78-
# fully diagnose those right now. When you read this, please come tell me
79-
# I suck for letting this float. --daniel 2011-04-21
80-
Signal.stubs(:trap)
81-
82-
# Set the confdir and vardir to gibberish so that tests
83-
# have to be correctly mocked.
84-
Puppet[:confdir] = '/dev/null'
85-
Puppet[:vardir] = '/dev/null'
86-
87-
# Avoid opening ports to the outside world
88-
Puppet.settings[:bindaddress] = '127.0.0.1'
89-
end
90-
91-
config.after :each do
92-
Puppet.settings.clear
93-
94-
Puppet::Node::Environment.clear
95-
Puppet::Util::Storage.clear
96-
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'
97-
98-
PuppetlabsSpec::Files.cleanup
99-
end
100-
end
101-
end
102-
103-
# JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534)
104-
unless Puppet.constants.include? 'Test'
105-
module Puppet::Test
106-
# This is a stub class to allow the stdlib tests to run in Puppet 2.6
107-
# This class will be removed in another commit.
108-
class LogCollector
109-
def initialize(logs)
110-
@logs = logs
111-
end
112-
113-
def <<(value)
114-
@logs << value
115-
end
116-
end
117-
end
118-
Puppet::Util::Log.newdesttype :log_collector do
119-
match 'Puppet::Test::LogCollector'
120-
121-
def initialize(messages)
122-
@messages = messages
123-
end
124-
125-
def handle(msg)
126-
@messages << msg
127-
end
128-
end
129-
end
130-
13154
# And here is where we do the main rspec configuration / setup.
13255
RSpec.configure do |config|
13356
# Detect whether the module is overriding the choice of mocking framework
13457
# @mock_framework is used since more than seven years, and we need to avoid
13558
# `mock_framework`'s autoloading to distinguish between the default, and
13659
# the module's choice.
13760
if config.instance_variable_get(:@mock_framework).nil?
138-
RSpec.warn_deprecation('puppetlabs_spec_helper: defaults `mock_with` to `:mocha`. See https://github.com/puppetlabs/puppetlabs_spec_helper#mock_with to choose a sensible value for you')
139-
config.mock_with :mocha
140-
end
141-
142-
# determine whether we can use the new API or not, and call the appropriate initializer method.
143-
if defined?(Puppet::Test::TestHelper)
144-
# This case is handled by rspec-puppet since v1.0.0 (via 41257b33cb1f9ade4426b044f70be511b0c89112)
145-
else
146-
Puppet::PuppetSpecInitializer.initialize_via_fallback_compatibility(config)
61+
config.mock_with :rspec
14762
end
14863

14964
# Here we do some general setup that is relevant to all initialization modes, regardless

lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
require 'stringio'
44
require 'rspec/expectations'
55

6-
########################################################################
7-
# Backward compatibility for Jenkins outdated environment.
8-
module RSpec::Matchers::BlockAliases
9-
if method_defined?(:should) && !method_defined?(:to)
10-
alias to should
11-
end
12-
if method_defined? :should_not
13-
alias to_not should_not unless method_defined? :to_not
14-
alias not_to should_not unless method_defined? :not_to
15-
end
16-
end
17-
########################################################################
186
# Custom matchers...
197
RSpec::Matchers.define :have_matching_element do |expected|
208
match do |actual|

lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,6 @@
77
# PuppetInternals provides a set of methods that interface
88
# with internal puppet implementations.
99
module PuppetlabsSpec::PuppetInternals
10-
# parser_scope is intended to return a Puppet::Parser::Scope
11-
# instance suitable for placing in a test harness with the intent of
12-
# testing parser functions from modules.
13-
def scope(parts = {})
14-
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
15-
16-
if %r{^2\.[67]}.match?(Puppet.version)
17-
# loadall should only be necessary prior to 3.x
18-
# Please note, loadall needs to happen first when creating a scope, otherwise
19-
# you might receive undefined method `function_*' errors
20-
Puppet::Parser::Functions.autoloader.loadall
21-
end
22-
23-
scope_compiler = parts[:compiler] || compiler
24-
scope_parent = parts[:parent] || scope_compiler.topscope
25-
26-
scope = if %r{^2\.[67]}.match?(Puppet.version)
27-
Puppet::Parser::Scope.new(compiler: scope_compiler)
28-
else
29-
Puppet::Parser::Scope.new(scope_compiler)
30-
end
31-
32-
scope.source = Puppet::Resource::Type.new(:node, 'foo')
33-
scope.parent = scope_parent
34-
scope
35-
end
36-
module_function :scope
37-
3810
def resource(parts = {})
3911
resource_type = parts[:type] || :hostclass
4012
resource_name = parts[:name] || 'testing'
@@ -51,11 +23,7 @@ def compiler(parts = {})
5123
def node(parts = {})
5224
node_name = parts[:name] || 'testinghost'
5325
options = parts[:options] || {}
54-
node_environment = if Puppet.version.to_f >= 4.0
55-
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
56-
else
57-
Puppet::Node::Environment.new(parts[:environment] || 'test')
58-
end
26+
node_environment = Puppet::Node::Environment.create(parts[:environment] || 'test', [])
5927
options[:environment] = node_environment
6028
Puppet::Node.new(node_name, options)
6129
end

lib/puppetlabs_spec_helper/rake_tasks.rb

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,10 @@
122122

123123
desc 'Build puppet module package'
124124
task :build do
125-
if Gem::Specification.find_by_name('puppet').version < Gem::Version.new('6.0.0')
126-
Rake::Task['build:pmt'].invoke
127-
else
128-
Rake::Task['build:pdk'].invoke
129-
end
125+
Rake::Task['build:pdk'].invoke
130126
end
131127

132128
namespace :build do
133-
desc 'Build Puppet module package with PMT (Puppet < 6.0.0 only)'
134-
task :pmt do
135-
require 'puppet/face'
136-
137-
pmod = Puppet::Face['module', :current]
138-
pmod.build('./')
139-
end
140-
141129
desc 'Build Puppet module with PDK'
142130
task :pdk do
143131
require 'pdk/util'
@@ -204,9 +192,6 @@
204192
PuppetSyntax.exclude_paths << 'vendor/**/*'
205193
PuppetSyntax.exclude_paths << '.vendor/**/*'
206194
PuppetSyntax.exclude_paths << 'plans/**/*'
207-
if Puppet.version.to_f < 4.0
208-
PuppetSyntax.exclude_paths << 'types/**/*'
209-
end
210195

211196
desc 'Check syntax of Ruby files and call :syntax and :metadata_lint'
212197
task :validate do
@@ -232,15 +217,6 @@
232217
end
233218
end
234219

235-
task :metadata do
236-
warn "The 'metadata' task is deprecated. Please use 'metadata_lint' instead."
237-
if Rake::Task.task_defined?(:metadata_lint)
238-
Rake::Task[:metadata_lint].invoke
239-
else
240-
warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
241-
end
242-
end
243-
244220
desc 'Print development version of module'
245221
task :compute_dev_version do
246222
version = ''
@@ -263,7 +239,7 @@
263239
# If the branch is a release branch we append an 'r' into the new_version,
264240
# this is due to the release branch buildID conflicting with main branch when trying to push to the staging forge.
265241
# More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
266-
new_version = if (build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']))
242+
new_version = if (build = ENV['BUILD_NUMBER'])
267243
if branch.eql? 'release'
268244
'%s-%s%04d-%s' % [version, 'r', build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
269245
else

lib/puppetlabs_spec_helper/version.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@
22

33
module PuppetlabsSpecHelper
44
VERSION = '4.0.1'
5-
6-
# compat for pre-1.2.0 users; deprecated
7-
module Version
8-
STRING = PuppetlabsSpecHelper::VERSION
9-
end
105
end

puppet_spec_helper.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

puppetlabs_spec_helper.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ Gem::Specification.new do |spec|
2626
spec.executables = Dir['bin/**/*'].map { |f| File.basename(f) }
2727
spec.require_paths = ['lib']
2828

29-
spec.required_ruby_version = Gem::Requirement.new('>= 2.7'.freeze)
29+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
3030

3131
spec.add_runtime_dependency 'mocha', '~> 1.0'
3232
spec.add_runtime_dependency 'pathspec', '~> 1.0'
3333
spec.add_runtime_dependency 'puppet-lint', '~> 3.0'
3434
spec.add_runtime_dependency 'puppet-syntax', '~> 3.0'
3535
spec.add_runtime_dependency 'rspec-github', '~> 2.0'
3636
spec.add_runtime_dependency 'rspec-puppet', '~> 2.0'
37+
38+
spec.requirements << 'puppet, >= 6.0.0'
3739
end

0 commit comments

Comments
 (0)