Skip to content

Commit

Permalink
Adding support for custom source template to yum_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean OMeara committed Feb 13, 2014
1 parent 69bd248 commit e576d3e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -136,6 +136,8 @@ end
and repositories
* `repositoryid` - Must be a unique name for each repository, one word.
Defaults to name attribute.
* `source` - Use a custom template source instead of the default one
in the yum cookbook
* `sslcacert` - Path to the directory containing the databases of the
certificate authorities yum should use to verify SSL certificates.
Defaults to none - uses system default
Expand Down
8 changes: 6 additions & 2 deletions providers/repository.rb
Expand Up @@ -37,8 +37,12 @@ def whyrun_supported?
# of these when dropping Chef 10 support.

template "/etc/yum.repos.d/#{new_resource.repositoryid}.repo" do
source 'repo.erb'
cookbook 'yum'
if new_resource.source.nil?
source 'repo.erb'
cookbook 'yum'
else
source new_resource.source
end
mode '0644'
variables(:config => new_resource)
notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately
Expand Down
1 change: 1 addition & 0 deletions resources/repository.rb
Expand Up @@ -50,6 +50,7 @@
attribute :report_instanceid, :kind_of => [TrueClass, FalseClass], :default => nil
attribute :repositoryid, :kind_of => String, :regex => /.*/, :name_attribute => true
attribute :skip_if_unavailable, :kind_of => [TrueClass, FalseClass], :default => nil
attribute :source, :kind_of => String, :regex => /.*/, :default => nil
attribute :sslcacert, :kind_of => String, :regex => /.*/, :default => nil
attribute :sslclientcert, :kind_of => String, :regex => /.*/, :default => nil
attribute :sslclientkey, :kind_of => String, :regex => /.*/, :default => nil
Expand Down
51 changes: 51 additions & 0 deletions spec/unit/test_repository_eight_spec.rb
@@ -0,0 +1,51 @@
require 'spec_helper'

describe 'yum_test::test_repository_eight' do
let(:test_repository_eight_run) do
ChefSpec::Runner.new(
:step_into => 'yum_repository'
).converge(described_recipe)
end

let(:test_repository_eight_template) do
test_repository_eight_run.template('/etc/yum.repos.d/test8.repo')
end

let(:test_repository_eight_content) do
'Hello there, I am a custom template.
baseurl: http://drop.the.baseurl.biz
Have a nice day.
'
end

context 'creating a yum_repository with minimal parameters' do
it 'creates yum_repository[test8]' do
expect(test_repository_eight_run).to create_yum_repository('test8')
end

it 'steps into yum_repository and creates template[/etc/yum.repos.d/test8.repo]' do
expect(test_repository_eight_run).to create_template('/etc/yum.repos.d/test8.repo')
end

it 'steps into yum_repository and renders file[/etc/yum.repos.d/test8.repo]' do
expect(test_repository_eight_run).to render_file('/etc/yum.repos.d/test8.repo').with_content(test_repository_eight_content)
end

it 'steps into yum_repository and runs execute[yum-makecache-test8]' do
expect(test_repository_eight_run).to_not run_execute('yum-makecache-test8')
end

it 'steps into yum_repository and runs ruby_block[yum-cache-reload-test8]' do
expect(test_repository_eight_run).to_not run_ruby_block('yum-cache-reload-test8')
end

it 'sends a :run to execute[yum-makecache-test8]' do
expect(test_repository_eight_template).to notify('execute[yum-makecache-test8]')
end

it 'sends a :create to ruby_block[yum-cache-reload-test8]' do
expect(test_repository_eight_template).to notify('ruby_block[yum-cache-reload-test8]')
end
end

end
@@ -0,0 +1,7 @@
# The simplest case
yum_repository 'test8' do
source 'custom_template.erb'
description 'an test'
baseurl 'http://drop.the.baseurl.biz'
action :create
end
@@ -0,0 +1,3 @@
Hello there, I am a custom template.
baseurl: <%= @config.baseurl %>
Have a nice day.

0 comments on commit e576d3e

Please sign in to comment.