pdk 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3c5a5c1229e58da80498533964f4d7ae26cd5e7
4
- data.tar.gz: 656f786a2d964d6ee08da649d7649580a9ea24d0
3
+ metadata.gz: 93cc8f9f706dd2ce506fe5cba80f8dc1b850be29
4
+ data.tar.gz: f8132274481cb6f6cdcb60241829d32de7e33118
5
5
  SHA512:
6
- metadata.gz: de547cceb59992ac724afbfd57888c9aea06bb875dff612d5f4fab63e52b25f39fead90fb9720fc9915c4bff40774efe1d03174742884c2903f44555b8a03a5f
7
- data.tar.gz: c716798699ba50f829f8b444b41706c12d0f4310ae0ad80efd000f893ef82dd34cde7c193dcef98c059ad79f9d011cd9a4d77f625eb6eab0b0bd99cfa73e9adc
6
+ metadata.gz: ae5eeee330f86efe4d4fcc728aea7260fa0a066da55e21f120e0cf983750d5f12bc1c72422b58e435e1d46be94de9e07dfd071f37eebcf0482705186a879ba9f
7
+ data.tar.gz: 11a7de86e1765630c50d0adff32af9131262eaa4fb6e17a0ad86cd6f2218834f04e79f75a549f38ecfd8db95444a8d8a8d8201f20c8d4aa20cb2b22e7a929d80
@@ -4,6 +4,58 @@ All changes to this repo will be documented in this file.
4
4
  See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) for a high-level summary.
5
5
 
6
6
 
