Update Vagrant tests to be compatible with new structure

This commit is contained in:
Chris Price 2012-07-29 13:35:39 -07:00
parent 2703830d58
commit 9eab95eee0
9 changed files with 80 additions and 117 deletions

View file

@ -33,7 +33,7 @@
# Sample Usage:
#
# postgresql::database_user { 'frank':
# password_hash => postgresql_passowrd('password'),
# password_hash => postgresql_password('frank', 'password'),
# }
#

6
spec/Vagrantfile vendored
View file

@ -28,8 +28,12 @@ Vagrant::Config.run do |config|
# Resolve DNS via NAT
config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
# Share the stdlib module
# TODO: it would be better to install this via the puppet module tool
config.vm.share_folder "puppetlabs-stdlib-module", "/usr/share/puppet/modules/stdlib", "../../puppetlabs-stdlib"
# Share the postgressql module
config.vm.share_folder "puppet-postgresql-module", "/usr/share/puppet/modules/postgresql", "../postgresql"
config.vm.share_folder "puppet-postgresql-module", "/usr/share/puppet/modules/postgresql", ".."
# Share the module of test classes
config.vm.share_folder "puppet-postgresql-tests", "/usr/share/puppet/modules/postgresql_tests", "."

View file

@ -16,20 +16,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class postgresql_tests::test_db($db, $version = '8.4') {
class postgresql_tests::test_db($db) {
package {"postgresql-$version":
ensure => present,
}
service {"postgresql-$version":
ensure => running,
require => Package["postgresql-$version"],
}
include postgresql::server
postgresql::db { $db:
version => $version,
encoding => 'SQL_ASCII', # Unfortunately, this puppet module will not make the package install with UTF-8 encoding
require => Service["postgresql-$version"],
user => $db,
password => $db,
}
}

View file

@ -0,0 +1,45 @@
# puppet-postgresql
# For all details and documentation:
# http://github.com/inkling/puppet-postgresql
#
# Copyright 2012- Inkling Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class postgresql_tests::test_grant_create($user, $password, $db) {
include postgresql::server
# Since we are not testing pg_hba or any of that, make a local user for ident auth
user { $user:
ensure => present,
}
postgresql::database_user { $user:
password_hash => postgresql_password($user, $password),
require => [ Class['postgresql::server'],
User[$user] ],
}
postgresql::database { $db:
require => Class['postgresql::server'],
}
postgresql::database_grant { "grant create test":
privilege => 'CREATE',
db => $db,
role => $user,
require => [ Postgresql::Database[$db],
Postgresql::Database_user[$user] ],
}
}

View file

@ -1,57 +0,0 @@
# puppet-postgresql
# For all details and documentation:
# http://github.com/inkling/puppet-postgresql
#
# Copyright 2012- Inkling Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class postgresql_tests::test_grant_select($user, $password, $db, $table, $version = '8.4') {
package {"postgresql-$version":
ensure => present,
}
service {"postgresql-$version":
ensure => running,
require => Package["postgresql-$version"],
}
# Since we are not testing pg_hba or any of that, make a local user for ident auth
user { $user:
ensure => present,
}
postgresql::user { $user:
password => $password,
version => $version,
require => [ Service["postgresql-$version"],
User[$user] ],
}
postgresql::psql { "CREATE TABLE $table (foo int)":
version => $version,
db => $db,
unless => "SELECT tablename from pg_tables where tablename = '$table'",
}
postgresql::grant { "GRANT SELECT ON $table TO $user":
version => $version,
perm => 'SELECT',
grantee => $user,
on_object => $table,
user => 'postgres',
require => [ Postgresql::Psql["CREATE TABLE $table (foo int)"],
Postgresql::User[$user] ]
}
}

View file

