-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from aerostitch/add_repo_provider
Add repo provider/type
- Loading branch information
Showing
10 changed files
with
330 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'puppet/provider' | ||
|
||
module_lib = Pathname.new(__FILE__).parent.parent.parent.parent | ||
require File.join module_lib, 'puppet_x/aptly/cli' | ||
|
||
Puppet::Type.type(:aptly_repo).provide(:cli) do | ||
|
||
mk_resource_methods | ||
|
||
def create | ||
Puppet.info("Creating Aptly Repository #{name}}") | ||
|
||
Puppet_X::Aptly::Cli.execute( | ||
object: :repo, | ||
action: 'create', | ||
arguments: [ name ], | ||
flags: { | ||
'component' => resource[:default_component], | ||
'distribution' => resource[:default_distribution], | ||
} | ||
) | ||
end | ||
|
||
def destroy | ||
Puppet.info("Destroying Aptly Repository #{name}") | ||
|
||
Puppet_X::Aptly::Cli.execute( | ||
object: :repo, | ||
action: 'drop', | ||
arguments: [ name ], | ||
flags: { 'force' => resource[:force] ? 'true' : 'false' }, | ||
) | ||
end | ||
|
||
def exists? | ||
Puppet.debug("Check if Repository #{name} exists") | ||
|
||
Puppet_X::Aptly::Cli.execute( | ||
object: :repo, | ||
action: 'list', | ||
flags: { 'raw' => 'true' }, | ||
exceptions: false, | ||
).lines.map(&:chomp).include? name | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'puppet/parameter/boolean' | ||
|
||
Puppet::Type.newtype(:aptly_repo) do | ||
@doc = %q{Creates a new Aptly repo | ||
} | ||
|
||
ensurable | ||
|
||
newparam(:name, :namevar => true) do | ||
desc "The name of the Aptly repo. Example : frontend_apps" | ||
end | ||
|
||
newparam(:force, :boolean => true, :parent => Puppet::Parameter::Boolean) do | ||
desc "Force to drop the Apt repository even if it used as source of some snapshot" | ||
defaultto :true | ||
end | ||
|
||
newparam(:default_component) do | ||
desc "Default component when publishing. Example : main" | ||
validate do |value| | ||
unless value.instance_of? String | ||
raise ArgumentError , "%s is not a valid component (should be a string)" % value | ||
end | ||
end | ||
defaultto 'main' | ||
end | ||
|
||
newparam(:default_distribution) do | ||
desc "Default distribution when publishing" | ||
validate do |value| | ||
unless value.instance_of? String | ||
raise ArgumentError , "%s is not a valid distribution (should be a string)" % value | ||
end | ||
end | ||
defaultto '' | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# == Define aptly::repo | ||
# | ||
# Manages an apt repo. | ||
# | ||
define aptly::repo ( | ||
$ensure = 'present', | ||
$default_distribution = $::lsbdistcodename, | ||
$default_component = 'main', | ||
) { | ||
validate_string( | ||
$default_distribution, | ||
$default_component | ||
) | ||
|
||
aptly_repo { $name: | ||
ensure => $ensure, | ||
default_distribution => $default_distribution, | ||
default_component => $default_component, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe 'aptly::repo' do | ||
context 'basic repo' do | ||
let(:title) { 'my_custom_repo' } | ||
let(:params) {{ | ||
:default_component => 'stable', | ||
:default_distribution => 'xenial', | ||
}} | ||
|
||
it 'should call the aptly_repo provider' do | ||
is_expected.to contain_aptly_repo('my_custom_repo')\ | ||
.with_ensure('present')\ | ||
.with_default_component('stable')\ | ||
.with_default_distribution('xenial') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'spec_helper' | ||
require 'puppet/type/aptly_repo' | ||
|
||
describe Puppet::Type.type(:aptly_repo).provider(:cli) do | ||
let(:resource) do | ||
Puppet::Type.type(:aptly_repo).new( | ||
:name => 'foo', | ||
:ensure => 'present', | ||
) | ||
end | ||
|
||
let(:provider) do | ||
described_class.new(resource) | ||
end | ||
|
||
[:create, :destroy, :exists? ].each do |method| | ||
it "should have a(n) #{method}" do | ||
expect(provider).to respond_to(method) | ||
end | ||
end | ||
|
||
describe '#create' do | ||
it 'should create the repo' do | ||
Puppet_X::Aptly::Cli.expects(:execute).with( | ||
object: :repo, | ||
action: 'create', | ||
arguments: [ 'foo' ], | ||
flags: { | ||
'component' => 'main', | ||
'distribution' => '', | ||
} | ||
) | ||
provider.create | ||
end | ||
end | ||
|
||
describe '#destroy' do | ||
it 'should drop the repo' do | ||
Puppet_X::Aptly::Cli.expects(:execute).with( | ||
object: :repo, | ||
action: 'drop', | ||
arguments: ['foo'], | ||
flags: { 'force' => 'true' }, | ||
) | ||
provider.destroy | ||
end | ||
end | ||
|
||
describe '#exists?' do | ||
it 'should check the repo list' do | ||
Puppet_X::Aptly::Cli.stubs(:execute).with( | ||
object: :repo, | ||
action: 'list', | ||
flags: { 'raw' => 'true' }, | ||
exceptions: false, | ||
).returns "foo\ntest-snap\nbar" | ||
expect(provider.exists?).to eq(true) | ||
end | ||
it 'should handle without repo' do | ||
Puppet_X::Aptly::Cli.stubs(:execute).with( | ||
object: :repo, | ||
action: 'list', | ||
flags: { 'raw' => 'true' }, | ||
exceptions: false, | ||
).returns '' | ||
expect(provider.exists?).to eq(false) | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.