summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-03-24 18:14:57 -0700
committerdanielsdeleo <dan@getchef.com>2015-03-25 08:13:34 -0700
commit93c669196f53d21cf2b973b014c2cde4e0c3313a (patch)
tree59bd141848d7036167cdc6522491f24ae788bb9d
parenta6fbf127d3eeb38d73fa4b9aec98ef34cf897f85 (diff)
downloadchef-policyfile-erchef-integration.tar.gz
Handle cookbook artfact format differences when fetching cookbookspolicyfile-erchef-integration
Cookbook artifacts differ in these ways: * the name field is the cookbook name instead of name+version * there is no "cookbook_name" field * cookbook artifacts don't have a json_class when downloaded from the server * there is an identifier field
-rw-r--r--lib/chef/cookbook/remote_file_vendor.rb2
-rw-r--r--lib/chef/policy_builder/policyfile.rb6
-rw-r--r--spec/unit/cookbook/file_vendor_spec.rb36
3 files changed, 34 insertions, 10 deletions
diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb
index 2ddce31001..9d895b168e 100644
--- a/lib/chef/cookbook/remote_file_vendor.rb
+++ b/lib/chef/cookbook/remote_file_vendor.rb
@@ -30,7 +30,7 @@ class Chef
def initialize(manifest, rest)
@manifest = manifest
- @cookbook_name = @manifest[:cookbook_name]
+ @cookbook_name = @manifest[:cookbook_name] || @manifest[:name]
@rest = rest
end
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index f85d72f121..0c7c07f9f3 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -370,7 +370,7 @@ class Chef
def artifact_manifest_for(cookbook_name, lock_data)
identifier = lock_data["identifier"]
rel_url = "cookbook_artifacts/#{cookbook_name}/#{identifier}"
- http_api.get(rel_url)
+ inflate_cbv_object(http_api.get(rel_url))
rescue Exception => e
message = "Error loading cookbook #{cookbook_name} with identifier #{identifier} from #{rel_url}: #{e.class} - #{e.message}"
err = Chef::Exceptions::CookbookNotFound.new(message)
@@ -378,6 +378,10 @@ class Chef
raise err
end
+ def inflate_cbv_object(raw_manifest)
+ Chef::CookbookVersion.from_cb_artifact_data(raw_manifest)
+ end
+
end
end
end
diff --git a/spec/unit/cookbook/file_vendor_spec.rb b/spec/unit/cookbook/file_vendor_spec.rb
index 4fad7d5808..145541a63f 100644
--- a/spec/unit/cookbook/file_vendor_spec.rb
+++ b/spec/unit/cookbook/file_vendor_spec.rb
@@ -21,9 +21,6 @@ describe Chef::Cookbook::FileVendor do
let(:file_vendor_class) { Class.new(described_class) }
- # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest
- let(:manifest) { {:cookbook_name => "bob"} }
-
context "when configured to fetch files over http" do
let(:http) { double("Chef::REST") }
@@ -40,19 +37,42 @@ describe Chef::Cookbook::FileVendor do
expect(file_vendor_class.initialization_options).to eq(http)
end
- it "creates a RemoteFileVendor for a given manifest" do
- file_vendor = file_vendor_class.create_from_manifest(manifest)
- expect(file_vendor).to be_a_kind_of(Chef::Cookbook::RemoteFileVendor)
- expect(file_vendor.rest).to eq(http)
- expect(file_vendor.cookbook_name).to eq("bob")
+ context "with a manifest from a cookbook version" do
+
+ # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest
+ let(:manifest) { {:cookbook_name => "bob", :name => "bob-1.2.3"} }
+
+ it "creates a RemoteFileVendor for a given manifest" do
+ file_vendor = file_vendor_class.create_from_manifest(manifest)
+ expect(file_vendor).to be_a_kind_of(Chef::Cookbook::RemoteFileVendor)
+ expect(file_vendor.rest).to eq(http)
+ expect(file_vendor.cookbook_name).to eq("bob")
+ end
+
end
+ context "with a manifest from a cookbook artifact" do
+
+ # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest
+ let(:manifest) { {:name => "bob"} }
+
+ it "creates a RemoteFileVendor for a given manifest" do
+ file_vendor = file_vendor_class.create_from_manifest(manifest)
+ expect(file_vendor).to be_a_kind_of(Chef::Cookbook::RemoteFileVendor)
+ expect(file_vendor.rest).to eq(http)
+ expect(file_vendor.cookbook_name).to eq("bob")
+ end
+
+ end
end
context "when configured to load files from disk" do
let(:cookbook_path) { %w[/var/chef/cookbooks /var/chef/other_cookbooks] }
+ # A manifest is a Hash of the format defined by Chef::CookbookVersion#manifest
+ let(:manifest) { {:cookbook_name => "bob"} }
+
before do
file_vendor_class.fetch_from_disk(cookbook_path)
end