r10k 3.9.2 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec_tests.yml +1 -1
  3. data/.travis.yml +0 -10
  4. data/CHANGELOG.mkd +33 -0
  5. data/README.mkd +6 -0
  6. data/doc/dynamic-environments/configuration.mkd +25 -0
  7. data/doc/dynamic-environments/usage.mkd +26 -0
  8. data/doc/puppetfile.mkd +18 -5
  9. data/integration/Rakefile +3 -1
  10. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  11. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +3 -9
  12. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +21 -25
  13. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -3
  14. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +3 -3
  15. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -3
  16. data/lib/r10k/action/deploy/environment.rb +17 -2
  17. data/lib/r10k/action/deploy/module.rb +38 -7
  18. data/lib/r10k/action/puppetfile/check.rb +7 -5
  19. data/lib/r10k/action/puppetfile/install.rb +22 -16
  20. data/lib/r10k/action/puppetfile/purge.rb +12 -9
  21. data/lib/r10k/action/runner.rb +45 -10
  22. data/lib/r10k/cli/deploy.rb +5 -0
  23. data/lib/r10k/cli/puppetfile.rb +0 -1
  24. data/lib/r10k/content_synchronizer.rb +16 -4
  25. data/lib/r10k/environment/base.rb +64 -11
  26. data/lib/r10k/environment/with_modules.rb +6 -10
  27. data/lib/r10k/git/cache.rb +1 -1
  28. data/lib/r10k/git/rugged/credentials.rb +77 -0
  29. data/lib/r10k/git/stateful_repository.rb +8 -0
  30. data/lib/r10k/git.rb +3 -0
  31. data/lib/r10k/initializers.rb +4 -0
  32. data/lib/r10k/module/base.rb +42 -1
  33. data/lib/r10k/module/definition.rb +64 -0
  34. data/lib/r10k/module/forge.rb +17 -4
  35. data/lib/r10k/module/git.rb +24 -2
  36. data/lib/r10k/module/local.rb +2 -3
  37. data/lib/r10k/module/svn.rb +12 -1
  38. data/lib/r10k/module.rb +20 -2
  39. data/lib/r10k/module_loader/puppetfile/dsl.rb +42 -0
  40. data/lib/r10k/module_loader/puppetfile.rb +272 -0
  41. data/lib/r10k/puppetfile.rb +82 -160
  42. data/lib/r10k/settings/definition.rb +1 -1
  43. data/lib/r10k/settings.rb +58 -2
  44. data/lib/r10k/source/base.rb +10 -0
  45. data/lib/r10k/source/git.rb +5 -0
  46. data/lib/r10k/source/svn.rb +4 -0
  47. data/lib/r10k/util/purgeable.rb +70 -8
  48. data/lib/r10k/version.rb +1 -1
  49. data/locales/r10k.pot +165 -65
  50. data/r10k.gemspec +2 -0
  51. data/spec/fixtures/unit/action/r10k_forge_auth.yaml +4 -0
  52. data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +3 -0
  53. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  54. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +9 -0
  55. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +9 -0
  56. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_subdir_2/ignored_1 +0 -0
  57. data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
  58. data/spec/r10k-mocks/mock_env.rb +3 -0
  59. data/spec/r10k-mocks/mock_source.rb +7 -3
  60. data/spec/unit/action/deploy/environment_spec.rb +105 -30
  61. data/spec/unit/action/deploy/module_spec.rb +232 -42
  62. data/spec/unit/action/puppetfile/check_spec.rb +17 -5
  63. data/spec/unit/action/puppetfile/install_spec.rb +42 -36
  64. data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
  65. data/spec/unit/action/runner_spec.rb +122 -26
  66. data/spec/unit/environment/base_spec.rb +30 -17
  67. data/spec/unit/environment/git_spec.rb +2 -2
  68. data/spec/unit/environment/svn_spec.rb +4 -3
  69. data/spec/unit/environment/with_modules_spec.rb +2 -1
  70. data/spec/unit/git/cache_spec.rb +14 -0
  71. data/spec/unit/git/rugged/credentials_spec.rb +29 -0
  72. data/spec/unit/git/stateful_repository_spec.rb +5 -0
  73. data/spec/unit/module/base_spec.rb +54 -8
  74. data/spec/unit/module/forge_spec.rb +59 -5
  75. data/spec/unit/module/git_spec.rb +67 -17
  76. data/spec/unit/module/svn_spec.rb +35 -5
  77. data/spec/unit/module_loader/puppetfile_spec.rb +403 -0
  78. data/spec/unit/module_spec.rb +28 -0
  79. data/spec/unit/puppetfile_spec.rb +125 -189
  80. data/spec/unit/settings_spec.rb +47 -2
  81. data/spec/unit/util/purgeable_spec.rb +38 -6
  82. metadata +28 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a9adbfc4e0f834dfdec6b9703325c61c617ec21d2261034aa3ba702ae9a0710
