r10k 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.mkd +150 -0
  3. data/README.mkd +10 -1
  4. data/doc/dynamic-environments/configuration.mkd +31 -0
  5. data/doc/dynamic-environments/quickstart.mkd +33 -79
  6. data/doc/faq.mkd +67 -0
  7. data/doc/git/providers.mkd +37 -0
  8. data/doc/puppetfile.mkd +73 -0
  9. data/integration/lib/r10k_utils.rb +47 -2
  10. data/integration/pre-suite/01_git_config.rb +9 -8
  11. data/integration/pre-suite/02_pe_r10k.rb +5 -8
  12. data/integration/scripts/setup_r10k_env_centos5.sh +1 -1
  13. data/integration/scripts/setup_r10k_env_centos6.sh +1 -1
  14. data/integration/scripts/setup_r10k_env_rhel7.sh +1 -1
  15. data/integration/scripts/setup_r10k_env_sles11.sh +1 -1
  16. data/integration/scripts/setup_r10k_env_sles12.sh +1 -1
  17. data/integration/scripts/setup_r10k_env_ubuntu1004.sh +1 -1
  18. data/integration/scripts/setup_r10k_env_ubuntu1204.sh +1 -1
  19. data/integration/scripts/setup_r10k_env_ubuntu1404.sh +1 -1
  20. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +1 -1
  21. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +1 -1
  22. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +1 -1
  23. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +1 -1
  24. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +1 -1
  25. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +1 -1
  26. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +1 -1
  27. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +1 -1
  28. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +1 -1
  29. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +1 -1
  30. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +1 -1
  31. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +1 -1
  32. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +1 -1
  33. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +1 -1
  34. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +1 -1
  35. data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
  36. data/integration/tests/basic_functionality/negative/attempt_to_install_peonly_module_without_license.rb +71 -0
  37. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +7 -2
  38. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +3 -2
  39. data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +3 -2
  40. data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +56 -0
  41. data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
  42. data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
  43. data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +2 -1
  44. data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +2 -1
  45. data/integration/tests/command_line/deploy_env_without_mod_update.rb +3 -2
  46. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +3 -2
  47. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +2 -1
  48. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +2 -1
  49. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +3 -4
  50. data/integration/tests/git_source/git_source_git.rb +7 -2
  51. data/integration/tests/git_source/git_source_ssh.rb +3 -2
  52. data/integration/tests/git_source/git_source_submodule.rb +2 -1
  53. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +2 -1
  54. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +2 -1
  55. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +2 -1
  56. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +2 -1
  57. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +3 -3
  58. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  59. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +9 -5
  60. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +9 -2
  61. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +2 -1
  62. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +2 -1
  63. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +2 -1
  64. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +7 -2
  65. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +3 -4
  66. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +2 -1
  67. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +2 -1
  68. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +2 -1
  69. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +2 -1
  70. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +10 -4
  71. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +9 -2
  72. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +2 -1
  73. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +2 -1
  74. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +7 -2
  75. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +2 -1
  76. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +9 -2
  77. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +2 -1
  78. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  79. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +2 -1
  80. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +2 -1
  81. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +2 -1
  82. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +2 -1
  83. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +2 -1
  84. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +2 -1
  85. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +3 -2
  86. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +3 -2
  87. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +2 -1
  88. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +4 -3
  89. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -2
  90. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +4 -3
  91. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -2
  92. data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +3 -2
  93. data/lib/r10k/action/base.rb +31 -0
  94. data/lib/r10k/action/deploy/deploy_helpers.rb +34 -0
  95. data/lib/r10k/action/deploy/display.rb +57 -75
  96. data/lib/r10k/action/deploy/environment.rb +52 -15
  97. data/lib/r10k/action/deploy/module.rb +13 -18
  98. data/lib/r10k/action/puppetfile/check.rb +8 -18
  99. data/lib/r10k/action/puppetfile/install.rb +13 -27
  100. data/lib/r10k/action/puppetfile/purge.rb +8 -17
  101. data/lib/r10k/action/runner.rb +39 -3
  102. data/lib/r10k/cli.rb +1 -3
  103. data/lib/r10k/cli/deploy.rb +3 -1
  104. data/lib/r10k/cli/puppetfile.rb +2 -2
  105. data/lib/r10k/deployment.rb +8 -6
  106. data/lib/r10k/deployment/config.rb +18 -65
  107. data/lib/r10k/environment/base.rb +19 -0
  108. data/lib/r10k/environment/git.rb +9 -0
  109. data/lib/r10k/environment/svn.rb +9 -0
  110. data/lib/r10k/forge/module_release.rb +21 -14
  111. data/lib/r10k/git.rb +6 -0
  112. data/lib/r10k/git/alternates.rb +20 -6
  113. data/lib/r10k/git/cache.rb +1 -1
  114. data/lib/r10k/git/rugged/bare_repository.rb +5 -0
  115. data/lib/r10k/git/rugged/base_repository.rb +6 -20
  116. data/lib/r10k/git/rugged/credentials.rb +66 -0
  117. data/lib/r10k/git/rugged/thin_repository.rb +16 -11
  118. data/lib/r10k/git/rugged/working_repository.rb +15 -7
  119. data/lib/r10k/git/shellgit/bare_repository.rb +9 -4
  120. data/lib/r10k/git/shellgit/thin_repository.rb +8 -10
  121. data/lib/r10k/git/stateful_repository.rb +1 -1
  122. data/lib/r10k/initializers.rb +55 -0
  123. data/lib/r10k/module.rb +1 -0
  124. data/lib/r10k/module/base.rb +3 -2
  125. data/lib/r10k/module/forge.rb +14 -6
  126. data/lib/r10k/module/local.rb +36 -0
  127. data/lib/r10k/module/metadata_file.rb +2 -2
  128. data/lib/r10k/puppetfile.rb +1 -1
  129. data/lib/r10k/settings.rb +86 -0
  130. data/lib/r10k/settings/collection.rb +118 -0
  131. data/lib/r10k/settings/definition.rb +112 -0
  132. data/lib/r10k/settings/enum_definition.rb +22 -0
  133. data/lib/r10k/settings/loader.rb +96 -0
  134. data/lib/r10k/settings/uri_definition.rb +19 -0
  135. data/lib/r10k/util/subprocess/runner/windows.rb +4 -4
  136. data/lib/r10k/version.rb +1 -1
  137. data/r10k.gemspec +2 -3
  138. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
  139. data/spec/fixtures/unit/util/subprocess/{posix/runner → runner}/no-execute.sh +0 -0
  140. data/spec/integration/git/rugged/thin_repository_spec.rb +2 -2
  141. data/spec/integration/git/rugged/working_repository_spec.rb +9 -0
  142. data/spec/integration/git/shellgit/thin_repository_spec.rb +2 -2
  143. data/spec/integration/git/stateful_repository_spec.rb +1 -1
  144. data/spec/r10k-mocks/mock_config.rb +10 -13
  145. data/spec/r10k-mocks/mock_env.rb +8 -0
  146. data/spec/shared-examples/deploy-actions.rb +69 -0
  147. data/spec/shared-examples/puppetfile-action.rb +17 -0
  148. data/spec/unit/action/cri_runner_spec.rb +3 -1
  149. data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
  150. data/spec/unit/action/deploy/display_spec.rb +31 -0
  151. data/spec/unit/action/deploy/environment_spec.rb +56 -0
  152. data/spec/unit/action/deploy/module_spec.rb +17 -0
  153. data/spec/unit/action/puppetfile/check_spec.rb +26 -0
  154. data/spec/unit/action/puppetfile/install_spec.rb +68 -0
  155. data/spec/unit/action/puppetfile/purge_spec.rb +19 -0
  156. data/spec/unit/action/runner_spec.rb +10 -9
  157. data/spec/unit/deployment/config_spec.rb +20 -44
  158. data/spec/unit/deployment_spec.rb +1 -1
  159. data/spec/unit/environment/git_spec.rb +20 -0
  160. data/spec/unit/environment/svn_spec.rb +20 -0
  161. data/spec/unit/forge/module_release_spec.rb +6 -3
  162. data/spec/unit/git/alternates_spec.rb +38 -12
  163. data/spec/unit/git/cache_spec.rb +4 -0
  164. data/spec/unit/git/rugged/credentials_spec.rb +74 -0
  165. data/spec/unit/initializers_spec.rb +68 -0
  166. data/spec/unit/module/base_spec.rb +2 -2
  167. data/spec/unit/module/forge_spec.rb +11 -3
  168. data/spec/unit/module/metadata_file_spec.rb +0 -1
  169. data/spec/unit/puppetfile_spec.rb +11 -0
  170. data/spec/unit/settings/collection_spec.rb +122 -0
  171. data/spec/unit/settings/definition_spec.rb +78 -0
  172. data/spec/unit/settings/enum_definition_spec.rb +20 -0
  173. data/spec/unit/{deployment/config → settings}/loader_spec.rb +50 -2
  174. data/spec/unit/settings/uri_definition_spec.rb +23 -0
  175. data/spec/unit/settings_spec.rb +151 -0
  176. data/spec/unit/util/subprocess/runner/posix_spec.rb +1 -1
  177. data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
  178. metadata +53 -90
  179. data/lib/r10k/deployment/config/loader.rb +0 -59
  180. data/lib/shared/puppet/module_tool/metadata.rb +0 -197
  181. data/lib/shared/puppet_forge/connection.rb +0 -64
  182. data/lib/shared/puppet_forge/connection/connection_failure.rb +0 -26
  183. data/lib/shared/puppet_forge/error.rb +0 -41
  184. data/lib/shared/puppet_forge/tar.rb +0 -10
  185. data/lib/shared/puppet_forge/tar/mini.rb +0 -81
  186. data/lib/shared/puppet_forge/unpacker.rb +0 -68
  187. data/lib/shared/puppet_forge/v3.rb +0 -13
  188. data/lib/shared/puppet_forge/v3/module.rb +0 -69
  189. data/lib/shared/puppet_forge/v3/module_release.rb +0 -85
  190. data/lib/shared/puppet_forge/version.rb +0 -3
  191. data/spec/unit/puppet/module_tool/metadata_spec.rb +0 -301
  192. data/spec/unit/puppet_forge/connection/connection_failure_spec.rb +0 -28
  193. data/spec/unit/puppet_forge/connection_spec.rb +0 -41
  194. data/spec/unit/puppet_forge/tar/mini_spec.rb +0 -87
  195. data/spec/unit/puppet_forge/tar_spec.rb +0 -9
  196. data/spec/unit/puppet_forge/unpacker_spec.rb +0 -59
  197. data/spec/unit/puppet_forge/v3/module_release_spec.rb +0 -83
  198. data/spec/unit/puppet_forge/v3/module_spec.rb +0 -75
