r10k 3.10.0 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -10
  3. data/CHANGELOG.mkd +33 -0
  4. data/README.mkd +6 -0
  5. data/doc/dynamic-environments/configuration.mkd +25 -7
  6. data/doc/dynamic-environments/usage.mkd +26 -0
  7. data/doc/puppetfile.mkd +18 -5
  8. data/integration/Rakefile +2 -0
  9. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  10. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +15 -13
  11. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -3
  12. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +3 -3
  13. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -3
  14. data/lib/r10k/action/base.rb +1 -1
  15. data/lib/r10k/action/deploy/deploy_helpers.rb +4 -0
  16. data/lib/r10k/action/deploy/display.rb +1 -1
  17. data/lib/r10k/action/deploy/environment.rb +19 -9
  18. data/lib/r10k/action/deploy/module.rb +41 -11
  19. data/lib/r10k/action/puppetfile/check.rb +7 -5
  20. data/lib/r10k/action/puppetfile/install.rb +22 -16
  21. data/lib/r10k/action/puppetfile/purge.rb +12 -9
  22. data/lib/r10k/action/runner.rb +40 -4
  23. data/lib/r10k/action/visitor.rb +3 -0
  24. data/lib/r10k/cli/deploy.rb +5 -0
  25. data/lib/r10k/cli/puppetfile.rb +0 -1
  26. data/lib/r10k/content_synchronizer.rb +16 -4
  27. data/lib/r10k/environment/bare.rb +4 -7
  28. data/lib/r10k/environment/base.rb +64 -11
  29. data/lib/r10k/environment/plain.rb +16 -0
  30. data/lib/r10k/environment/with_modules.rb +6 -10
  31. data/lib/r10k/environment.rb +1 -0
  32. data/lib/r10k/errors.rb +5 -0
  33. data/lib/r10k/git/rugged/credentials.rb +77 -0
  34. data/lib/r10k/git/stateful_repository.rb +8 -0
  35. data/lib/r10k/git.rb +3 -0
  36. data/lib/r10k/initializers.rb +14 -7
  37. data/lib/r10k/logging.rb +78 -1
  38. data/lib/r10k/module/base.rb +42 -1
  39. data/lib/r10k/module/definition.rb +64 -0
  40. data/lib/r10k/module/forge.rb +11 -2
  41. data/lib/r10k/module/git.rb +23 -1
  42. data/lib/r10k/module/local.rb +6 -3
  43. data/lib/r10k/module/svn.rb +11 -0
  44. data/lib/r10k/module.rb +20 -2
  45. data/lib/r10k/module_loader/puppetfile/dsl.rb +8 -3
  46. data/lib/r10k/module_loader/puppetfile.rb +109 -28
  47. data/lib/r10k/puppetfile.rb +11 -13
  48. data/lib/r10k/settings/definition.rb +1 -1
  49. data/lib/r10k/settings.rb +89 -1
  50. data/lib/r10k/source/yaml.rb +1 -1
  51. data/lib/r10k/util/purgeable.rb +6 -2
  52. data/lib/r10k/util/setopts.rb +2 -0
  53. data/lib/r10k/util/subprocess.rb +1 -0
  54. data/lib/r10k/version.rb +1 -1
  55. data/locales/r10k.pot +168 -68
  56. data/r10k.gemspec +2 -0
  57. data/r10k.yaml.example +28 -0
  58. data/spec/fixtures/unit/action/r10k_logging.yaml +12 -0
  59. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  60. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +10 -0
  61. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +10 -0
  62. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +1 -0
  63. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/{managed_subdir_2 → subdir_allowlisted_2}/ignored_1 +0 -0
  64. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +1 -0
  65. data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +1 -0
  66. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +1 -0
  67. data/spec/integration/util/purageable_spec.rb +41 -0
  68. data/spec/r10k-mocks/mock_env.rb +3 -0
  69. data/spec/r10k-mocks/mock_source.rb +7 -3
  70. data/spec/unit/action/deploy/environment_spec.rb +96 -30
  71. data/spec/unit/action/deploy/module_spec.rb +217 -51
  72. data/spec/unit/action/puppetfile/check_spec.rb +17 -5
  73. data/spec/unit/action/puppetfile/install_spec.rb +42 -36
  74. data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
  75. data/spec/unit/action/runner_spec.rb +132 -9
  76. data/spec/unit/environment/bare_spec.rb +13 -0
  77. data/spec/unit/environment/base_spec.rb +30 -17
  78. data/spec/unit/environment/git_spec.rb +2 -2
  79. data/spec/unit/environment/plain_spec.rb +8 -0
  80. data/spec/unit/environment/svn_spec.rb +4 -3
  81. data/spec/unit/environment/with_modules_spec.rb +3 -2
  82. data/spec/unit/git/rugged/credentials_spec.rb +29 -0
  83. data/spec/unit/git/stateful_repository_spec.rb +5 -0
  84. data/spec/unit/module/base_spec.rb +54 -8
  85. data/spec/unit/module/forge_spec.rb +51 -4
  86. data/spec/unit/module/git_spec.rb +67 -9
  87. data/spec/unit/module/svn_spec.rb +35 -5
  88. data/spec/unit/module_loader/puppetfile_spec.rb +108 -33
  89. data/spec/unit/module_spec.rb +12 -1
  90. data/spec/unit/puppetfile_spec.rb +33 -3
  91. data/spec/unit/settings_spec.rb +43 -2
  92. data/spec/unit/util/purgeable_spec.rb +22 -11
  93. metadata +31 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db8e1373846da121e13c6bdd3f74c7eadac79d356d65628157d1f0b6c0939f23
