Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CONT-1027) Deprecate pe-version option #1252

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Metrics/MethodLength:
# Offense count: 5
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 195
Max: 200

# Offense count: 45
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -199,7 +199,6 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 4
Style/OpenStructUse:
Exclude:
- 'lib/pdk/template/renderer/v1/template_file.rb'
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ This command runs all available unit tests.
### `pdk console` command
The pdk console command executes a session of the puppet debugger when inside a module and allows for exploration of puppet code. See the official [puppet debugger site](https://www.puppet-debugger.com) for more info and the official docs [site here.](https://docs.puppet-debugger.com)

To use, execute `pdk console` from inside your module directory. You can also supply the `--puppet-version` or `--pe-version` or `--puppet-dev` to swap out the puppet version when using the console.
To use, execute `pdk console` from inside your module directory. You can also supply the `--puppet-version` or `--puppet-dev` to swap out the puppet version when using the console.

Example (from within a module):

* `pdk console --puppet-version=5`
* `pdk console --pe-version=2018.1`

The `pdk console` command will also pass through any puppet debugger arguments you wish to use.

Expand Down
3 changes: 1 addition & 2 deletions docs/pdk_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ For every successful command line invocation of PDK, we collect:
`customized`, or `default`. For customized files, we do not record what
changed, only that it was changed in the `.sync.yml` file.

> **Note:** All arguments and non-Boolean option values, except `--puppet-version`
and `--pe-version` are redacted in our collected data.
> **Note:** All arguments and non-Boolean option values, except `--puppet-version` are redacted in our collected data
Invalid commands are submitted as a distinct analytics events with the arguments
and option values redacted.
Expand Down
14 changes: 4 additions & 10 deletions docs/pdk_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,14 @@ Within the module directory:
```bash
pdk test unit --list

pdk test unit [--tests=<TEST_LIST>] [--format=<FORMAT>[:<TARGET_FILE>]] [--pe-version=<VERSION>] [--puppet-version=<VERSION>]
pdk test unit [--tests=<TEST_LIST>] [--format=<FORMAT>[:<TARGET_FILE>]] [--puppet-version=<VERSION>]

```
For example:
```bash
pdk test unit --tests=test1,test2,test3 --puppet-version=5

pdk test unit --format=junit:report.xml --pe-version=2018.1 -c
```
To learn more, see the [validating and testing modules](pdk_testing.md) topic.
Expand All @@ -419,8 +417,7 @@ topic.
|`--clean-fixtures`, `-c`|Cleans test fixtures, removing them from the directory and downloading them again the next time you run `pdk test unit`.|None.|If not specified, does not clean test fixtures.|
|`--format=<FORMAT>[:<TARGET_FILE>]`|Specifies the format of the output. Optionally, you can specify a target file for the given output format, such as `--format=junit:report.xml` . You can specify multiple `--format` options if each has a distinct output target. To output to standard output or standard error, specify `stdout` or `stderr` as the target value.|<ul><li>`junit` (JUnit XML)</li><li>`text` (plain text)</li></ul>|If not specified, does not output to a file, but displays errors in the terminal.|
|`--list`|Displays a list of unit tests and their descriptions. Using this option lists the tests without running them.|No value. Optional `--verbose` or `-v` flag displays more information.|No default.|
|`--pe-version`|Specifies the Puppet Enterprise (PE) version to run unit tests against.|A string indicating the PE version to test against, such as "2017.3.5" or "2018.1".|If not specified, tests against the most recent compatible Puppet version included in the PDK package.|
|`--puppet-dev`|When specified, PDK runs unit tests against the current Puppet source from GitHub. To use this option, you must have network access to https://github.com. You cannot specify `--puppet-dev` together with the `--puppet-version=` or `--pe-version=` options.|None.|If not specified, PDK runs unit tests against default values or those specified by `--puppet` version or `--pe-version`.|
|`--puppet-dev`|When specified, PDK runs unit tests against the current Puppet source from GitHub. To use this option, you must have network access to https://github.com. You cannot specify `--puppet-dev` together with the `--puppet-version=` options.|None.|If not specified, PDK runs unit tests against default values or those specified by `--puppet-version`.|
|`--puppet-version`|Specifies the Puppet gem version to run unit tests against.|A string indicating the Puppet version to test against, such as "5.4.2" or "5.5".|If not specified, tests against the most recent compatible Puppet version included in the PDK package.|
|`--tests=<TEST_LIST>`|A comma-separated list of tests to run. Use this during development to pinpoint a single failing test.|See the `--list` output for available values.|No default.|
|`--verbose`|When specified, PDK outputs a single line description for each test as the test is executed. This option uses the RSpec `documentation` format. For more information, see [RSpec Core 2.5](https://relishapp.com/rspec/rspec-core/v/2-5/docs/command-line/format-option#documentation-format).|None.|None.|
Expand Down Expand Up @@ -461,15 +458,13 @@ Within the module directory:
```bash
pdk validate --list
pdk validate [--format=<FORMAT>][:<TARGET_FILE>]] [<VALIDATIONS>] [<TARGETS>*] [--auto-correct] [--parallel] [--pe-version=<VERSION>] [--puppet-version=<VERSION>]
pdk validate [--format=<FORMAT>][:<TARGET_FILE>]] [<VALIDATIONS>] [<TARGETS>*] [--auto-correct] [--parallel] [--puppet-version=<VERSION>]
```
For example:
```bash
pdk validate --parallel --pe-version=2018.1
pdk validate --format=text:report.xml --auto-correct --parallel
```
Expand All @@ -483,8 +478,7 @@ topic.
|`--format=<FORMAT>[:<TARGET_FILE>]`|Specifies the format of the output. Optionally, you can specify a target file for the given output format, such as `--format=junit:report.xml` . You can specify multiple `--format` options if each has a distinct output target. To output to standard output or standard error, specify `stdout` or `stderr` as the target value.|<ul><li>`junit` (JUnit XML)</li><li>`text` (plain text)</li></ul>|No default.|
|`--list`|Displays a list of available validations and their descriptions. Using this option lists the tests without running them.|None.|No default.|
|`--parallel`|Runs all validations simultaneously, using multiple threads.|None.|If not specified, validations are run in succession on a single thread.|
|`--pe-version`|Specifies the  Puppet Enterprise (PE) version to run validations against.|A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1".|If not specified, validates against the most recent compatible Puppet version included in the PDK package.|
|`--puppet-dev`|When specified, PDK validates against the current Puppet source from GitHub. To use this option, you must have network access to https://github.com. You cannot specify `--puppet-dev` together with the `--puppet-version=` or `--pe-version=` options.|None.|If not specified, PDK validates against default values or those specified by `--puppet` version or `--pe-version`.|
|`--puppet-dev`|When specified, PDK validates against the current Puppet source from GitHub. To use this option, you must have network access to https://github.com. You cannot specify `--puppet-dev` together with the `--puppet-version=` options.|None.|If not specified, PDK validates against default values or those specified by `--puppet-version`.|
|`--puppet-version`|Specifies the Puppet gem version to run validations against.|A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5".|If not specified, validates against the most recent compatible Puppet version included in the PDK package.|
|`<TARGETS>`|A list of directories or individual files to validate. Validations which are not applicable to individual files will be skipped for those files.|A space-separated list of directories or files.|Validates all available directories and files.|
|`<VALIDATIONS>`|A comma-separated list of validations to run or `all` for all validations. In PowerShell, this list must be enclosed in single quotes, such as `pdk validate 'puppet,metadata'`|See the `--list`output for a list of available validations.|`all`|
20 changes: 4 additions & 16 deletions docs/pdk_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,9 @@ send your validation output to a file in either JUnit or text format.
```
To validate against a specific version of Puppet or PE, add the
`--puppet-version` or `--pe-version` option flag.
`--puppet-version` option flag.
For example, to validate against PE 2018.1, run:
```no-highlight
pdk validate --pe-version 2018.1
```
To validate against Puppet 5.5.12, run:
For example. To validate against Puppet 5.5.12, run:
```no-highlight
pdk validate --puppet-version 5.5.12
Expand Down Expand Up @@ -209,16 +203,10 @@ correctly performs the functions you expect it to.
pdk test unit --tests=<TEST1>,<TEST2>
```
To unit test against a specific version of Puppet or PE, add a version
To unit test against a specific version of Puppet, add a version
option flag.
For example, to test against against PE 2018.1, run:
```no-highlight
pdk test unit --pe-version 2018.1
```
To test against Puppet 5.5.12, run:
For example. To test against Puppet 5.5.12, run:
```no-highlight
pdk test unit --puppet-version 5.5.12
Expand Down
2 changes: 1 addition & 1 deletion lib/pdk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def self.full_interview_option(dsl)

def self.puppet_version_options(dsl)
dsl.option nil, 'puppet-version', 'Puppet version to run tests or validations against.', argument: :required
dsl.option nil, 'pe-version', 'Puppet Enterprise version to run tests or validations against.', argument: :required
dsl.option nil, 'pe-version', '(Deprecated) Puppet Enterprise version to run tests or validations against.', argument: :required
end

def self.puppet_dev_option(dsl)
Expand Down
5 changes: 5 additions & 0 deletions lib/pdk/cli/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ def validate_puppet_version_opts(opts)
raise PDK::CLI::ExitWithError, format('You cannot specify a %{first} and %{second} at the same time.', first: offending[0], second: offending[1])
end

# We want to mark setting the PE as deprecated.
if opts[:'pe-version'] || PDK::Util::Env['PDK_PE_VERSION']
PDK.logger.warn('Specifying a Puppet Enterprise version is now deprecated and will be removed in a future version. Please use --puppet-version or PDK_PUPPET_VERSION instead.')
end

if puppet_dev_specs.size == 2
warning_str = 'Puppet dev flag from command line: "--puppet-dev" '
warning_str += 'overrides value from environment: "PDK_PUPPET_DEV=true". You should not specify both.'
Expand Down
34 changes: 0 additions & 34 deletions lib/pdk/util/puppet_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,40 +174,6 @@ def parse_specified_version(version_str)
raise ArgumentError, format('%{version} is not a valid version number.', version: version_str)
end

def pe_version_map
@pe_version_map ||= fetch_pe_version_map.map do |version_map|
maps = version_map['versions'].map do |pe_release|
requirements = ["= #{pe_release['version']}"]

# Some PE release have a .0 Z release, which causes problems when
# the user specifies "X.Y" expecting to get the latest Z and
# instead getting the oldest.
requirements << "!= #{pe_release['version'].gsub(/\.\d+\Z/, '')}" if pe_release['version'].end_with?('.0')
{
requirement: Gem::Requirement.create(requirements),
gem_version: pe_release['puppet']
}
end

maps << {
requirement: requirement_from_forge_range(version_map['release']),
gem_version: version_map['versions'].find { |r| r['version'] == version_map['latest'] }['puppet']
}
end.flatten
end

def fetch_pe_version_map
require 'pdk/util/vendored_file'

map = PDK::Util::VendoredFile.new('pe_versions.json', PE_VERSIONS_URL).read

JSON.parse(map)
rescue PDK::Util::VendoredFile::DownloadError => e
raise PDK::CLI::FatalError, e.message
rescue JSON::ParserError
raise PDK::CLI::FatalError, 'Failed to parse Puppet Enterprise version map file.'
end

def requirement_from_forge_range(range_str)
Gem::Requirement.create("~> #{range_str.gsub(/\.x\Z/, '.0')}")
end
Expand Down
16 changes: 0 additions & 16 deletions spec/acceptance/version_changer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@
end
end

# PE mapping test have been marked as pending due to an issue with concurrent-ruby versions in
# older Puppet gems. This is being tracked and will be resolved in a future version.
{ '2021.7.1' => '7.20.0' }.each do |pe_version, puppet_version|
xcontext "when requesting --pe-version #{pe_version}" do
describe command("pdk validate --pe-version #{pe_version}") do
its(:exit_status) { is_expected.to eq(0) }
end

describe file('Gemfile.lock') do
its(:exit_status) { is_expected.to eq(0) }
it { is_expected.to exist }
its(:content) { is_expected.to match(/^\s+puppet \(#{Regexp.escape(puppet_version)}(\)|-)/im) }
end
end
end

describe 'puppet-dev uses the correct puppet env' do
before(:all) do
File.open(File.join('manifests', 'init.pp'), 'w') do |f|
Expand Down
12 changes: 0 additions & 12 deletions spec/unit/pdk/cli/console_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@
expect { console_cmd.run(['--puppet-version=7', '--run-once', '--quiet', '--execute=$foo = 123']) }.to exit_zero
end

it 'can pass --pe-version' do
allow(PDK::CLI::Util).to receive(:puppet_from_opts_or_env).with({ 'pe-version': '2023.0' }, true).and_return(gemset: { puppet: '7.23.0' }, ruby_version: '2.7.7')
allow(PDK::Util::Bundler).to receive(:ensure_bundle!).with(puppet: '7.23.0')
command = instance_double(PDK::CLI::Exec::InteractiveCommand)
allow(PDK::Util::RubyVersion).to receive(:versions).and_return('2.7.7' => '2.7.0')
allow(command).to receive(:context=).with(:pwd)
allow(command).to receive(:update_environment).with({ 'PUPPET_GEM_VERSION' => '7.23.0' })
allow(command).to receive(:execute!).and_return(exit_code: 0)
allow(PDK::CLI::Exec::InteractiveCommand).to receive(:new).and_return(command)
expect { console_cmd.run(['--pe-version=2023.0', '--run-once', '--quiet', '--execute=$foo = 123']) }.to exit_zero
end

it 'can pass --puppet-dev' do
allow(PDK::CLI::Util).to receive(:puppet_from_opts_or_env).with({ 'puppet-dev': '' }, true)
.and_return(gemset: { puppet: 'file:///home/user1/.pdk/cache/src/puppet' }, ruby_version: '2.7.7')
Expand Down
64 changes: 0 additions & 64 deletions spec/unit/pdk/cli/test/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,6 @@
end
end

context 'when --puppet-version and --pe-version are specified' do
it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(/cannot specify.*--pe-version.*and.*--puppet-version/i))

expect do
PDK::CLI.run(['test', 'unit', '--puppet-version', '4.10.10', '--pe-version', '2018.1.1'])
end.to exit_nonzero
end

it 'does not submit the command to analytics' do
expect(analytics).not_to receive(:screen_view)

expect do
PDK::CLI.run(['test', 'unit', '--puppet-version', '4.10.10', '--pe-version', '2018.1.1'])
end.to exit_nonzero
end
end

context 'with --puppet-version' do
let(:puppet_version) { '5.3' }
let(:puppet_env) do
Expand Down Expand Up @@ -379,50 +361,4 @@
end.to exit_zero
end
end

context 'with --pe-version' do
let(:pe_version) { '2017.2' }
let(:puppet_env) do
{
ruby_version: '2.1.9',
gemset: { puppet: '4.10.9' }
}
end

before do
allow(PDK::CLI::Util).to receive(:puppet_from_opts_or_env).with(hash_including('pe-version': pe_version)).and_return(puppet_env)
allow(PDK::Test::Unit).to receive(:invoke).and_return(0)
allow(PDK::CLI::Util).to receive(:module_version_check)
allow(PDK::Util).to receive(:module_root).and_return(EMPTY_MODULE_ROOT)
end

it 'activates resolved puppet version' do
expect(PDK::Util::Bundler).to receive(:ensure_bundle!).with(puppet_env[:gemset])

expect do
test_unit_cmd.run_this(["--pe-version=#{pe_version}"])
end.to exit_zero
end

it 'activates resolved ruby version' do
expect(PDK::Util::RubyVersion).to receive(:use).with(puppet_env[:ruby_version])

expect do
test_unit_cmd.run_this(["--pe-version=#{pe_version}"])
end.to exit_zero
end

it 'submits the command to analytics' do
expect(analytics).to receive(:screen_view).with(
'test_unit',
cli_options: "pe-version=#{pe_version}",
output_format: 'default',
ruby_version: RUBY_VERSION
)

expect do
test_unit_cmd.run_this(["--pe-version=#{pe_version}"])
end.to exit_zero
end
end
end
Loading