puppet 2.7.13 → 2.7.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (215) hide show
  1. data/CHANGELOG +144 -1
  2. data/conf/osx/preflight +1 -1
  3. data/conf/redhat/puppet.spec +9 -5
  4. data/conf/suse/puppet.spec +4 -1
  5. data/conf/windows/eventlog/Rakefile +32 -0
  6. data/conf/windows/eventlog/puppetres.dll +0 -0
  7. data/conf/windows/eventlog/puppetres.mc +18 -0
  8. data/ext/rack/files/apache2.conf +3 -0
  9. data/install.rb +23 -1
  10. data/lib/puppet.rb +1 -1
  11. data/lib/puppet/agent.rb +1 -14
  12. data/lib/puppet/application/kick.rb +1 -1
  13. data/lib/puppet/application/module.rb +11 -0
  14. data/lib/puppet/daemon.rb +74 -3
  15. data/lib/puppet/defaults.rb +1 -1
  16. data/lib/puppet/face/certificate.rb +1 -1
  17. data/lib/puppet/face/help/man.erb +1 -1
  18. data/lib/puppet/face/module.rb +17 -0
  19. data/lib/puppet/face/module/build.rb +10 -4
  20. data/lib/puppet/face/module/changes.rb +5 -5
  21. data/lib/puppet/face/module/generate.rb +6 -4
  22. data/lib/puppet/face/module/install.rb +122 -32
  23. data/lib/puppet/face/module/list.rb +234 -33
  24. data/lib/puppet/face/module/search.rb +56 -23
  25. data/lib/puppet/face/module/uninstall.rb +33 -38
  26. data/lib/puppet/face/module/upgrade.rb +84 -0
  27. data/lib/puppet/feature/eventlog.rb +6 -0
  28. data/lib/puppet/forge.rb +67 -122
  29. data/lib/puppet/forge/cache.rb +1 -1
  30. data/lib/puppet/forge/repository.rb +6 -25
  31. data/lib/puppet/indirector/facts/network_device.rb +1 -1
  32. data/lib/puppet/interface/action.rb +1 -1
  33. data/lib/puppet/module.rb +79 -28
  34. data/lib/puppet/module_tool.rb +72 -34
  35. data/lib/puppet/module_tool/applications.rb +12 -14
  36. data/lib/puppet/module_tool/applications/application.rb +21 -19
  37. data/lib/puppet/module_tool/applications/builder.rb +4 -4
  38. data/lib/puppet/module_tool/applications/checksummer.rb +12 -3
  39. data/lib/puppet/module_tool/applications/generator.rb +1 -1
  40. data/lib/puppet/module_tool/applications/installer.rb +163 -34
  41. data/lib/puppet/module_tool/applications/searcher.rb +2 -3
  42. data/lib/puppet/module_tool/applications/uninstaller.rb +84 -36
  43. data/lib/puppet/module_tool/applications/unpacker.rb +4 -26
  44. data/lib/puppet/module_tool/applications/upgrader.rb +109 -0
  45. data/lib/puppet/module_tool/checksums.rb +2 -2
  46. data/lib/puppet/module_tool/contents_description.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +2 -2
  48. data/lib/puppet/module_tool/errors.rb +9 -0
  49. data/lib/puppet/module_tool/errors/base.rb +15 -0
  50. data/lib/puppet/module_tool/errors/installer.rb +90 -0
  51. data/lib/puppet/module_tool/errors/shared.rb +115 -0
  52. data/lib/puppet/module_tool/errors/uninstaller.rb +45 -0
  53. data/lib/puppet/module_tool/errors/upgrader.rb +72 -0
  54. data/lib/puppet/module_tool/metadata.rb +2 -2
  55. data/lib/puppet/module_tool/modulefile.rb +7 -7
  56. data/lib/puppet/module_tool/shared_behaviors.rb +161 -0
  57. data/lib/puppet/module_tool/skeleton.rb +1 -1
  58. data/lib/puppet/node/environment.rb +4 -2
  59. data/lib/puppet/parser/ast/leaf.rb +1 -1
  60. data/lib/puppet/parser/functions/create_resources.rb +3 -2
  61. data/lib/puppet/parser/scope.rb +44 -9
  62. data/lib/puppet/provider/augeas/augeas.rb +2 -2
  63. data/lib/puppet/provider/exec.rb +8 -3
  64. data/lib/puppet/provider/exec/shell.rb +1 -2
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +10 -4
  66. data/lib/puppet/provider/package/gem.rb +1 -1
  67. data/lib/puppet/provider/package/pkg.rb +10 -21
  68. data/lib/puppet/provider/selmodule/semodule.rb +1 -2
  69. data/lib/puppet/provider/service/upstart.rb +33 -17
  70. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  71. data/lib/puppet/rails/inventory_node.rb +7 -7
  72. data/lib/puppet/reports/http.rb +4 -1
  73. data/lib/puppet/reports/tagmail.rb +8 -1
  74. data/lib/puppet/resource/type.rb +1 -1
  75. data/lib/puppet/test/test_helper.rb +138 -0
  76. data/lib/puppet/type.rb +9 -1
  77. data/lib/puppet/type/file.rb +18 -10
  78. data/lib/puppet/type/package.rb +13 -9
  79. data/lib/puppet/type/resources.rb +1 -1
  80. data/lib/puppet/type/ssh_authorized_key.rb +3 -4
  81. data/lib/puppet/type/sshkey.rb +4 -4
  82. data/lib/puppet/type/user.rb +1 -0
  83. data/lib/puppet/type/vlan.rb +1 -1
  84. data/lib/puppet/util.rb +31 -14
  85. data/lib/puppet/util/autoload.rb +1 -1
  86. data/lib/puppet/util/command_line.rb +2 -6
  87. data/lib/puppet/util/instrumentation/indirection_probe.rb +1 -1
  88. data/lib/puppet/util/instrumentation/instrumentable.rb +1 -1
  89. data/lib/puppet/util/instrumentation/listeners/log.rb +1 -1
  90. data/lib/puppet/util/instrumentation/listeners/performance.rb +1 -1
  91. data/lib/puppet/util/log.rb +3 -1
  92. data/lib/puppet/util/log/destinations.rb +38 -0
  93. data/lib/puppet/util/monkey_patches.rb +45 -0
  94. data/lib/puppet/util/network_device/base.rb +1 -1
  95. data/lib/puppet/util/network_device/cisco.rb +1 -1
  96. data/lib/puppet/util/network_device/cisco/facts.rb +1 -1
  97. data/lib/puppet/util/network_device/cisco/interface.rb +1 -1
  98. data/lib/puppet/util/network_device/config.rb +1 -1
  99. data/lib/puppet/util/network_device/ipcalc.rb +1 -1
  100. data/lib/puppet/util/network_device/transport.rb +1 -1
  101. data/lib/puppet/util/network_device/transport/base.rb +1 -1
  102. data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
  103. data/lib/puppet/util/settings.rb +2 -11
  104. data/lib/puppet/util/settings/file_setting.rb +3 -5
  105. data/lib/puppet/util/terminal.rb +16 -0
  106. data/lib/puppet/util/zaml.rb +3 -1
  107. data/lib/semver.rb +15 -7
  108. data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -1
  109. data/spec/fixtures/unit/parser/lexer/arithmetic_expression.pp +1 -1
  110. data/spec/fixtures/unit/provider/package/pkg/dummy +1 -0
  111. data/spec/fixtures/unit/provider/package/pkg/incomplete +1 -0
  112. data/spec/fixtures/unit/provider/package/pkg/publisher +2 -0
  113. data/spec/fixtures/unit/provider/package/pkg/simple +4 -0
  114. data/spec/fixtures/unit/reports/tagmail/tagmail_email.conf +2 -0
  115. data/spec/fixtures/yaml/report0.25.x.yaml +1 -1
  116. data/spec/fixtures/yaml/report2.6.x.yaml +1 -1
  117. data/spec/integration/faces/documentation_spec.rb +1 -1
  118. data/spec/integration/network/rest_authconfig_spec.rb +1 -1
  119. data/spec/lib/puppet_spec/compiler.rb +6 -0
  120. data/spec/lib/puppet_spec/database.rb +30 -0
  121. data/spec/lib/puppet_spec/files.rb +4 -2
  122. data/spec/shared_behaviours/path_parameters.rb +2 -29
  123. data/spec/shared_contexts/platform.rb +43 -0
  124. data/spec/spec_helper.rb +36 -65
  125. data/spec/unit/agent_spec.rb +0 -32
  126. data/spec/unit/application/kick_spec.rb +2 -2
  127. data/spec/unit/daemon_spec.rb +1 -17
  128. data/spec/unit/face/module/install_spec.rb +158 -0
  129. data/spec/unit/face/module/list_spec.rb +182 -0
  130. data/spec/unit/face/module/search_spec.rb +163 -0
  131. data/spec/unit/face/module/uninstall_spec.rb +77 -0
  132. data/spec/unit/face/module/upgrade_spec.rb +26 -0
  133. data/spec/unit/forge/repository_spec.rb +0 -30
  134. data/spec/unit/forge_spec.rb +28 -86
  135. data/spec/unit/indirector/catalog/active_record_spec.rb +45 -65
  136. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +5 -18
  137. data/spec/unit/indirector/resource/active_record_spec.rb +2 -11
  138. data/spec/unit/indirector/resource/ral_spec.rb +7 -2
  139. data/spec/unit/module_spec.rb +240 -107
  140. data/spec/unit/module_tool/application_spec.rb +3 -5
  141. data/spec/unit/module_tool/applications/application_spec.rb +19 -0
  142. data/spec/unit/module_tool/applications/installer_spec.rb +205 -0
  143. data/spec/unit/module_tool/applications/uninstaller_spec.rb +206 -0
  144. data/spec/unit/module_tool/applications/upgrader_spec.rb +37 -0
  145. data/spec/unit/module_tool/metadata_spec.rb +2 -2
  146. data/spec/unit/module_tool_spec.rb +109 -1
  147. data/spec/unit/node/environment_spec.rb +16 -1
  148. data/spec/unit/parser/ast/leaf_spec.rb +16 -1
  149. data/spec/unit/parser/collector_spec.rb +2 -12
  150. data/spec/unit/parser/functions/create_resources_spec.rb +135 -86
  151. data/spec/unit/parser/functions/generate_spec.rb +2 -10
  152. data/spec/unit/parser/scope_spec.rb +345 -16
  153. data/spec/unit/provider/augeas/augeas_spec.rb +19 -0
  154. data/spec/unit/provider/exec/shell_spec.rb +17 -14
  155. data/spec/unit/provider/exec/windows_spec.rb +1 -7
  156. data/spec/unit/provider/exec_spec.rb +35 -0
  157. data/spec/unit/provider/nameservice/directoryservice_spec.rb +10 -0
  158. data/spec/unit/provider/package/dpkg_spec.rb +2 -1
  159. data/spec/unit/provider/package/gem_spec.rb +15 -0
  160. data/spec/unit/provider/package/openbsd_spec.rb +5 -4
  161. data/spec/unit/provider/package/pacman_spec.rb +3 -2
  162. data/spec/unit/provider/package/pkg_spec.rb +56 -33
  163. data/spec/unit/provider/selmodule_spec.rb +11 -4
  164. data/spec/unit/provider/service/redhat_spec.rb +1 -3
  165. data/spec/unit/provider/service/smf_spec.rb +1 -3
  166. data/spec/unit/provider/service/upstart_spec.rb +38 -0
  167. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +28 -0
  168. data/spec/unit/rails/host_spec.rb +6 -12
  169. data/spec/unit/rails/param_value_spec.rb +3 -8
  170. data/spec/unit/rails/resource_spec.rb +2 -8
  171. data/spec/unit/reports/http_spec.rb +47 -31
  172. data/spec/unit/reports/tagmail_spec.rb +77 -0
  173. data/spec/unit/resource/type_spec.rb +2 -2
  174. data/spec/unit/resource_spec.rb +18 -20
  175. data/spec/unit/semver_spec.rb +31 -13
  176. data/spec/unit/type/exec_spec.rb +8 -15
  177. data/spec/unit/type/group_spec.rb +0 -9
  178. data/spec/unit/type/package_spec.rb +10 -0
  179. data/spec/unit/type/resources_spec.rb +4 -5
  180. data/spec/unit/type/ssh_authorized_key_spec.rb +4 -15
  181. data/spec/unit/type/sshkey_spec.rb +9 -11
  182. data/spec/unit/type/user_spec.rb +123 -127
  183. data/spec/unit/type_spec.rb +20 -0
  184. data/spec/unit/util/command_line_spec.rb +2 -2
  185. data/spec/unit/util/instrumentation/data_spec.rb +1 -1
  186. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +1 -1
  187. data/spec/unit/util/instrumentation/instrumentable_spec.rb +1 -1
  188. data/spec/unit/util/instrumentation/listener_spec.rb +1 -1
  189. data/spec/unit/util/instrumentation/listeners/log_spec.rb +1 -1
  190. data/spec/unit/util/instrumentation/listeners/performance_spec.rb +1 -1
  191. data/spec/unit/util/instrumentation_spec.rb +1 -1
  192. data/spec/unit/util/log/destinations_spec.rb +4 -8
  193. data/spec/unit/util/log_spec.rb +47 -0
  194. data/spec/unit/util/reference_spec.rb +1 -1
  195. data/spec/unit/util/settings/file_setting_spec.rb +9 -0
  196. data/spec/unit/util/settings_spec.rb +0 -53
  197. data/spec/unit/util/terminal_spec.rb +42 -0
  198. data/spec/unit/util/zaml_spec.rb +7 -0
  199. data/spec/unit/util_spec.rb +63 -20
  200. data/tasks/rake/manpages.rake +1 -1
  201. data/test/data/snippets/arithmetic_expression.pp +1 -1
  202. data/test/other/puppet.rb +0 -1
  203. data/test/util/log.rb +6 -6
  204. metadata +41 -16
  205. data/lib/puppet/external/event-loop.rb +0 -1
  206. data/lib/puppet/external/event-loop/better-definers.rb +0 -367
  207. data/lib/puppet/external/event-loop/event-loop.rb +0 -355
  208. data/lib/puppet/external/event-loop/signal-system.rb +0 -218
  209. data/lib/puppet/face/module/clean.rb +0 -30
  210. data/lib/puppet/module_tool/applications/cleaner.rb +0 -16
  211. data/lib/puppet/module_tool/skeleton/templates/generator/metadata.json +0 -12
  212. data/lib/puppet/module_tool/utils.rb +0 -5
  213. data/lib/puppet/module_tool/utils/interrogation.rb +0 -25
  214. data/spec/integration/module_tool_spec.rb +0 -475
  215. data/spec/unit/module_tool/uninstaller_spec.rb +0 -124
