diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..1ee192b --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,5 @@ +fixtures: + repositories: + stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + symlinks: + eyplib: "#{source_dir}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edb819a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*~ +/pkg/ +/.vagrant +/junit +/log +/spec/fixtures/manifests +/spec/fixtures/modules +/Gemfile.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9ddb2dc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,45 @@ +--- +language: ruby +sudo: required +services: + - docker +script: + - bundle exec rspec spec/acceptance +bundler_args: --without system_tests +matrix: + include: + - rvm: default + env: LINT=puppetcode + dist: trusty + bundler_args: + script: bundle exec rake lint + - rvm: default + env: LINT=metadata + dist: trusty + bundler_args: + script: bundle exec rake metadata_lint + - rvm: default + env: JOB=validate + dist: trusty + bundler_args: + script: bundle exec rake validate + - rvm: default + env: BEAKER_set="centos5-docker" + dist: trusty + bundler_args: + script: sudo service docker restart ; sleep 10 && bundle exec rspec spec/acceptance/*_spec.rb + - rvm: default + env: BEAKER_set="centos6-docker" + dist: trusty + bundler_args: + script: sudo service docker restart ; sleep 10 && bundle exec rspec spec/acceptance/*_spec.rb + - rvm: default + env: BEAKER_set="centos7-docker" + dist: trusty + bundler_args: + script: sudo service docker restart ; sleep 10 && bundle exec rspec spec/acceptance/*_spec.rb + - rvm: default + env: BEAKER_set="ubuntu14-docker" + dist: trusty + bundler_args: + script: sudo service docker restart ; sleep 10 && bundle exec rspec spec/acceptance/*_spec.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..be325d9 --- /dev/null +++ b/Gemfile @@ -0,0 +1,18 @@ +source 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3'] +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 0.1.0' +gem 'puppet-lint', '>= 0.3.2' +gem 'facter', '>= 1.7.0' + +group :system_tests do + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false + gem 'beaker_spec_helper', :require => false + gem 'beaker-puppet_install_helper', :require => false + gem 'serverspec', :require => false + gem 'rspec', '< 3.2', :require => false if RUBY_VERSION =~ /^1\.8/ + gem 'rspec-puppet', :require => false + gem 'metadata-json-lint', :require => false +end diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f7b0b1 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +# eyplib + +#### Table of Contents + +1. [Overview](#overview) +2. [Module Description](#module-description) +3. [Setup](#setup) + * [What eyplib affects](#what-eyplib-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with eyplib](#beginning-with-eyplib) +4. [Usage](#usage) +5. [Reference](#reference) +5. [Limitations](#limitations) +6. [Development](#development) + * [Contributing](#contributing) + +## Overview + +A one-maybe-two sentence summary of what the module does/what problem it solves. +This is your 30 second elevator pitch for your module. Consider including +OS/Puppet version it works with. + +## Module Description + +If applicable, this section should have a brief description of the technology +the module integrates with and what that integration enables. This section +should answer the questions: "What does this module *do*?" and "Why would I use +it?" + +If your module has a range of functionality (installation, configuration, +management, etc.) this is the time to mention it. + +## Setup + +### What eyplib affects + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute on the system it's installed on. +* This is a great place to stick any warnings. +* Can be in list or paragraph form. + +### Setup Requirements + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +### Beginning with eyplib + +The very basic steps needed for a user to get the module up and running. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you may wish to include an additional section here: Upgrading +(For an example, see http://forge.puppetlabs.com/puppetlabs/firewall). + +## Usage + +Put the classes, types, and resources for customizing, configuring, and doing +the fancy stuff with your module here. + +## Reference + +Here, list the classes, types, providers, facts, etc contained in your module. +This section should include all of the under-the-hood workings of your module so +people know what the module is touching on their system but don't need to mess +with things. (We are working on automating this section!) + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. + +## Development + +We are pushing to have acceptance testing in place, so any new feature should +have some test to check both presence and absence of any feature + +### Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Added some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..39246f9 --- /dev/null +++ b/Rakefile @@ -0,0 +1,21 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] + +desc "Validate manifests, templates, and ruby files" +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..e2ba650 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,12 @@ +# == Class: eyplib +# +# === eyplib documentation +# +class eyplib inherits eyplib::params{ + + # service definition and notification: + # + # notify => Class['eyplib::service'], + # class { 'eyplib::service': } + +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..326f6ba --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,35 @@ +class eyplib::params { + + case $::osfamily + { + 'redhat': + { + case $::operatingsystemrelease + { + /^[5-7].*$/: + { + } + default: { fail("Unsupported RHEL/CentOS version! - ${::operatingsystemrelease}") } + } + } + 'Debian': + { + case $::operatingsystem + { + 'Ubuntu': + { + case $::operatingsystemrelease + { + /^14.*$/: + { + } + default: { fail("Unsupported Ubuntu version! - ${::operatingsystemrelease}") } + } + } + 'Debian': { fail('Unsupported') } + default: { fail('Unsupported Debian flavour!') } + } + } + default: { fail('Unsupported OS!') } + } +} diff --git a/manifests/service.pp b/manifests/service.pp new file mode 100644 index 0000000..ca60e15 --- /dev/null +++ b/manifests/service.pp @@ -0,0 +1,25 @@ +class eyplib::service ( + $manage_service=true, + $manage_docker_service=true, + $ensure ='running', + $enable =true, + ) inherits eyplib::params { + + # + validate_bool($manage_docker_service) + validate_bool($manage_service) + validate_bool($enable) + + validate_re($ensure, [ '^running$', '^stopped$' ], "Not a valid daemon status: ${ensure}") + + if(getvar('::eyp_docker_iscontainer')==undef or + getvar('::eyp_docker_iscontainer')==false or + getvar('::eyp_docker_iscontainer') =~ /false/ or + $manage_docker_service) + { + if($manage_service) + { + #service or exec here + } + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..86c5d04 --- /dev/null +++ b/metadata.json @@ -0,0 +1,49 @@ +{ + "name": "eyp-eyplib", + "version": "0.1.0", + "author": "eyp", + "summary": null, + "license": "Apache-2.0", + "source": "https://github.com/AtlasIT-AM/eyp-eyplib", + "project_page": null, + "issues_url": "https://github.com/AtlasIT-AM/eyp-eyplib/issues", + "dependencies": [ + {"name":"puppetlabs/stdlib","version_requirement":">= 1.0.0"} + ], + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ "5", "6", "7" ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ "5", "6", "7" ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ "5", "6", "7" ] + }, + { + "operatingsystem": "OEL", + "operatingsystemrelease": [ "5", "6", "7" ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ "5", "6", "7" ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ "14.04" ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": ">= 3.0.0" + }, + { + "name": "puppet", + "version_requirement": ">= 3.0.0" + } + ] +} diff --git a/spec/acceptance/base_spec.rb b/spec/acceptance/base_spec.rb new file mode 100644 index 0000000..4c8d81b --- /dev/null +++ b/spec/acceptance/base_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper_acceptance' +require_relative './version.rb' + +describe 'eyplib class' do + + context 'basic setup' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOF + + class { 'eyplib': } + + EOF + + # Run it twice and test for idempotency + expect(apply_manifest(pp).exit_code).to_not eq(1) + expect(apply_manifest(pp).exit_code).to eq(0) + end + + end +end diff --git a/spec/acceptance/nodesets/centos5-docker.yml b/spec/acceptance/nodesets/centos5-docker.yml new file mode 100644 index 0000000..563ebd2 --- /dev/null +++ b/spec/acceptance/nodesets/centos5-docker.yml @@ -0,0 +1,16 @@ +HOSTS: + centos-5-x64: + default_apply_opts: + order: random + strict_variables: + platform: el-5-x86_64 + hypervisor : docker + image: centos:5 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'rm -rf /var/run/network/*' + - 'yum install -y gcc make crontabs tar wget java-1.7.0-openjdk java-1.7.0-openjdk-devel' +CONFIG: + type: foss + log_level: debug diff --git a/spec/acceptance/nodesets/centos6-docker.yml b/spec/acceptance/nodesets/centos6-docker.yml new file mode 100644 index 0000000..b54ef32 --- /dev/null +++ b/spec/acceptance/nodesets/centos6-docker.yml @@ -0,0 +1,16 @@ +HOSTS: + centos-6-x64: + default_apply_opts: + order: random + strict_variables: + platform: el-6-x86_64 + hypervisor : docker + image: centos:6 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'rm -rf /var/run/network/*' + - 'yum install -y gcc make crontabs tar wget curl' +CONFIG: + type: foss + log_level: debug diff --git a/spec/acceptance/nodesets/centos7-docker.yml b/spec/acceptance/nodesets/centos7-docker.yml new file mode 100644 index 0000000..e99b37c --- /dev/null +++ b/spec/acceptance/nodesets/centos7-docker.yml @@ -0,0 +1,16 @@ +HOSTS: + centos-7-x64: + default_apply_opts: + order: random + strict_variables: + platform: el-7-x86_64 + hypervisor : docker + image: centos:7 + docker_preserve_image: true + docker_cmd: '["/usr/sbin/init"]' + docker_image_commands: + - 'rm -rf /var/run/network/*' + - 'yum install -y gcc make crontabs tar wget iproute java-1.7.0-openjdk java-1.7.0-openjdk-devel' +CONFIG: + type: foss + log_level: debug diff --git a/spec/acceptance/nodesets/ubuntu14-docker.yml b/spec/acceptance/nodesets/ubuntu14-docker.yml new file mode 100644 index 0000000..82cf2a8 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu14-docker.yml @@ -0,0 +1,14 @@ +HOSTS: + ubuntu-14-04: + default_apply_opts: + order: random + strict_variables: + platform: ubuntu-14.04-x64 + hypervisor : docker + image: ubuntu:14.04 + docker_preserve_image: true + docker_image_commands: + - 'apt-get install gcc make tar wget openjdk-7-jdk openjdk-7-jre -y' +CONFIG: + type: foss + log_level: debug diff --git a/spec/acceptance/version.rb b/spec/acceptance/version.rb new file mode 100644 index 0000000..a744070 --- /dev/null +++ b/spec/acceptance/version.rb @@ -0,0 +1,16 @@ + +_osfamily = fact('osfamily') +_operatingsystem = fact('operatingsystem') +_operatingsystemrelease = fact('operatingsystemrelease').to_f + +case _osfamily +when 'RedHat' + $examplevar = 'valrh' + +when 'Debian' + $examplevar = 'valdeb' + +else + $examplevar = '-_-' + +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..4682249 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,36 @@ + +require 'spec_helper' + +describe 'eyplib' do + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + context "eyplib class without any parameters" do + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_service('eyplib') } + it { is_expected.to contain_package('eyplib').with_ensure('present') } + end + end + end + end + + context 'unsupported operating system' do + describe 'eyplib class without any parameters' do + let(:facts) do + { + :osfamily => 'SOFriki', + :operatingsystem => 'SOFregit', + } + end + + it { + expect { should raise_error(Puppet::Error) } + } + end + end +end 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..07ff720 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,22 @@ +require 'beaker-rspec' +require 'beaker/puppet_install_helper' + +run_puppet_install_helper + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + puppet_module_install(:source => proj_root, :module_name => 'eyplib') + hosts.each do |host| + # dependencies + on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + end + end +end diff --git a/tests/init.pp b/tests/init.pp new file mode 100644 index 0000000..5ca606e --- /dev/null +++ b/tests/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# http://docs.puppetlabs.com/guides/tests_smoke.html +# +include eyplib