puppet 2.7.22 → 2.7.23

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 (55) hide show
  1. data/CHANGELOG +21 -0
  2. data/Rakefile +0 -2
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/packaging/README.md +88 -33
  5. data/ext/packaging/packaging.rake +45 -0
  6. data/ext/packaging/spec/tasks/build_object_spec.rb +2 -0
  7. data/ext/packaging/tasks/00_utils.rake +94 -54
  8. data/ext/packaging/tasks/10_setupvars.rake +40 -28
  9. data/ext/packaging/tasks/apple.rake +20 -27
  10. data/ext/packaging/tasks/build.rake +3 -8
  11. data/ext/packaging/tasks/deb.rake +12 -36
  12. data/ext/packaging/tasks/deb_repos.rake +28 -36
  13. data/ext/packaging/tasks/fetch.rake +1 -2
  14. data/ext/packaging/tasks/jenkins.rake +22 -56
  15. data/ext/packaging/tasks/jenkins_dynamic.rake +111 -0
  16. data/ext/packaging/tasks/mock.rake +101 -56
  17. data/ext/packaging/tasks/pe_deb.rake +5 -7
  18. data/ext/packaging/tasks/pe_remote.rake +30 -42
  19. data/ext/packaging/tasks/pe_rpm.rake +3 -11
  20. data/ext/packaging/tasks/pe_ship.rake +14 -18
  21. data/ext/packaging/tasks/pe_sign.rake +11 -0
  22. data/ext/packaging/tasks/pe_tar.rake +1 -1
  23. data/ext/packaging/tasks/release.rake +0 -6
  24. data/ext/packaging/tasks/remote_build.rake +1 -13
  25. data/ext/packaging/tasks/retrieve.rake +1 -1
  26. data/ext/packaging/tasks/rpm.rake +15 -10
  27. data/ext/packaging/tasks/rpm_repos.rake +45 -56
  28. data/ext/packaging/tasks/ship.rake +46 -37
  29. data/ext/packaging/tasks/sign.rake +22 -14
  30. data/ext/packaging/tasks/tar.rake +1 -1
  31. data/ext/packaging/tasks/template.rake +1 -1
  32. data/ext/packaging/templates/README +1 -0
  33. data/ext/packaging/templates/downstream.xml.erb +32 -0
  34. data/ext/packaging/templates/packaging.xml.erb +182 -0
  35. data/ext/packaging/templates/repo.xml.erb +93 -0
  36. data/lib/puppet.rb +2 -0
  37. data/lib/puppet/file_system.rb +3 -0
  38. data/lib/puppet/file_system/path_pattern.rb +97 -0
  39. data/lib/puppet/module.rb +25 -4
  40. data/lib/puppet/module_tool/applications/unpacker.rb +5 -1
  41. data/lib/puppet/parser/files.rb +20 -15
  42. data/lib/puppet/parser/parser_support.rb +10 -1
  43. data/lib/puppet/parser/type_loader.rb +48 -28
  44. data/lib/puppet/version.rb +1 -1
  45. data/spec/unit/file_system/path_pattern_spec.rb +139 -0
  46. data/spec/unit/module_spec.rb +8 -1
  47. data/spec/unit/module_tool/applications/unpacker_spec.rb +6 -0
  48. data/spec/unit/parser/files_spec.rb +6 -67
  49. data/spec/unit/parser/parser_spec.rb +15 -5
  50. data/spec/unit/parser/type_loader_spec.rb +14 -33
  51. data/spec/unit/resource/type_collection_spec.rb +39 -55
  52. metadata +11 -5
  53. data/Gemfile.lock +0 -44
  54. data/ext/packaging/tasks/pe_sles.rake +0 -101
  55. data/ext/packaging/tasks/pre_tasks.rake +0 -0
@@ -11,6 +11,7 @@ class Puppet::Module
11
11
  class IncompatiblePlatform < Error; end
12
12
  class MissingMetadata < Error; end
13
13
  class InvalidName < Error; end
14
+ class InvalidFilePattern < Error; end
14
15
 
15
16
  include Puppet::Util::Logging
16
17
 
@@ -138,10 +139,16 @@ class Puppet::Module
138
139
  # Return the list of manifests matching the given glob pattern,
139
140
  # defaulting to 'init.{pp,rb}' for empty modules.
140
141
  def match_manifests(rest)