@@ -1,20 +1,19 @@
1
1
  require 'pathname'
2
2
  require 'tmpdir'
3
3
 
4
- module Puppet::Module::Tool
4
+ module Puppet::ModuleTool
5
5
  module Applications
6
6
  class Unpacker < Application
7
7
 
8
8
  def initialize(filename, options = {})
9
9
  @filename = Pathname.new(filename)
10
- parse_filename!
10
+ parsed = parse_filename(filename)
11
11
  super(options)
12
- @module_dir = Pathname.new(options[:install_dir]) + @module_name
12
+ @module_dir = Pathname.new(options[:target_dir]) + parsed[:dir_name]
13
13
  end
14
14
 
15
15
  def run
16
16
  extract_module_to_install_dir
17
- tag_revision
18
17
 
19
18
  # Return the Pathname object representing the directory where the
20
19
  # module release archive was unpacked the to, and the module release
@@ -23,23 +22,12 @@ module Puppet::Module::Tool
23
22
  end
24
23
 
25
24
  private
26
-
27
- def tag_revision
28
- File.open("#{@module_dir}/REVISION", 'w') do |f|
29
- f.puts "module: #{@username}/#{@module_name}"
30
- f.puts "version: #{@version}"
31
- f.puts "url: file://#{@filename.expand_path}"
32
- f.puts "installed: #{Time.now}"
33
- end
34
- end
35
-
36
25
  def extract_module_to_install_dir