4
- data.tar.gz: f46775713081247843c4189a13349458c7dd2691ce0e9cf99ae02b1e3d21bceb
3
+ metadata.gz: f378346234a9e8a8d92b3acb64735f88ca6b8e8edd60aa33adad9a09d7efd537
4
+ data.tar.gz: 1b94403eb2e5cb420939d85b73ec299c709418afabb45705f70b1cfb8606a1f5
5
5
  SHA512:
6
- metadata.gz: 979de4fa8399e28f4fdf742b8ca5a23a4f116a96a7131ad93bcdb859db16aae59cea5e45fd8fa03c98229fd1f321f25334775f4a4efe27eb90464bac2b1d8b37
7
- data.tar.gz: efefb07a7a85813a0b967110e05a28a8e4badf5987cd13fec95b37dafd8dc3fdf86081f1c6a023a667c0a8f5416e53cd50ef84bb5fd39a6f70085ff2737e5913
6
+ metadata.gz: a3eda38f3fc6e79ea62082c7c71bd65383089dce82e87dc6473c1f278f1560239f3e2189df28ef23a9ce8e47f3446cdd63e8794344ee62895914353bdcdec6ee
7
+ data.tar.gz: 0dc89955ede8226bf59c7cd4f8e03d9a89688700f5767d0578884fce97643c937f3363dd0d965404fd2b900128b181874dfb129952d64891a3700516239a2af6
@@ -15,7 +15,7 @@ jobs:
15
15
  - {os: ubuntu-18.04, ruby: 2.5}
16
16
  - {os: ubuntu-18.04, ruby: 2.6}
17
17
  - {os: ubuntu-18.04, ruby: 2.7}
18
- - {os: ubuntu-18.04, ruby: jruby-9.2.9.0}
18
+ - {os: ubuntu-18.04, ruby: jruby-9.2.10.0}
19
19
  - {os: windows-2016, ruby: 2.5}
20
20
  - {os: windows-2016, ruby: 2.6}
21
21
  - {os: windows-2016, ruby: 2.7}
data/.travis.yml CHANGED
@@ -10,18 +10,8 @@ jdk:
10
10
  before_install: gem install bundler -v '< 2' --no-document
11
11
  matrix:
12
12
  include:
13
- - stage: r10k tests
14
- rvm: 2.7.0
15
- - stage: r10k tests
16
- rvm: 2.6.5
17
- - stage: r10k tests
18
- rvm: 2.5.0
19
- - stage: r10k tests
20
- rvm: 2.4.0
21
13
  - stage: r10k tests
22
14
  rvm: 2.3.0
23
- - stage: r10k tests
24
- rvm: jruby
25
15
  - stage: r10k container tests
26
16
  dist: focal
27
17
  language: ruby
data/CHANGELOG.mkd CHANGED
@@ -4,7 +4,40 @@ CHANGELOG
4
4
  Unreleased
5
5
  ----------
6
6
 