141
- pat = File.join(path, MANIFESTS, rest || 'init')
142
- [manifest("init.pp"),manifest("init.rb")].compact + Dir.
143
- glob(pat + (File.extname(pat).empty? ? '.{pp,rb}' : '')).
144
- reject { |f| FileTest.directory?(f) }
142
+ if rest
143
+ wanted_manifests = wanted_manifests_from(rest)
144
+ searched_manifests = wanted_manifests.glob.reject { |f| FileTest.directory?(f) }
145
+ else
146
+ searched_manifests = []
147
+ end
148
+
149
+ # (#4220) Always ensure init.pp in case class is defined there.
150
+ init_manifests = [manifest("init.pp"), manifest("init.rb")].compact
151
+ init_manifests + searched_manifests
145
152
  end
146
153
 
147
154
  def metadata_file
@@ -286,6 +293,20 @@ class Puppet::Module
286
293
 
287
294
  private
288
295
 
296
+ def wanted_manifests_from(pattern)
297
+ begin
298
+ extended = File.extname(pattern).empty? ? "#{pattern}.{pp,rb}" : pattern
299
+ relative_pattern = Puppet::FileSystem::PathPattern.relative(extended)
300
+ rescue Puppet::FileSystem::PathPattern::InvalidPattern => error
301
+ raise Puppet::Module::InvalidFilePattern.new(
302
+ "The pattern \"#{pattern}\" to find manifests in the module \"#{name}\" " +
303
+ "is invalid and potentially unsafe.", error)
304
+ end
305
+
306
+ absolute_path_to_manifests = Puppet::FileSystem::PathPattern.absolute(subpath(MANIFESTS))
307
+ relative_pattern.prefix_with(absolute_path_to_manifests)
308
+ end
309
+
289
310
  def subpath(type)
290
311
  return File.join(path, type) unless type.to_s == "plugins"
291
312
 
@@ -9,7 +9,8 @@ module Puppet::ModuleTool
9
9
  @filename = Pathname.new(filename)
10
10
  parsed = parse_filename(filename)
11
11
  super(options)
12
- @module_dir = Pathname.new(options[:target_dir]) + parsed[:dir_name]
12
+ @module_path = Pathname(options[:target_dir])
13
+ @module_dir = @module_path + parsed[:dir_name]
13
14
  end
14
15
 
15
16
  def run
@@ -46,6 +47,9 @@ module Puppet::ModuleTool
46
47
  else
47
48
  Puppet::Util.execute("tar xzf #{@filename} -C #{build_dir}")
48
49
  end
50
+ Puppet::Util.execute("find #{build_dir} -type d -exec chmod 755 {} +")
51
+ Puppet::Util.execute("find #{build_dir} -type f -exec chmod 644 {} +")
52
+ Puppet::Util.execute("chown -R #{@module_path.stat.uid}:#{@module_path.stat.gid} #{build_dir}")
49
53
  rescue Puppet::ExecutionFailure => e
50
54
  raise RuntimeError, "Could not extract contents of module archive: #{e.message}"
51
55
  end
@@ -8,23 +8,25 @@ require 'puppet/parser/parser'
8
8
  module Puppet::Parser::Files
9
9
  module_function
10
10
 
11
- # Return a list of manifests (as absolute filenames) that match +pat+
12
- # with the current directory set to +cwd+. If the first component of
13
- # +pat+ does not contain any wildcards and is an existing module, return
14
- # a list of manifests in that module matching the rest of +pat+
15
- # Otherwise, try to find manifests matching +pat+ relative to +cwd+
16
- def find_manifests(start, options = {})
17
- cwd = options[:cwd] || Dir.getwd
18
- module_name, pattern = split_file_path(start)
11
+ # Return a list of manifests as absolute filenames matching the given
12
+ # pattern.
13
+ #
14
+ # @param pattern [String] A reference for a file in a module. It is the format "<modulename>/<file glob>"
15
+ # @param environment [Puppet::Node::Environment] the environment of modules
16
+ #
17
+ # @return [Array(String, Array<String>)] the module name and the list of files found
18
+ # @api private
19
+ def find_manifests_in_modules(pattern, environment)
20
+ module_name, file_pattern = split_file_path(pattern)
19
21
  begin
20
- if mod = Puppet::Module.find(module_name, options[:environment])
21
- return [mod.name, mod.match_manifests(pattern)]
22
+ if mod = Puppet::Module.find(module_name, environment)
23
+ return [mod.name, mod.match_manifests(file_pattern)]
22
24
  end
