Skip to content

Commit

Permalink
Modernize the module
Browse files Browse the repository at this point in the history
* Drop the unused dependency on puppetlabs-stdlib
* Use hiera to load variables rather than params.pp
* Move package installation from git::install to git
* Add Puppet 4 type checks
* Make the binary path a parameter to init so it can
  be overridden globally
  • Loading branch information
ekohl authored and mmoll committed Jun 29, 2017
1 parent 157829c commit ed88231
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 92 deletions.
2 changes: 0 additions & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fixtures:
symlinks:
git: "#{source_dir}"
repositories:
stdlib: 'git://github.com/puppetlabs/puppetlabs-stdlib'
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ env:
matrix:
fast_finish: true
include:
# Limit the OS set we test Ruby 2.2 with.
- rvm: 2.2.6
env: PUPPET_VERSION=4.6 ONLY_OS="debian-8-x86_64,centos-7-x86_64,ubuntu-16-x86_64,ubuntu-16.04-x86_64,freebsd-10-amd64,windows-2012 R2-x64"
# Limit the OS set we test Ruby 2.3 with.
- rvm: 2.3.0
env: PUPPET_VERSION=4.6 ONLY_OS="debian-8-x86_64,centos-7-x86_64,ubuntu-16-x86_64,ubuntu-16.04-x86_64,freebsd-10-amd64,windows-2012 R2-x64"
- rvm: 2.4.1
env: PUPPET_VERSION=4.6 ONLY_OS="debian-8-x86_64,centos-7-x86_64,ubuntu-16-x86_64,ubuntu-16.04-x86_64,freebsd-10-amd64,windows-2012 R2-x64"
- rvm: 2.4.1
env: PUPPET_VERSION=5.0 ONLY_OS="debian-8-x86_64,centos-7-x86_64,ubuntu-16-x86_64,ubuntu-16.04-x86_64,freebsd-10-amd64,windows-2012 R2-x64"
bundler_args: --without system_tests development
sudo: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ gem 'beaker-rspec', {"groups"=>["system_tests"]}
gem 'beaker-puppet_install_helper', {"groups"=>["system_tests"]}
gem 'metadata-json-lint'
gem 'kafo_module_lint'
gem 'rgen' # until https://tickets.puppetlabs.com/browse/PDOC-168 is resolved

# vim:ft=ruby
2 changes: 2 additions & 0 deletions data/DragonFly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
git::bin: "/usr/local/bin/git"
2 changes: 2 additions & 0 deletions data/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
git::bin: "/usr/local/bin/git"
4 changes: 4 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
git::package: "git"
git::package_ensure: "installed"
git::bin: "/usr/bin/git"
22 changes: 22 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
version: 4
datadir: data
hierarchy:
- name: "Full Version"
backend: yaml
path: "%{facts.os.name}-%{facts.os.release.full}"

- name: "Major Version"
backend: yaml
path: "%{facts.os.name}-%{facts.os.release.major}"

- name: "Distribution Name"
backend: yaml
path: "%{facts.os.name}"

- name: "Operating System Family"
backend: yaml
path: "%{facts.os.family}"

- name: "common"
backend: yaml
27 changes: 23 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@
# Sets up requirements for git. See git::repo for more information on how to
# use this module.
#
# == Parameters:
#
# $bin:: The path to the git binary
#
# $package:: Override the name of the git package(s) to include.
#
# $package_ensure:: Override the git package ensure
#
# == Usage:
#
# Example: Override the git version
#
# class { 'git':
# package_ensure => '2.1.0',
# }
#
class git (
$package = $::git::params::package,
$package_ensure = $::git::params::package_ensure,
) inherits ::git::params {
include ::git::install
$bin = undef,
$package = undef,
$package_ensure = undef,
) {
package { $package:
ensure => $package_ensure,
}
}
10 changes: 0 additions & 10 deletions manifests/install.pp

This file was deleted.

32 changes: 0 additions & 32 deletions manifests/params.pp

This file was deleted.

30 changes: 15 additions & 15 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#
# $mode:: Mode of the repository root. Defaults to 0755.
#
# $bin:: Git binary. Defaults to /usr/bin/git or /usr/local/bin/git.
# $workdir:: The working directory while executing git
#
# $args:: Optional arguments to the git command
#
# $bin:: Git binary
#
# == Usage:
#
Expand All @@ -25,20 +29,17 @@
# }
#
define git::repo (
$target,
$bare = false,
$source = false,
$user = 'root',
$group = 'root',
$mode = '0755',
$workdir = '/tmp',
$args = undef,
$bin = $git::params::bin,
String $target,
Boolean $bare = false,
Boolean $source = false,
String $user = 'root',
String $group = 'root',
String $mode = '0755',
String $workdir = '/tmp',
Optional[String] $args = undef,
String $bin = $::git::bin,
) {

if $args {
validate_string($args)
}
require ::git

$args_real = $bare ? {
true => "${args} --bare",
Expand Down Expand Up @@ -66,7 +67,6 @@
command => $cmd,
creates => $creates,
cwd => $workdir,
require => Class['git::install'],
user => $user,
}
}
15 changes: 6 additions & 9 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
"foreman",
"git"
],
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 2.0.0 < 5.0.0"
}
],
"dependencies": [],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 3.0.0 < 5.0.0"
"version_requirement": ">= 4.6.1 < 6.0.0"
}
],
"data_provider": "hiera",
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
Expand All @@ -49,14 +45,15 @@
{
"operatingsystem": "Fedora",
"operatingsystemrelease": [
"21"
"25"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"7",
"8"
"8",
"9"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
facts
end

it { should compile.with_all_deps }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git').with_ensure('installed') }
end
end
end
60 changes: 43 additions & 17 deletions spec/defines/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,51 @@
end

let(:title) { 'mygit' }
let(:params) do
{
:target => '/tmp/somerepo.git',
:bare => true,
:source => false,
:user => 'root',
:workdir => '/tmp',
:args => '-c core.sharedRepository=true',
:bin => 'git'
}

context 'with minimal parameters' do
let :pre_condition do
'include ::git'
end

let(:params) do
{
:target => '/tmp/somerepo',
}
end

binary = ['DragonflyBSD', 'FreeBSD'].include?(facts[:osfamily]) ? '/usr/local/bin/git' : '/usr/bin/git'

it do
should contain_exec('git_repo_for_mygit').with(
'command' => "#{binary} init /tmp/somerepo",
'creates' => '/tmp/somerepo/.git',
'cwd' => '/tmp',
'user' => 'root',
)
end
end

it do
should contain_exec('git_repo_for_mygit').with(
'command' => "git init -c core.sharedRepository=true --bare /tmp/somerepo.git",
'creates' => '/tmp/somerepo.git/objects',
'cwd' => '/tmp',
'user' => 'root'
)
context 'with explicit parameters' do
let(:params) do
{
:target => '/tmp/somerepo.git',
:bare => true,
:source => false,
:user => 'root',
:workdir => '/tmp',
:args => '-c core.sharedRepository=true',
:bin => 'git',
}
end

it do
should contain_exec('git_repo_for_mygit').with(
'command' => "git init -c core.sharedRepository=true --bare /tmp/somerepo.git",
'creates' => '/tmp/somerepo.git/objects',
'cwd' => '/tmp',
'user' => 'root',
)
end
end
end
end
Expand Down

0 comments on commit ed88231

Please sign in to comment.