Defined Type: tp::test

Defined in:
manifests/test.pp

Overview

tp::test

Creates test scripts to check if the application managed by Tiny Puppet is runnign correctly.

Parameters:

  • ensure (Variant[Boolean,String]) (defaults to: present)
  • source (Variant[Undef,String,Array]) (defaults to: undef)
  • template (Variant[Undef,String,Array]) (defaults to: undef)
  • epp (Variant[Undef,String]) (defaults to: undef)
  • content (Variant[Undef,String]) (defaults to: undef)
  • options_hash (Hash) (defaults to: {})
  • settings_hash (Hash) (defaults to: {})
  • data_module (String[1]) (defaults to: 'tinydata')
  • verbose (Boolean) (defaults to: false)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'manifests/test.pp', line 6

define tp::test (

  Variant[Boolean,String] $ensure              = present,

  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       = {},

  String[1]               $data_module         = 'tinydata',

  Boolean                 $verbose             = false,

) {
  # Settings evaluation
  $tp_settings=tp_lookup($title,'settings',$data_module,'deep_merge')
  $settings = $tp_settings + $settings_hash

  include tp

  $base_dir            = "${tp::tp_dir}/test"
  $app_dir             = "${tp::tp_dir}/app"
  $shellvars_dir       = "${tp::tp_dir}/shellvars"
  # Default options and computed variables
  $options_defaults = {
    check_timeout          => '10',
    check_service_command  => "${tp::check_service_command} ${settings[service_name]} ${tp::check_service_command_post}",
    check_package_command  => $settings['package_provider'] ? {
      'gem'   => "gem list -i ${settings[package_name]}",
      'pip'   => "pip show ${settings[package_name]}",
      default => $tp::check_package_command,
    },
    check_port_command     => 'check_tcp',
    check_port_critical    => '10',
    check_port_warning     => '5',
    check_port_host        => '127.0.0.1',
  }

  $options = merge($options_defaults, $options_hash)

  $array_package_name=any2array($settings['package_name'])
  $array_service_name=any2array($settings['service_name'])
  $array_tcp_port=any2array($settings['tcp_port'])

  $epp_params = {
    options => $options,
    options_hash => $options_hash,
  }
  # Find out the file's content value
  if $content {
    $file_content = $content
  } elsif $template {
    $template_ext = $template[-4,4]
    $file_content = $template_ext ? {
      '.epp'  => epp($template,$epp_params),
      '.erb'  => template($template),
      default => template($template),
    }
  } elsif $epp {
    $file_content = epp($epp,$epp_params)
  } else {
    $file_content = undef
  }

  $sane_title = regsubst($title, '/', '_', 'G')

  if $file_content
  or $source {
    file { "${base_dir}/${sane_title}":
      ensure  => $ensure,
      mode    => '0755',
      owner   => 'root',
      content => $file_content,
      source  => $source,
      tag     => 'tp_test',
    }
  }
}