23
25
  rescue Puppet::Module::InvalidName
24
- # Than that would be a "no."
26
+ # one of the modules being loaded might have an invalid name and so
27
+ # looking for one might blow up since we load them lazily.
25
28
  end
26
- abspat = File::expand_path(start, cwd)
27
- [nil, Dir.glob(abspat + (File.extname(abspat).empty? ? '{.pp,.rb}' : '' )).uniq.reject { |f| FileTest.directory?(f) }]
29
+ [nil, []]
28
30
  end
29
31
 
30
32
  # Find the concrete file denoted by +file+. If +file+ is absolute,
@@ -80,9 +82,12 @@ module Puppet::Parser::Files
80
82
 
81
83
  # Split the path into the module and the rest of the path, or return
82
84
  # nil if the path is empty or absolute (starts with a /).
83
- # This method can return nil & anyone calling it needs to handle that.
84
85
  def split_file_path(path)
85
- path.split(File::SEPARATOR, 2) unless path == "" or Puppet::Util.absolute_path?(path)
86
+ if path == "" or Puppet::Util.absolute_path?(path)
87
+ nil
88
+ else
89
+ path.split(File::SEPARATOR, 2)
90
+ end
86
91
  end
87
92
 
88
93
  end
@@ -101,7 +101,16 @@ class Puppet::Parser::Parser
101
101
  end
102
102
 
103
103
  def import(file)
104
- known_resource_types.loader.import(file, @lexer.file)
104
+ if @lexer.file
105
+ # use a path relative to the file doing the importing
106
+ dir = File.dirname(@lexer.file)
107
+ else
108
+ # otherwise assume that everything needs to be from where the user is
109
+ # executing this command. Normally, this would be in a "puppet apply -e"
110
+ dir = Dir.pwd
111
+ end
112
+
113
+ known_resource_types.loader.import(file, dir)
105
114
  end
106
115
 
107
116
  def initialize(env)
@@ -59,40 +59,34 @@ class Puppet::Parser::TypeLoader
59
59
  end
60
60
  end
61
61
 
62
- # Import our files.
63
- def import(file, current_file = nil)
62
+ # Import manifest files that match a given file glob pattern.
63
+ #
64
+ # @param pattern [String] the file glob to apply when determining which files
65
+ # to load
66
+ # @param dir [String] base directory to use when the file is not
67
+ # found in a module
68
+ # @api private
69
+ def import(pattern, dir)
64
70
  return if Puppet[:ignoreimport]
65
71
 
66
- # use a path relative to the file doing the importing
67
- if current_file
68
- dir = current_file.sub(%r{[^/]+$},'').sub(/\/$/, '')
69
- else
70
- dir = "."
71
- end
72
- if dir == ""
73
- dir = "."
74
- end
72
+ modname, files = Puppet::Parser::Files.find_manifests_in_modules(pattern, environment)
73
+ if files.empty?
74
+ abspat = File.expand_path(pattern, dir)
75
+ file_pattern = abspat + (File.extname(abspat).empty? ? '{.pp,.rb}' : '' )
75
76
 
76
- pat = file
77
- modname, files = Puppet::Parser::Files.find_manifests(pat, :cwd => dir, :environment => environment)
78
- if files.size == 0
79
- raise Puppet::ImportError.new("No file(s) found for import of '#{pat}'")
80
- end
77
+ files = Dir.glob(file_pattern).uniq.reject { |f| FileTest.directory?(f) }
78
+ modname = nil
81
79
 
82
- loaded_asts = []
83
- files.each do |file|
84
- unless Puppet::Util.absolute_path?(file)
85
- file = File.join(dir, file)
80
+ if files.empty?
81
+ raise_no_files_found(pattern)
86
82
  end
87
- @loading_helper.do_once(file) do
88
- loaded_asts << parse_file(file)
89
- end
90
- end
91
- loaded_asts.inject([]) do |loaded_types, ast|
92
- loaded_types + known_resource_types.import_ast(ast, modname)
93
83
  end
84
+
85
+ load_files(modname, files)
94
86
  end
95
87
 
88
+ # Load all of the manifest files in all known modules.
89
+ # @api private
96
90
  def import_all
97
91
  module_names = []
98
92
  # Collect the list of all known modules