4
- data.tar.gz: 7fd4694a5e33f692213339db0422fa7db58d38f84d63f2586593665f8acae8cc
3
+ metadata.gz: 13a5d7be1f8e4f5794ad944ef12cfbe32d6a7e704371e8f8137227507857600a
4
+ data.tar.gz: a9060539b639c566371a1c23c28d19910d63649dedeca67ab4b9237d0a43bfab
5
5
  SHA512:
6
- metadata.gz: 272021e80cc4ce7ba4d11f3316bd972d7498e102a1f4d4aa9c0bcf83eeef60bd283c9fb4db74ad37e854b2ebc60f6ba28d3c251ae51cb54fb2ae03a4842d4bb8
7
- data.tar.gz: 3689ec04b7dd2a4597199fd2fddba3e06a903b682760aacd565f96e42a604c42a6ef340f598c37ee4e1c1cfc4f4912c1132880de98bb734d86aac39475a45342
6
+ metadata.gz: aa2a7a28f9d30468bd17d6e54b4e6202a3290779391efe95409a16648f2eb81a5dd7483964b9c7d3bad8fafbb808fa99a86b6a7c2c0cdac5a5f1d5140e20efd0
7
+ data.tar.gz: 1ee18ff19d30c76a6f00a9650eff77ccf0cae1f60c789a5ae8c90fd725a8c4197f587d4bc1d6a6288b8452ba1c3db07cdfa30030d7fad7e130639283b5f56722
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,6 +4,39 @@ CHANGELOG
4
4
  Unreleased
5
5
  ----------
6
6
 
