diff options
-rw-r--r-- | chef/lib/chef/cookbook_version.rb | 23 | ||||
-rw-r--r-- | chef/spec/unit/cookbook_manifest_spec.rb | 58 |
2 files changed, 68 insertions, 13 deletions
diff --git a/chef/lib/chef/cookbook_version.rb b/chef/lib/chef/cookbook_version.rb index d5c04f5966..87397446f0 100644 --- a/chef/lib/chef/cookbook_version.rb +++ b/chef/lib/chef/cookbook_version.rb @@ -753,13 +753,24 @@ class Chef fqdn = node[:fqdn] + # Break version into components, eg: "5.7.1" => [ "5.7.1", "5.7", "5" ] + search_versions = [] + parts = version.to_s.split('.') + + parts.size.times do + search_versions << parts.join('.') + parts.pop + end + # Most specific to least specific places to find the path - [ - File.join(segment.to_s, "host-#{fqdn}", path), - File.join(segment.to_s, "#{platform}-#{version}", path), - File.join(segment.to_s, platform.to_s, path), - File.join(segment.to_s, "default", path) - ] + search_path = [ File.join(segment.to_s, "host-#{fqdn}", path) ] + search_versions.each do |v| + search_path << File.join(segment.to_s, "#{platform}-#{v}", path) + end + search_path << File.join(segment.to_s, platform.to_s, path) + search_path << File.join(segment.to_s, "default", path) + + search_path else [File.join(segment, path)] end diff --git a/chef/spec/unit/cookbook_manifest_spec.rb b/chef/spec/unit/cookbook_manifest_spec.rb index 5f35177758..105b0f2d39 100644 --- a/chef/spec/unit/cookbook_manifest_spec.rb +++ b/chef/spec/unit/cookbook_manifest_spec.rb @@ -35,11 +35,17 @@ describe "Chef::CookbookVersion manifest" do { :name => "afile.rb", :path => "files/ubuntu-9.10/afile.rb", - :checksum => "csum-platver", + :checksum => "csum-platver-full", :specificity => "ubuntu-9.10" }, { :name => "afile.rb", + :path => "files/newubuntu-9/afile.rb", + :checksum => "csum-platver-partial", + :specificity => "newubuntu-9" + }, + { + :name => "afile.rb", :path => "files/ubuntu/afile.rb", :checksum => "csum-plat", :specificity => "ubuntu" @@ -68,15 +74,28 @@ describe "Chef::CookbookVersion manifest" do { :name => "anotherfile1.rb", :path => "files/ubuntu-9.10/adirectory/anotherfile1.rb.platform-version", - :checksum => "csum-platver-1", + :checksum => "csum-platver-full-1", :specificity => "ubuntu-9.10" }, { :name => "anotherfile2.rb", :path => "files/ubuntu-9.10/adirectory/anotherfile2.rb.platform-version", - :checksum => "csum-platver-2", + :checksum => "csum-platver-full-2", :specificity => "ubuntu-9.10" }, + + { + :name => "anotherfile1.rb", + :path => "files/newubuntu-9/adirectory/anotherfile1.rb.platform-version", + :checksum => "csum-platver-partial-1", + :specificity => "newubuntu-9" + }, + { + :name => "anotherfile2.rb", + :path => "files/newubuntu-9/adirectory/anotherfile2.rb.platform-version", + :checksum => "csum-platver-partial-2", + :specificity => "nweubuntu-9" + }, { :name => "anotherfile1.rb", @@ -121,7 +140,7 @@ describe "Chef::CookbookVersion manifest" do manifest_record[:checksum].should == "csum-host" end - it "should return a manifest record based on priority preference: platform & version" do + it "should return a manifest record based on priority preference: platform & full version" do node = Chef::Node.new node[:platform] = "ubuntu" node[:platform_version] = "9.10" @@ -129,7 +148,18 @@ describe "Chef::CookbookVersion manifest" do manifest_record = @cookbook.preferred_manifest_record(node, :files, "afile.rb") manifest_record.should_not be_nil - manifest_record[:checksum].should == "csum-platver" + manifest_record[:checksum].should == "csum-platver-full" + end + + it "should return a manifest record based on priority preference: platform & partial version" do + node = Chef::Node.new + node[:platform] = "newubuntu" + node[:platform_version] = "9.10" + node[:fqdn] = "differenthost.example.org" + + manifest_record = @cookbook.preferred_manifest_record(node, :files, "afile.rb") + manifest_record.should_not be_nil + manifest_record[:checksum].should == "csum-platver-partial" end it "should return a manifest record based on priority preference: platform only" do @@ -170,7 +200,7 @@ describe "Chef::CookbookVersion manifest" do checksums.sort.should == ["csum-host-1", "csum-host-2"] end - it "should return a directory of manifest records based on priority preference: platform & version" do + it "should return a directory of manifest records based on priority preference: platform & full version" do node = Chef::Node.new node[:platform] = "ubuntu" node[:platform_version] = "9.10" @@ -181,7 +211,21 @@ describe "Chef::CookbookVersion manifest" do manifest_records.size.should == 2 checksums = manifest_records.map{ |manifest_record| manifest_record[:checksum] } - checksums.sort.should == ["csum-platver-1", "csum-platver-2"] + checksums.sort.should == ["csum-platver-full-1", "csum-platver-full-2"] + end + + it "should return a directory of manifest records based on priority preference: platform & partial version" do + node = Chef::Node.new + node[:platform] = "newubuntu" + node[:platform_version] = "9.10" + node[:fqdn] = "differenthost.example.org" + + manifest_records = @cookbook.preferred_manifest_records_for_directory(node, :files, "adirectory") + manifest_records.should_not be_nil + manifest_records.size.should == 2 + + checksums = manifest_records.map{ |manifest_record| manifest_record[:checksum] } + checksums.sort.should == ["csum-platver-partial-1", "csum-platver-partial-2"] end it "should return a directory of manifest records based on priority preference: platform only" do |