Skip to content

Commit

Permalink
Implement tests and code for Odoo 10. Fixes #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
dallinb committed Dec 27, 2016
1 parent 0086d2e commit e32e361
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
33 changes: 33 additions & 0 deletions examples/odoo10.pp
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions examples/odoo9.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}

class { '::odoo':
config_file => '/etc/odoo/openerp-server.conf',
install_wkhtmltopdf => true,
settings => {
'options' => {
Expand Down
19 changes: 13 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -23,7 +30,7 @@
}

$defaults = {
path => '/etc/odoo/openerp-server.conf',
path => $config_file,
require => Package['odoo'],
notify => Service['odoo'],
}
Expand Down
80 changes: 80 additions & 0 deletions manifests/repo10.pp
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
73 changes: 69 additions & 4 deletions spec/acceptance/odoo_spec.rb
Original file line number Diff line number Diff line change
@@ -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']
}
Expand All @@ -11,6 +11,7 @@ class { '::odoo::repo9':
}
class { '::odoo':
config_file => '/etc/odoo/openerp-server.conf',
install_wkhtmltopdf => true,
settings => {
'options' => {
Expand All @@ -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 }
Expand Down
73 changes: 73 additions & 0 deletions spec/classes/repo10_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions spec/classes/repo9_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
osfamily: 'Debian'
}
end
end

it do
should contain_class('odoo::repo9').only_with(
Expand Down Expand Up @@ -58,7 +58,7 @@
{
osfamily: 'RedHat'
}
end
end

it do
should contain_yumrepo('odoo').with(
Expand Down

0 comments on commit e32e361

Please sign in to comment.