@ -16,13 +16,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class postgresql_tests::test_initdb($dir, $version = '8.4') {
class postgresql_tests::test_initdb {
package {"postgresql-$version":
ensure => present,
}
include postgresql::server
postgresql::initdb { $dir:
version => $version,
class { "postgresql::initdb":
require => Class['postgresql::server']
}
}

View file

@ -16,23 +16,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class postgresql_tests::test_psql($command = $title, $unless, $version = '8.4') {
class postgresql_tests::test_psql($command = $title, $unless) {
package {"postgresql-$version":
ensure => present,
}
service {"postgresql-$version":
ensure => running,
require => Package["postgresql-$version"],
}
include postgresql::server
postgresql::psql { $title:
db => 'postgres',
user => 'postgres',
command => $command,
unless => $unless,
version => $version,
require => Service["postgresql-$version"],
require => Class['postgresql::server'],
}
}

View file

@ -16,26 +16,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
class postgresql_tests::test_user($user, $password, $version = '8.4') {
class postgresql_tests::test_user($user, $password) {
package {"postgresql-$version":
ensure => present,
}
service {"postgresql-$version":
ensure => running,
require => Package["postgresql-$version"],
}
include postgresql::server
# Since we are not testing pg_hba or any of that, make a local user for ident auth
user { $user:
ensure => present,
}
postgresql::user { $user:
password => $password,
version => $version,
require => [ Service["postgresql-$version"],
postgresql::database_user { $user:
password_hash => postgresql_password($user, $password),
require => [ Class['postgresql::server'],
User[$user] ],
}
}

View file

@ -31,6 +31,7 @@ require 'vagrant'
describe "postgresql" do
def sudo_and_log(*args)
@logger.debug("Running command: '#{args[0]}'")
@env.primary_vm.channel.sudo(args[0]) do |ch, data|
@logger.debug(data)
end
@ -38,7 +39,7 @@ describe "postgresql" do
before(:all) do
@logger = Logger.new(STDOUT)
@logger.level = Logger::WARN # TODO: get from environment or rspec?
@logger.level = Logger::DEBUG # TODO: get from environment or rspec?
vagrant_dir = File.dirname(__FILE__)
@env = Vagrant::Environment::new(:cwd => vagrant_dir)
@ -64,22 +65,18 @@ describe "postgresql" do
@logger.info("starting")
# A bare-minimum class to initdb the specified dir
test_class = 'class {"postgresql_tests::test_initdb": dir => "/tmp/initdb", version => "8.4" }'
test_class = 'class {"postgresql_tests::test_initdb": }'
# Run once to check for crashes
sudo_and_log("puppet apply -e '#{test_class}'")
# Run again to check for idempotence via --detailed-exitcodes
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
# Run postgres on a different port so we don't have to deal w/ the one ubuntu starts up
# NOTE: -n prevent prompting for password in case sudoers is wonky
# NOTE: -l prevents hanging attach to stdout of pg_ctl
# NOTE: -o "-p 57575" passes the option on to the underlying posgres command
sudo_and_log('sudo -n -u postgres /usr/lib/postgresql/8.4/bin/pg_ctl start --pgdata /tmp/initdb -l /tmp/pgctl_stdout -o "-p 57575" && sleep 1')
sudo_and_log("service postgresql-8.4 restart")
# Connect to it and list the databases
sudo_and_log('sudo -n -u postgres /usr/lib/postgresql/8.4/bin/psql -p 57575 --list --tuples-only')
sudo_and_log('sudo -n -u postgres /usr/lib/postgresql/8.4/bin/psql --list --tuples-only')
end
end
@ -87,7 +84,7 @@ describe "postgresql" do
it 'should idempotently create a db that we can connect to' do
# A bare-minimum class to add a DB to postgres, which will be running due to ubuntu
test_class = 'class {"postgresql_tests::test_db": db => "postgresql_test_db", version => "8.4" }'
test_class = 'class {"postgresql_tests::test_db": db => "postgresql_test_db" }'
# Run once to check for crashes
sudo_and_log("puppet apply -e '#{test_class}'")
@ -102,7 +99,7 @@ describe "postgresql" do
describe 'postgresql::psql' do
it 'should run some SQL when the unless query returns no rows' do
test_class = 'class {"postgresql_tests::test_psql": command => "SELECT \'foo\'", unless => "SELECT 1 WHERE 1=2", version => "8.4"}'
test_class = 'class {"postgresql_tests::test_psql": command => "SELECT \'foo\'", unless => "SELECT 1 WHERE 1=2" }'
# Run once to get all packages set up
sudo_and_log("puppet apply -e '#{test_class}'")
@ -112,7 +109,7 @@ describe "postgresql" do
end
it 'should not run SQL when the unless query returns rows' do
test_class = 'class {"postgresql_tests::test_psql": command => "SELECT * FROM pg_datbase limit 1", unless => "SELECT 1 WHERE 1=1", version => "8.4"}'
test_class = 'class {"postgresql_tests::test_psql": command => "SELECT * FROM pg_datbase limit 1", unless => "SELECT 1 WHERE 1=1" }'
# Run once to get all packages set up
sudo_and_log("puppet apply -e '#{test_class}'")
@ -124,7 +121,7 @@ describe "postgresql" do
describe 'postgresql::user' do
it 'should idempotently create a user who can log in' do
test_class = 'class {"postgresql_tests::test_user": user => "postgresql_test_user", password => "postgresql_test_password", version => "8.4"}'
test_class = 'class {"postgresql_tests::test_user": user => "postgresql_test_user", password => "postgresql_test_password" }'
# Run once to check for crashes
sudo_and_log("puppet apply -e '#{test_class}'")
@ -138,8 +135,8 @@ describe "postgresql" do
end
describe 'postgresql::grant' do
it 'should grant access so a user can select from a table' do
test_class = 'class {"postgresql_tests::test_grant_select": db => "postgres", table => "test_table", user => "psql_grant_tester", password => "psql_grant_pw", version => "8.4"}'
it 'should grant access so a user can create in a database' do
test_class = 'class {"postgresql_tests::test_grant_create": db => "postgres", user => "psql_grant_tester", password => "psql_grant_pw" }'
# Run once to check for crashes
sudo_and_log("puppet apply -e '#{test_class}'")
@ -148,7 +145,7 @@ describe "postgresql" do
sudo_and_log("puppet apply --detailed-exitcodes -e '#{test_class}'")
# Check that the user can select from the table in
sudo_and_log('sudo -u psql_grant_tester psql --command="select * from test_table limit 1" postgres')
sudo_and_log('sudo -u psql_grant_tester psql --command="create table foo (foo int)" postgres')
end
end
end