Unverified Commit ff0769ad authored by Tim Smith's avatar Tim Smith Committed by GitHub

Merge pull request #70 from bmhatfield/cleanup

Convert the HWRP :user_ulimit to a standard custom resource
parents e74b86ee 57bec750
name: delivery
on: [push, pull_request]
jobs:
delivery:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
- name: Run Chef Delivery
uses: actionshub/chef-delivery@master
env:
CHEF_LICENSE: accept-no-persist
\ No newline at end of file
......@@ -37,13 +37,11 @@ doc/
# chef stuff
Berksfile.lock
.kitchen
.kitchen.local.yml
kitchen.local.yml
vendor/
.coverage/
.zero-knife.rb
Policyfile.lock.json
Cheffile.lock
.librarian/
# vagrant stuff
.vagrant/
......
dist: trusty
sudo: false
addons:
apt:
sources:
- chef-current-trusty
packages:
- chefdk
# Don't `bundle install`
install: echo "skip bundle install"
branches:
only:
- master
# Ensure we make ChefDK's Ruby the default
before_script:
- eval "$(chef shell-init bash)"
script:
- chef --version
- cookstyle --version
- foodcritic --version
- chef exec delivery local all
......@@ -45,22 +45,19 @@ a.out
# Testing #
###########
.watchr
.rspec
spec/*
spec/fixtures/*
test/*
features/*
examples/*
Guardfile
Procfile
.kitchen*
.rubocop.yml
spec/*
Rakefile
.travis.yml
.foodcritic
.codeclimate.yml
appveyor.yml
# SCM #
#######
......@@ -92,16 +89,4 @@ Policyfile.lock.json
CONTRIBUTING*
CHANGELOG*
TESTING*
MAINTAINERS.toml
# Strainer #
############
Colanderfile
Strainerfile
.colander
.strainer
# Vagrant #
###########
.vagrant
Vagrantfile
require 'chef/resource'
class Chef
class Resource
class UlimitUser < Chef::Resource
resource_name :user_ulimit
property :username, String, name_property: true
property :filename, String, default: lazy { |r| r.username == '*' ? '00_all_limits' : "#{r.username}_limits" }
property :filehandle_limit, [String, Integer]
property :filehandle_soft_limit, [String, Integer]
property :filehandle_hard_limit, [String, Integer]
property :process_limit, [String, Integer]
property :process_soft_limit, [String, Integer]
property :process_hard_limit, [String, Integer]
property :memory_limit, [String, Integer]
property :core_limit, [String, Integer]
property :core_soft_limit, [String, Integer]
property :core_hard_limit, [String, Integer]
property :stack_limit, [String, Integer]
property :stack_soft_limit, [String, Integer]
property :stack_hard_limit, [String, Integer]
property :rtprio_limit, [String, Integer]
property :rtprio_soft_limit, [String, Integer]
property :rtprio_hard_limit, [String, Integer]
property :virt_limit, [String, Integer]
action :create do
new_resource.filename = "#{new_resource.filename}.conf" unless new_resource.filename.include?('.conf')
template "/etc/security/limits.d/#{new_resource.filename}" do
source 'ulimit.erb'
cookbook 'ulimit'
mode '0644'
variables(
ulimit_user: new_resource.username,
filehandle_limit: new_resource.filehandle_limit,
filehandle_soft_limit: new_resource.filehandle_soft_limit,
filehandle_hard_limit: new_resource.filehandle_hard_limit,
process_limit: new_resource.process_limit,
process_soft_limit: new_resource.process_soft_limit,
process_hard_limit: new_resource.process_hard_limit,
memory_limit: new_resource.memory_limit,
core_limit: new_resource.core_limit,
core_soft_limit: new_resource.core_soft_limit,
core_hard_limit: new_resource.core_hard_limit,
stack_limit: new_resource.stack_limit,
stack_soft_limit: new_resource.stack_soft_limit,
stack_hard_limit: new_resource.stack_hard_limit,
rtprio_limit: new_resource.rtprio_limit,
rtprio_soft_limit: new_resource.rtprio_soft_limit,
rtprio_hard_limit: new_resource.rtprio_hard_limit,
virt_limit: new_resource.virt_limit
)
end
end
action :delete do
new_resource.filename = "#{new_resource.filename}.conf" unless new_resource.filename.include?('.conf')
file "/etc/security/limits.d/#{new_resource.filename}" do
action :delete
end
end
end
end
end
resource_name :user_ulimit
property :username, String, name_property: true
property :filename, String, default: lazy { |r| r.username == '*' ? '00_all_limits' : "#{r.username}_limits" }
property :filehandle_limit, [String, Integer]
property :filehandle_soft_limit, [String, Integer]
property :filehandle_hard_limit, [String, Integer]
property :process_limit, [String, Integer]
property :process_soft_limit, [String, Integer]
property :process_hard_limit, [String, Integer]
property :memory_limit, [String, Integer]
property :core_limit, [String, Integer]
property :core_soft_limit, [String, Integer]
property :core_hard_limit, [String, Integer]
property :stack_limit, [String, Integer]
property :stack_soft_limit, [String, Integer]
property :stack_hard_limit, [String, Integer]
property :rtprio_limit, [String, Integer]
property :rtprio_soft_limit, [String, Integer]
property :rtprio_hard_limit, [String, Integer]
property :virt_limit, [String, Integer]
action :create do
new_resource.filename = "#{new_resource.filename}.conf" unless new_resource.filename.include?('.conf')
template "/etc/security/limits.d/#{new_resource.filename}" do
source 'ulimit.erb'
cookbook 'ulimit'
mode '0644'
variables(
ulimit_user: new_resource.username,
filehandle_limit: new_resource.filehandle_limit,
filehandle_soft_limit: new_resource.filehandle_soft_limit,
filehandle_hard_limit: new_resource.filehandle_hard_limit,
process_limit: new_resource.process_limit,
process_soft_limit: new_resource.process_soft_limit,
process_hard_limit: new_resource.process_hard_limit,
memory_limit: new_resource.memory_limit,
core_limit: new_resource.core_limit,
core_soft_limit: new_resource.core_soft_limit,
core_hard_limit: new_resource.core_hard_limit,
stack_limit: new_resource.stack_limit,
stack_soft_limit: new_resource.stack_soft_limit,
stack_hard_limit: new_resource.stack_hard_limit,
rtprio_limit: new_resource.rtprio_limit,
rtprio_soft_limit: new_resource.rtprio_soft_limit,
rtprio_hard_limit: new_resource.rtprio_hard_limit,
virt_limit: new_resource.virt_limit
)
end
end
action :delete do
new_resource.filename = "#{new_resource.filename}.conf" unless new_resource.filename.include?('.conf')
file "/etc/security/limits.d/#{new_resource.filename}" do
action :delete
end
end
require 'spec_helper'
describe 'custom resource test recipe on ubuntu 16.04' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04') }
let(:chef_run) { runner.converge('test::default') }
it 'converges successfully' do
expect { :chef_run }.to_not raise_error
end
end
require 'spec_helper'
describe 'user_ulimit resource' do
step_into :user_ulimit
platform 'ubuntu'
context 'without the filename specified' do
recipe do
user_ulimit 'tomcat' do
filehandle_soft_limit 8192
end
end
it { is_expected.to create_template('/etc/security/limits.d/tomcat_limits.conf') }
end
context 'with the filename specified and not ending in .conf' do
recipe do
user_ulimit 'tomcat' do
filename 'foo'
filehandle_soft_limit 8192
end
end
it { is_expected.to create_template('/etc/security/limits.d/foo.conf') }
end
context 'with the filename specified and ending in .conf' do
recipe do
user_ulimit 'tomcat' do
filename 'foo.conf'
filehandle_soft_limit 8192
end
end
it { is_expected.to create_template('/etc/security/limits.d/foo.conf') }
end
context 'with the username set to *' do
recipe do
user_ulimit 'tomcat' do
username '*'
filehandle_soft_limit 8192
end
end
it { is_expected.to create_template('/etc/security/limits.d/00_all_limits.conf') }
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment