Skip to content

Commit

Permalink
Adds EL7 support with systemd, removes --refresh parameter that is no…
Browse files Browse the repository at this point in the history
… longer used in devpi-server, updates travis configuration with matrix / deploy on tags, more thorough readme with examples
  • Loading branch information
jlyheden committed Feb 19, 2016
1 parent 754bd94 commit 1cda445
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 66 deletions.
4 changes: 4 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ platforms:
driver_plugin: vagrant
driver_config:
box: puppetlabs/centos-6.5-64-puppet
- name: centos7
driver_plugin: vagrant
driver_config:
box: centos/7
- name: vbox-ubuntu-server-12042
driver_plugin: vagrant
driver_config:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.3-p547
2.1.6
21 changes: 14 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
rvm: 1.9.3
env:
- PUPPET_VERSION=3.7.3
sudo: false
language: ruby
bundler_args: --without kitchen
script:
- bundle exec rake lint
- bundle exec rake validate
- bundle exec rake spec
before_deploy:
- bundle exec rake clean
- bundle exec rake set_travis_version
matrix:
include:
- rvm: 1.9.3
env: PUPPET_VERSION="= 3.7.3"
- rvm: 1.9.3
env: PUPPET_VERSION="= 3.7.3" FUTURE_PARSER="yes"
- rvm: 1.9.3
env: PUPPET_VERSION="~> 4.0"
deploy:
skip_cleanup: true
provider: puppetforge
on:
tags: true
branch: master
user:
secure: "ESKUavziAJK/watXniM6PhhyGbiZzkd6Yd4LkVXJt9u9e8l4AQ9CSrGIruGVMkwxEg5ezRnRU8+PcPrKfxtnr48gjCsrLgi+IKIHuK+sTxTyJDo9V1OZ44iaBHFviF59f2yiiQDt9JqflfYd/sm1OudDQoczWdVXO/JgnX4r7tY="
password:
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.5.1', '<=3.7.2']
puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.5.1', '<=3.7.3']

group :rspec, :kitchen do
gem 'librarian-puppet', '2.0.0'
gem 'librarian-puppet', '2.1.0'
gem 'puppet', puppetversion
gem 'rspec_junit_formatter'
gem 'puppet-blacksmith'
Expand All @@ -13,12 +13,12 @@ group :rspec do
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '< 1.1.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git'
gem 'rspec-puppet'
gem 'puppet-syntax'
end

group :kitchen do
gem 'puppet_forge', '<= 1.0.2'
gem 'puppet_forge', '< 2.0.0'
gem 'test-kitchen'
gem 'kitchen-puppet'
gem 'kitchen-docker'
Expand Down
66 changes: 59 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# devpi