7
+ 3.12.0
8
+ ------
9
+
10
+ - (RK-308) Provide a `forge.allow_puppetfile_override` setting that, when true, causes a `forge` declaration in the Puppetfile to override `forge.baseurl`. [#1214](https://github.com/puppetlabs/r10k/pull/1214)
11
+ - (CODEMGMT-1415) Provide an `--incremental` flag to only sync those modules in a Puppetfile whose definitions have changed since last sync, or those whose versions could change. [#1200](https://github.com/puppetlabs/r10k/pull/1200)
12
+ - (CODEMGMT-1454) Ensure missing repo caches are re-synced [#1210](https://github.com/puppetlabs/r10k/pull/1210)
13
+ - (PF-2437) Allow token authentication to be used with the Forge. [#1192](https://github.com/puppetlabs/r10k/pull/1192)
14
+ - Only run the module postrun command for environments in which the module was modified. [#1215](https://github.com/puppetlabs/r10k/issues/1215)
15
+
16
+ 3.11.0
17
+ ------
18
+
19
+ - Always sync git cache on `ref: 'HEAD'` [#1182](https://github.com/puppetlabs/r10k/pull/1182)
20
+ - (CODEMGMT-1421, CODEMGMT-1422, CODEMGMT-1457) Add setting `exclude_spec` to remove the spec dir from module deployment[#1189](https://github.com/puppetlabs/r10k/pull/1189)[#1198](https://github.com/puppetlabs/r10k/pull/1198)[#1204](https://github.com/puppetlabs/r10k/pull/1204)
21
+ - (RK-369) Make module deploys run the postrun command if any environments were updated. [#982](https://github.com/puppetlabs/r10k/issues/982)
22
+ - Add support for Github App auth token. This allows r10k to authenticate under strict SSO/2FA guidelines that cannot utilize machine users for code deployment. [#1180](https://github.com/puppetlabs/r10k/pull/1180)
23
+ - Restore the ability to load a Puppetfile from a relative `basedir`. [#1202](https://github.com/puppetlabs/r10k/pull/1202), [#1203](https://github.com/puppetlabs/r10k/pull/1203)
24
+
25
+ 3.10.0
26
+ ------
27
+
28
+ - Add `authorization_token` setting to allow authentication to a custom Forge server. [#1181](https://github.com/puppetlabs/r10k/pull/1181)
29
+ - (RK-135) Attempting to download the latest version for a module that has no Forge releases will now issue a meaningful error. [#1177](https://github.com/puppetlabs/r10k/pull/1177)
30
+ - Added an interface to R10K::Source::Base named `reload!` for updating the environments list for a given deployment; `reload!` is called before deployment purges to make r10k deploy pools more threadsafe. [#1172](https://github.com/puppetlabs/r10k/pull/1172)
31
+ - Remove username and password from remote url in cache directory name [#1186](https://github.com/puppetlabs/r10k/pull/1186)
32
+ - Purging efficiency is greatly improved. R10K will no longer recurse into directories that match recursive purge exclusions. This should significantly improve the deploy times for those users who enable the "environment" purge level. [#1178](https://github.com/puppetlabs/r10k/pull/1178)
33
+
34
+ 3.9.3
35
+ -----
36
+
37
+ - Fixes a regression when using `--default_branch_override` with Puppetfiles containing Forge modules. [#1173](https://github.com/puppetlabs/r10k/issues/1173)
38
+
7
39
  3.9.2
40
+ -----
8
41
 
9
42
  - Makes the third parameter to R10K::Actions optional, restoring backwards compatability broken in 3.9.1.
10
43
 
data/README.mkd CHANGED
@@ -66,6 +66,12 @@ a git repository using Bundler for dependencies:
66
66
  bundle install
67
67
  bundle exec r10k help
68
68
 
69
+ ### Arch Linux
70
+
71
+ Arch Linux provides a [system package](https://archlinux.org/packages/community/any/r10k/) for r10k.
72
+ This is built against the [system Ruby](https://archlinux.org/packages/extra/x86_64/ruby/) (which is Ruby 3.0.2 as of 2021-08-03).
73
+ This package is maintained by [Tim Meusel](https://github.com/bastelfreak).
74
+
69
75
  Usage
70
76
  -----
71
77
 
@@ -165,11 +165,22 @@ interactions. See the global proxy setting documentation for more information an
165
165
  The 'baseurl' setting indicates where Forge modules should be installed from.
166
166
  This defaults to 'https://forgeapi.puppetlabs.com'
167
167
 
168
+ #### authorization_token
169
+
170
+ The 'authorization_token' setting allows you to provide a token for authenticating to a Forge server.
171
+ You will need to prepend your token with 'Bearer ' to authenticate to the Forge or when using your own Artifactory server.
172
+
168
173
  ```yaml
169
174
  forge:
170
175
  baseurl: 'https://private-forge.mysite'
176
+ authorization_token: 'Bearer mysupersecretauthtoken'
171
177
  ```
172
178
 
179
+ #### allow_puppetfile_override
180
+
181
+ The `allow_puppetfile_override` setting causes r10k to respect [`forge` declarations](https://github.com/puppetlabs/r10k/blob/main/doc/puppetfile.mkd#forge)
182
+ in Puppetfiles, overriding the `baseurl` setting and allowing per-environment configuration of the Forge URL.
183
+
173
184
  Deployment options
174
185
  ------------------
175
186
 
@@ -336,6 +347,20 @@ deploy:
336
347
  puppet_conf: '/opt/puppet/conf/puppet.conf'
337
348
  ```
338
349
 
350
+ #### exclude_spec
351
+
352
+ During module deployment, r10k's default behavior is to deploy the spec directory.
353
+ This behavior can be configured for all modules using the `exclude_spec` setting in the r10k config.
354
+ This config setting can be overridden in each module definition in the Puppetfile
355
+ or more globally via the CLI for deploys. The following example sets all modules to
356
+ not deploy the spec dir.
357
+
358
+
359
+ ```yaml
360
+ deploy:
361
+ exclude_spec: true
362
+ ```
363
+
339
364
  Source options
340
365
  --------------
341
366
 
@@ -62,6 +62,32 @@ useful if you want to make sure that a given environment is fully up to date.
62
62
 
63
63
  - - -
64
64
 
65
+ There is also a middle ground between updating all modules and updating no modules.
66
+ It is often desirable to update the environment and then update only those modules
67
+ whose definitions have changed in the Puppetfile, or whose content _could_ have
68
+ changed since the last deployment (eg, Forge modules with their version set to
69
+ `:latest` or Git modules who point to a `branch` ref).
70
+
71
+ This can be achieved by assuming content is unchanged locally on disk. This is the
72
+ opposite of what one would assume during a module development cycle, when a user
73
+ might be making local edits to test code changes. However, in production, access
74
+ to puppet code is usually locked down, and updates are deployed through automated
75
+ invocations of R10K.
76
+
77
+ In these cases, deploys where most modules are unchanged and reference exact
78
+ versions (ie, not `:latest` or a branch as mentioned above), this invocation
79
+ may shorten deployment times dozens of seconds if not minutes depending on how
80
+ many modules meet the above criteria (approximately 1 minute for every 400 modules).
81
+
82
+ To take advantage of this, set as many modules as possible in the Puppetfile to
83
+ explicit, static version. These are released Forge versions, or Git modules using
84
+ the `:tag`, or `:commit` keys. Git `:ref`s containing only the full 40 character
85
+ commit SHA will also be treated as static versions. Then invoke a deploy with:
86
+
87
+ r10k deploy environment production --modules --incremental
88
+
89
+ - - -
90
+
65
91
  Update a single environment and specify a default branch override:
66
92
 
67
93
  r10k deploy environment my_working_environment --modules --default-branch-override default_branch_override
data/doc/puppetfile.mkd CHANGED
@@ -51,10 +51,9 @@ handles modules.
51
51
  ### forge
52
52
 
53
53
  The `forge` setting specifies which server that Forge based modules are fetched
54
- from. This is currently a noop and is provided for compatibility with
55
- librarian-puppet.
56
-
57
- R10k supports setting the Forge to use _globally_ in `r10k.yaml`. see [Configuration](/doc/dynamic-environments/configuration.mkd#baseurl) for details.
54
+ from. This declaration is only respected if [`forge.allow_puppetfile_override`](/dynamic-environments/configuration.mkd#allow_puppetfile_override)
55
+ is set to true in the main `r10k.yaml`. Otherwise, use [`forge.baseurl`](/doc/dynamic-environments/configuration.mkd#baseurl)
56
+ to globally configure where modules should be downloaded from.
58
57
 
59
58
  ### moduledir
60
59
 
@@ -130,7 +129,8 @@ with a git commit, branch reference, or a tag.
130
129
  When a module is installed using `:tag` or `:commit`, r10k assumes that the
131
130
  given object is a tag or commit and can do some optimizations around fetching
132
131
  the object. If the tag or commit is already available r10k will skip network
133
- operations when updating the repo, which can speed up install times.
132
+ operations when updating the repo, which can speed up install times. When
133
+ `:ref` is set to track `HEAD`, it will synchronize the module on each run.
134
134
 
135
135
  Module versions can also be specified using `:branch` to track a specific
136
136
  branch reference.
@@ -312,6 +312,19 @@ module.
312
312
  For more information see the [FAQ entry](faq.mkd#how-do-i-prevent-r10k-from-removing-modules-in-the-modules-directory-of-my-git-repository)
313
313
  on managing internal and external modules in the same directory.
314
314
 
315
+ ### Per-Item spec dir deployment
316
+
317
+ During deployment, r10k's default behavior is to deploy the spec directory. The
318
+ Puppetfile can modify this per module, overriding settings from the default
319
+ r10k config. The following example sets the module to not deploy the spec
320
+ directory.
321
+
322
+ ```
323
+ mod 'apache',
324
+ :git => 'git@github.com:puppetlabs/puppetlabs-apache.git',
325
+ :exclude_spec => true
326
+ ```
327
+
315
328
  ### Per-Item Install Path
316
329
 
317
330
  Git and SVN content types support installing into an alternate path without changing
data/integration/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rototiller'
2
+ require 'fileutils'
2
3
 
3
4
  namespace :ci do
4
5
  namespace :test do
@@ -59,13 +60,14 @@ end
59
60
  desc 'Generate a host configuration used by Beaker'
60
61
  rototiller_task :beaker_hostgenerator do |t|
61
62
  if ENV['BEAKER_HOST'].nil?
63
+ FileUtils.mkdir_p 'configs'
62
64
  t.add_command do |c|
63
65
  c.name = 'beaker-hostgenerator'
64
66
  c.argument = '> configs/generated'
65
67
  end
66
68
 
67
69
  # This is a hack :(
68
- t.add_flag(:name => '', :default => 'centos6-64mdca-64.fa', :override_env => 'TEST_TARGET')
70
+ t.add_flag(:name => '', :default => 'centos7-64mdca-64.fa', :override_env => 'TEST_TARGET')
69
71
 
70
72
  t.add_flag(:name => '--global-config', :default => '{forge_host=forge-aio01-petest.puppetlabs.com}', :override_env => 'BHG_GLOBAL_CONFIG')
71
73
  end
@@ -0,0 +1,176 @@
1
+ require 'git_utils'
2
+ require 'r10k_utils'
3
+ require 'master_manipulator'
4
+
5
+
6
+ test_name 'Basic Environment Deployment Workflows'
7
+
8
+ # This isn't a block because we want to use the local variables throughout the file
9
+ step 'init'
10
+ @env_path = on(master, puppet('config print environmentpath')).stdout.rstrip
11
+ r10k_fqp = get_r10k_fqp(master)
12
+
13
+ control_repo_gitdir = '/git_repos/environments.git'
14
+ control_repo_worktree = '/root/environments'
15
+ last_commit = git_last_commit(master, control_repo_worktree)
16
+ git_provider = ENV['GIT_PROVIDER']
17
+
18
+ config_path = get_r10k_config_file_path(master)
19
+ config_backup_path = "#{config_path}.bak"
20
+
21
+ puppetfile1 =<<-EOS
22
+ mod 'puppetlabs/apache', '0.10.0'
23
+ mod 'puppetlabs/stdlib', '8.0.0'
24
+ EOS
25
+
26
+ r10k_conf = <<-CONF
27
+ cachedir: '/var/cache/r10k'
28
+ git:
29
+ provider: '#{git_provider}'
30
+ sources:
31
+ control:
32
+ basedir: "#{@env_path}"
33
+ remote: "#{control_repo_gitdir}"
34
+ deploy:
35
+ purge_levels: ['deployment','environment','puppetfile']
36
+
37
+ CONF
38
+
39
+
40
+ def and_stdlib_is_correct
41
+ metadata_path = "#{@env_path}/production/modules/stdlib/metadata.json"
42
+ on(master, "test -f #{metadata_path}", accept_all_exit_codes: true) do |result|
43
+ assert(result.exit_code == 0, 'stdlib content has been inappropriately purged')
44
+ end
45
+ metadata_info = JSON.parse(on(master, "cat #{metadata_path}").stdout)
46
+ assert(metadata_info['version'] == '8.0.0', 'stdlib deployed to wrong version')
47
+ end
48
+
49
+ teardown do
50
+ on(master, "mv #{config_backup_path} #{config_path}")
51
+ clean_up_r10k(master, last_commit, control_repo_worktree)
52
+ end
53
+
54
+ step 'Set up r10k and control repo' do
55
+
56
+ # Backup and replace r10k config
57
+ on(master, "mv #{config_path} #{config_backup_path}")
58
+ create_remote_file(master, config_path, r10k_conf)
59
+
60
+ # Place our Puppetfile in the control repo's production branch
61
+ git_on(master, 'checkout production', control_repo_worktree)
62
+ create_remote_file(master, "#{control_repo_worktree}/Puppetfile", puppetfile1)
63
+ git_add_commit_push(master, 'production', 'add Puppetfile for Basic Deployment test', control_repo_worktree)
64
+
65
+ # Ensure the production environment will be deployed anew
66
+ on(master, "rm -rf #{@env_path}/production")
67
+ end
68
+
69
+ test_path = "#{@env_path}/production/modules/apache/metadata.json"
70
+ step 'Test initial environment deploy works' do
71
+ on(master, "#{r10k_fqp} deploy environment production --verbose=info") do |result|
72
+ assert(result.output =~ /.*Deploying module to .*apache.*/, 'Did not log apache deployment')
73
+ assert(result.output =~ /.*Deploying module to .*stdlib.*/, 'Did not log stdlib deployment')
74
+ end
75
+ on(master, "test -f #{test_path}", accept_all_exit_codes: true) do |result|
76
+ assert(result.exit_code == 0, 'Expected module in Puppetfile was not installed')
77
+ end
78
+
79
+ and_stdlib_is_correct
80
+ end
81
+
82
+ original_apache_info = JSON.parse(on(master, "cat #{test_path}").stdout)
83
+
84
+ step 'Test second run of deploy updates control repo, but leaves moduledir untouched' do
85
+ puppetfile2 =<<-EOS
86
+ # Current latest of apache is 6.5.1 as of writing this test
87
+ mod 'puppetlabs/apache', :latest
88
+ mod 'puppetlabs/stdlib', '8.0.0'
89
+ mod 'puppetlabs/concat', '7.0.0'
90
+ EOS
91
+
92
+ git_on(master, 'checkout production', control_repo_worktree)
93
+ create_remote_file(master, "#{control_repo_worktree}/Puppetfile", puppetfile2)
94
+ git_add_commit_push(master, 'production', 'add Puppetfile for Basic Deployment test', control_repo_worktree)
95
+
96
+ on(master, "#{r10k_fqp} deploy environment production --verbose=info") do |result|
97
+ refute(result.output =~ /.*Deploying module to .*apache.*/, 'Inappropriately updated apache')
98
+ refute(result.output =~ /.*Deploying module to .*stdlib.*/, 'Inappropriately updated stdlib')
99
+ end
100
+
101
+ on(master, "test -f #{test_path}", accept_all_exit_codes: true) do |result|
102
+ assert(result.exit_code == 0, 'Expected module content in Puppetfile was inappropriately purged')
103
+ end
104
+
105
+ new_apache_info = JSON.parse(on(master, "cat #{test_path}").stdout)
106
+ on(master, "cat #{@env_path}/production/Puppetfile | grep ':latest'", accept_all_exit_codes: true) do |result|
107
+ assert(result.exit_code == 0, 'Puppetfile not updated on subsequent r10k deploys')
108
+ end
109
+
110
+ assert(original_apache_info['version'] == new_apache_info['version'] &&
111
+ new_apache_info['version'] == '0.10.0',
112
+ 'Module content updated on subsequent r10k invocations w/o providing --modules')
113
+
114
+ on(master, "test -f #{@env_path}/production/modules/concat/metadata.json", accept_all_exit_codes: true) do |result|
115
+ assert(result.exit_code == 1, 'Module content deployed on subsequent r10k invocation w/o providing --modules')
116
+ end
117
+
118
+ and_stdlib_is_correct
119
+ end
120
+
121
+ step 'Test --modules updates modules' do
122
+ on(master, "#{r10k_fqp} deploy environment production --modules --verbose=info") do |result|
123
+ assert(result.output =~ /.*Deploying module to .*apache.*/, 'Did not log apache deployment')
124
+ assert(result.output =~ /.*Deploying module to .*stdlib.*/, 'Did not log stdlib deployment')
125
+ assert(result.output =~ /.*Deploying module to .*concat.*/, 'Did not log concat deployment')
126
+ end
127
+
128
+ on(master, "test -f #{test_path}", accept_all_exit_codes: true) do |result|
129
+ assert(result.exit_code == 0, 'Expected module content in Puppetfile was inappropriately purged')
130
+ end
131
+
132
+ on(master, "test -f #{@env_path}/production/modules/concat/metadata.json", accept_all_exit_codes: true) do |result|
133
+ assert(result.exit_code == 0, 'New module content was not deployed when providing --modules')
134
+ end
135
+
136
+ new_apache_info = JSON.parse(on(master, "cat #{test_path}").stdout)
137
+ apache_major_version = new_apache_info['version'].split('.').first.to_i
138
+ assert(apache_major_version > 5, 'Module not updated correctly using --modules')
139
+
140
+ and_stdlib_is_correct
141
+ end
142
+
143
+ step 'Test --modules --incremental deploys changed & dynamic modules, but not unchanged, static modules' do
144
+ puppetfile3 =<<-EOS
145
+ # Current latest of apache is 6.5.1 as of writing this test
146
+ mod 'puppetlabs/apache', :latest
147
+ mod 'puppetlabs/stdlib', '8.0.0'
148
+ mod 'puppetlabs/concat', '7.1.0'
149
+ EOS
150
+
151
+ git_on(master, 'checkout production', control_repo_worktree)
152
+ create_remote_file(master, "#{control_repo_worktree}/Puppetfile", puppetfile3)
153
+ git_add_commit_push(master, 'production', 'add Puppetfile for Basic Deployment test', control_repo_worktree)
154
+
155
+ on(master, "#{r10k_fqp} deploy environment production --modules --incremental --verbose=debug1") do |result|
156
+ assert(result.output =~ /.*Deploying module to .*apache.*/, 'Did not log apache deployment')
157
+ assert(result.output =~ /.*Deploying module to .*concat.*/, 'Did not log concat deployment')
158
+ assert(result.output =~ /.*Not updating module stdlib, assuming content unchanged.*/, 'Did not log notice of skipping stdlib')
159
+ end
160
+
161
+ on(master, "test -f #{test_path}", accept_all_exit_codes: true) do |result|
162
+ assert(result.exit_code == 0, 'Expected module content in Puppetfile was inappropriately purged')
163
+ end
164
+
165
+ new_apache_info = JSON.parse(on(master, "cat #{test_path}").stdout)
166
+ apache_major_version = new_apache_info['version'].split('.').first.to_i
167
+ assert(apache_major_version > 5, 'Module not updated correctly using --modules & --incremental')
168
+
169
+ concat_info = JSON.parse(on(master, "cat #{@env_path}/production/modules/concat/metadata.json").stdout)
170
+ concat_minor_version = concat_info['version'].split('.')[1].to_i
171
+ assert(concat_minor_version == 1, 'Module not updated correctly using --modules & --incremental')
172
+
173
+ and_stdlib_is_correct
174
+ end
175
+
176
+
@@ -10,7 +10,7 @@ last_commit = git_last_commit(master, git_environments_path)
10
10
  r10k_fqp = get_r10k_fqp(master)
11
11
 
12
12
  #Verification
13
- error_notification_regex = /Does 'puppetlabs-regret' have at least one published release?/
13
+ error_notification_regex = /The module puppetlabs-regret does not appear to have any published releases/
14
14
 
15
15
  #File
16
16
  puppet_file = <<-PUPPETFILE
@@ -40,12 +40,6 @@ git_add_commit_push(master, 'production', 'Add module.', git_environments_path)
40
40
 
41
41
  #Tests
42
42
  step "Deploy production environment via r10k with specified module deleted"
43
- on(master, "#{r10k_fqp} deploy environment -p -v", :acceptable_exit_codes => 1) do |result|
44
- if get_puppet_version(master) < 4.0
45
- assert_match(error_notification_regex, result.stderr, 'Unexpected error was detected!')
46
- else
47
- expect_failure('expected to fail due to RK-135') do
48
- assert_match(error_notification_regex, result.stderr, 'Unexpected error was detected!')
49
- end
50
- end
43
+ on(master, "#{r10k_fqp} deploy environment -p -v --trace", :acceptable_exit_codes => 1) do |result|
44
+ assert_match(error_notification_regex, result.stderr, 'Unexpected error was detected!')
51
45
  end
@@ -1,12 +1,15 @@
1
1
  require 'git_utils'
2
2
  require 'r10k_utils'
3
3
  require 'master_manipulator'
4
- test_name 'CODEMGMT-73 - C63184 - Single Environment Purge Unmanaged Modules'
4
+ test_name 'CODEMGMT-78 - Puppetfile Purge --puppetfile & --moduledir flag usage'
5
5
 
6
6
  #Init
7
7
  master_certname = on(master, puppet('config', 'print', 'certname')).stdout.rstrip
8
- git_environments_path = '/root/environments'
9
- last_commit = git_last_commit(master, git_environments_path)
8
+ environments_path = on(master, puppet('config', 'print', 'environmentpath')).stdout.strip
9
+ moduledir = File.join(environments_path, 'production', 'modules')
10
+ puppetfile_path = File.join(environments_path, 'production', 'Puppetfile')
11
+ git_remote_environments_path = '/root/environments'
12
+ last_commit = git_last_commit(master, git_remote_environments_path)
10
13
  r10k_fqp = get_r10k_fqp(master)
11
14
 
12
15
  #Verification
@@ -14,14 +17,12 @@ motd_path = '/etc/motd'
14
17
  motd_contents = 'Hello!'
15
18
  motd_contents_regex = /\A#{motd_contents}\z/
16
19
 
17
- error_message_regex = /Blah/
18
-
19
20
  #File
20
- puppet_file = <<-PUPPETFILE
21
+ puppetfile = <<-PUPPETFILE
21
22
  mod "puppetlabs/xinetd"
22
23
  PUPPETFILE
23
24
 
24
- puppet_file_path = File.join(git_environments_path, 'Puppetfile')
25
+ remote_puppetfile_path = File.join(git_remote_environments_path, 'Puppetfile')
25
26
 
26
27
  #Manifest
27
28
  manifest = <<-MANIFEST
@@ -30,12 +31,12 @@ manifest = <<-MANIFEST
30
31
  }
31
32
  MANIFEST
32
33
 
33
- site_pp_path = File.join(git_environments_path, 'manifests', 'site.pp')
34
+ remote_site_pp_path = File.join(git_remote_environments_path, 'manifests', 'site.pp')
34
35
  site_pp = create_site_pp(master_certname, manifest)
35
36
 
36
37
  #Teardown
37
38
  teardown do
38
- clean_up_r10k(master, last_commit, git_environments_path)
39
+ clean_up_r10k(master, last_commit, git_remote_environments_path)
39
40
 
40
41
  step 'Remove "/etc/motd" File'
41
42
  on(agents, "rm -rf #{motd_path}")
@@ -46,27 +47,24 @@ step 'Stub Forge on Master'
46
47
  stub_forge_on(master)
47
48
 
48
49
  step 'Checkout "production" Branch'
49
- git_on(master, 'checkout production', git_environments_path)
50
-
51
- step 'Manually Install the "motd" Module from the Forge'
52
- on(master, puppet('module install puppetlabs-motd'))
50
+ git_on(master, 'checkout production', git_remote_environments_path)
53
51
 
54
52
  step 'Create "Puppetfile" for the "production" Environment'
55
- create_remote_file(master, puppet_file_path, puppet_file)
53
+ create_remote_file(master, remote_puppetfile_path, puppetfile)
56
54
 
57
55
  step 'Inject New "site.pp" to the "production" Environment'
58
- inject_site_pp(master, site_pp_path, site_pp)
56
+ inject_site_pp(master, remote_site_pp_path, site_pp)
59
57
 
60
58
  step 'Push Changes'
61
- git_add_commit_push(master, 'production', 'Update site.pp and add module.', git_environments_path)
59
+ git_add_commit_push(master, 'production', 'Update site.pp and add module.', git_remote_environments_path)
62
60
 
63
- #Tests
64
61
  step 'Deploy Environments via r10k'
65
- on(master, "#{r10k_fqp} deploy environment -v -p")
62
+ on(master, "#{r10k_fqp} deploy environment --modules --verbose debug --trace")
66
63
 
67
- step 'Plug-in Sync Agents'
68
- on(agents, puppet("plugin download --server #{master}"))
64
+ step 'Manually Install the "motd" Module from the Forge'
65
+ on(master, puppet("module install puppetlabs-motd --modulepath #{moduledir}"))
69
66
 
67
+ #Tests
70
68
  agents.each do |agent|
71
69
  step 'Run Puppet Agent Against "production" Environment'
72
70
  on(agent, puppet('agent', '--test', '--environment production'), :acceptable_exit_codes => 2) do |result|
@@ -80,14 +78,12 @@ agents.each do |agent|
80
78
  end
81
79
 
82
80
  step 'Use r10k to Purge Unmanaged Modules'
83
- on(master, "#{r10k_fqp} puppetfile purge -v", :acceptable_exit_codes => 1)
81
+ on(master, "#{r10k_fqp} puppetfile purge --puppetfile #{puppetfile_path} --moduledir #{moduledir} --verbose debug --trace")
84
82
 
85
83
  #Agent will fail because r10k will purge the "motd" module
86
84
  agents.each do |agent|
87
85
  step 'Attempt to Run Puppet Agent'
88
- on(agent, puppet('agent', '--test', '--environment production'), :acceptable_exit_codes => 0) do |result|
89
- expect_failure('Expected to fail due to CODEMGMT-78') do
90
- assert_match(error_message_regex, result.stderr, 'Expected error was not detected!')
91
- end
86
+ on(agent, puppet('agent', '--test', '--environment production'), :acceptable_exit_codes => 1) do |result|
87
+ assert_match(/Could not find declared class motd/, result.stderr, 'Module was not purged')
92
88
  end
93
89
  end