37
26
  delete_existing_installation_or_abort!
38
27
 
39
28
  build_dir = Puppet::Forge::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}"
40
29
  build_dir.mkpath
41
30
  begin
42
- Puppet.notice "Installing #{@filename.basename} to #{@module_dir.expand_path}"
43
31
  unless system "tar xzf #{@filename} -C #{build_dir}"
44
32
  raise RuntimeError, "Could not extract contents of module archive."
45
33
  end
@@ -53,17 +41,7 @@ module Puppet::Module::Tool
53
41
 
54
42
  def delete_existing_installation_or_abort!
55
43
  return unless @module_dir.exist?
56
-
57
- if !options[:force]
58
- Puppet.warning "Existing module '#{@module_dir.expand_path}' found"
59
- response = prompt "Overwrite module installed at #{@module_dir.expand_path}? [y/N]"
60
- unless response =~ /y/i
61
- raise RuntimeError, "Aborted installation."
62
- end
63
- end
64
-
65
- Puppet.warning "Deleting #{@module_dir.expand_path}"
66
- FileUtils.rm_rf @module_dir
44
+ FileUtils.rm_rf(@module_dir, :secure => true)
67
45
  end
68
46
  end
69
47
  end
@@ -0,0 +1,109 @@
1
+ module Puppet::ModuleTool
2
+ module Applications
3
+ class Upgrader < Application
4
+
5
+ include Puppet::ModuleTool::Errors
6
+
7
+ def initialize(name, options)
8
+ @action = :upgrade
9
+ @environment = Puppet::Node::Environment.new(Puppet.settings[:environment])
10
+ @module_name = name
11
+ @options = options
12
+ @force = options[:force]
13
+ @ignore_dependencies = options[:force] || options[:ignore_dependencies]
14
+ @version = options[:version]
15
+ end
16
+
17
+ def run
18
+ begin
19
+ results = { :module_name => @module_name }
20
+
21
+ get_local_constraints
22
+
23
+ if @installed[@module_name].length > 1
24
+ raise MultipleInstalledError,
25
+ :action => :upgrade,
26
+ :module_name => @module_name,
27
+ :installed_modules => @installed[@module_name].sort_by { |mod| @environment.modulepath.index(mod.modulepath) }
28
+ elsif @installed[@module_name].empty?
29
+ raise NotInstalledError,
30
+ :action => :upgrade,
31
+ :module_name => @module_name
32
+ end
33
+
34
+ @module = @installed[@module_name].last
35
+ results[:installed_version] = @module.version ? @module.version.sub(/^(?=\d)/, 'v') : nil
36
+ results[:requested_version] = @version || (@conditions[@module_name].empty? ? :latest : :best)
37
+ dir = @module.modulepath
38
+
39
+ Puppet.notice "Found '#{@module_name}' (#{colorize(:cyan, results[:installed_version] || '???')}) in #{dir} ..."
40
+ if !@options[:force] && @module.has_metadata? && @module.has_local_changes?
41
+ raise LocalChangesError,
42
+ :action => :upgrade,
43
+ :module_name => @module_name,
44
+ :requested_version => @version || (@conditions[@module_name].empty? ? :latest : :best),
45
+ :installed_version => @module.version
46
+ end
47
+
48
+ begin
49
+ get_remote_constraints
50
+ rescue => e
51
+ raise UnknownModuleError, results.merge(:repository => Puppet::Forge.repository.uri)
52
+ else
53
+ raise UnknownVersionError, results.merge(:repository => Puppet::Forge.repository.uri) if @remote.empty?
54
+ end
55
+
56
+ if !@options[:force] && @versions["#{@module_name}"].last[:vstring].sub(/^(?=\d)/, 'v') == (@module.version || '0.0.0').sub(/^(?=\d)/, 'v')
57
+ raise VersionAlreadyInstalledError,
58
+ :module_name => @module_name,
59
+ :requested_version => @version || ((@conditions[@module_name].empty? ? 'latest' : 'best') + ": #{@versions["#{@module_name}"].last[:vstring].sub(/^(?=\d)/, 'v')}"),
60
+ :installed_version => @installed[@module_name].last.version,
61
+ :conditions => @conditions[@module_name] + [{ :module => :you, :version => @version }]
62
+ end
63
+
64
+ @graph = resolve_constraints({ @module_name => @version })
65
+
66
+ # This clean call means we never "cache" the module we're installing, but this
67
+ # is desired since module authors can easily rerelease modules different content but the same
68
+ # version number, meaning someone with the old content cached will be very confused as to why
69
+ # they can't get new content.
70
+ # Long term we should just get rid of this caching behavior and cleanup downloaded modules after they install
71
+ # but for now this is a quick fix to disable caching
72
+ Puppet::Forge::Cache.clean
73
+ tarballs = download_tarballs(@graph, @graph.last[:path])
74
+
75
+ unless @graph.empty?
76
+ Puppet.notice 'Upgrading -- do not interrupt ...'
77
+ tarballs.each do |hash|
78
+ hash.each do |dir, path|
79
+ Unpacker.new(path, @options.merge(:target_dir => dir)).run
80
+ end
81
+ end
82
+ end
83
+
84
+ results[:result] = :success
85
+ results[:base_dir] = @graph.first[:path]
86
+ results[:affected_modules] = @graph
87
+ rescue VersionAlreadyInstalledError => e
88
+ results[:result] = :noop
89
+ results[:error] = {
90
+ :oneline => e.message,
91
+ :multiline => e.multiline
92
+ }
93
+ rescue => e
94
+ results[:error] = {
95
+ :oneline => e.message,
96
+ :multiline => e.respond_to?(:multiline) ? e.multiline : [e.to_s, e.backtrace].join("\n")
97
+ }
98
+ ensure
99
+ results[:result] ||= :failure
100
+ end
101
+
102
+ return results
103
+ end
104
+
105
+ private
106
+ include Puppet::ModuleTool::Shared
107
+ end
108
+ end
109
+ end
@@ -1,6 +1,6 @@
1
1
  require 'digest/md5'
2
2
 
3
- module Puppet::Module::Tool
3
+ module Puppet::ModuleTool
4
4
 
5
5
  # = Checksums
6
6
  #
@@ -25,7 +25,7 @@ module Puppet::Module::Tool
25
25
  unless @data
26
26
  @data = {}
27
27
  @path.find do |descendant|
28
- if Puppet::Module::Tool.artifact?(descendant)
28
+ if Puppet::ModuleTool.artifact?(descendant)
29
29
  Find.prune
30
30
  elsif descendant.file?
31
31
  path = descendant.relative_path_from(@path)
@@ -1,4 +1,4 @@
1
- module Puppet::Module::Tool
1
+ module Puppet::ModuleTool
2
2
 
3
3
  # = ContentsDescription
4
4
  #
@@ -1,4 +1,4 @@
1
- module Puppet::Module::Tool
1
+ module Puppet::ModuleTool
2
2
 
3
3
  class Dependency
4
4
 
@@ -8,7 +8,7 @@ module Puppet::Module::Tool
8
8
  def initialize(full_module_name, version_requirement = nil, repository = nil)
9
9
  @full_module_name = full_module_name
10
10
  # TODO: add error checking, the next line raises ArgumentError when +full_module_name+ is invalid
11
- @username, @name = Puppet::Module::Tool.username_and_modname_from(full_module_name)
11
+ @username, @name = Puppet::ModuleTool.username_and_modname_from(full_module_name)
12
12
  @version_requirement = version_requirement
13
13
  @repository = repository ? Puppet::Forge::Repository.new(repository) : nil
14
14
  end
@@ -0,0 +1,9 @@
1
+ module Puppet::ModuleTool
2
+ module Errors
3
+ require 'puppet/module_tool/errors/base'
4
+ require 'puppet/module_tool/errors/installer'
5
+ require 'puppet/module_tool/errors/uninstaller'
6
+ require 'puppet/module_tool/errors/upgrader'
7
+ require 'puppet/module_tool/errors/shared'
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Puppet::ModuleTool::Errors
2
+ class ModuleToolError < StandardError
3
+ def v(version)
4
+ (version || '???').to_s.sub(/^(?=\d)/, 'v')
5
+ end
6
+
7
+ def vstring
8
+ if @action == :upgrade
9
+ "#{v(@installed_version)} -> #{v(@requested_version)}"
10
+ else
11
+ "#{v(@installed_version || @requested_version)}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,90 @@
1
+ module Puppet::ModuleTool::Errors
2
+
3
+ class InstallError < ModuleToolError; end
4
+
5
+ class AlreadyInstalledError < InstallError
6
+ def initialize(options)
7
+ @module_name = options[:module_name]
8
+ @installed_version = v(options[:installed_version])
9
+ @requested_version = v(options[:requested_version])
10
+ @local_changes = options[:local_changes]
11
+ super "'#{@module_name}' (#{@requested_version}) requested; '#{@module_name}' (#{@installed_version}) already installed"
12
+ end
13
+
14
+ def multiline
15
+ message = []
16
+ message << "Could not install module '#{@module_name}' (#{@requested_version})"
17
+ message << " Module '#{@module_name}' (#{@installed_version}) is already installed"
18
+ message << " Installed module has had changes made locally" unless @local_changes.empty?
19
+ message << " Use `puppet module upgrade` to install a different version"
20
+ message << " Use `puppet module install --force` to re-install only this module"
21
+ message.join("\n")
22
+ end
23
+ end
24
+
25
+ class InstallConflictError < InstallError
26
+ def initialize(options)
27
+ @requested_module = options[:requested_module]
28
+ @requested_version = v(options[:requested_version])
29
+ @dependency = options[:dependency]
30
+ @directory = options[:directory]
31
+ @metadata = options[:metadata]
32
+ super "'#{@requested_module}' (#{@requested_version}) requested; Installation conflict"
33
+ end
34
+
35
+ def multiline
36
+ message = []
37
+ message << "Could not install module '#{@requested_module}' (#{@requested_version})"
38
+
39
+ if @dependency
40
+ message << " Dependency '#{@dependency[:name]}' (#{v(@dependency[:version])}) would overwrite #{@directory}"
41
+ else
42
+ message << " Installation would overwrite #{@directory}"
43
+ end
44
+
45
+ if @metadata
46
+ message << " Currently, '#{@metadata[:name]}' (#{v(@metadata[:version])}) is installed to that directory"
47
+ end
48
+
49
+ message << " Use `puppet module install --dir <DIR>` to install modules elsewhere"
50
+
51
+ if @dependency
52
+ message << " Use `puppet module install --ignore-dependencies` to install only this module"
53
+ else
54
+ message << " Use `puppet module install --force` to install this module anyway"
55
+ end
56
+
57
+ message.join("\n")
58
+ end
59
+ end
60
+
61
+ class MissingPackageError < InstallError
62
+ def initialize(options)
63
+ @requested_package = options[:requested_package]
64
+ super "#{@requested_package} requested; Package #{@requested_package} does not exist"
65
+ end
66
+
67
+ def multiline
68
+ <<-MSG.strip
69
+ Could not install package #{@requested_package}
70
+ Package #{@requested_package} does not exist
71
+ MSG
72
+ end
73
+ end
74
+
75
+ class MissingInstallDirectoryError < InstallError
76
+ def initialize(options)
77
+ @requested_module = options[:requested_module]
78
+ @requested_version = options[:requested_version]
79
+ @directory = options[:directory]
80
+ super "'#{@requested_module}' (#{@requested_version}) requested; Directory #{@directory} does not exist"
81
+ end
82
+
83
+ def multiline
84
+ <<-MSG.strip
85
+ Could not install module '#{@requested_module}' (#{@requested_version})
86
+ Directory #{@directory} does not exist
87
+ MSG
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,115 @@
1
+ module Puppet::ModuleTool::Errors
2
+
3
+ class NoVersionsSatisfyError < ModuleToolError
4
+ def initialize(options)
5
+ @requested_name = options[:requested_name]
6
+ @requested_version = options[:requested_version]
7
+ @installed_version = options[:installed_version]
8
+ @dependency_name = options[:dependency_name]
9
+ @conditions = options[:conditions]
10
+ @action = options[:action]
11
+
12
+ super "Could not #{@action} '#{@requested_name}' (#{vstring}); module '#{@dependency_name}' cannot satisfy dependencies"
13
+ end
14
+
15
+ def multiline
16
+ same_mod = @requested_name == @dependency_name
17
+
18
+ message = []
19
+ message << "Could not #{@action} module '#{@requested_name}' (#{vstring})"
20
+ message << " No version of '#{@dependency_name}' will satisfy dependencies"
21
+ message << " You specified '#{@requested_name}' (#{v(@requested_version)})" if same_mod
22
+ message += @conditions.select { |c| c[:module] != :you }.sort_by { |c| c[:module] }.map do |c|
23
+ " '#{c[:module]}' (#{v(c[:version])}) requires '#{@dependency_name}' (#{v(c[:dependency])})"
24
+ end
25
+ message << " Use `puppet module #{@action} --force` to #{@action} this module anyway" if same_mod
26
+ message << " Use `puppet module #{@action} --ignore-dependencies` to #{@action} only this module" unless same_mod
27
+
28
+ message.join("\n")
29
+ end
30
+ end
31
+
32
+ class InvalidDependencyCycleError < ModuleToolError
33
+ def initialize(options)
34
+ @module_name = options[:module_name]
35
+ @requested_module = options[:requested_module]
36
+ @requested_version = options[:requested_version]
37
+ @conditions = options[:conditions]
38
+ @source = options[:source][1..-1]
39
+
40
+ super "'#{@requested_module}' (#{v(@requested_version)}) requested; Invalid dependency cycle"
41
+ end
42
+
43
+ def multiline
44
+ trace = []
45
+ trace << "You specified '#{@source.first[:name]}' (#{v(@requested_version)})"
46
+ trace += @source[1..-1].map { |m| "which depends on '#{m[:name]}' (#{v(m[:version])})" }
47
+
48
+ message = []
49
+ message << "Could not install module '#{@requested_module}' (#{v(@requested_version)})"
50
+ message << " No version of '#{@module_name}' will satisfy dependencies"
51
+ message << trace.map { |s| " #{s}" }.join(",\n")
52
+ message << " Use `puppet module install --force` to install this module anyway"
53
+
54
+ message.join("\n")
55
+ end
56
+ end
57
+
58
+ class NotInstalledError < ModuleToolError
59
+ def initialize(options)
60
+ @module_name = options[:module_name]
61
+ @suggestions = options[:suggestions] || []
62
+ @action = options[:action]
63
+ super "Could not #{@action} '#{@module_name}'; module is not installed"
64
+ end
65
+
66
+ def multiline
67
+ message = []
68
+ message << "Could not #{@action} module '#{@module_name}'"
69
+ message << " Module '#{@module_name}' is not installed"
70
+ message += @suggestions.map do |suggestion|
71
+ " You may have meant `puppet module #{@action} #{suggestion}`"
72
+ end
73
+ message << " Use `puppet module install` to install this module" if @action == :upgrade
74
+ message.join("\n")
75
+ end
76
+ end
77
+
78
+ class MultipleInstalledError < ModuleToolError
79
+ def initialize(options)
80
+ @module_name = options[:module_name]
81
+ @modules = options[:installed_modules]
82
+ @action = options[:action]
83
+ super "Could not #{@action} '#{@module_name}'; module appears in multiple places in the module path"
84
+ end
85
+
86
+ def multiline
87
+ message = []
88
+ message << "Could not #{@action} module '#{@module_name}'"
89
+ message << " Module '#{@module_name}' appears multiple places in the module path"
90
+ message += @modules.map do |mod|
91
+ " '#{@module_name}' (#{v(mod.version)}) was found in #{mod.modulepath}"
92
+ end
93
+ message << " Use the `--modulepath` option to limit the search to specific directories"
94
+ message.join("\n")
95
+ end
96
+ end
97
+
98
+ class LocalChangesError < ModuleToolError
99
+ def initialize(options)
100
+ @module_name = options[:module_name]
101
+ @requested_version = options[:requested_version]
102
+ @installed_version = options[:installed_version]
103
+ @action = options[:action]
104
+ super "Could not #{@action} '#{@module_name}'; module is not installed"
105
+ end
106
+
107
+ def multiline
108
+ message = []
109
+ message << "Could not #{@action} module '#{@module_name}' (#{vstring})"
110
+ message << " Installed module has had changes made locally"
111
+ message << " Use `puppet module #{@action} --force` to #{@action} this module anyway"
112
+ message.join("\n")
113
+ end
114
+ end
115
+ end