Skip to content

Commit

Permalink
Add travis tests (#5)
Browse files Browse the repository at this point in the history
* added travis yml
  • Loading branch information
ryancurrah committed Jul 28, 2017
1 parent 8e855d9 commit c3f8d67
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format documentation
34 changes: 34 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
language: python
python:
- "2.7"

# command to install dependencies
before_install:
- sudo apt-get install software-properties-common
- sudo apt-add-repository -y ppa:brightbox/ruby-ng
- sudo apt-get update
- sudo apt-get install ruby2.3 rsync
- sudo gem install serverspec rake
- sudo curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com
- sudo sh bootstrap-salt.sh

install:
# Copy state, pillar and minion conf
- sudo mkdir -p /srv/salt/states /srv/pillar
- sudo rsync -av . /srv/salt/states/ --exclude .git
- sudo cp .travis/minion /etc/salt/minion
- sudo cp .travis/state_top.sls /srv/salt/states/top.sls
- sudo cp .travis/pillar_top.sls /srv/pillar/top.sls
- sudo cp pillar.example /srv/pillar/pillar.sls
- sudo service salt-minion restart

# Additional debug help
- sudo cat /var/log/salt/*

# See what kind of travis box you're on
- sudo salt-call grains.items --local

# command to run tests
script:
- sudo salt-call state.highstate --local --retcode-passthrough
- sudo rake spec
4 changes: 4 additions & 0 deletions .travis/minion
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file_client: local
file_roots:
base:
- /srv/salt/states
3 changes: 3 additions & 0 deletions .travis/pillar_top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base:
'*':
- pillar # should be limits, but to make copying .travis.yml easier named it pillar
3 changes: 3 additions & 0 deletions .travis/state_top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base:
'*':
- limits
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0] - 2017-07-27
* Initial release
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
# SaltStack formula for setting user limits in PAM module
[![Build Status](https://travis-ci.org/ryancurrah/limits-formula.svg?branch=master)](https://travis-ci.org/ryancurrah/limits-formula)

# limits-formula

SaltStack formula for setting user limits in PAM module

## Description

The pam_limits.so module applies ulimit limits, nice priority and number of simultaneous login sessions
limit to user login sessions. This description of the configuration file syntax applies to the
/etc/security/limits.conf file and *.conf files in the /etc/security/limits.d directory.

## More Info
## Tests

The Travis CI tests run the state on a Ubuntu server. By running the state it checks that there is no syntax errors and that it works for Ubuntu. Other operating systems are NOT tested therefore have a risk of not working on them. ServerSpec is used to verify that the state installed the proper packages and created limits.conf with the proper owner, group, mode and settings.

## Example Pillar

```yaml
limits:
users:
johndoe:
- limit_type: hard
limit_item: core
limit_value: unlimited
- limit_type: hard
limit_item: nproc
limit_value: 1000
janedoe:
- limit_type: hard
limit_item: locks
limit_value: 300
groups:
employees:
- limit_type: hard
limit_item: cpu
limit_value: 5
- limit_type: hard
limit_item: nproc
limit_value: 500
```

## More info about limits

[http://linux.die.net/man/5/limits.conf](http://linux.die.net/man/5/limits.conf)

Expand All @@ -27,4 +61,3 @@ limit to user login sessions. This description of the configuration file syntax
* danoe
* tampakrap
* cboltz

27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rake'
require 'rspec/core/rake_task'

task :spec => 'spec:all'
task :default => :spec

namespace :spec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end

task :all => targets
task :default => :all

targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end
2 changes: 1 addition & 1 deletion limits/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pam:
file.managed:
- user: root
- group: root
- mode: 440
- mode: 644
- template: jinja
- source: salt://limits/files/limits.conf
- require:
Expand Down
2 changes: 1 addition & 1 deletion pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ limits:
limit_value: 5
- limit_type: hard
limit_item: nproc
limit_value: 500
limit_value: 500
50 changes: 50 additions & 0 deletions spec/localhost/limits_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'spec_helper'

describe package('login'), :if => os[:family] == 'debian' do
it { should be_installed }
end

describe package('login'), :if => os[:family] == 'ubuntu' do
it { should be_installed }
end

describe package('pam'), :if => os[:family] == 'centos' do
it { should be_installed }
end

describe package('pam'), :if => os[:family] == 'fedora' do
it { should be_installed }
end

describe package('pam'), :if => os[:family] == 'redhat' do
it { should be_installed }
end

describe package('pam'), :if => os[:family] == 'amazon' do
it { should be_installed }
end

describe package('sys-libs/pam'), :if => os[:family] == 'gentoo' do
it { should be_installed }
end

describe package('login'), :if => os[:family] == 'mint' do
it { should be_installed }
end

describe package('pam'), :if => os[:family] == 'suse' do
it { should be_installed }
end

describe file('/etc/security/limits.conf') do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should be_mode 644 }
its(:content) { should match /^# User limit specification$/ }
its(:content) { should match /^johndoe hard core unlimited$/ }
its(:content) { should match /^johndoe hard nproc 1000$/ }
its(:content) { should match /^janedoe hard locks 300$/ }
its(:content) { should match /^# Group limit specification$/ }
its(:content) { should match /^@employees hard cpu 5$/ }
its(:content) { should match /^@employees hard nproc 500$/ }
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'serverspec'

set :backend, :exec

0 comments on commit c3f8d67

Please sign in to comment.