@@ -7,6 +7,7 @@ test_name 'CODEMGMT-73 - C63184 - Single Environment Purge Unmanaged Modules'
7
7
  master_certname = on(master, puppet('config', 'print', 'certname')).stdout.rstrip
8
8
  git_environments_path = '/root/environments'
9
9
  last_commit = git_last_commit(master, git_environments_path)
10
+ r10k_fqp = get_r10k_fqp(master)
10
11
 
11
12
  #Verification
12
13
  motd_path = '/etc/motd'
@@ -61,7 +62,7 @@ git_add_commit_push(master, 'production', 'Update site.pp and add module.', git_
61
62
 
62
63
  #Tests
63
64
  step 'Deploy Environments via r10k'
64
- on(master, 'r10k deploy environment -v -p')
65
+ on(master, "#{r10k_fqp} deploy environment -v -p")
65
66
 
66
67
  step 'Plug-in Sync Agents'
67
68
  on(agents, puppet("plugin download --server #{master}"))
@@ -79,7 +80,7 @@ agents.each do |agent|
79
80
  end
80
81
 
81
82
  step 'Use r10k to Purge Unmanaged Modules'
82
- on(master, 'r10k puppetfile purge -v', :acceptable_exit_codes => 1)
83
+ on(master, "#{r10k_fqp} puppetfile purge -v", :acceptable_exit_codes => 1)
83
84
 
84
85
  #Agent will fail because r10k will purge the "motd" module
85
86
  agents.each do |agent|
@@ -7,6 +7,7 @@ test_name 'CODEMGMT-111 - C63600 - Single Environment Switch Between Forge and G
7
7
  master_certname = on(master, puppet('config', 'print', 'certname')).stdout.rstrip
8
8
  env_path = on(master, puppet('config print environmentpath')).stdout.rstrip
9
9
  prod_env_modules_path = File.join(env_path, 'production', 'modules')
10
+ r10k_fqp = get_r10k_fqp(master)
10
11
 
11
12
  git_environments_path = '/root/environments'
12
13
  last_commit = git_last_commit(master, git_environments_path)
@@ -73,7 +74,7 @@ git_add_commit_push(master, 'production', 'Update site.pp and add modules.', git
73
74
 
74
75
  #Tests
75
76
  step 'Deploy "production" Environment via r10k'
76
- on(master, 'r10k deploy environment -v -p')
77
+ on(master, "#{r10k_fqp} deploy environment -v -p")
77
78
 
78
79
  step 'Update MOTD Template'
79
80
  create_remote_file(master, motd_template_path, motd_template_contents_forge)
@@ -101,7 +102,7 @@ step 'Push Changes'
101
102
  git_add_commit_push(master, 'production', 'Update site.pp and Puppetfile.', git_environments_path)
102
103
 
103
104
  step 'Deploy "production" Environment Again via r10k'
104
- on(master, 'r10k deploy environment -v -p')
105
+ on(master, "#{r10k_fqp} deploy environment -v -p")
105
106
 
106
107
  agents.each do |agent|
107
108
  step 'Run Puppet Agent'
@@ -7,6 +7,7 @@ test_name 'CODEMGMT-62 - C59260 - Single Environment with Unicode File Paths'
7
7
  master_certname = on(master, puppet('config', 'print', 'certname')).stdout.rstrip
8
8
  environment_path = on(master, puppet('config', 'print', 'environmentpath')).stdout.rstrip
9
9
  prod_env_modules_path = File.join(environment_path, 'production', 'modules')
10
+ r10k_fqp = get_r10k_fqp(master)
10
11
 
11
12
  git_environments_path = '/root/environments'
12
13
  last_commit = git_last_commit(master, git_environments_path)
@@ -47,7 +48,7 @@ git_add_commit_push(master, 'production', 'Update site.pp and add modules.', git
47
48
 
48
49
  #Tests
49
50
  step 'Deploy "production" Environment via r10k'
50
- on(master, 'r10k deploy environment -v')
51
+ on(master, "#{r10k_fqp} deploy environment -v")
51
52
 
52
53
  #Note: Usually a full Puppet Run would be performed for verification.
53
54
  #Since Puppet has problems with Unicode, this test will verify the file
@@ -10,6 +10,7 @@ prod_env_modules_path = File.join(env_path, 'production', 'modules')
10
10
 
11
11
  git_environments_path = '/root/environments'
12
12
  last_commit = git_last_commit(master, git_environments_path)
13
+ r10k_fqp = get_r10k_fqp(master)
13
14
 
14
15
  #Verification
15
16
  motd_path = '/etc/motd'
@@ -76,7 +77,7 @@ git_add_commit_push(master, 'production', 'Update site.pp and add modules.', git
76
77
 
77
78
  #Tests
78
79
  step 'Deploy "production" Environment via r10k'
79
- on(master, 'r10k deploy environment -v -p')
80
+ on(master, "#{r10k_fqp} deploy environment -v -p")
80
81
 
81
82
  step 'Update MOTD Template'
82
83
  create_remote_file(master, motd_template_path, motd_template_contents)
@@ -112,7 +113,7 @@ step 'Push Changes'
112
113
  git_add_commit_push(master, 'production', 'Update site.pp and Puppetfile.', git_environments_path)
113
114
 
114
115
  step 'Deploy "production" Environment Again via r10k'
115
- on(master, 'r10k deploy environment -v -p')
116
+ on(master, "#{r10k_fqp} deploy environment -v -p")
116
117
 
117
118
  agents.each do |agent|
118
119
  step 'Run Puppet Agent'
@@ -141,7 +142,7 @@ step 'Push Changes'
141
142
  git_add_commit_push(master, 'production', 'Update site.pp and add modules.', git_environments_path)
142
143
 
143
144
  step 'Deploy "production" Environment Again via r10k'
144
- on(master, 'r10k deploy environment -v -p')
145
+ on(master, "#{r10k_fqp} deploy environment -v -p")
145
146
 
146
147
  step 'Update MOTD Template'
147
148
  create_remote_file(master, motd_template_path, motd_template_contents)
@@ -9,6 +9,7 @@ git_environments_path = '/root/environments'
9
9
  last_commit = git_last_commit(master, git_environments_path)
10
10
  local_files_root_path = ENV['FILES'] || 'files'
11
11
  helloworld_module_path = File.join(local_files_root_path, 'modules', 'helloworld')
12
+ r10k_fqp = get_r10k_fqp(master)
12
13
 
13
14
  initial_env_names = ['production', 'stage', 'test']
14
15
 
@@ -92,7 +93,7 @@ end
92
93
 
93
94
  #Tests
94
95
  step 'Deploy Environments via r10k'
95
- on(master, 'r10k deploy environment -v')
96
+ on(master, "#{r10k_fqp} deploy environment -v")
96
97
 
97
98
  #Initial Verification
98
99
  initial_env_names.each do |env|
@@ -128,7 +129,7 @@ git_on(master, 'branch -D test', git_environments_path)
128
129
  git_on(master, 'push origin --delete test', git_environments_path)
129
130
 
130
131
  step 'Re-deploy Environments via r10k'
131
- on(master, 'r10k deploy environment -v -p')
132
+ on(master, "#{r10k_fqp} deploy environment -v -p")
132
133
 
133
134
  #Second Pass Verification
134
135
  agents.each do |agent|
@@ -9,6 +9,7 @@ git_environments_path = '/root/environments'
9
9
  last_commit = git_last_commit(master, git_environments_path)
10
10
  local_files_root_path = ENV['FILES'] || 'files'
11
11
  helloworld_module_path = File.join(local_files_root_path, 'modules', 'helloworld')
12
+ r10k_fqp = get_r10k_fqp(master)
12
13
 
13
14
  initial_env_names = ['production', 'stage']
14
15
 
@@ -51,7 +52,7 @@ end
51
52
 
52
53
  #Tests
53
54
  step 'Deploy Environments via r10k'
54
- on(master, 'r10k deploy environment -v')
55
+ on(master, "#{r10k_fqp} deploy environment -v")
55
56
 
56
57
  #Initial Verification
57
58
  initial_env_names.each do |env|
@@ -71,7 +72,7 @@ git_on(master, 'branch -D stage', git_environments_path)
71
72
  git_on(master, 'push origin --delete stage', git_environments_path)
72
73
 
73
74
  step 'Re-deploy Environments via r10k'
74
- on(master, 'r10k deploy environment -v')
75
+ on(master, "#{r10k_fqp} deploy environment -v")
75
76
 
76
77
  #Second Pass Verification
77
78
  agents.each do |agent|
@@ -96,7 +97,7 @@ step 'Push Changes to "stage" Environment'
96
97
  git_push(master, 'stage', git_environments_path)
97
98
 
98
99
  step 'Re-deploy Environments via r10k'
99
- on(master, 'r10k deploy environment -v')
100
+ on(master, "#{r10k_fqp} deploy environment -v")
100
101
 
101
102
  #Final Verification
102
103
  initial_env_names.each do |env|
@@ -6,6 +6,7 @@ test_name 'CODEMGMT-155 - C62421 - Multiple Environments with Existing Unmanaged
6
6
  #Init
7
7
  master_certname = on(master, puppet('config', 'print', 'certname')).stdout.rstrip
8
8
  environment_path = on(master, puppet('config', 'print', 'environmentpath')).stdout.rstrip
9
+ r10k_fqp = get_r10k_fqp(master)
9
10
 
10
11
  git_environments_path = '/root/environments'
11
12
  last_commit = git_last_commit(master, git_environments_path)
@@ -43,7 +44,7 @@ git_add_commit_push(master, 'production', 'Update site.pp and add module.', git_
43
44
 
44
45
  #Tests
45
46
  step 'Deploy "production" Environment via r10k'
46
- on(master, 'r10k deploy environment -v')
47
+ on(master, "#{r10k_fqp} deploy environment -v")
47
48
 
48
49
  agents.each do |agent|
49
50
  step 'Run Puppet Agent'
@@ -65,7 +66,7 @@ agents.each do |agent|
65
66
  end
66
67
 
67
68
  step 'Re-deploy Environments via r10k'
68
- on(master, 'r10k deploy environment -v') do |result|
69
+ on(master, "#{r10k_fqp} deploy environment -v") do |result|
69
70
  assert_match(removal_message_test_env_regex, result.output, 'Unexpected error was detected!')
70
71
  end
71
72
 
@@ -6,6 +6,7 @@ test_name 'CODEMGMT-155 - C64588 - Single Environment with Git Module Using a Br
6
6
  #Init
7
7
  master_certname = on(master, puppet('config', 'print', 'certname')).stdout.rstrip
8
8
  environment_path = on(master, puppet('config', 'print', 'environmentpath')).stdout.rstrip
9
+ r10k_fqp = get_r10k_fqp(master)
9
10
 
10
11
  git_repo_parent_path = '/git_repos'
11
12
  git_repo_module_name = 'helloworld_module'
@@ -72,7 +73,7 @@ git_add_commit_push(master, 'production', 'Update site.pp and add module.', git_
72
73
 
73
74
  #Tests
74
75
  step 'Deploy "production" Environment via r10k'
75
- on(master, 'r10k deploy environment -v -p')
76
+ on(master, "#{r10k_fqp} deploy environment -v -p")
76
77
 
77
78
  agents.each do |agent|
78
79
  step 'Run Puppet Agent'
@@ -88,7 +89,7 @@ on(master, "chmod -R 644 #{git_module_clone_path}")
88
89
  git_add_commit_push(master, 'master', 'Update module.', git_module_clone_path)
89
90
 
90
91
  step 'Deploy "production" Environment Again via r10k'
91
- on(master, 'r10k deploy environment -v -p')
92
+ on(master, "#{r10k_fqp} deploy environment -v -p")
92
93
 
93
94
  agents.each do |agent|
94
95
  step 'Run Puppet Agent'
@@ -0,0 +1,31 @@
1
+ require 'r10k/util/setopts'
2
+ require 'r10k/logging'
3
+
4
+ module R10K
5
+ module Action
6
+ class Base
7
+
8
+ include R10K::Logging
9
+ include R10K::Util::Setopts
10
+
11
+ attr_accessor :settings
12
+
13
+ def initialize(opts, argv, settings = {})
14
+ @opts = opts
15
+ @argv = argv
16
+ @settings = settings
17
+
18
+ setopts(opts, allowed_initialize_opts)
19
+ end
20
+
21
+ private
22
+
23
+ def allowed_initialize_opts
24
+ {
25
+ :config => true,
26
+ :trace => true,
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ module R10K
2
+ module Action
3
+ module Deploy
4
+ module DeployHelpers
5
+
6
+ # Ensure that a config file has been found (and presumably loaded) and exit
7
+ # with a helpful error if it hasn't.
8
+ #
9
+ # @raise [SystemExit] If no config file was loaded
10
+ def expect_config!
11
+ if @config.nil?
12
+ logger.fatal("No configuration file given, no config file found in current directory, and no global config present")
13
+ exit(8)
14
+ end
15
+ end
16
+
17
+ # Check to see if the deploy write_lock setting has been set, and log the lock message
18
+ # and exit if it has been set.
19
+ #
20
+ # @param config [Hash] The r10k config hash
21
+ #
22
+ # @raise [SystemExit] if the deploy write_lock setting has been set
23
+ def check_write_lock!(config)
24
+ write_lock = config.fetch(:deploy, {})[:write_lock]
25
+ if write_lock
26
+ logger.fatal("Making changes to deployed environments has been administratively disabled.")
27
+ logger.fatal("Reason: #{write_lock}")
28
+ exit(16)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,102 +1,84 @@
1
- require 'r10k/util/setopts'
2
1
  require 'r10k/deployment'
3
- require 'r10k/logging'
2
+ require 'r10k/action/base'
3
+ require 'r10k/action/deploy/deploy_helpers'
4
4
 
5
5
  module R10K
6
6
  module Action
7
7
  module Deploy
8
- class Display
9
-
10
- include R10K::Util::Setopts
11
- include R10K::Logging
12
-
13
- def initialize(opts, argv)
14
- @opts = opts
15
- @argv = argv
16
- setopts(opts, {
17
- :config => :self,
18
- :puppetfile => :self,
19
- :detail => :self,
20
- :trace => :self
21
- })
22
-
23
- @level = 4
24
- @indent = 0
25
- end
8
+ class Display < R10K::Action::Base
9
+
10
+ include R10K::Action::Deploy::DeployHelpers
26
11
 
27
12
  def call
28
- @visit_ok = true
29
- deployment = R10K::Deployment.load_config(@config)
30
- deployment.accept(self)
31
- @visit_ok
32
- end
13
+ expect_config!
14
+ deployment = R10K::Deployment.new(@settings)
33
15
 
34
- include R10K::Action::Visitor
16
+ if @fetch
17
+ deployment.preload!
18
+ end
35
19
 
36
- private
20
+ output = { :sources => deployment.sources.map { |source| source_info(source, @argv) } }
37
21
 
38
- def visit_deployment(deployment)
39
- yield
40
- end
22
+ case @format
23
+ when 'json' then json_format(output)
24
+ else yaml_format(output)
25
+ end
41
26
 
42
- def visit_source(source)
43
- source.generate_environments
44
- display_text("#{source.name} (#{source.basedir})")
45
- yield
27
+ # exit 0
28
+ true
46
29
  end
47
30
 
48
- def visit_environment(environment)
49
- if !(@argv.empty? || @argv.include?(environment.dirname))
50
- return
51
- end
31
+ private
52
32
 
53
- indent do
54
- display_text("- " + environment.dirname)
55
- if @puppetfile
56
- indent do
57
- display_text("modules:")
58
- yield
59
- end
60
- end
61
- end
33
+ def json_format(output)
34
+ require 'json'
35
+ puts JSON.pretty_generate(output)
62
36
  end
63
37
 
64
- def visit_puppetfile(puppetfile)
65
- puppetfile.load
66
- yield
38
+ def yaml_format(output)
39
+ require 'yaml'
40
+ puts output.to_yaml
67
41
  end
68
42
 
69
- def visit_module(mod)
70
- indent do
71
- display_text("- " + mod.title)
72
- if @detail
73
- indent do
74
- properties = mod.properties
75
- str = properties.keys.sort.map do |key|
76
- "#{key}: #{properties[key]}"
77
- end.join("\n")
78
- display_text(str)
79
- end
80
- end
81
- end
43
+ def source_info(source, argv=[])
44
+ source_info = {
45
+ :name => source.name,
46
+ :basedir => source.basedir,
47
+ }
48
+
49
+ source_info[:prefix] = source.prefix if source.prefix
50
+ source_info[:remote] = source.remote if source.respond_to?(:remote)
51
+
52
+ env_list = source.environments.select { |env| argv.empty? || argv.include?(env.name) }
53
+ source_info[:environments] = env_list.map { |env| environment_info(env) }
54
+
55
+ source_info
82
56
  end
83
57
 
84
- def indent(&block)
85
- @indent += @level
86
- block.call
87
- ensure
88
- @indent -= @level
58
+ def environment_info(env)
59
+ if !@puppetfile && !@detail
60
+ env.dirname
61
+ else
62
+ env_info = env.info.merge({
63
+ :status => (env.status rescue nil),
64
+ })
65
+
66
+ env_info[:modules] = env.modules.map { |mod| module_info(mod) } if @puppetfile
67
+
68
+ env_info
69
+ end
89
70
  end
90
71
 
91
- def indent_text(str)
92
- space = " " * @indent
93
- str.lines.map do |line|
94
- space + line
95
- end.join
72
+ def module_info(mod)
73
+ if @detail
74
+ { :name => mod.title, :properties => mod.properties }
75
+ else
76
+ mod.title
77
+ end
96
78
  end
97
79
 
98
- def display_text(str)
99
- puts indent_text(str)
80
+ def allowed_initialize_opts
81
+ super.merge(puppetfile: :self, detail: :self, format: :self, fetch: :self)
100
82
  end
101
83
  end
102
84
  end
@@ -2,31 +2,30 @@ require 'r10k/util/setopts'
2
2
  require 'r10k/deployment'
3
3
  require 'r10k/logging'
4
4
  require 'r10k/action/visitor'
5
+ require 'r10k/action/base'
6
+ require 'r10k/action/deploy/deploy_helpers'
7
+ require 'json'
5
8
 
6
9
  module R10K
7
10
  module Action
8
11
  module Deploy
9
- class Environment
12
+ class Environment < R10K::Action::Base
10
13
 
11
- include R10K::Util::Setopts
12
- include R10K::Logging
13
-
14
- def initialize(opts, argv)
15
- @opts = opts
16
- @argv = argv.map { |arg| arg.gsub(/\W/,'_') }
17
- setopts(opts, {
18
- :config => :self,
19
- :puppetfile => :self,
20
- :purge => :self,
21
- :trace => :self
22
- })
14
+ include R10K::Action::Deploy::DeployHelpers
23
15
 
16
+ def initialize(opts, argv, settings = {})
24
17
  @purge = true
18
+ super
19
+ @argv = @argv.map { |arg| arg.gsub(/\W/,'_') }
25
20
  end
26
21
 
27
22
  def call
28
23
  @visit_ok = true
29
- deployment = R10K::Deployment.load_config(@config)
24
+
25
+ expect_config!
26
+ deployment = R10K::Deployment.new(@settings)
27
+ check_write_lock!(@settings)
28
+
30
29
  deployment.accept(self)
31
30
  @visit_ok
32
31
  end
@@ -43,12 +42,18 @@ module R10K
43
42
  deployment.preload!
44
43
  deployment.validate!
45
44
 
45
+ undeployable = undeployable_environment_names(deployment.environments, @argv)
46
+ if !undeployable.empty?
47
+ @visit_ok = false
48
+ logger.error "Environment(s) \'#{undeployable.join(", ")}\' cannot be found in any source and will not be deployed."
49
+ end
50
+
46
51
  yield
47
52
 
48
53
  deployment.purge! if @purge
49
54
 
50
55
  ensure
51
- if (postcmd = deployment.config.setting(:postrun))
56
+ if (postcmd = @settings[:postrun])
52
57
  subproc = R10K::Util::Subprocess.new(postcmd)
53
58
  subproc.logger = logger
54
59
  subproc.execute
@@ -64,16 +69,24 @@ module R10K
64
69
  logger.debug1("Environment #{environment.dirname} does not match environment name filter, skipping")
65
70
  return
66
71
  end
72
+
73
+ started_at = Time.new
74
+
67
75
  status = environment.status
68
76
  logger.info "Deploying environment #{environment.path}"
77
+
69
78
  environment.sync
79
+ logger.info "Environment #{environment.dirname} is now at #{environment.signature}"
70
80
 
71
81
  if status == :absent || @puppetfile
72
82
  if status == :absent
73
83
  logger.debug("Environment #{environment.dirname} is new, updating all modules")
74
84
  end
85
+
75
86
  yield
76
87
  end
88
+
89
+ write_environment_info!(environment, started_at)
77
90
  end
78
91
 
79
92
  def visit_puppetfile(puppetfile)
@@ -86,6 +99,30 @@ module R10K
86
99
  logger.info "Deploying module #{mod.path}"
87
100
  mod.sync
88
101
  end
102
+
103
+ def write_environment_info!(environment, started_at)
104
+ File.open("#{environment.path}/.r10k-deploy.json", 'w') do |f|
105
+ deploy_info = environment.info.merge({
106
+ :started_at => started_at,
107
+ :finished_at => Time.new,
108
+ })
109
+
110
+ f.puts(JSON.pretty_generate(deploy_info))
111
+ end
112
+ end
113
+
114
+ def undeployable_environment_names(environments, expected_names)
115
+ if expected_names.empty?
116
+ []
117
+ else
118
+ known_names = environments.map(&:dirname)
119
+ expected_names - known_names
120
+ end
121
+ end
122
+
123
+ def allowed_initialize_opts
124
+ super.merge(puppetfile: :self, cachedir: :self, purge: true)
125
+ end
89
126
  end
90
127
  end
91
128
  end