Skip to content

Commit c6739d0

Browse files
committedJun 26, 2014
Add spec testing framework, clean up lint issues, fix ::debian subclass.
1. Added in a Travis-CI compatible spec-testing framework. 2. Added real spec tests for the opsmatic::debian class 3. Fixed the opsmatic::debian class to use the puppetlabs 'apt' module -- this module is far better than doing the work by hand, and is the standard for installing aptitude repositories on debian hosts. This also fixes a bug where the 'wget' exec statement was being run on EVERY puppet run, which is terrible. 4. Renamed the puppet-reporter class to puppet_reporter -- dashes in class names are not allowed. 5. Linted all the modules.
1 parent 76ac7c0 commit c6739d0

14 files changed

+199
-55
lines changed
 

‎.fixtures.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fixtures:
2+
repositories:
3+
"apt": "https://github.com/puppetlabs/puppetlabs-apt"
4+
"stdlib":
5+
"repo": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
6+
"ref": "v2.2.1"
7+
symlinks:
8+
"opsmatic": "#{source_dir}"

‎.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: ruby
2+
bundler_args: --without development
3+
script:
4+
- "bundle exec rake lint"
5+
- "bundle exec rake spec SPEC_OPTS='--format documentation --color'"
6+
rvm:
7+
- 1.8.7
8+
- 1.9.3
9+
- 2.0.0
10+
env:
11+
- PUPPET_GEM_VERSION="~> 3.4.0"
12+
- PUPPET_GEM_VERSION="~> 3.5.0"

‎Gemfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
source "https://rubygems.org"
2+
3+
# Required for unit testing
4+
gem 'facter', :require => false, :group => :test
5+
gem 'puppet', :require => false, :group => :test
6+
gem 'puppet-lint', :require => false, :group => :test
7+
gem 'puppetlabs_spec_helper', :require => false, :group => :test
8+
gem 'rake', :require => false, :group => :test
9+
gem "rspec-puppet", :require => false, :group => :test
10+
gem 'rspec-hiera-puppet', :require => false, :group => :test
11+
gem 'rspec-mocks', :require => false, :group => :test

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Usage
1616
To use this module you will need to set the variable `$token` in
1717
your puppet configuration:
1818

