From e973c0eb64c40042684bd192e645853242e428db Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Tue, 3 Feb 2015 16:03:24 -0500 Subject: [PATCH] Initial commit of working puppet module Initial commit of puppet module with testing baked in. It's delicious --- .fixtures.yml | 13 +++++++++++++ .gitignore | 9 +++++++++ Gemfile | 19 ++++++++++++++++++ LICENSE | 13 +++++++++++++ README.md | 26 +++++++++++++++++++++++++ Rakefile | 4 ++++ manifests/init.pp | 22 +++++++++++++++++++++ metadata.json | 29 ++++++++++++++++++++++++++++ spec/acceptance/hub_spec.rb | 18 +++++++++++++++++ spec/acceptance/nodesets/default.yml | 11 +++++++++++ spec/classes/hub_spec.rb | 17 ++++++++++++++++ spec/spec.opts | 7 +++++++ spec/spec_helper.rb | 1 + spec/spec_helper_acceptance.rb | 27 ++++++++++++++++++++++++++ templates/install_hub.sh.erb | 17 ++++++++++++++++ tests/init.pp | 1 + 16 files changed, 234 insertions(+) create mode 100644 .fixtures.yml create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100644 manifests/init.pp create mode 100644 metadata.json create mode 100644 spec/acceptance/hub_spec.rb create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/classes/hub_spec.rb create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb create mode 100644 spec/spec_helper_acceptance.rb create mode 100644 templates/install_hub.sh.erb create mode 100644 tests/init.pp diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..6495052 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,13 @@ +fixtures: + forge_modules: + stdlib: + repo: "puppetlabs/stdlib" + ref: "4.3.2" + wget: + repo: "maestrodev/wget" + ref: "1.5.5" + git: + repo: "puppetlabs/git" + ref: "0.3.0" + symlinks: + "hub": "#{source_dir}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5db85e --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +pkg/ +Gemfile.lock +vendor/ +spec/fixtures/ +.vagrant/ +.bundle/ +coverage/ +.idea/ +*.iml diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ead1766 --- /dev/null +++ b/Gemfile @@ -0,0 +1,19 @@ +source "https://rubygems.org" + +group :development, :unit_tests do + gem 'rake' + gem 'rspec-puppet' + gem 'puppetlabs_spec_helper' + gem 'puppet-lint' + gem 'simplecov' + gem 'puppet_facts' + gem 'json' +end + +group :system_tests do + gem 'beaker-rspec' + gem 'serverspec' +end + +gem 'facter' +gem 'puppet' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..039b2c9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright 2015 Jake Champlin (Minted.com) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b582014 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +Hub Puppet Module +================= + +This puppet module installs the CLI Utility Hub. + +Also by dependency resolution, installs wget and git both from the forge. + +``` +"dependencies": [ + {"name":"puppetlabs/stdlib","version_requirement":">= 4.3.2"}, + {"name":"maestrodev/wget","version_requirement":">= 1.5.5"}, + {"name":"puppetlabs/git","version_requirement":">= 0.3.0"}, +] +``` + +This module has puppetlabs-spec tests written and beaker acceptance tests written to fully cover the extent of the module. + +To test: +```bash +bundle install +rake spec # For RSpec Unit Tests +rake spec_clean # To clean out fixtures directory +rspec spec/acceptance # To Launch, Test, and Destroy a new Vagrant VM w/ Beaker +``` + +(c) 2015 Minted.com diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..df65dce --- /dev/null +++ b/Rakefile @@ -0,0 +1,4 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' + +PuppetLint.configuration.ignore_paths = [ "spec/**/*.pp", "pkg/**/*.pp"] diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..bab5921 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,22 @@ +# Copyright (C) 2015 Minted Inc. +# All Rights Reserved + +class hub( $version = '2.2.0-rc1' ) { + + include wget + include git + + file { '/usr/local/src/install_hub.sh': + content => template('hub/install_hub.sh.erb'), + mode => '0755', + owner => root, + group => root, + } ~> + + exec { 'install_hub': + cwd => '/usr/local/src', + command => '/usr/local/src/install_hub.sh', + refreshonly => true, + } + +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..9172ba6 --- /dev/null +++ b/metadata.json @@ -0,0 +1,29 @@ +{ + "name": "minted-hub", + "version": "0.0.1", + "author": "Jake Champlin", + "summary": "Installs Hub from Github", + "license": "Apache-2.0", + "source": "https://github.com/minted/minted-hub", + "project_page": "https://github.com/minted/minted-hub", + "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", + "operatingsystem_support": [ + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "12.04" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": "3.x" + } + ], + "dependencies": [ + {"name":"puppetlabs/stdlib","version_requirement":">= 4.3.2"}, + {"name":"maestrodev/wget","version_requirement":">= 1.5.5"}, + {"name":"puppetlabs/git","version_requirement":">= 0.3.0"}, + ] +} diff --git a/spec/acceptance/hub_spec.rb b/spec/acceptance/hub_spec.rb new file mode 100644 index 0000000..211a5e6 --- /dev/null +++ b/spec/acceptance/hub_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper_acceptance' + +describe 'hub class' do + + it 'should work with no errors' do + pp = <<-EOS + class { 'hub': + version => '2.2.0-rc1', + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + + it 'should be installed' do + shell('/usr/local/bin/hub --version') + end +end diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..c66000b --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-12042-x64: + roles: + - master + platform: ubuntu-server-12.04-amd64 + box: ubuntu-server-12042-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box + hypervisor: vagrant +CONFIG: + type: foss + vagrant_ssh_port_random: true diff --git a/spec/classes/hub_spec.rb b/spec/classes/hub_spec.rb new file mode 100644 index 0000000..0eb678c --- /dev/null +++ b/spec/classes/hub_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'hub', :type => :class do + # Wget is included + it { should contain_class('wget') } + + # Git Class is included + it { should contain_class('git') } + + # Install Hub Script + it { should contain_file('/usr/local/src/install_hub.sh').with({ + 'mode' => '0755', + 'owner' => 'root', + 'group' => 'root', + })} + +end diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..3386d62 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,7 @@ +--format +s +--colour +--loadby +mtime +--backtrace +--deprecation-out diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..b25581d --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,27 @@ +require 'beaker-rspec' + +# Install Puppet +foss_opts = { :default_action => 'gem_install' } + +install_puppet( foss_opts ) + +hosts.each do |host| + on host, "mkdir -p #{host['distmoduledir']}" +end + +RSpec.configure do |c| + # Root Project + project_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + c.formatter = :documentation + + c.before :suite do + hosts.each do |host| + copy_module_to(host, :source => project_root, :module_name => 'hub') + shell("/bin/touch #{default['puppetpath']}/hiera.yaml") + on host, puppet('module install puppetlabs-stdlib --version 4.3.2'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install maestrodev-wget --version 1.5.5'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module install puppetlabs-git --version 0.3.0'), { :acceptable_exit_codes => [0,1] } + end + end +end diff --git a/templates/install_hub.sh.erb b/templates/install_hub.sh.erb new file mode 100644 index 0000000..341cb98 --- /dev/null +++ b/templates/install_hub.sh.erb @@ -0,0 +1,17 @@ +#!/bin/sh + +version=<%= @version %> +architecture=<%= scope['::architecture'] %> + +name=hub-linux-${architecture}-${version} +filename=${name}.tar.gz +url=https://github.com/github/hub/releases/download/v${version}/${filename} + +dirname=hub_${version}_linux_${architecture} + +cd /usr/local/src +wget --no-check-certificate $url +tar xzf $filename +cd $dirname +cp etc/hub.bash_completion.sh /etc/bash_completion.d/ +cp hub /usr/local/bin/ diff --git a/tests/init.pp b/tests/init.pp new file mode 100644 index 0000000..69f946c --- /dev/null +++ b/tests/init.pp @@ -0,0 +1 @@ +class { 'hub': }