@@ -113,7 +107,7 @@ class Puppet::Parser::TypeLoader
113
107
  mod = Puppet::Module.new(name, :environment => environment)
114
108
  Find.find(File.join(mod.path, "manifests")) do |path|
115
109
  if path =~ /\.pp$/ or path =~ /\.rb$/
116
- import(path)
110
+ load_files(mod.name, [path])
117
111
  end
118
112
  end
119
113
  end
@@ -133,7 +127,7 @@ class Puppet::Parser::TypeLoader
133
127
  return nil if fqname == "" # special-case main.
134
128
  name2files(fqname).each do |filename|
135
129
  begin
136
- imported_types = import(filename)
130
+ imported_types = import_from_modules(filename)
137
131
  if result = imported_types.find { |t| t.type == type and t.name == fqname }
138
132
  Puppet.debug "Automatically imported #{fqname} from #{filename} into #{environment}"
139
133
  return result
@@ -157,6 +151,32 @@ class Puppet::Parser::TypeLoader
157
151
 
158
152
  private
159
153
 
154
+ def import_from_modules(pattern)
155
+ modname, files = Puppet::Parser::Files.find_manifests_in_modules(pattern, environment)
156
+ if files.empty?
157
+ raise_no_files_found(pattern)
158
+ end
159
+
160
+ load_files(modname, files)
161
+ end
162
+
163
+ def raise_no_files_found(pattern)
164
+ raise Puppet::ImportError, "No file(s) found for import of '#{pattern}'"
165
+ end
166
+
167
+ def load_files(modname, files)
168
+ loaded_asts = []
169
+ files.each do |file|
170
+ @loading_helper.do_once(file) do
171
+ loaded_asts << parse_file(file)
172
+ end
173
+ end
174
+
175
+ loaded_asts.collect do |ast|
176
+ known_resource_types.import_ast(ast, modname)
177
+ end.flatten
178
+ end
179
+
160
180
  # Return a list of all file basenames that should be tried in order
161
181
  # to load the object with the given fully qualified name.
162
182
  def name2files(fqname)
@@ -6,7 +6,7 @@
6
6
  # Raketasks and such to set the version based on the output of `git describe`
7
7
  #
8
8
  module Puppet
9
- PUPPETVERSION = '2.7.22'
9
+ PUPPETVERSION = '2.7.23'
10
10
 
11
11
  def self.version