7
+ ## [v1.5.0](https://github.com/puppetlabs/pdk/tree/v1.5.0) (2018-04-30)
8
+ [Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.4.1...v1.5.0)
9
+
10
+ **Implemented enhancements:**
11
+
12
+ - \(PDK-904\) Warns users of pdk version compatibility [\#482](https://github.com/puppetlabs/pdk/pull/482) ([bmjen](https://github.com/bmjen))
13
+ - \(maint\) Allow `pdk bundle` to work without `--` [\#466](https://github.com/puppetlabs/pdk/pull/466) ([DavidS](https://github.com/DavidS))
14
+ - \(PDK-877\) Make PDK compatible with Ruby 2.5 [\#459](https://github.com/puppetlabs/pdk/pull/459) ([scotje](https://github.com/scotje))
15
+ - Ruby 2.4.3 transition [\#453](https://github.com/puppetlabs/pdk/pull/453) ([bmjen](https://github.com/bmjen))
16
+ - \(PDK-846\) add Resource API type unit test template [\#451](https://github.com/puppetlabs/pdk/pull/451) ([tphoney](https://github.com/tphoney))
17
+ - \(PDK-785\) Add --puppet-version and --pe-version CLI options [\#448](https://github.com/puppetlabs/pdk/pull/448) ([rodjek](https://github.com/rodjek))
18
+
19
+ **Fixed bugs:**
20
+
21
+ - \(PDK-877\) `make\_tmpdir\_name': undefined method `make\_tmpname' for Dir::Tmpname:Module [\#455](https://github.com/puppetlabs/pdk/issues/455)
22
+ - pdk validate fails if host puppet.conf contains deprecated settings [\#304](https://github.com/puppetlabs/pdk/issues/304)
23
+ - \(maint\) Allow module name to contain underscores when verifying [\#491](https://github.com/puppetlabs/pdk/pull/491) ([rodjek](https://github.com/rodjek))
24
+ - \(MAINT\) Make Bundler update\_lock! helper more resilient [\#489](https://github.com/puppetlabs/pdk/pull/489) ([scotje](https://github.com/scotje))
25
+ - \(maint\) Unhide parallel flag in test unit. [\#486](https://github.com/puppetlabs/pdk/pull/486) ([bmjen](https://github.com/bmjen))
26
+ - \(PDK-831, PDK-832\) Fix ability to unmanage/delete files via .sync.yml [\#479](https://github.com/puppetlabs/pdk/pull/479) ([bmjen](https://github.com/bmjen))
27
+ - \(MAINT\) Use `bundle lock --update` to pin json to built-in versions [\#460](https://github.com/puppetlabs/pdk/pull/460) ([scotje](https://github.com/scotje))
28
+
29
+ **Closed issues:**
30
+
31
+ - PDK should default to mock\_with :rspec and resolve deprecation message [\#477](https://github.com/puppetlabs/pdk/issues/477)
32
+ - Support for template URL with a branch [\#447](https://github.com/puppetlabs/pdk/issues/447)
33
+ - Any interest in adding a `--parallel` option to `pdk test unit`? [\#446](https://github.com/puppetlabs/pdk/issues/446)
34
+ - Installing PDK from .deb causes unmet dependencies on Ubuntu 17.10 Artful [\#370](https://github.com/puppetlabs/pdk/issues/370)
35
+ - Repo Configs Contain Invalid URLs [\#319](https://github.com/puppetlabs/pdk/issues/319)
36
+ - Gems not found in pre-release [\#254](https://github.com/puppetlabs/pdk/issues/254)
37
+
38
+ **Merged pull requests:**
39
+
40
+ - \(FIXUP\) Fix issue where PDK was invoking wrong Ruby on Windows [\#492](https://github.com/puppetlabs/pdk/pull/492) ([scotje](https://github.com/scotje))
41
+ - \(maint\) Update package testing for ruby 2.4.4. [\#488](https://github.com/puppetlabs/pdk/pull/488) ([bmjen](https://github.com/bmjen))
42
+ - \(MAINT\) Fix package tests for version selection and airgapped usage [\#485](https://github.com/puppetlabs/pdk/pull/485) ([scotje](https://github.com/scotje))
43
+ - \(maint\) Some minor corrections to CLI strings. [\#484](https://github.com/puppetlabs/pdk/pull/484) ([bmjen](https://github.com/bmjen))
44
+ - \(maint\) Remove static PE version map from PDK::Util::PuppetVersion [\#483](https://github.com/puppetlabs/pdk/pull/483) ([rodjek](https://github.com/rodjek))
45
+ - \(PDK-842\) Wire puppet-version and pe-version options into subcommands [\#480](https://github.com/puppetlabs/pdk/pull/480) ([scotje](https://github.com/scotje))
46
+ - \(FIXUP\) Revert incorrect path change in PDK::CLI::Exec.bundle\_bin [\#478](https://github.com/puppetlabs/pdk/pull/478) ([scotje](https://github.com/scotje))
47
+ - \(maint\) Allow users to major or major.minor versions [\#475](https://github.com/puppetlabs/pdk/pull/475) ([rodjek](https://github.com/rodjek))
48
+ - \(PDK-923\) Honour PDK::Util::RubyVersion.active\_ruby\_version when executing commands [\#474](https://github.com/puppetlabs/pdk/pull/474) ([rodjek](https://github.com/rodjek))
49
+ - \(MAINT\) Fix argument bug with BundleHelper\#update\_lock! [\#473](https://github.com/puppetlabs/pdk/pull/473) ([scotje](https://github.com/scotje))
50
+ - \(PDK-921\) Update PDK::Util::Bundler helpers to support gem switching [\#472](https://github.com/puppetlabs/pdk/pull/472) ([scotje](https://github.com/scotje))
51
+ - Link to PDK template repo [\#470](https://github.com/puppetlabs/pdk/pull/470) ([turbodog](https://github.com/turbodog))
52
+ - \(maint\) Update bundler before build because Ruby 2.5 [\#465](https://github.com/puppetlabs/pdk/pull/465) ([DavidS](https://github.com/DavidS))
53
+ - \(MAINT\) Refactor templatedir path\_or\_url calculation [\#462](https://github.com/puppetlabs/pdk/pull/462) ([scotje](https://github.com/scotje))
54
+ - \(PDK-840\) Add PDK::Util::PuppetVersion.from\_module\_metadata [\#461](https://github.com/puppetlabs/pdk/pull/461) ([rodjek](https://github.com/rodjek))
55
+ - \(maint\) bump dev version [\#458](https://github.com/puppetlabs/pdk/pull/458) ([bmjen](https://github.com/bmjen))
56
+ - \(MAINT\) Add Ruby 2.5 to Travis and Appveyor config [\#457](https://github.com/puppetlabs/pdk/pull/457) ([scotje](https://github.com/scotje))
57
+ - \(maint\) Fixup remaining ruby 2.4.3 issues [\#454](https://github.com/puppetlabs/pdk/pull/454) ([bmjen](https://github.com/bmjen))
58
+
7
59
  ## [v1.4.1](https://github.com/puppetlabs/pdk/tree/v1.4.1) (2018-02-26)
8
60
  [Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.4.0...v1.4.1)
9
61
 
@@ -13,6 +65,7 @@ See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) f
13
65
 
14
66
  **Merged pull requests:**
15
67
 
68
+ - Release 1.4.1 amend [\#443](https://github.com/puppetlabs/pdk/pull/443) ([bmjen](https://github.com/bmjen))
16
69
  - Updates msg in pdk update on unconverted module [\#442](https://github.com/puppetlabs/pdk/pull/442) ([bmjen](https://github.com/bmjen))
17
70
  - Release 1.4.1 amend [\#441](https://github.com/puppetlabs/pdk/pull/441) ([bmjen](https://github.com/bmjen))
18
71
  - \(maint\) pdk update checks if module is pdk compat [\#440](https://github.com/puppetlabs/pdk/pull/440) ([bmjen](https://github.com/bmjen))
data/README.md CHANGED
@@ -50,29 +50,29 @@ This command asks a series of metadata questions and then generates the basic co
50
50
 
51
51
  To generate a class in your module, use the `pdk new class` command, specifying the name of your new class. To generate the main class of the module, which is defined in an `init.pp` file, give the class the same name as the module.
52
52
 
53
- 1. From the command line, in your module's directory, run:
53
+ 1. From the command line, in your module's directory, run:
54
54
  ```
55
- pdk new class class_name
55
+ pdk new class class_name
56
56
  ```
57
57
 
58
- PDK creates the new class manifest and a test file (as `class_name_spec.rb`) in your module's `/spec/classes` directory.
58
+ PDK creates the new class manifest and a test file (as `class_name_spec.rb`) in your module's `/spec/classes` directory.
59
59
 
60
60
  ### Generate a defined type
61
61
 
62
62
  To generate a defined type in your module, use the `pdk new defined_type` command, specifying the name of your new defined type.
63
63
 
64
- 1. From the command line, in your module's directory, run:
64
+ 1. From the command line, in your module's directory, run:
65
65
  ```
66
66
  pdk new defined_type defined_type_name
67
67
  ```
68
68
 
69
- PDK creates the new defined\_type manifest and a test file (as `defined_type_name_spec.rb`) in your module's `/spec/defines` directory.
69
+ PDK creates the new defined\_type manifest and a test file (as `defined_type_name_spec.rb`) in your module's `/spec/defines` directory.
70
70
 
71
71
  ### Generate a task
72
72
 
73
73
  To generate a task in your module, use the `pdk new task` command, specifying the name of your new task.
74
74
 
75
- 1. From the command line, in your module's directory, run:
75
+ 1. From the command line, in your module's directory, run:
76
76
  ```
77
77
  pdk new task task_name
78
78
  ```
@@ -93,7 +93,7 @@ This command validates the metadata, Puppet code syntax and style, and Ruby synt
93
93
 
94
94
  ### Run unit tests
95
95
 
96
- PDK's default template sets up [rspec](http://rspec.info/) for Ruby-level unit testing, and [rspec-puppet](https://github.com/rodjek/rspec-puppet/) for catalog-level unit testing.
96
+ PDK's [default template](https://github.com/puppetlabs/pdk-templates) sets up [rspec](http://rspec.info/) for Ruby-level unit testing, and [rspec-puppet](https://github.com/rodjek/rspec-puppet/) for catalog-level unit testing.
97
97
 
98
98
  In the module's directory, run unit tests with:
99
99
 
@@ -111,28 +111,6 @@ This command executes arbitrary commands in a bundler context within the module
111
111
 
112
112
  Note that for most uses, you must use the `--` to separate bundler options from pdk options. Compare the following two commands:
113
113
 
114
- ```
115
- $ pdk bundle exec rake -T
116
- bundle: illegal option -- T
117
-
118
- ```
119
-
120
- and
121
-
122
- ```
123
- $ pdk bundle -- exec rake -T
124
- rake beaker # Run beaker acceptance tests
125
- rake beaker:sets # List available beaker nodesets
126
- rake beaker:ssh[set,node] # Try to use vagrant to login to the Beaker node
127
- rake build # Build puppet module package
128
- [...]
129
- ```
130
-
131
- #### Known issues
132
-
133
-
134
- Note that for PowerShell the `--` must be escaped using a backtick ( <code>`-- </code> ) or the shell parses it and strips it out of the command. See [PDK-408](https://tickets.puppet.com/browse/PDK-408) for details.
135
-
136
114
  ## Module Compatibility
137
115
 
138
116
  **PDK Version Compatibility:** Modules created with PDK version validate against and run on all Puppet and Ruby version combinations currently under maintenance (see https://docs.puppet.com/puppet/latest/about_agent.html and https://puppet.com/misc/puppet-enterprise-lifecycle)
@@ -11,6 +11,7 @@ require 'pdk/i18n'
11
11
  require 'pdk/logger'
12
12
  require 'pdk/report'
13
13
  require 'pdk/util/version'
14
+ require 'pdk/util/puppet_version'
14
15
 
15
16
  module PDK::CLI
16
17
  def self.run(args)
@@ -49,6 +50,11 @@ module PDK::CLI
49
50
  dsl.option nil, 'full-interview', _('When specified, interactive querying of metadata will include all optional questions.')
50
51
  end
51
52
 
53
+ def self.puppet_version_options(dsl)
54
+ dsl.option nil, 'puppet-version', _('Puppet version to run tests or validations against.'), argument: :required
55
+ dsl.option nil, 'pe-version', _('Puppet Enterprise version to run tests or validations against.'), argument: :required
56
+ end
57
+
52
58
  @base_cmd = Cri::Command.define do
53
59
  name 'pdk'
54
60
  usage _('pdk command [options]')
@@ -2,11 +2,7 @@
2
2
  module PDK::CLI
3
3
  @bundle_cmd = @base_cmd.define_command do
4
4
  name 'bundle'
5
- if Gem.win_platform?
6
- usage _('bundle `-- [bundler_options]')
7
- else
8
- usage _('bundle -- [bundler_options]')
9
- end
5
+ usage _('bundle [bundler_options]')
10
6
  summary _('(Experimental) Command pass-through to bundler')
11
7
  description _(<<-EOF
12
8
  [experimental] For advanced users, pdk bundle runs arbitrary commands in the bundler environment that pdk manages.
@@ -15,14 +11,24 @@ Careless use of this command can lead to errors that pdk can't help recover from
15
11
  Note that for PowerShell the '--' needs to be escaped using a backtick: '`--' to avoid it being parsed by the shell.
16
12
  EOF
17
13
  )
14
+ skip_option_parsing
18
15
 
19
16
  run do |_opts, args, _cmd|
20
17
  PDK::CLI::Util.ensure_in_module!(
21
18
  message: _('`pdk bundle` can only be run from inside a valid module directory.'),
22
19
  )
23
20
 
21
+ PDK::CLI::Util.validate_puppet_version_opts({})
22
+
23
+ # Ensure that the correct Ruby is activated before running commend.
24
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env({})
25
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
26
+
27
+ gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
28
+
24
29
  command = PDK::CLI::Exec::Command.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
25
30
  c.context = :module
31
+ c.update_environment(gemfile_env)
26
32
  end
27
33
 
28
34
  result = command.execute!
@@ -6,6 +6,7 @@ require 'tty-which'
6
6
 
7
7
  require 'pdk/util'
8
8
  require 'pdk/util/git'
9
+ require 'pdk/util/ruby_version'
9
10
 
10
11
  module PDK
11
12
  module CLI
@@ -14,6 +15,10 @@ module PDK
14
15
  Command.new(*cmd).execute!
15
16
  end
16
17
 
18
+ def self.execute_with_env(env, *cmd)
19
+ Command.new(*cmd).tap { |c| c.environment = env }.execute!
20
+ end
21
+
17
22
  def self.ensure_bin_present!(bin_path, bin_name)
18
23
  message = _('Unable to find `%{name}`. Check that it is installed and try again.') % {
19
24
  name: bin_name,
@@ -30,24 +35,31 @@ module PDK
30
35
 
31
36
  def self.bundle_bin
32
37
  bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
33
- vendored_bin_path = File.join('private', 'ruby', '2.1.9', 'bin', bundle_bin)
38
+ vendored_bin_path = File.join('private', 'ruby', PDK::Util::RubyVersion.active_ruby_version, 'bin', bundle_bin)
34
39
 
35
40
  try_vendored_bin(vendored_bin_path, bundle_bin)
36
41
  end
37
42
 
38
43
  def self.try_vendored_bin(vendored_bin_path, fallback)
39
44
  unless PDK::Util.package_install?
40
- PDK.logger.debug(_("PDK package installation not found. Trying '%{fallback}' from the system PATH instead.") % { fallback: fallback })
45
+ PDK.logger.debug(_("PDK package installation not found. Trying '%{fallback}' from the system PATH instead.") % {
46
+ fallback: fallback,
47
+ })
41
48
  return fallback
42
49
  end
43
50
 
44
- if File.exist?(File.join(PDK::Util.pdk_package_basedir, vendored_bin_path))
45
- PDK.logger.debug(_("Using '%{vendored_bin_path}' from PDK package.") % { vendored_bin_path: vendored_bin_path })
46
- File.join(PDK::Util.pdk_package_basedir, vendored_bin_path)
47
- else
48
- PDK.logger.debug(_("Could not find '%{vendored_bin_path}' in PDK package. Trying '%{fallback}' from the system PATH instead.") % { fallback: fallback, vendored_bin_path: vendored_bin_path })
49
- fallback
51
+ vendored_bin_full_path = File.join(PDK::Util.pdk_package_basedir, vendored_bin_path)
52
+
53
+ unless File.exist?(vendored_bin_full_path)
54
+ PDK.logger.debug(_("Could not find '%{vendored_bin}' in PDK package. Trying '%{fallback}' from the system PATH instead.") % {
55
+ fallback: fallback,
56
+ vendored_bin: vendored_bin_full_path,
57
+ })
58
+ return fallback
50
59
  end
60
+
61
+ PDK.logger.debug(_("Using '%{vendored_bin}' from PDK package.") % { vendored_bin: vendored_bin_full_path })
62
+ vendored_bin_full_path
51
63
  end
52
64
 
53
65
  # TODO: decide how/when to connect stdin to child process for things like pry
@@ -105,6 +117,10 @@ module PDK
105
117
  @spinner = TTY::Spinner.new("[:spinner] #{message}", opts.merge(PDK::CLI::Util.spinner_opts_for_platform))
106
118
  end
107
119
 
120
+ def update_environment(additional_env)
121
+ @environment.merge!(additional_env)
122
+ end
123
+
108
124
  def execute!
109
125
  # Start spinning if configured.
110
126
  @spinner.auto_spin if @spinner
@@ -115,26 +131,13 @@ module PDK
115
131
  end
116
132
 
117
133
  if context == :module
118
- # `bundle install --path` ignores all "system" installed gems and causes unnecessary package installs
119
- # `bundle install` (without --path) installs into GEM_HOME, which by default is non-user writeable
120
- # To still use the pre-installed packages, but allow folks to install additional gems
121
- # we set GEM_HOME to the user's cachedir, and put all other cache locations onto GEM_PATH
122
- # See https://stackoverflow.com/a/11277228 for background
123
- @process.environment['GEM_HOME'] = File.join(PDK::Util.cachedir, 'ruby', RbConfig::CONFIG['ruby_version'])
124
-
125
- if PDK::Util.package_install?
126
- # Subprocesses use their own set of gems which are managed by pdk or installed with the package.
127
- @process.environment['GEM_PATH'] = File.join(PDK::Util.package_cachedir, 'ruby', RbConfig::CONFIG['ruby_version'])
128
- else
129
- # This allows the subprocess to find the 'bundler' gem, which isn't in the cachedir above for gem installs.
130
- bundler_gem_path = File.absolute_path(File.join(`gem which bundler`, '..', '..', '..', '..'))
131
- @process.environment['GEM_PATH'] = bundler_gem_path
132
- end
134
+ @process.environment['GEM_HOME'] = PDK::Util::RubyVersion.gem_home
135
+ @process.environment['GEM_PATH'] = PDK::Util::RubyVersion.gem_path
133
136
 
134
137
  # Make sure invocation of Ruby prefers our private installation.
135
138
  package_binpath = PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
136
139
  @process.environment['PATH'] = [
137
- RbConfig::CONFIG['bindir'],
140
+ PDK::Util::RubyVersion.bin_path,
138
141
  File.join(@process.environment['GEM_HOME'], 'bin'),
139
142
  File.join(@process.environment['GEM_PATH'], 'bin'),
140
143
  package_binpath,
@@ -201,12 +204,18 @@ module PDK
201
204
 
202
205
  def run_process!
203
206
  command_string = argv.join(' ')
207
+
204
208
  PDK.logger.debug(_("Executing '%{command}'") % { command: command_string })
209
+
205
210
  if context == :module
206
- PDK.logger.debug(_("Command environment: GEM_HOME is '%{gem_home}' and GEM_PATH is '%{gem_path}'") % { gem_home: @process.environment['GEM_HOME'],
207
- gem_path: @process.environment['GEM_PATH'] })
211
+ PDK.logger.debug(_('Command environment:'))
212
+ @process.environment.each do |var, val|
213
+ PDK.logger.debug(" #{var}: #{val}")
214
+ end
208
215
  end
216
+
209
217
  start_time = Time.now
218
+
210
219
  begin
211
220
  @process.start
212
221
  rescue ChildProcess::LaunchError => e
@@ -223,7 +232,9 @@ module PDK
223
232
  # Wait indfinitely if no timeout set.
224
233
  @process.wait
225
234
  end
235
+
226
236
  @duration = Time.now - start_time
237
+
227
238
  PDK.logger.debug(_("Execution of '%{command}' complete (duration: %{duration_in_seconds}s; exit code: %{exit_code})") %
228
239
  { command: command_string, duration_in_seconds: @duration, exit_code: @process.exit_code })
229
240
  end
@@ -7,8 +7,9 @@ module PDK::CLI
7
7
  usage _('unit [options]')
8
8
  summary _('Run unit tests.')
9
9
 
10
+ PDK::CLI.puppet_version_options(self)
10
11
  flag nil, :list, _('List all available unit test files.')
11
- flag nil, :parallel, _('Run unit tests in parallel.'), hidden: true
12
+ flag nil, :parallel, _('Run unit tests in parallel.')
12
13
  flag :v, :verbose, _('More verbose output. Displays examples in each unit test file.')
13
14
 
14
15
  option nil, :tests, _('Specify a comma-separated list of unit test files to run.'), argument: :required, default: '' do |values|
@@ -21,11 +22,15 @@ module PDK::CLI
21
22
  run do |opts, _args, _cmd|
22
23
  require 'pdk/tests/unit'
23
24
 
25
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
26
+
24
27
  PDK::CLI::Util.ensure_in_module!(
25
28
  message: _('Unit tests can only be run from inside a valid module directory.'),
26
29
  log_level: :info,
27
30
  )
28
31
 
32
+ PDK::CLI::Util.module_version_check
33
+
29
34
  report = nil
30
35
 
31
36
  if opts[:list]
@@ -57,6 +62,11 @@ module PDK::CLI
57
62
  }]
58
63
  end
59
64
 
65
+ # Ensure that the bundled gems are up to date and correct Ruby is activated before running tests.
66
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
67
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
68
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
69
+
60
70
  exit_code = PDK::Test::Unit.invoke(report, opts)
61
71
 
62
72
  report_formats.each do |format|
@@ -1,15 +1,6 @@
1
1
  module PDK
2
2
  module CLI
3
3
  module Util
4
- MODULE_FOLDERS = %w[
5
- manifests
6
- lib
7
- tasks
8
- facts.d
9
- functions
10
- types
11
- ].freeze
12
-
13
4
  # Ensures the calling code is being run from inside a module directory.
14
5
  #
15
6
  # @param opts [Hash] options to change the behavior of the check logic.
@@ -21,7 +12,7 @@ module PDK
21
12
  # contain a Puppet module.
22
13
  def ensure_in_module!(opts = {})
23
14
  return unless PDK::Util.module_root.nil?
24
- return if opts[:check_module_layout] && PDK::CLI::Util::MODULE_FOLDERS.any? { |dir| File.directory?(dir) }
15
+ return if opts[:check_module_layout] && PDK::Util.in_module_root?
25
16
 
26
17
  message = opts.fetch(:message, _('This command must be run from inside a valid module (no metadata.json found).'))
27
18
  raise PDK::CLI::ExitWithError.new(message, opts)
@@ -65,6 +56,112 @@ module PDK
65
56
  true
66
57
  end
67
58
  module_function :interactive?
59
+
60
+ def module_version_check
61
+ module_pdk_ver = PDK::Util.module_pdk_version
62
+
63
+ # This means the module does not have a pdk-version tag in the metadata.json
64
+ # and will require a pdk convert.
65
+ if module_pdk_ver.nil?
66
+ PDK.logger.warn _('This module is not PDK compatible. Run `pdk convert` to make it compatible with your version of PDK.')
67
+ # This checks that the version of pdk in the module's metadata is older
68
+ # than 1.3.1, which means the module will need to run pdk convert to the
69
+ # new templates.
70
+ elsif Gem::Version.new(module_pdk_ver) < Gem::Version.new('1.3.1')
71
+ PDK.logger.warn _('This module template is out of date. Run `pdk convert` to make it compatible with your version of PDK.')
72
+ # This checks if the version of the installed PDK is older than the
73
+ # version in the module's metadata, and advises the user to upgrade to
74
+ # their install of PDK.
75
+ elsif Gem::Version.new(PDK::VERSION) < Gem::Version.new(module_pdk_ver)
76
+ PDK.logger.warn _('This module is compatible with a newer version of PDK. Upgrade your version of PDK to ensure compatibility.')
77
+ # This checks if the version listed in the module's metadata is older
78
+ # than the installed PDK, and advises the user to run pdk update.
79
+ elsif Gem::Version.new(PDK::VERSION) > Gem::Version.new(module_pdk_ver)
80
+ PDK.logger.warn _('This module is compatible with an older version of PDK. Run `pdk update` to update it to your version of PDK.')
81
+ end
82
+ end
83
+ module_function :module_version_check
84
+
85
+ def puppet_from_opts_or_env(opts)
86
+ desired_puppet_version = (opts || {})[:'puppet-version'] || ENV['PDK_PUPPET_VERSION']
87
+ desired_pe_version = (opts || {})[:'pe-version'] || ENV['PDK_PE_VERSION']
88
+
89
+ begin
90
+ puppet_env =
91
+ if desired_puppet_version
92
+ PDK::Util::PuppetVersion.find_gem_for(desired_puppet_version)
93
+ elsif desired_pe_version
94
+ PDK::Util::PuppetVersion.from_pe_version(desired_pe_version)
95
+ else
96
+ PDK::Util::PuppetVersion.from_module_metadata || PDK::Util::PuppetVersion.latest_available
97
+ end
98
+ rescue ArgumentError => e
99
+ raise PDK::CLI::ExitWithError, e.message
100
+ end
101
+
102
+ # Notify user of what Ruby version will be used.
103
+ PDK.logger.info(_('Using Ruby %{version}') % {
104
+ version: puppet_env[:ruby_version],
105
+ })
106
+
107
+ gemset = { puppet: puppet_env[:gem_version].to_s }
108
+
109
+ # Notify user of what gems are being activated.
110
+ gemset.each do |gem, version|
111
+ next if version.nil?
112
+
113
+ PDK.logger.info(_('Using %{gem} %{version}') % {
114
+ gem: gem.to_s.capitalize,
115
+ version: version,
116
+ })
117
+ end
118
+
119
+ {
120
+ gemset: gemset,
121
+ ruby_version: puppet_env[:ruby_version],
122
+ }
123
+ end
124
+ module_function :puppet_from_opts_or_env
125
+
126
+ def validate_puppet_version_opts(opts)
127
+ puppet_ver_specs = []
128
+ puppet_ver_specs << '--puppet-version option' if opts[:'puppet-version']
129
+ puppet_ver_specs << 'PDK_PUPPET_VERSION environment variable' if ENV['PDK_PUPPET_VERSION'] && !ENV['PDK_PUPPET_VERSION'].empty?
130
+
131
+ pe_ver_specs = []
132
+ pe_ver_specs << '--pe-version option' if opts[:'pe-version']
133
+ pe_ver_specs << 'PDK_PE_VERSION environment variable' if ENV['PDK_PE_VERSION'] && !ENV['PDK_PE_VERSION'].empty?
134
+
135
+ puppet_ver_specs.each do |pup_ver_spec|
136
+ next if pe_ver_specs.empty?
137
+
138
+ offending = [pup_ver_spec, pe_ver_specs[0]].sort
139
+
140
+ raise PDK::CLI::ExitWithError, _('You cannot specify a %{first} and %{second} at the same time.') % {
141
+ first: offending[0],
142
+ second: offending[1],
143
+ }
144
+ end
145
+
146
+ if puppet_ver_specs.size == 2
147
+ warning_str = 'Puppet version option from command line: "--puppet-version=%{pup_ver_opt}" '
148
+ warning_str += 'overrides value from environment: "PDK_PUPPET_VERSION=%{pup_ver_env}". You should not specify both.'
149
+
150
+ PDK.logger.warn(_(warning_str) % {
151
+ pup_ver_opt: opts[:'puppet-version'],
152
+ pup_ver_env: ENV['PDK_PUPPET_VERSION'],
153
+ })
154
+ elsif pe_ver_specs.size == 2
155
+ warning_str = 'Puppet Enterprise version option from command line: "--pe-version=%{pe_ver_opt}" '
156
+ warning_str += 'overrides value from environment: "PDK_PE_VERSION=%{pe_ver_env}". You should not specify both.'
157
+
158
+ PDK.logger.warn(_(warning_str) % {
159
+ pup_ver_opt: opts[:'pe-version'],
160
+ pup_ver_env: ENV['PDK_PE_VERSION'],
161
+ })
162
+ end
163
+ end
164
+ module_function :validate_puppet_version_opts
68
165
  end
69
166
  end
70
167
  end