7
+ 3.13.0
8
+ ------
9
+
10
+ - Restore Ruby 3 compatibility [#1234](https://github.com/puppetlabs/r10k/pull/1234)
11
+ - (RK-381) Do not recurse into symlinked dirs when finding files to purge. [#1233](https://github.com/puppetlabs/r10k/pull/1233)
12
+ - Purge should remove unmanaged directories, in addition to unmanaged files. [#1222](https://github.com/puppetlabs/r10k/pull/1222)
13
+ - Rename experimental environment type "bare" to "plain". [#1228](https://github.com/puppetlabs/r10k/pull/1228)
14
+ - Add support for specifying additional logging ouputs. [#1230](https://github.com/puppetlabs/r10k/issues/1230)
15
+
16
+ 3.12.1
17
+ ------
18
+
19
+ - Fix requiring individual R10K::Actions without having already required 'r10k'. [#1223](https://github.com/puppetlabs/r10k/issues/1223)
20
+ - Fix evaluation of Puppetfiles that include local modules. [#1224](https://github.com/puppetlabs/r10k/pull/1224)
21
+
22
+ 3.12.0
23
+ ------
24
+
25
+ - (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)
26
+ - (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)
27
+ - (CODEMGMT-1454) Ensure missing repo caches are re-synced [#1210](https://github.com/puppetlabs/r10k/pull/1210)
28
+ - (PF-2437) Allow token authentication to be used with the Forge. [#1192](https://github.com/puppetlabs/r10k/pull/1192)
29
+ - Only run the module postrun command for environments in which the module was modified. [#1215](https://github.com/puppetlabs/r10k/issues/1215)
30
+
31
+ 3.11.0
32
+ ------
33
+
34
+ - Always sync git cache on `ref: 'HEAD'` [#1182](https://github.com/puppetlabs/r10k/pull/1182)
35
+ - (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)
36
+ - (RK-369) Make module deploys run the postrun command if any environments were updated. [#982](https://github.com/puppetlabs/r10k/issues/982)
37
+ - 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)
38
+ - 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)
39
+
7
40
  3.10.0
8
41
  ------
9
42
 
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
 
@@ -167,9 +167,8 @@ This defaults to 'https://forgeapi.puppetlabs.com'
167
167
 
168
168
  #### authorization_token
169
169
 
170
- The 'authorization_token' setting allows you to provide a token for authenticating to a
171
- custom Forge server. When set, 'baseurl' must also be set.
172
- You will need to prepend your token with 'Bearer ' if using Artifactory as your Forge server.
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.
173
172
 
174
173
  ```yaml
175
174
  forge:
@@ -177,6 +176,11 @@ forge:
177
176
  authorization_token: 'Bearer mysupersecretauthtoken'
178
177
  ```
179
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
+
180
184
  Deployment options
181
185
  ------------------
182
186
 
@@ -343,6 +347,20 @@ deploy:
343
347
  puppet_conf: '/opt/puppet/conf/puppet.conf'
344
348
  ```
345
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
+
346
364
  Source options
347
365
  --------------
348
366
 
@@ -742,16 +760,16 @@ modules:
742
760
  version: 62d07f2
743
761
  ```
744
762
 
745
- ### Bare Environment Type
763
+ ### Plain Environment Type
746
764
 
747
765
  A "control repository" typically contains a hiera.yaml, an environment.conf, a manifests/site.pp file, and a few other things. However, none of these are strictly necessary for an environment to be functional if modules can be deployed to it.
748
766
 
749
- The bare environment type allows sources that support environment modules to operate without a control repo being required. Modules can be deployed directly.
767
+ The plain environment type allows sources that support environment modules to operate without a control repo being required. Modules can be deployed directly.
750
768
 
751
769
  ```yaml
752
770
  ---
753
771
  production:
754
- type: bare
772
+ type: plain
755
773
  modules:
756
774
  puppetlabs-stdlib:
757
775
  type: forge
@@ -765,7 +783,7 @@ production:
765
783
  version: 62d07f2
766
784
 
767
785
  development:
768
- type: bare
786
+ type: plain
769
787
  modules:
770
788
  puppetlabs-stdlib:
771
789
  type: forge
@@ -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,6 +60,7 @@ 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'
@@ -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
+
@@ -5,9 +5,11 @@ 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
- moduledir = on(master, puppet('config', 'print', 'environmentpath')).stdout.strip + '/production/modules'
9
- git_environments_path = '/root/environments'
10
- 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)
11
13
  r10k_fqp = get_r10k_fqp(master)
12
14
 
13
15
  #Verification
@@ -16,11 +18,11 @@ motd_contents = 'Hello!'
16
18
  motd_contents_regex = /\A#{motd_contents}\z/
17
19
 
18
20
  #File
19
- puppet_file = <<-PUPPETFILE
21
+ puppetfile = <<-PUPPETFILE
20
22
  mod "puppetlabs/xinetd"
21
23
  PUPPETFILE
22
24
 
23
- puppet_file_path = File.join(git_environments_path, 'Puppetfile')
25
+ remote_puppetfile_path = File.join(git_remote_environments_path, 'Puppetfile')
24
26
 
25
27
  #Manifest
26
28
  manifest = <<-MANIFEST
@@ -29,12 +31,12 @@ manifest = <<-MANIFEST
29
31
  }
30
32
  MANIFEST
31
33
 
32
- 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')
33
35
  site_pp = create_site_pp(master_certname, manifest)
34
36
 
35
37
  #Teardown
36
38
  teardown do
37
- clean_up_r10k(master, last_commit, git_environments_path)
39
+ clean_up_r10k(master, last_commit, git_remote_environments_path)
38
40
 
39
41
  step 'Remove "/etc/motd" File'
40
42
  on(agents, "rm -rf #{motd_path}")
@@ -45,19 +47,19 @@ step 'Stub Forge on Master'
45
47
  stub_forge_on(master)
46
48
 
47
49
  step 'Checkout "production" Branch'
48
- git_on(master, 'checkout production', git_environments_path)
50
+ git_on(master, 'checkout production', git_remote_environments_path)
49
51
 
50
52
  step 'Create "Puppetfile" for the "production" Environment'
51
- create_remote_file(master, puppet_file_path, puppet_file)
53
+ create_remote_file(master, remote_puppetfile_path, puppetfile)
52
54
 
53
55
  step 'Inject New "site.pp" to the "production" Environment'
54
- inject_site_pp(master, site_pp_path, site_pp)
56
+ inject_site_pp(master, remote_site_pp_path, site_pp)
55
57
 
56
58
  step 'Push Changes'
57
- 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)
58
60
 
59
61
  step 'Deploy Environments via r10k'
60
- on(master, "#{r10k_fqp} deploy environment -v -p")
62
+ on(master, "#{r10k_fqp} deploy environment --modules --verbose debug --trace")
61
63
 
62
64
  step 'Manually Install the "motd" Module from the Forge'
63
65
  on(master, puppet("module install puppetlabs-motd --modulepath #{moduledir}"))
@@ -76,7 +78,7 @@ agents.each do |agent|
76
78
  end
77
79
 
78
80
  step 'Use r10k to Purge Unmanaged Modules'
79
- on(master, "#{r10k_fqp} puppetfile purge -v --puppetfile #{puppet_file_path} --moduledir #{moduledir}")
81
+ on(master, "#{r10k_fqp} puppetfile purge --puppetfile #{puppetfile_path} --moduledir #{moduledir} --verbose debug --trace")
80
82
 
81
83
  #Agent will fail because r10k will purge the "motd" module
82
84
  agents.each do |agent|
@@ -24,7 +24,7 @@ stage_env_notify_message = 'This is a different message'
24
24
  stage_env_notify_message_regex = /#{stage_env_notify_message}/
25
25
 
26
26
  #Verification for "test" Environment
27
- test_env_error_message_regex = /Error:.*Could not.*environment '?test'?/
27
+ test_env_message_regex = /Environment 'test' not found on server/
28
28
 
29
29
  #Verification for "temp" Environment
30
30
  test_env_notify_message_regex = /I am in the temp environment/
@@ -157,7 +157,7 @@ agents.each do |agent|
157
157
  end
158
158
 
159
159
  step 'Attempt to Run Puppet Agent Against "test" Environment'
160
- on(agent, puppet('agent', '--test', '--environment test'), :acceptable_exit_codes => 1) do |result|
161
- assert_match(test_env_error_message_regex, result.stderr, 'Expected error was not detected!')
160
+ on(agent, puppet('agent', '--test', '--environment test'), :acceptable_exit_codes => 2) do |result|
161
+ assert_match(test_env_message_regex, result.stdout, 'Expected message not found!')
162
162
  end
163
163
  end
@@ -15,7 +15,7 @@ initial_env_names = ['production', 'stage']
15
15
 
16
16
  #Verification
17
17
  notify_message_regex = /I am in the production environment/
18
- stage_env_error_message_regex = /Error:.*Could not.*environment '?stage'?/
18
+ stage_env_message_regex = /Environment 'stage' not found on server/
19
19
 
20
20
  #Manifest
21
21
  site_pp_path = File.join(git_environments_path, 'manifests', 'site.pp')
@@ -83,8 +83,8 @@ agents.each do |agent|
83
83
  end
84
84
 
85
85
  step 'Attempt to Run Puppet Agent Against "stage" Environment'
86
- on(agent, puppet('agent', '--test', '--environment stage'), :acceptable_exit_codes => 1) do |result|
87
- assert_match(stage_env_error_message_regex, result.stderr, 'Expected error was not detected!')
86
+ on(agent, puppet('agent', '--test', '--environment stage'), :acceptable_exit_codes => 2) do |result|
87
+ assert_match(stage_env_message_regex, result.stdout, 'Expected message not found!')
88
88
  end
89
89
  end
90
90
 
@@ -22,7 +22,7 @@ site_pp = create_site_pp(master_certname, ' include helloworld')
22
22
  notify_message_prod_env_regex = /I am in the production environment/
23
23
  notify_message_test_env_regex = /I am in the test environment/
24
24
  removal_message_test_env_regex = /Removing unmanaged path.*test/
25
- error_message_regex = /Could not retrieve (catalog from remote server|information from environment test)/
25
+ missing_message_regex = /Environment 'test' not found on server/
26
26
 
27
27
  #Teardown
28
28
  teardown do
@@ -72,7 +72,7 @@ end
72
72
 
73
73
  agents.each do |agent|
74
74
  step 'Run Puppet Agent Against "test" Environment'
75
- on(agent, puppet('agent', '--test', '--environment test'), :acceptable_exit_codes => 1) do |result|
76
- assert_match(error_message_regex, result.stderr, 'Expected message not found!')
75
+ on(agent, puppet('agent', '--test', '--environment test'), :acceptable_exit_codes => 2) do |result|
76
+ assert_match(missing_message_regex, result.stdout, 'Expected message not found!')
77
77
  end
78
78
  end
@@ -1,5 +1,5 @@
1
- require 'r10k/util/setopts'
2
1
  require 'r10k/logging'
2
+ require 'r10k/util/setopts'
3
3
 
4
4
  module R10K
5
5
  module Action
@@ -1,8 +1,12 @@
1
+ require 'r10k/logging'
2
+
1
3
  module R10K
2
4
  module Action
3
5
  module Deploy
4
6
  module DeployHelpers
5
7
 
8
+ include R10K::Logging
9
+
6
10
  # Ensure that a config file has been found (and presumably loaded) and exit
7
11
  # with a helpful error if it hasn't.
8
12
  #
@@ -1,6 +1,6 @@
1
- require 'r10k/deployment'
2
1
  require 'r10k/action/base'
3
2
  require 'r10k/action/deploy/deploy_helpers'
3
+ require 'r10k/deployment'
4
4
 
5
5
  module R10K
6
6
  module Action