From e32e361ec027dbe8418fdaa0de7de427d6c87b2e Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Tue, 27 Dec 2016 15:23:01 +0000 Subject: [PATCH] Implement tests and code for Odoo 10. Fixes #9. --- Vagrantfile | 2 +- examples/odoo10.pp | 33 +++++++++++++++ examples/odoo9.pp | 1 + manifests/init.pp | 19 ++++++--- manifests/repo10.pp | 80 ++++++++++++++++++++++++++++++++++++ spec/acceptance/odoo_spec.rb | 73 ++++++++++++++++++++++++++++++-- spec/classes/repo10_spec.rb | 73 ++++++++++++++++++++++++++++++++ spec/classes/repo9_spec.rb | 4 +- 8 files changed, 272 insertions(+), 13 deletions(-) create mode 100644 examples/odoo10.pp create mode 100644 manifests/repo10.pp create mode 100644 spec/classes/repo10_spec.rb diff --git a/Vagrantfile b/Vagrantfile index fad95d2..4b952ba 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 = 'odoo9.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/odoo9.pp b/examples/odoo9.pp index f28d04f..1a0f349 100644 --- a/examples/odoo9.pp +++ b/examples/odoo9.pp @@ -18,6 +18,7 @@ } class { '::odoo': + config_file => '/etc/odoo/openerp-server.conf', install_wkhtmltopdf => true, settings => { 'options' => { diff --git a/manifests/init.pp b/manifests/init.pp index ff1e871..937c30d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,11 +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'). +# @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, @@ -23,7 +30,7 @@ } $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/spec/acceptance/odoo_spec.rb b/spec/acceptance/odoo_spec.rb index e56a53d..b27d926 100644 --- a/spec/acceptance/odoo_spec.rb +++ b/spec/acceptance/odoo_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper_acceptance' describe 'odoo module' do - odoo9_pp = <<-EOS + install_odoo9_pp = <<-EOS class { 'postgresql::server': before => Class['odoo'] } @@ -11,6 +11,7 @@ class { '::odoo::repo9': } class { '::odoo': + config_file => '/etc/odoo/openerp-server.conf', install_wkhtmltopdf => true, settings => { 'options' => { @@ -22,18 +23,82 @@ class { '::odoo': '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(odoo9_pp, catch_failures: true) - expect(apply_manifest(odoo9_pp, + apply_manifest(install_odoo9_pp, catch_failures: true) + 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, + } + 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) + 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/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 index b7f5fe6..1880f84 100644 --- a/spec/classes/repo9_spec.rb +++ b/spec/classes/repo9_spec.rb @@ -19,7 +19,7 @@ { osfamily: 'Debian' } - end + end it do should contain_class('odoo::repo9').only_with( @@ -58,7 +58,7 @@ { osfamily: 'RedHat' } - end + end it do should contain_yumrepo('odoo').with(