12
12
  @puppet_version || PUPPETVERSION
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+ require 'puppet_spec/files'
3
+ require 'puppet/file_system'
4
+
5
+ describe Puppet::FileSystem::PathPattern do
6
+ include PuppetSpec::Files
7
+ InvalidPattern = Puppet::FileSystem::PathPattern::InvalidPattern
8
+
9
+ describe 'relative' do
10
+ it "can not be created with a traversal up the directory tree" do
11
+ expect do
12
+ Puppet::FileSystem::PathPattern.relative("my/../other")
13
+ end.to raise_error(InvalidPattern, "PathPatterns cannot be created with directory traversals.")
14
+ end
15
+
16
+ it "can be created with a '..' prefixing a filename" do
17
+ Puppet::FileSystem::PathPattern.relative("my/..other").to_s.should eq("my/..other")
18
+ end
19
+
20
+ it "can be created with a '..' suffixing a filename" do
21
+ Puppet::FileSystem::PathPattern.relative("my/other..").to_s.should eq("my/other..")
22
+ end
23
+
24
+ it "can be created with a '..' embedded in a filename" do
25
+ Puppet::FileSystem::PathPattern.relative("my/ot..her").to_s.should eq("my/ot..her")
26
+ end
27
+
28
+ it "can not be created with a \\0 byte embedded" do
29
+ expect do
30
+ Puppet::FileSystem::PathPattern.relative("my/\0/other")
31
+ end.to raise_error(InvalidPattern, /PathPatterns cannot be created with a zero byte./)
32
+ end
33
+
34
+ it "can not be created with a windows drive" do
35
+ expect do
36
+ Puppet::FileSystem::PathPattern.relative("c:\\relative\\path")
37
+ end.to raise_error(InvalidPattern, "A relative PathPattern cannot be prefixed with a drive.")
38
+ end
39
+
40
+ it "can not be created with a windows drive (with space)" do
41
+ expect do
42
+ Puppet::FileSystem::PathPattern.relative(" c:\\relative\\path")
43
+ end.to raise_error(InvalidPattern, "A relative PathPattern cannot be prefixed with a drive.")
44
+ end
45
+
46
+ it "can not create an absolute relative path" do
47
+ expect do
48
+ Puppet::FileSystem::PathPattern.relative("/no/absolutes")
49
+ end.to raise_error(InvalidPattern, "A relative PathPattern cannot be an absolute path.")
50
+ end
51
+
52
+ it "can not create an absolute relative path (with space)" do
53
+ expect do
54
+ Puppet::FileSystem::PathPattern.relative("\t/no/absolutes")
55
+ end.to raise_error(InvalidPattern, "A relative PathPattern cannot be an absolute path.")
56
+ end
57
+
58
+ it "can not create a relative path that is a windows path relative to the current drive" do
59
+ expect do
60
+ Puppet::FileSystem::PathPattern.relative("\\no\relatives")
61
+ end.to raise_error(InvalidPattern, "A PathPattern cannot be a Windows current drive relative path.")
62
+ end
63
+
64
+ it "creates a relative PathPattern from a valid relative path" do
65
+ Puppet::FileSystem::PathPattern.relative("a/relative/path").to_s.should eq("a/relative/path")
66
+ end
67
+
68
+ it "is not absolute" do
69
+ Puppet::FileSystem::PathPattern.relative("a/relative/path").should_not be_absolute
70
+ end
71
+ end
72
+
73
+ describe 'absolute' do
74
+ it "can not create a relative absolute path" do
75
+ expect do
76
+ Puppet::FileSystem::PathPattern.absolute("no/relatives")
77
+ end.to raise_error(InvalidPattern, "An absolute PathPattern cannot be a relative path.")
78
+ end
79
+
80
+ it "can not create an absolute path that is a windows path relative to the current drive" do
81
+ expect do
82
+ Puppet::FileSystem::PathPattern.absolute("\\no\\relatives")
83
+ end.to raise_error(InvalidPattern, "A PathPattern cannot be a Windows current drive relative path.")
84
+ end
85
+
86
+ it "creates an absolute PathPattern from a valid absolute path" do
87
+ Puppet::FileSystem::PathPattern.absolute("/an/absolute/path").to_s.should eq("/an/absolute/path")
88
+ end
89
+
90
+ it "creates an absolute PathPattern from a valid Windows absolute path" do
91
+ Puppet::FileSystem::PathPattern.absolute("c:/absolute/windows/path").to_s.should eq("c:/absolute/windows/path")
92
+ end
93
+
94
+ it "is absolute" do
95
+ Puppet::FileSystem::PathPattern.absolute("c:/absolute/windows/path").should be_absolute
96
+ end
97
+
98
+ it "can be created with a '..' embedded in a filename on windows", :if => Puppet.features.microsoft_windows? do
99
+ Puppet::FileSystem::PathPattern.absolute(%q{c:\..my\ot..her\one..}).to_s.should eq(%q{c:\..my\ot..her\one..})
100
+ end
101
+ end
102
+
103
+ it "prefixes the relative path pattern with another path" do
104
+ pattern = Puppet::FileSystem::PathPattern.relative("docs/*_thoughts.txt")
105
+ prefix = Puppet::FileSystem::PathPattern.absolute("/prefix")
106
+
107
+ absolute_pattern = pattern.prefix_with(prefix)
108
+
109
+ absolute_pattern.should be_absolute
110
+ absolute_pattern.to_s.should eq(File.join("/prefix", "docs/*_thoughts.txt"))
111
+ end
112
+
113
+ it "refuses to prefix with a relative pattern" do
114
+ pattern = Puppet::FileSystem::PathPattern.relative("docs/*_thoughts.txt")
115
+ prefix = Puppet::FileSystem::PathPattern.relative("prefix")
116
+
117
+ expect do
118
+ pattern.prefix_with(prefix)
119
+ end.to raise_error(InvalidPattern, "An absolute PathPattern cannot be a relative path.")
120
+ end
121
+
122
+ it "applies the pattern to the filesystem as a glob" do
123
+ dir = tmpdir('globtest')
124
+ create_file_in(dir, "found_one")
125
+ create_file_in(dir, "found_two")
126
+ create_file_in(dir, "third_not_found")
127
+
128
+ pattern = Puppet::FileSystem::PathPattern.relative("found_*").prefix_with(
129
+ Puppet::FileSystem::PathPattern.absolute(dir))
130
+
131
+ pattern.glob.should include(File.join(dir, "found_one"))
132
+ pattern.glob.should include(File.join(dir, "found_two"))
133
+ pattern.glob.should_not include(File.join(dir, "third_not_found"))
134
+ end
135
+
136
+ def create_file_in(dir, name)
137
+ File.open(File.join(dir, name), "w") { |f| f.puts "data" }
138
+ end
139
+ end
@@ -604,7 +604,8 @@ describe Puppet::Module, "when finding matching manifests" do
604
604
  end