[![Build Status](https://secure.travis-ci.org/unibet/puppet-devpi.png)](http://travis-ci.org/unibet/puppet-devpi)
[![Puppet Forge](https://img.shields.io/puppetforge/v/unibet/devpi.svg)](https://forge.puppetlabs.com/unibet/devpi)
[![Puppet Forge](https://img.shields.io/puppetforge/f/unibet/devpi.svg)](https://forge.puppetlabs.com/unibet/devpi)

#### Table of Contents

Expand All @@ -21,7 +23,7 @@ Manages devpi - PyPI server and packaging/testing/release tool

## Module Description

Installs devpi via pip, manages upstart script and service.
Installs devpi via pip, manages upstart/systemd script and service.

## Setup

Expand All @@ -31,31 +33,81 @@ Installs devpi via pip, manages upstart script and service.
* Creates user devpi (configurable)
* Creates service devpi-server
* Installs pip package devpi-server
* Optionally installs pip package devpi-client

### Setup Requirements **OPTIONAL**
### Setup Requirements

Requires python, pip and modern enough setuptools

### Beginning with devpi

Install it using PMT:
```
puppet module install unibet-devpi
```

## Usage

Put the classes, types, and resources for customizing, configuring, and doing
the fancy stuff with your module here.
Usage in its simplest form:

```
class { '::devpi': }
```

If you want the client installed as well:

```
class { '::devpi':
client => true
}
```

You may want to install devpi contained in a virtualenv in which case you could declare it as follows (using the stankevich-python module for virtualenv management):

```
$virtualenv = '/venv'
::python::virtualenv { $virtualenv:
ensure => present,
systempkgs => false,
timeout => 0,
}
::python::pip { 'devpi-server':
pkgname => 'devpi-server==2.1.5',
virtualenv => $virtualenv,
}
class { '::devpi':
virtualenv => $virtualenv
}
```

Setting custom port and host listener:

```
class { '::devpi':
listen_host => '127.0.0.1',
listen_port => 13141
}
```

## Reference

The only external facing class should be "devpi". Uses the anchor pattern for class containment, so you can form dependencies to Class['devpi'] and expect that all resources within the devpi module are executed.
The only external facing class should be "devpi". It uses the anchor pattern for class containment so you can form dependencies to Class['devpi'] and expect all resources declared within the devpi class to be realized.

## Limitations

Only tested on EL6
Only tested on EL6 and EL7

## Development

All pull requests are welcome
We welcome all pull requests that comes with rspec tests covering the new functionality.

Tests can be executed locally using bundler:
```
bundle install
bundle exec rake lint
bundle exec rake validate
bundle exec rake spec
```
16 changes: 0 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,3 @@ desc "Run integration tests"
task :integration do
sh "kitchen test all --destroy=always --parallel"
end

desc "Set patch version in metadata.json based on env var TRAVIS_BUILD_NUMBER"
task :set_travis_version do
require 'json'
travis_build_number = ENV['TRAVIS_BUILD_NUMBER']
metadata_json = File.read('metadata.json')
data_hash = JSON.parse(metadata_json)
version = data_hash["version"]
new_version = "#{version.split(".")[0,2].join(".")}.#{travis_build_number}"
data_hash["version"] = new_version
File.open('metadata.json', 'w') do |f|
f.write(JSON.pretty_generate(data_hash))
end
puts "Travis build number: #{travis_build_number}"
puts "New version: #{new_version}"
end
29 changes: 21 additions & 8 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
$listen_host = $::devpi::listen_host,
$listen_port = $::devpi::listen_port,
$server_dir = $::devpi::server_dir,
$refresh = $::devpi::refresh,
$virtualenv = $::devpi::virtualenv,
) {
) inherits ::devpi::params {

file { "/etc/init/${::devpi::service_name}.conf":
ensure => $::devpi::ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/upstart.erb")
if $::devpi::params::systemd {
$devpi_path = $virtualenv ? {
'' => '/usr/bin/devpi-server',
default => "${virtualenv}/bin/devpi-server"
}
file { "/usr/lib/systemd/system/${::devpi::service_name}.service":
ensure => $::devpi::ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/systemd.service.erb")
}
} else {
file { "/etc/init/${::devpi::service_name}.conf":
ensure => $::devpi::ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/upstart.erb")
}
}

}
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@
Class['::devpi::service']
}

if $::devpi::params::systemd {
Class['::devpi::config'] ~>
class {'::devpi::systemd': } ->
Class['::devpi::service']
}

}
14 changes: 14 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,18 @@
$package_client = 'devpi-client'
$service = 'devpi-server'
$server_dir = '/opt/devpi'

case $::osfamily {
redhat: {
$systemd = $::operatingsystemmajrelease ? {
5 => false,
6 => false,
default => true
}
}
default: {
fail("Unsupported :osfamily ${::osfamily}")
}
}

}
9 changes: 7 additions & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class devpi::service {
class devpi::service inherits ::devpi::params {

$provider = $::devpi::params::systemd ? {
true => 'systemd',
default => 'upstart'
}

service { $::devpi::service_name:
ensure => $::devpi::service_ensure,
enable => $::devpi::service_enable,
provider => 'upstart'
provider => $provder
}

}
7 changes: 7 additions & 0 deletions manifests/systemd.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class devpi::systemd {
exec { 'devpi_systemctl_daemon_reload':
command => 'systemctl daemon-reload',
path => '/bin:/usr/bin:/sbin:/usr/sbin',
refreshonly => true
}
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unibet-devpi",
"version": "0.1.0",
"version": "0.2.0",
"author": "unibet",
"summary": "Puppet module to manage python devpi repositories",
"license": "Apache 2.0",
Expand Down
79 changes: 64 additions & 15 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,72 @@
require 'spec_helper'
describe 'devpi' do

context 'with defaults for all parameters' do
it { should compile.with_all_deps }
it { should_not contain_package('devpi-client') }
it { should contain_package('devpi-server') }
it { should contain_service('devpi-server') }
it { should contain_user('devpi') }
it { should contain_file('/opt/devpi') }
it { should contain_file('/etc/init/devpi-server.conf').with_content(/exec su - devpi -c "devpi-server --host 0.0.0.0 --port 3141 --refresh 3600 --serverdir \/opt\/devpi"\n/) }
end
[6,7].each do |osmaj|
context "on RedHat#{osmaj}" do
let(:facts) do
{
:operatingsystemmajrelease => osmaj
}
end

context "with defaults for all parameters" do

it { should compile.with_all_deps }
it { should_not contain_package('devpi-client') }
it { should contain_package('devpi-server') }
it { should contain_service('devpi-server') }
it { should contain_user('devpi') }
it { should contain_file('/opt/devpi') }
if osmaj == 6 then
it {
should contain_file('/etc/init/devpi-server.conf')
.with_content(/exec su - devpi -c "devpi-server --host 0.0.0.0 --port 3141 --serverdir \/opt\/devpi"\n/)
}
it {
should_not contain_class('devpi::config').that_notifies('Class[devpi::systemd]')
}
elsif osmaj == 7 then
it {
should contain_file('/usr/lib/systemd/system/devpi-server.service')
.with_content(/User=devpi\nGroup=devpi\nExecStart=\/usr\/bin\/devpi-server --host 0.0.0.0 --port 3141 --serverdir \/opt\/devpi\n/)
}
it {
should contain_class('devpi::config').that_notifies('Class[devpi::systemd]')
}
end
end

context 'with client => true' do
let :params do {
:client => true
} end

context 'with client => true' do
let :params do {
:client => true
} end
it { should compile.with_all_deps }
it { should contain_package('devpi-client') }
end

it { should compile.with_all_deps }
it { should contain_package('devpi-client') }
context 'with virtualenv => /venv' do
let :params do {
:virtualenv => '/venv'
} end

it { should compile.with_all_deps }
it { should_not contain_class('devpi::package') }
if osmaj == 6 then
it {
should contain_file('/etc/init/devpi-server.conf')
.with_content(/exec su - devpi -c "\/venv\/bin\/devpi-server --host 0.0.0.0 --port 3141 --serverdir \/opt\/devpi"\n/)
}
elsif osmaj == 7 then
it {
should contain_file('/usr/lib/systemd/system/devpi-server.service')
.with_content(/User=devpi\nGroup=devpi\nExecStart=\/venv\/bin\/devpi-server --host 0.0.0.0 --port 3141 --serverdir \/opt\/devpi\n/)
}
end
end

end
end


end
12 changes: 12 additions & 0 deletions templates/systemd.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=devpi
Wants=basic.target
After=basic.target network.target

[Service]
User=<%= @user %>
Group=<%= @group %>
ExecStart=<%= @devpi_path %> --host <%= @listen_host %> --port <%= @listen_port %> --serverdir <%= @server_dir %>

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 1cda445

Please sign in to comment.