summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-09-28 11:42:04 -0700
committerTim Smith <tsmith@chef.io>2017-09-28 11:42:04 -0700
commitede166724c392757bb42c94d402adba748ab2b76 (patch)
tree1273c56dbb2e769bc38c4ce44b49d7ed1fda7441
parente5e2f14ad846af240a545bd87d0b431b513322c3 (diff)
downloadchef-ede166724c392757bb42c94d402adba748ab2b76.tar.gz
Allow specifying the cookbook for the source template
Also fix the cookbook_file lookup logic missing a method it needed for file based keys Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/zypper_repository.rb12
-rw-r--r--lib/chef/resource/zypper_repository.rb1
-rw-r--r--spec/unit/provider/zypper_repository_spec.rb8
3 files changed, 18 insertions, 3 deletions
diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb
index 4fff7c8632..31cf8839b2 100644
--- a/lib/chef/provider/zypper_repository.rb
+++ b/lib/chef/provider/zypper_repository.rb
@@ -72,12 +72,20 @@ class Chef
Shellwords.escape(new_resource.repo_name)
end
+ # return the specified cookbook name or the cookbook containing the
+ # resource.
+ #
+ # @return [String] name of the cookbook
+ def cookbook_name
+ new_resource.cookbook || new_resource.cookbook_name
+ end
+
# determine if a template file is available in the current run
# @param [String] path the path to the template file
#
# @return [Boolean] template file exists or doesn't
def template_available?(path)
- !path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path)
+ !path.nil? && run_context.has_template_in_cookbook?(cookbook_name, path)
end
# determine if a cookbook file is available in the run
@@ -99,7 +107,7 @@ class Chef
if uri.start_with?("http")
Chef::Log.debug("Will use :remote_file resource to cache the gpg key locally")
:remote_file
- elsif has_cookbook_file?(key)
+ elsif has_cookbook_file?(uri)
Chef::Log.debug("Will use :cookbook_file resource to cache the gpg key locally")
:cookbook_file
else
diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb
index 69a96b42cf..88b6fd9336 100644
--- a/lib/chef/resource/zypper_repository.rb
+++ b/lib/chef/resource/zypper_repository.rb
@@ -39,6 +39,7 @@ class Chef
property :mode, default: "0644"
property :refresh_cache, [true, false], default: true
property :source, String, regex: /.*/
+ property :cookbook, String
property :gpgautoimportkeys, [true, false], default: true
default_action :create
diff --git a/spec/unit/provider/zypper_repository_spec.rb b/spec/unit/provider/zypper_repository_spec.rb
index d909639d5a..89f6b288f6 100644
--- a/spec/unit/provider/zypper_repository_spec.rb
+++ b/spec/unit/provider/zypper_repository_spec.rb
@@ -34,7 +34,7 @@ uid nginx signing key <signing-key@nginx.com>
EOF
describe Chef::Provider::ZypperRepository do
- let(:new_resource) { Chef::Resource::ZypperRepository.new("nginx") }
+ let(:new_resource) { Chef::Resource::ZypperRepository.new("Nginx Repository") }
let(:shellout_env) { { env: { "LANG" => "en_US", "LANGUAGE" => "en_US" } } }
let(:provider) do
@@ -59,4 +59,10 @@ describe Chef::Provider::ZypperRepository do
it "responds to load_current_resource" do
expect(provider).to respond_to(:load_current_resource)
end
+
+ describe "#escaped_repo_name" do
+ it "returns an escaped repo name" do
+ expect(provider.escaped_repo_name).to eq('Nginx\\ Repository')
+ end
+ end
end