Skip to content

Commit

Permalink
Merge 0b465ba into c6a263a
Browse files Browse the repository at this point in the history
  • Loading branch information
alvagante committed Mar 23, 2018
2 parents c6a263a + 0b465ba commit b270093
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
11 changes: 8 additions & 3 deletions manifests/test.pp
Expand Up @@ -7,7 +7,10 @@

Variant[Boolean,String] $ensure = present,

String $template = 'tp/test/acceptance.erb',
Variant[Undef,String,Array] $source = undef,
Variant[Undef,String,Array] $template = undef,
Variant[Undef,String] $epp = undef,
Variant[Undef,String] $content = undef,

Hash $options_hash = { },
Hash $settings_hash = { },
Expand Down Expand Up @@ -47,13 +50,15 @@
$array_service_name=any2array($settings['service_name'])
$array_tcp_port=any2array($settings['tcp_port'])

if $template != '' {
$file_content = tp_content($content, $template, $epp)
if $file_content != '' {
file { "${base_dir}/${title}":
ensure => $ensure,
mode => '0755',
owner => 'root',
group => 'root',
content => template($template),
content => $file_content,
source => $source,
tag => 'tp_test',
}
}
Expand Down
51 changes: 34 additions & 17 deletions templates/tp.erb
Expand Up @@ -12,6 +12,8 @@ else
TINYDATA_DIR = '/etc/puppetlabs/code/modules/tinydata/data'
end

COMMAND_REDIR = ' > /dev/null 2>&1'

TP_APPS = Dir.entries(TP_APP_DIR).reject { |f| File.directory?(f) }

# Trap CTRL+C cleanly (in tp log)
Expand Down Expand Up @@ -45,33 +47,48 @@ end
def tp_test(app)
begin
settings = check_yaml app
puts
puts "### #{app} status"

# Run custom test script if exists
if File.exists?(TP_TEST_DIR + "/#{app}")
system(TP_TEST_DIR + "/#{app}")
system(TP_TEST_DIR + "/#{app}" + COMMAND_REDIR)
result = $?
if result == 0
puts "\e[32m# Test #{app}: OK \e[0m\n"
puts "- #{app}: \e[32m#{TP_TEST_DIR}/#{app} OK \e[0m\n"
else
puts "\e[41m# Test #{app}: ERROR #\e[0m\n"
puts "- #{app}: \e[31m#{TP_TEST_DIR}/#{app} ERROR \e[0m\n"
end
$error_exit = 1 if result != 0
else
if settings['package_name'] and settings['package_name'] != ""
Array(settings['package_name']).each do |s|
system("<%= @options['check_package_command'] %> " + s + " 2> /dev/null")
end

# Check package if defined
if settings['package_name'] and settings['package_name'] != ""
Array(settings['package_name']).each do |s|
if settings['package_provider'] == 'gem'
system("gem list | grep " + s + " " + COMMAND_REDIR)
elsif settings['package_provider'] == 'pip'
system("pip list | grep " + s + " " + COMMAND_REDIR)
else
system("<%= @options['check_package_command'] %> " + s + " " + COMMAND_REDIR)
end
result = $?
if result == 0
puts "- #{app}: \e[32mpackage #{s} OK \e[0m\n"
else
puts "- #{app}: \e[31mpackage #{s} ERROR \e[0m\n"
end
$error_exit = 1 if result != 0
end
end

if settings['service_name'] and settings['service_name'] != ""
Array(settings['service_name']).each do |s|
system("<%= @options['check_service_command'] %> " + s + " <%= @options['check_service_command_post'] %>")
end
# Check service if defined
if settings['service_name'] and settings['service_name'] != ""
Array(settings['service_name']).each do |s|
system("<%= @options['check_service_command'] %> " + s + " <%= @options['check_service_command_post'] %>" + COMMAND_REDIR)
result = $?
if result == 0
puts "\e[32m# Test #{app}: OK \e[0m\n"
puts "- #{app}: \e[32mservice #{s} OK \e[0m\n"
else
puts "\e[41m# Test #{app}: ERROR #\e[0m\n"
puts "- #{app}: \e[31mservice #{s} ERROR \e[0m\n"
end
$error_exit = 1 if result != 0
end
Expand All @@ -92,9 +109,9 @@ when 'test'
app.send("tp_test", app)
end
if $error_exit == 0
puts "\n\e[32m### ALL TESTS PASSED ###\e[0m\n"
puts "\n\e[32mAll tests OK\e[0m\n"
else
puts "\n\e[41m### SOME TESTS FAILED ###\e[0m\n"
puts "\n\e[31mSome test in ERROR\e[0m\n"
end
exit($error_exit)

Expand Down

0 comments on commit b270093

Please sign in to comment.