605
605
 
606
606
  it "should default to the 'init' file if no glob pattern is specified" do
607
- Dir.expects(:glob).with("/a/manifests/init.{pp,rb}").returns(%w{/a/manifests/init.pp})
607
+ FileTest.expects(:exist?).with("/a/manifests/init.pp").returns(true)
608
+ FileTest.expects(:exist?).with("/a/manifests/init.rb").returns(false)
608
609
 
609
610
  @mod.match_manifests(nil).should == %w{/a/manifests/init.pp}
610
611
  end
@@ -626,6 +627,12 @@ describe Puppet::Module, "when finding matching manifests" do
626
627
 
627
628
  @mod.match_manifests(@pq_glob_with_extension).should == []
628
629
  end
630
+
631
+ it "should raise an error if the pattern tries to leave the manifest directory" do
632
+ expect do
633
+ @mod.match_manifests("something/../../*")
634
+ end.to raise_error(Puppet::Module::InvalidFilePattern, /The pattern "something\/\.\.\/\.\.\/\*" to find manifests in the module "mymod" is invalid and potentially unsafe./)
635
+ end
629
636
  end
630
637
 
631
638
  describe Puppet::Module do
@@ -36,6 +36,9 @@ describe Puppet::ModuleTool::Applications::Unpacker, :fails_on_windows => true d
36
36
  context "on linux" do
37
37
  it "should attempt to untar file to temporary location using system tar" do
38
38
  Puppet::Util.expects(:execute).with("tar xzf #{filename} -C #{build_dir}").returns(true)
39
+ Puppet::Util.expects(:execute).with("find #{build_dir} -type d -exec chmod 755 {} +").returns(true)
40
+ Puppet::Util.expects(:execute).with("find #{build_dir} -type f -exec chmod 644 {} +").returns(true)
41
+ Puppet::Util.expects(:execute).with("chown -R #{build_dir.stat.uid}:#{build_dir.stat.gid} #{build_dir}").returns(true)
39
42
  unpacker.run
40
43
  end
41
44
  end
@@ -48,6 +51,9 @@ describe Puppet::ModuleTool::Applications::Unpacker, :fails_on_windows => true d
48
51
  it "should attempt to untar file to temporary location using gnu tar" do
49
52
  Puppet::Util.stubs(:which).with('gtar').returns('/usr/sfw/bin/gtar')
50
53
  Puppet::Util.expects(:execute).with("gtar xzf #{filename} -C #{build_dir}").returns(true)
54
+ Puppet::Util.expects(:execute).with("find #{build_dir} -type d -exec chmod 755 {} +").returns(true)
55
+ Puppet::Util.expects(:execute).with("find #{build_dir} -type f -exec chmod 644 {} +").returns(true)
56
+ Puppet::Util.expects(:execute).with("chown -R #{build_dir.stat.uid}:#{build_dir.stat.gid} #{build_dir}").returns(true)
51
57
  unpacker.run
52
58
  end
53
59
 
@@ -10,14 +10,6 @@ describe Puppet::Parser::Files do
10
10
  @basepath = make_absolute("/somepath")
11
11
  end
12
12
 
13
- it "should have a method for finding a template" do
14
- Puppet::Parser::Files.should respond_to(:find_template)
15
- end
16
-
17
- it "should have a method for finding manifests" do
18
- Puppet::Parser::Files.should respond_to(:find_manifests)
19
- end
20
-
21
13
  describe "when searching for templates" do
22
14
  it "should return fully-qualified templates directly" do
23
15
  Puppet::Parser::Files.expects(:modulepath).never
@@ -127,75 +119,22 @@ describe Puppet::Parser::Files do
127
119
  describe "when searching for manifests" do
128
120
  it "should ignore invalid modules" do
129
121
  mod = mock 'module'
