Skip to content

Commit

Permalink
Fix up tests for python3
Browse files Browse the repository at this point in the history
To support python3, we have to introduce a few new variables to support
this creation of a py3 virtualenv, and also to set wsgi python-home [1]
it. Just using activate_this.py didn't work.

In test, we also choose to use a separate virtualenv
`virtenv3-puppetboard` because `virtenv-puppetboard' will be created as
a py2 virtualenv by the other tests.

[1]: https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
  • Loading branch information
waipeng committed Oct 1, 2020
1 parent 28cca54 commit c5a13b8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion manifests/apache/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
Boolean $ldap_require_group = $puppetboard::params::ldap_require_group,
Optional[String] $ldap_require_group_dn = undef,
Hash $custom_apache_parameters = {},
Hash $wsgi_daemon_process_options_extra = {},
) inherits ::puppetboard::params {

$docroot = "${basedir}/puppetboard"
Expand All @@ -107,11 +108,13 @@
"${wsgi_alias}" => "${docroot}/wsgi.py",
}

$wsgi_daemon_process_options = {
$wsgi_daemon_process_options_default = {
threads => $threads,
group => $group,
user => $user,
}
$wsgi_daemon_process_options = merge($wsgi_daemon_process_options_default,
$wsgi_daemon_process_options_extra)

file { "${docroot}/wsgi.py":
ensure => present,
Expand Down
7 changes: 6 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
# (string) Python version to use in virtualenv.
# Defaults to 'system'
#
# [*virtualenv_dir*]
# (bool) Set location where virtualenv will be installed
# Defaults to false ($::puppetboard::params::virtualenv_dir)
#
# [*manage_user*]
# (bool) If true, manage (create) this group. If false do nothing.
# Defaults to true
Expand Down Expand Up @@ -195,6 +199,7 @@
Boolean $manage_git = false,
Boolean $manage_virtualenv = false,
String[1] $virtualenv_version = $puppetboard::params::virtualenv_version,
Optional[String] $virtualenv_dir = $puppetboard::params::virtualenv_dir,
Integer $reports_count = $puppetboard::params::reports_count,
String $default_environment = $puppetboard::params::default_environment,
String $listen = $puppetboard::params::listen,
Expand Down Expand Up @@ -256,7 +261,7 @@
require => Vcsrepo["${basedir}/puppetboard"],
}

python::virtualenv { "${basedir}/virtenv-puppetboard":
python::virtualenv { $virtualenv_dir:
ensure => present,
version => $virtualenv_version,
requirements => "${basedir}/puppetboard/requirements.txt",
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
$user = 'puppetboard'
$group = 'puppetboard'
$basedir = '/srv/puppetboard'
$virtualenv_dir = '/srv/puppetboard/virtenv-puppetboard'
$git_source = 'https://github.com/voxpupuli/puppetboard'
$puppetdb_host = 'localhost'
$puppetdb_port = 8080
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
{
"name": "puppet/python",
"version_requirement": ">= 1.12.0 < 4.0.0"
"version_requirement": ">= 1.12.0 < 5.0.0"
},
{
"name": "puppetlabs/vcsrepo",
Expand Down
25 changes: 20 additions & 5 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,29 @@ class { 'apache':
include epel
class { 'apache::mod::wsgi': wsgi_socket_prefix => '/var/run/wsgi' }
} else {
class { 'apache::mod::wsgi': }
class { 'apache::mod::wsgi':
package_name => "libapache2-mod-wsgi-py3",
mod_path => "/usr/lib/apache2/modules/mod_wsgi.so",
}
}
# Configure PuppetDB
class { 'puppetdb': disable_ssl => true, }
# Configure Puppetboard
class { 'puppetboard': }
class { 'puppetboard':
manage_virtualenv => true,
virtualenv_version => '3',
virtualenv_dir => '/srv/puppetboard/virtenv3-puppetboard',
}
# Access Puppetboard through pboard.example.com
class { 'puppetboard::apache::vhost':
vhost_name => 'pboard.example.com',
port => 80,
vhost_name => 'pboard.example.com',
port => 80,
wsgi_daemon_process_options_extra => {
python-home => '/srv/puppetboard/virtenv3-puppetboard',
},
}
EOS

Expand All @@ -66,7 +79,9 @@ class { 'puppetboard::apache::vhost':
# rubocop:disable RSpec/MultipleExpectations
it 'answers to localhost' do
shell('/usr/bin/curl localhost') do |r|
expect(r.stdout).to match(%r{Live from PuppetDB.})
# The default puppetboard page returns 404 on empty puppetdb
# https://github.com/voxpupuli/puppetboard/issues/515
expect(r.stdout).to match(%r{404 Not Found})
expect(r.exit_code).to be_zero
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# Install additional modules for soft deps
install_module_from_forge('puppetlabs-apache', '>= 2.1.0 < 6.0.0')
install_module_from_forge('puppetlabs-puppetdb', '>= 7.0.0 < 8.0.0')
install_module_from_forge('puppet-epel', '>= 3.0.0 < 4.0.0')
end
end

0 comments on commit c5a13b8

Please sign in to comment.