diff --git a/.fixtures.yml b/.fixtures.yml index e715c99..3a64031 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,4 +1,4 @@ --- fixtures: symlinks: - odoo9: "#{source_dir}" + odoo: "#{source_dir}" diff --git a/README.md b/README.md index 38b506c..f2b7087 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# odoo9 +# odoo [![CircleCI](https://circleci.com/gh/locp/puppet-odoo/tree/master.svg?style=svg)](https://circleci.com/gh/locp/puppet-odoo/tree/master) [![Build Status](https://travis-ci.org/locp/puppet-odoo.png?branch=master)](https://travis-ci.org/locp/puppet-odoo) @@ -8,9 +8,9 @@ ## Table of Contents 1. [Description](#description) -1. [Setup - The basics of getting started with odoo9](#setup) - * [What odoo9 affects](#what-odoo9-affects) - * [Beginning with odoo9](#beginning-with-odoo9) +1. [Setup - The basics of getting started with odoo](#setup) + * [What odoo affects](#what-odoo-affects) + * [Beginning with odoo](#beginning-with-odoo) 1. [Usage - Configuration options and additional functionality](#usage) 1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) 1. [Limitations - OS compatibility, etc.](#limitations) @@ -28,7 +28,7 @@ This module has now been renamed to locp-odoo. Please see the following: ## Setup -### What odoo9 affects +### What odoo affects * Installs the `odoo` package from the Odoo repository. * Configures `/etc/odoo/openerp-server.conf`. @@ -37,10 +37,10 @@ This module has now been renamed to locp-odoo. Please see the following: the Odoo nightly builds. * Optionally installs the `wkhtmltopdf` package from the Odoo repository. -### Beginning with odoo9 +### Beginning with odoo ```puppet -include ::odoo9 +include ::odoo ``` ## Usage @@ -54,14 +54,14 @@ server: ```puppet class { 'postgresql::server': - before => Class['odoo9'] + before => Class['odoo'] } -class { '::odoo9::repo': - before => Class['odoo9'] +class { '::odoo::repo': + before => Class['odoo'] } -class { '::odoo9': +class { '::odoo': install_wkhtmltopdf => true, settings => { 'options' => { diff --git a/Vagrantfile b/Vagrantfile index 637d46c..4b952ba 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -9,7 +9,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.hostname = 'node0' config.vm.box = 'puppetlabs/ubuntu-14.04-64-nocm' config.puppet_install.puppet_version = '3.8.2' - config.vm.synced_folder '.', '/etc/puppet/modules/odoo9' + config.vm.synced_folder '.', '/etc/puppet/modules/odoo' metadata_json_file = "#{File.dirname(__FILE__)}/metadata.json" if File.exist?(metadata_json_file) JSON.parse( @@ -24,7 +24,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provision 'shell', inline: 'puppet module install puppetlabs-postgresql' config.vm.provision 'puppet' do |puppet| puppet.manifests_path = 'examples' - puppet.manifest_file = 'init.pp' + puppet.manifest_file = 'odoo10.pp' end config.vm.network 'forwarded_port', guest: 8069, host: 8069 config.vm.provider 'virtualbox' do |vb| diff --git a/examples/odoo10.pp b/examples/odoo10.pp new file mode 100644 index 0000000..8c93ddd --- /dev/null +++ b/examples/odoo10.pp @@ -0,0 +1,33 @@ +# 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: +# https://docs.puppet.com/guides/tests_smoke.html +# +class { 'postgresql::server': + before => Class['odoo'] +} + +class { '::odoo::repo10': + before => Class['odoo'] +} + +class { '::odoo': + install_wkhtmltopdf => true, + settings => { + 'options' => { + 'admin_passwd' => 'XXX_TOP_SECRET_XXX', + 'db_host' => 'False', + 'db_port' => 'False', + 'db_user' => 'odoo', + 'db_password' => 'False', + 'addons_path' => '/usr/lib/python2.7/dist-packages/odoo/addons', + } + }, + version => present, +} diff --git a/examples/init.pp b/examples/odoo9.pp similarity index 82% rename from examples/init.pp rename to examples/odoo9.pp index ae565bc..1a0f349 100644 --- a/examples/init.pp +++ b/examples/odoo9.pp @@ -10,14 +10,15 @@ # https://docs.puppet.com/guides/tests_smoke.html # class { 'postgresql::server': - before => Class['odoo9'] + before => Class['odoo'] } -class { '::odoo9::repo': - before => Class['odoo9'] +class { '::odoo::repo9': + before => Class['odoo'] } -class { '::odoo9': +class { '::odoo': + config_file => '/etc/odoo/openerp-server.conf', install_wkhtmltopdf => true, settings => { 'options' => { @@ -29,5 +30,5 @@ 'addons_path' => '/usr/lib/python2.7/dist-packages/openerp/addons', } }, - version => '9.0c.20161009', + version => present, } diff --git a/manifests/init.pp b/manifests/init.pp index b435e89..eca8e14 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,10 +1,18 @@ +# Class: odoo # Install and configure Odoo Community. -# @param install_wkhtmltopdf [boolean] Whether or not to install the optional `wkhtmltopdf` package. -# @param settings [hash] A hash of settings to be passed to the `create_ini_settings` (see -# https://forge.puppet.com/puppetlabs/inifile#manage-multiple-ini_settings for details). -# @param version [string] The version of the `odoo` package to be installed. Valid values are **present**, **latest** -# or the version of the version of the package to be installed (i.e. '9.0c.20161009'). -class odoo9 ( +# @param config_file [string] The Odoo configuration file. Will need to be +# changed to `/etc/odoo/openerp-server.conf` for Odoo 9. +# @param install_wkhtmltopdf [boolean] Whether or not to install the optional +# `wkhtmltopdf` package. +# @param settings [hash] A hash of settings to be passed to the +# `create_ini_settings` (see +# https://forge.puppet.com/puppetlabs/inifile#manage-multiple-ini_settings +# for details). +# @param version [string] The version of the `odoo` package to be installed. +# Valid values are **present**, **latest** or the version of the version of +# the package to be installed (i.e. '9.0c.20161009'). +class odoo ( + $config_file = '/etc/odoo/odoo.conf', $install_wkhtmltopdf = false, $settings = {}, $version = present, @@ -21,8 +29,15 @@ notify => Service['odoo'] } + if $::osfamily == 'RedHat' { + exec { '/usr/bin/systemctl daemon-reload': + refreshonly => true, + subscribe => Package['odoo'], + } + } + $defaults = { - path => '/etc/odoo/openerp-server.conf', + path => $config_file, require => Package['odoo'], notify => Service['odoo'], } diff --git a/manifests/repo10.pp b/manifests/repo10.pp new file mode 100644 index 0000000..d299606 --- /dev/null +++ b/manifests/repo10.pp @@ -0,0 +1,80 @@ +# Install a repository to install an Odoo 10 package from. +# +# @param descr [string] A string to describe the repository. +# @param key_id [string] The key for the Debian APT repository. This option +# is ignored on the Red Hat family. +# @param key_url [string] A URL to the key for the Debian APT repository. +# This option is ignored on the Red Hat family. +# @param pkg_url [string] The URL to a package. This defaults to +# 'http://nightly.odoo.com/10.0/nightly/rpm/' on the Red +# Hat family and 'http://nightly.odoo.com/9.0/nightly/deb/' on Debian. +# @param release [string] The release for the Debian APT repository. This +# option is ignored on the Red Hat family. +# @param repos [string] The repos for the Debian APT repository. This option +# is ignored on the Red Hat family. +class odoo::repo10 ( + $ensure = present, + $descr = 'Odoo Nightly repository', + $key_id = '5D134C924CB06330DCEFE2A1DEF2A2198183CBB5', + $key_url = 'https://nightly.odoo.com/odoo.key', + $pkg_url = undef, + $release = './', + $repos = '', + ) { + case $::osfamily { + 'RedHat': { + if $pkg_url != undef { + $baseurl = $pkg_url + } else { + $baseurl = 'http://nightly.odoo.com/10.0/nightly/rpm/' + } + + yumrepo { 'odoo': + ensure => $ensure, + descr => $descr, + baseurl => $baseurl, + enabled => 1, + gpgcheck => 0, + } + } + 'Debian': { + include apt + include apt::update + + apt::key {'odookey': + ensure => $ensure, + id => $key_id, + source => $key_url, + before => Apt::Source['odoo'], + } + + if $pkg_url != undef { + $location = $pkg_url + } else { + $location = 'http://nightly.odoo.com/10.0/nightly/deb/' + } + + apt::source {'odoo': + ensure => $ensure, + location => $location, + comment => $descr, + release => $release, + repos => $repos, + include => { + 'src' => false, + }, + notify => Exec['update-odoo-repos'], + } + + # Required to wrap apt_update + exec {'update-odoo-repos': + refreshonly => true, + command => '/bin/true', + require => Exec['apt_update'], + } + } + default: { + warning("OS family ${::osfamily} not supported") + } + } +} diff --git a/manifests/repo.pp b/manifests/repo9.pp similarity index 94% rename from manifests/repo.pp rename to manifests/repo9.pp index 38e8b27..95033db 100644 --- a/manifests/repo.pp +++ b/manifests/repo9.pp @@ -7,7 +7,8 @@ # Hat family and 'http://nightly.odoo.com/9.0/nightly/deb/' on Debian. # @param release [string] The release for the Debian APT repository. This option is ignored on the Red Hat family. # @param repos [string] The repos for the Debian APT repository. This option is ignored on the Red Hat family. -class odoo9::repo ( +class odoo::repo9 ( + $ensure = present, $descr = 'Odoo Nightly repository', $key_id = '5D134C924CB06330DCEFE2A1DEF2A2198183CBB5', $key_url = 'https://nightly.odoo.com/odoo.key', @@ -24,7 +25,7 @@ } yumrepo { 'odoo': - ensure => present, + ensure => $ensure, descr => $descr, baseurl => $baseurl, enabled => 1, @@ -36,6 +37,7 @@ include apt::update apt::key {'odookey': + ensure => $ensure, id => $key_id, source => $key_url, before => Apt::Source['odoo'], @@ -48,6 +50,7 @@ } apt::source {'odoo': + ensure => $ensure, location => $location, comment => $descr, release => $release, diff --git a/metadata.json b/metadata.json index 188ba4e..e3cd118 100644 --- a/metadata.json +++ b/metadata.json @@ -1,8 +1,8 @@ { - "name": "locp-odoo9", + "name": "locp-odoo", "version": "0.1.2", "author": "locp", - "summary": "Puppet module to install Odoo 9.0 Community.", + "summary": "Puppet module to install Odoo Community.", "license": "Apache-2.0", "source": "https://github.com/locp/puppet-odoo", "project_page": "https://github.com/locp/puppet-odoo", diff --git a/spec/acceptance/odoo_spec.rb b/spec/acceptance/odoo_spec.rb index ea96301..b0fc306 100644 --- a/spec/acceptance/odoo_spec.rb +++ b/spec/acceptance/odoo_spec.rb @@ -1,20 +1,21 @@ require 'spec_helper_acceptance' -describe 'odoo9 class' do - odoo_pp = <<-EOS +describe 'odoo module' do + install_odoo9_pp = <<-EOS class { 'postgresql::server': - before => Class['odoo9'] + before => Class['odoo'] } - class { '::odoo9::repo': - before => Class['odoo9'] + class { '::odoo::repo9': + before => Class['odoo'] } - class { '::odoo9': + class { '::odoo': + config_file => '/etc/odoo/openerp-server.conf', install_wkhtmltopdf => true, settings => { 'options' => { - 'admin_passwd' => 'XXX_TOP_SECRET_XXX', + 'admin_passwd' => 'XXX_TOP_SECRET_XXX_9', 'db_host' => 'False', 'db_port' => 'False', 'db_user' => 'odoo', @@ -22,18 +23,94 @@ class { '::odoo9': 'addons_path' => '/usr/lib/python2.7/dist-packages/openerp/addons', } }, - version => 'present', + version => present, } EOS describe 'Odoo 9 installation.' do it 'should work with no errors' do - apply_manifest(odoo_pp, catch_failures: true) - expect(apply_manifest(odoo_pp, + apply_manifest(install_odoo9_pp, catch_failures: true) + end + + it 'should be idempotent' do + expect(apply_manifest(install_odoo9_pp, + catch_failures: true).exit_code).to be_zero + end + end + + describe package('odoo') do + it { is_expected.to be_installed } + end + + describe service('odoo') do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end + + uninstall_odoo9_pp = <<-EOS + service { 'odoo': + ensure => stopped, + } -> + package { 'odoo': + ensure => purged, + } -> + class { 'odoo::repo9': + ensure => absent, + } + + if $::osfamily == 'RedHat' { + exec { '/usr/bin/yum clean all': + before => Class['odoo::repo9'], + } + } + EOS + + describe 'Uninstall Odoo 9.' do + it 'should work with no errors' do + apply_manifest(uninstall_odoo9_pp, catch_failures: true) + end + end + + install_odoo10_pp = <<-EOS + class { 'postgresql::server': + before => Class['odoo'] + } + + class { '::odoo::repo10': + before => Class['odoo'] + } + + class { '::odoo': + install_wkhtmltopdf => true, + settings => { + 'options' => { + 'admin_passwd' => 'XXX_TOP_SECRET_XXX_10', + 'db_host' => 'False', + 'db_port' => 'False', + 'db_user' => 'odoo', + 'db_password' => 'False', + 'addons_path' => '/usr/lib/python2.7/dist-packages/odoo/addons', + } + }, + version => present, + } + EOS + + describe 'Odoo 10 installation.' do + it 'should work with no errors' do + apply_manifest(install_odoo10_pp, catch_failures: true) + end + + it 'should be idempotent' do + expect(apply_manifest(install_odoo10_pp, catch_failures: true).exit_code).to be_zero end end + describe package('odoo') do + it { is_expected.to be_installed } + end + describe service('odoo') do it { is_expected.to be_running } it { is_expected.to be_enabled } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 485ad47..8750d72 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe 'odoo9' do +describe 'odoo' do let(:pre_condition) do [ 'define ini_setting($ensure = nil, @@ -16,12 +16,36 @@ end end - context 'with defaults for all parameters' do + context 'with defaults for all parameters (debian)' do + let :facts do + { + osfamily: 'Debian' + } + end + + it do + should compile + should have_resource_count(2) + should contain_class('odoo') + should contain_package('odoo') + should contain_service('odoo') + end + end + + context 'with defaults for all parameters (red hat)' do + let :facts do + { + osfamily: 'RedHat' + } + end + it do should compile - should contain_class('odoo9') + should have_resource_count(3) + should contain_class('odoo') should contain_package('odoo') should contain_service('odoo') + should contain_exec('/usr/bin/systemctl daemon-reload') end end end diff --git a/spec/classes/repo10_spec.rb b/spec/classes/repo10_spec.rb new file mode 100644 index 0000000..3c199e3 --- /dev/null +++ b/spec/classes/repo10_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' +describe 'odoo::repo10' do + let(:pre_condition) do + [ + 'class apt() {}', + 'define apt::key($ensure, $id, $source) {}', + 'define apt::source($ensure, $location, $comment, $release, $repos, $include) {}', + 'class apt::update() {}' + ] + end + + let!(:stdlib_stubs) do + MockFunction.new('create_ini_settings', type: :statement) do |_f| + end + end + + context 'with defaults for all parameters (Debian)' do + let :facts do + { + osfamily: 'Debian' + } + end + + it do + should contain_class('odoo::repo10').only_with( + ensure: 'present', + descr: 'Odoo Nightly repository', + key_id: '5D134C924CB06330DCEFE2A1DEF2A2198183CBB5', + key_url: 'https://nightly.odoo.com/odoo.key', + pkg_url: nil, + release: './', + repos: '' + ) + + should contain_apt__key('odookey').with( + ensure: 'present', + id: '5D134C924CB06330DCEFE2A1DEF2A2198183CBB5', + source: 'https://nightly.odoo.com/odoo.key' + ) + + should contain_apt__source('odoo').with( + ensure: 'present', + location: 'http://nightly.odoo.com/10.0/nightly/deb/', + comment: 'Odoo Nightly repository', + release: './', + include: { 'src' => false } + ) + + should contain_exec('update-odoo-repos').with( + refreshonly: true, + command: '/bin/true' + ) + end + end + + context 'with defaults for all parameters (RedHat)' do + let :facts do + { + osfamily: 'RedHat' + } + end + + it do + should contain_yumrepo('odoo').with( + ensure: 'present', + descr: 'Odoo Nightly repository', + baseurl: 'http://nightly.odoo.com/10.0/nightly/rpm/', + enabled: 1, + gpgcheck: 0 + ) + end + end +end diff --git a/spec/classes/repo9_spec.rb b/spec/classes/repo9_spec.rb new file mode 100644 index 0000000..1880f84 --- /dev/null +++ b/spec/classes/repo9_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' +describe 'odoo::repo9' do + let(:pre_condition) do + [ + 'class apt() {}', + 'define apt::key($ensure, $id, $source) {}', + 'define apt::source($ensure, $location, $comment, $release, $repos, $include) {}', + 'class apt::update() {}' + ] + end + + let!(:stdlib_stubs) do + MockFunction.new('create_ini_settings', type: :statement) do |_f| + end + end + + context 'with defaults for all parameters (Debian)' do + let :facts do + { + osfamily: 'Debian' + } + end + + it do + should contain_class('odoo::repo9').only_with( + ensure: 'present', + descr: 'Odoo Nightly repository', + key_id: '5D134C924CB06330DCEFE2A1DEF2A2198183CBB5', + key_url: 'https://nightly.odoo.com/odoo.key', + pkg_url: nil, + release: './', + repos: '' + ) + + should contain_apt__key('odookey').with( + ensure: 'present', + id: '5D134C924CB06330DCEFE2A1DEF2A2198183CBB5', + source: 'https://nightly.odoo.com/odoo.key' + ) + + should contain_apt__source('odoo').with( + ensure: 'present', + location: 'http://nightly.odoo.com/9.0/nightly/deb/', + comment: 'Odoo Nightly repository', + release: './', + include: { 'src' => false } + ) + + should contain_exec('update-odoo-repos').with( + refreshonly: true, + command: '/bin/true' + ) + end + end + + context 'with defaults for all parameters (RedHat)' do + let :facts do + { + osfamily: 'RedHat' + } + end + + it do + should contain_yumrepo('odoo').with( + ensure: 'present', + descr: 'Odoo Nightly repository', + baseurl: 'http://nightly.odoo.com/9.0/nightly/rpm/', + enabled: 1, + gpgcheck: 0 + ) + end + end +end diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb deleted file mode 100644 index edde300..0000000 --- a/spec/classes/repo_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper' -describe 'odoo9::repo' do - let(:pre_condition) do - [ - 'class apt() {}', - 'define apt::key($id, $source) {}', - 'define apt::source($location, $comment, $release, $repos, $include) {}', - 'class apt::update() {}' - ] - end - - let!(:stdlib_stubs) do - MockFunction.new('create_ini_settings', type: :statement) do |_f| - end - end - - context 'with defaults for all parameters' do - let :facts do - { - osfamily: 'Debian' - } - end - - it do - should contain_class('odoo9::repo') - should contain_apt__key('odookey') - should contain_apt__source('odoo') - should contain_exec('update-odoo-repos') - end - end -end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 893708a..4041448 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -22,7 +22,7 @@ # Configure all nodes in nodeset c.before :suite do # Install module - puppet_module_install(source: module_root, module_name: 'odoo9') + puppet_module_install(source: module_root, module_name: 'odoo') hosts.each do |host| on host, puppet('module', 'install', 'puppetlabs-apt'), acceptable_exit_codes: [0, 1]