130
- Puppet::Node::Environment.new.expects(:module).with("mymod").raises(Puppet::Module::InvalidName, "name is invalid")
122
+ env = Puppet::Node::Environment.new
123
+ env.expects(:module).with("mymod").raises(Puppet::Module::InvalidName, "name is invalid")
131
124
  Puppet.expects(:value).with(:modulepath).never
132
125
  Dir.stubs(:glob).returns %w{foo}
133
126
 
134
- Puppet::Parser::Files.find_manifests("mymod/init.pp")
135
- end
136
- end
137
-
138
- describe "when searching for manifests when no module is found" do
139
- before do
140
- File.stubs(:find).returns(nil)
141
- end
142
-
143
- it "should not look for modules when paths are fully qualified" do
144
- Puppet.expects(:value).with(:modulepath).never
145
- file = @basepath + "/fully/qualified/file.pp"
146
- Dir.stubs(:glob).with(file).returns([file])
147
- Puppet::Parser::Files.find_manifests(file)
148
- end
149
-
150
- it "should return nil and an array of fully qualified files" do
151
- file = @basepath + "/fully/qualified/file.pp"
152
- Dir.stubs(:glob).with(file).returns([file])
153
- Puppet::Parser::Files.find_manifests(file).should == [nil, [file]]
154
- end
155
-
156
- it "should match against provided fully qualified patterns" do
157
- pattern = @basepath + "/fully/qualified/pattern/*"
158
- Dir.expects(:glob).with(pattern+'{.pp,.rb}').returns(%w{my file list})
159
- Puppet::Parser::Files.find_manifests(pattern)[1].should == %w{my file list}
160
- end
161
-
162
- it "should look for files relative to the current directory" do
163
- # We expand_path to normalize backslashes and slashes on Windows
164
- cwd = File.expand_path(Dir.getwd)
165
- Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"])
166
- Puppet::Parser::Files.find_manifests("foobar/init.pp")[1].should == ["#{cwd}/foobar/init.pp"]
167
- end
168
-
169
- it "should only return files, not directories" do
170
- pattern = @basepath + "/fully/qualified/pattern/*"
171
- file = @basepath + "/my/file"
172
- dir = @basepath + "/my/directory"
173
- Dir.expects(:glob).with(pattern+'{.pp,.rb}').returns([file, dir])
174
- FileTest.expects(:directory?).with(file).returns(false)
175
- FileTest.expects(:directory?).with(dir).returns(true)
176
- Puppet::Parser::Files.find_manifests(pattern)[1].should == [file]
177
- end
178
-
179
- it "should return files once only" do
180
- pattern = @basepath + "/fully/qualified/pattern/*"
181
- Dir.expects(:glob).with(pattern+'{.pp,.rb}').returns(%w{one two one})
182
- Puppet::Parser::Files.find_manifests(pattern)[1].should == %w{one two}
127
+ Puppet::Parser::Files.find_manifests_in_modules("mymod/init.pp", env)
183
128
  end
184
129
  end
185
130
 
186
131
  describe "when searching for manifests in a found module" do
187
132
  it "should return the name of the module and the manifests from the first found module" do
188
133
  mod = Puppet::Module.new("mymod")
189
- Puppet::Node::Environment.new.expects(:module).with("mymod").returns mod
190
- mod.expects(:match_manifests).with("init.pp").returns(%w{/one/mymod/manifests/init.pp})
191
- Puppet::Parser::Files.find_manifests("mymod/init.pp").should == ["mymod", ["/one/mymod/manifests/init.pp"]]
192
- end
193
-
194
- it "should use the node environment if specified" do
195
- mod = Puppet::Module.new("mymod")
196
- Puppet::Node::Environment.new("myenv").expects(:module).with("mymod").returns mod
134
+ env = Puppet::Node::Environment.new
135
+ env.expects(:module).with("mymod").returns mod
197
136
  mod.expects(:match_manifests).with("init.pp").returns(%w{/one/mymod/manifests/init.pp})
198
- Puppet::Parser::Files.find_manifests("mymod/init.pp", :environment => "myenv")[1].should == ["/one/mymod/manifests/init.pp"]
137
+ Puppet::Parser::Files.find_manifests_in_modules("mymod/init.pp", env).should == ["mymod", ["/one/mymod/manifests/init.pp"]]
199
138
  end
200
139
 
201
140
  after { Puppet.settings.clear }