19-
class { "opsmatic::puppet-reporter":
19+
class { "opsmatic::puppet_reporter":
2020
token => "my_integration_token",
2121
}
2222

‎Rakefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rubygems'
2+
require 'puppetlabs_spec_helper/rake_tasks'
3+
require 'puppet-lint/tasks/puppet-lint'
4+
5+
# Puppet-lint Rake Specific settings
6+
PuppetLint.configuration.send('disable_80chars')
7+
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
8+
PuppetLint.configuration.with_context = true
9+
PuppetLint.configuration.fail_on_warnings = true

‎manifests/debian.pp

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1+
# == Class opsmatic::debian
2+
#
3+
# Installs the Opsmatic Puppet Report processor on a Debian host.
4+
#
5+
# === Authors
6+
#
7+
# <TODO>
8+
#
19
class opsmatic::debian {
2-
3-
file { "opsmatic_public_debian_repo":
4-
path => "/etc/apt/sources.list.d/opsmatic_public.list",
5-
ensure => file,
6-
content => template("opsmatic/opsmatic_public.list.erb"),
7-
notify => Exec["opsmatic_public_update_repo_cache"],
8-
before => Exec["opsmatic_public_debian_key"]
9-
}
10-
11-
exec { "opsmatic_public_debian_key":
12-
command => "/usr/bin/wget -qO - https://packagecloud.io/gpg.key | apt-key add -",
13-
require => File["opsmatic_public_debian_repo"],
14-
notify => Exec["opsmatic_public_update_repo_cache"]
10+
apt::key { 'D59097AB':
11+
key_source => 'https://packagecloud.io/gpg.key',
1512
}
1613

17-
exec { "opsmatic_public_update_repo_cache":
18-
command => "/usr/bin/apt-get update",
19-
require => Exec["opsmatic_public_debian_key"]
14+
apt::source { 'opsmatic_public_debian_repo':
15+
location => 'https://packagecloud.io/opsmatic/public/any/',
16+
include_src => false,
17+
release => 'any',
18+
repos => 'main';
2019
}
21-
2220
}

‎manifests/init.pp

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
# == Class: opsmatic::init
2+
#
3+
# === Authors
4+
#
5+
# <TODO>
6+
#
17
class opsmatic::init {
28
}

‎manifests/params.pp

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
# == Class: opsmatic::params
2+
#
3+
# Common class parameters for the Opsmatic puppet class
4+
#
5+
# === Authors
6+
#
7+
# <TODO>
8+
#
19
class opsmatic::params {
210

311
# Integration token
4-
$token = ""
12+
$token = ''
513

614
# Opsmatic webhooks events endpoint
7-
$opsmatic_event_http = "https://api.opsmatic.com/webhooks/events"
15+
$opsmatic_event_http = 'https://api.opsmatic.com/webhooks/events'
816

917
}

‎manifests/puppet-reporter.pp

-35
This file was deleted.

‎manifests/puppet_reporter.pp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# == Class: opsmatic-puppet_reporter
2+
#
3+
# === Authors
4+
#
5+
# <TODO>
6+
#
7+
class opsmatic::puppet_reporter (
8+
$token = $opsmatic::params::token,
9+
) inherits opsmatic::params {
10+
11+
if $token == '' {
12+
fail("Your Opsmatic install token is not defined in ${token}")
13+
}
14+
15+
case $::operatingsystem {
16+
'Debian', 'Ubuntu': { include opsmatic::debian }
17+
default: { fail('Opsmatic Puppet Reporter only supported on Debian and Ubuntu') }
18+
}
19+
20+
package { 'opsmatic-puppet-reporter':
21+
ensure => present,
22+
require => File['opsmatic_public_debian_repo']
23+
}
24+
25+
service { 'opsmatic-puppet-reporter':
26+
ensure => running,
27+
enable => true;
28+
provider => upstart,
29+
require => Package['opsmatic-puppet-reporter'],
30+
}
31+
32+
file { '/etc/init/opsmatic-puppet-reporter.conf':
33+
ensure => file,
34+
owner => 'root',
35+
group => 'root',
36+
mode => '0644',
37+
content => template('opsmatic/puppet_reporter_upstart.erb'),
38+
notify => Service['opsmatic-puppet-reporter'],
39+
}
40+
41+
}

‎metadata.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "opsmatic",
3+
"version": "0.1.2",
4+
"source": "https://github.com/opsmatic/puppet-opsmatic",
5+
"author": "Opsmatic",
6+
"license": "Apache-2.0",
7+
"project_page": "https://github.com/opsmatic/puppet-opsmatic",
8+
"summary": "A Puppet module for installing Opsmatic reporter on Puppet runs",
9+
"operatingsystem_support": [
10+
{
11+
"operatingsystem": "Debian",
12+
"operatingsystemrelease": [
13+
"6",
14+
"7"
15+
]
16+
},
17+
{
18+
"operatingsystem": "Ubuntu",
19+
"operatingsystemrelease": [
20+
"10.04",
21+
"12.04"
22+
]
23+
}
24+
],
25+
"requirements": [
26+
{ "name": "puppet", "version_requirement": "3.x" }
27+
],
28+
"dependencies": [
29+
{ "name": "puppetlabs/apt", "version_requirement": ">= 1.0.0" }
30+
]
31+
}

‎scenarios.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
__default_facts: &default_facts
2+
unittest: true
3+
local_run: true
4+
architecture: x86_64
5+
ipaddress: 127.0.0.1
6+
osfamily: Debian
7+
operatingsystem: Ubuntu
8+
operatingsystemrelease: 12
9+
lsbdistid: Ubuntu
10+
lsbdistcodename: precise
11+
lsbdistrelease: 12.04
12+
lsbmajdistrelease: 12
13+
disable_asserts: true
14+
interfaces: eth0
15+
memorysize: 16.00 GB
16+
processorcount: 1
17+
processor0: UnitTest Processor 0
18+
hardwaremodel: x86_64
19+
hostname: unittest
20+
domain: localdomain
21+
puppetversion: 3.2.3
22+
rubyversion: 1.8.7
23+
facterversion: 1.7.4
24+
kernel: linux
25+
kernelrelease: 3.2.0-23-generic
26+
concat_basedir: /var/lib/puppet/concat
27+
fqdn: unittest.cloud.nextdoor.com

‎spec/classes/debian_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper'
2+
3+
# Facts mocked up for unit testing
4+
FACTS = {
5+
:osfamily => 'Debian',
6+
:operatingsystem => 'Ubuntu',
7+
:operatingsystemrelease => '12',
8+
:lsbdistid => 'Ubuntu',
9+
:lsbdistcodename => 'precise',
10+
:lsbdistrelease => '12.04',
11+
:lsbmajdistrelease => '12',
12+
:kernel => 'linux',
13+
}
14+
15+
describe 'opsmatic::debian', :type => 'class' do
16+
context 'default params' do
17+
let(:facts) { FACTS }
18+
it do
19+
should compile.with_all_deps
20+
should contain_apt__key('D59097AB').with(
21+
'key_source' => 'https://packagecloud.io/gpg.key')
22+
should contain_apt__source('opsmatic_public_debian_repo').with(
23+
'location' => 'https://packagecloud.io/opsmatic/public/any/')
24+
end
25+
end
26+
end

‎spec_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'rubygems'
2+
require 'puppetlabs_spec_helper/module_spec_helper'

0 commit comments

Comments
 (0)
Please sign in to comment.