Commit 47c6f16e authored by Markus Frosch's avatar Markus Frosch 📣
Browse files

master/icinga2/selftest: Replace icinga2 with the rewritten module

parent 90bc9e6f
Pipeline #201 failed with stage
in 2 minutes and 26 seconds
class icinga2_testing::helpers::icinga2::ido_mysql(
$ido_dbname = $::icinga2::feature::ido_mysql::database,
$ido_username = $::icinga2::feature::ido_mysql::user,
$ido_password = $::icinga2::feature::ido_mysql::password,
) inherits ::icinga2::feature::ido_mysql # lint:ignore:inherits_across_namespaces
{
# Install schema
if $::osfamily == 'Debian' {
$_schema_create = '/usr/share/dbconfig-common/data/icinga2-ido-mysql/install/mysql'
}
elsif $::osfamily == 'Redhat' {
$_schema_create = '/usr/share/icinga2-ido-mysql/schema/mysql.sql'
}
else {
fail("Schema creating not supported on ${::operatingsystem} (${::osfamily})")
}
$_mysql = "mysql -B -u '${ido_username}' '${ido_dbname}'"
Package['icinga2-ido-mysql'] ->
exec { 'import icinga2 mysql schema':
user => 'root',
path => $::path,
command => "${_mysql} < '${_schema_create}'",
unless => "${_mysql} --execute='SELECT version FROM icinga_dbversion;'",
environment => [
"MYSQL_PWD=${ido_password}",
],
} ~> Class['::icinga2::service']
unless defined(File['icinga2-schema-upgrade']) {
file { 'icinga2-schema-upgrade':
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
path => '/usr/local/bin/icinga2-schema-upgrade',
content => file('icinga2_testing/icinga2-schema-upgrade'),
}
}
exec { 'icinga2-schema-upgrade-mysql':
path => $::path,
environment => [
"IDO_DATABASE=${ido_dbname}",
"IDO_USERNAME=${ido_username}",
"IDO_PASSWORD=${ido_password}",
],
logoutput => true,
command => '/usr/local/bin/icinga2-schema-upgrade',
onlyif => '/usr/local/bin/icinga2-schema-upgrade --check',
notify => Class['::icinga2::service'],
require => [
Exec['import icinga2 mysql schema'],
File['icinga2-schema-upgrade'],
],
}
}
class icinga2_testing::helpers::icinga2::ido_pgsql(
$ido_dbname = $::icinga2::feature::ido_pgsql::database,
$ido_username = $::icinga2::feature::ido_pgsql::user,
$ido_password = $::icinga2::feature::ido_pgsql::password,
) inherits ::icinga2::feature::ido_pgsql # lint:ignore:inherits_across_namespaces
{
# Install schema
if $::osfamily == 'Debian' {
$_schema_create = '/usr/share/dbconfig-common/data/icinga2-ido-pgsql/install/pgsql'
}
elsif $::osfamily == 'Redhat' {
$_schema_create = '/usr/share/icinga2-ido-pgsql/schema/pgsql.sql'
}
else {
fail("Schema creating not supported on ${::operatingsystem} (${::osfamily})")
}
$_psql = "psql -U '${ido_username}' -h '${icinga2::feature::ido_pgsql::host}' -d '${ido_dbname}'"
Package['icinga2-ido-pgsql'] ->
exec { 'import icinga2 pgsql schema':
user => 'root',
path => $::path,
command => "${_psql} < '${_schema_create}'",
unless => "${_psql} -c 'SELECT version FROM icinga_dbversion'",
environment => [
"PGPASSWORD=${ido_password}",
],
} ~> Class['::icinga2::service']
unless defined(File['icinga2-schema-upgrade']) {
file { 'icinga2-schema-upgrade':
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
path => '/usr/local/bin/icinga2-schema-upgrade',
content => file('icinga2_testing/icinga2-schema-upgrade'),
}
}
exec { 'icinga2-schema-upgrade-pgsql':
path => $::path,
environment => [
"IDO_DATABASE=${ido_dbname}",
"IDO_USERNAME=${ido_username}",
"IDO_PASSWORD=${ido_password}",
],
logoutput => true,
command => '/usr/local/bin/icinga2-schema-upgrade',
onlyif => '/usr/local/bin/icinga2-schema-upgrade --check',
notify => Class['::icinga2::service'],
require => [
Exec['import icinga2 pgsql schema'],
File['icinga2-schema-upgrade'],
],
}
}
class icinga2_testing::profiles::icinga2
{
class { '::icinga2':
manage_repos => false,
manage_database => false,
purge_confd => true,
}
include ::icinga2::objects
contain ::icinga2
contain ::icinga2::feature::command
contain ::icinga2::pki::puppet
Class['icinga2::pki::puppet'] ~> Class['icinga2::service']
# setup API connections
class { '::icinga2::feature::api':
accept_commands => true,
accept_config => true,
manage_zone => false,
}
contain ::icinga2::feature::api
contain ::icinga2_notificationtest
}
\ No newline at end of file
......@@ -20,7 +20,8 @@ class icinga2_testing::profiles::selftest (
ensure_resource(file, $zone_dir, { ensure => directory })
ensure_resource(file, $global_zone, { ensure => directory })
$_zones = hiera_hash('icinga2::object::zone')
$_zones = hiera_hash('icinga2::feature::api::zones')
$_endpoints = hiera_hash('icinga2::feature::api::endpoints')
file { $config_base:
ensure => directory,
......
......@@ -8,8 +8,9 @@ class icinga2_testing::roles::autorole
notice("Running autorole in instance=${::icingatest_instance} - role=${::icingatest_role} - hostno=${::icingatest_hostno}")
# check config that has to be present in hiera
$zones_config = hiera('icinga2::object::zone')
$repo_version = hiera('icinga2_testing::profiles::repository::version')
$_UNUSED_endpoint_config = hiera('icinga2::feature::api::endpoints')
$_UNUSED_zones_config = hiera('icinga2::feature::api::zones')
$_UNUSED_repo_version = hiera('icinga2_testing::profiles::repository::version')
if $::icingatest_role == 'master' {
validate_integer($::icingatest_hostno)
......
......@@ -8,10 +8,10 @@ class icinga2_testing::roles::master(
contain ::icinga2_testing::profiles::repository
contain "::icinga2_testing::profiles::${database}"
Class["::icinga2_testing::profiles::${database}"] -> Class["::icinga2_testing::helpers::icinga2::ido_${database}"]
Class["::icinga2_testing::profiles::${database}"] -> Class["::icinga2::feature::ido${database}"]
contain ::icinga2_testing::profiles::icinga2
contain "::icinga2_testing::helpers::icinga2::ido_${database}"
contain "::icinga2::feature::ido${database}"
contain ::icinga2_testing::profiles::icingaweb2
......
......@@ -10,13 +10,16 @@
# Zone <%= zone %>
#######################################
<% zone_hash['endpoints'].each do |host, details| -%>
<%-
zone_hash['endpoints'].each do |host|
details = @_endpoints[host]
-%>
object Host "<%= host %>" {
import "generic-host"
address = <%= scope.function_icinga2_config_value([details['host']]) %>
address = <%= details['host'].dump %>
vars.zone = <%= scope.function_icinga2_config_value([zone]) %>
vars.zone = <%= zone.dump %>
vars.role = "icinga"
<%-# NOTE: We are assuming all hosts are the same! -%>
......
......@@ -67,10 +67,10 @@ apply Service "icinga cluster zone <%= zone %>" {
check_command = "cluster-zone"
vars.cluster_zone = <%= scope.function_icinga2_config_value([zone]) %>
vars.cluster_zone = <%= zone.dump %>
assign where host.vars.role == "icinga"
ignore where host.vars.zone == <%= scope.function_icinga2_config_value([zone]) %>
ignore where host.vars.zone == <%= zone.dump %>
}
<% end -%>
......
......@@ -8,6 +8,9 @@ template Host "generic-host" {
check_interval = 1m
retry_interval = 30s
enable_flapping = true
flapping_threshold = 60.0
check_command = "hostalive4"
}
......
......@@ -11,6 +11,7 @@ apply Service "test-ok" {
vars.dummy_text = "This check is always OK."
vars.dummy_state = 0
vars.type = "test"
vars.notification = "test"
assign where host.vars.test_type == "simple"
......@@ -24,6 +25,7 @@ apply Service "test-warning" {
vars.dummy_text = "This check is always WARNING."
vars.dummy_state = 1
vars.type = "test"
vars.notification = "test"
assign where host.vars.test_type == "simple"
......@@ -37,6 +39,7 @@ apply Service "test-critical" {
vars.dummy_text = "This check is always CRITICAL."
vars.dummy_state = 2
vars.type = "test"
vars.notification = "test"
assign where host.vars.test_type == "simple"
......@@ -50,6 +53,7 @@ apply Service "test-unknown" {
vars.dummy_text = "This check is always UNKNOWN."
vars.dummy_state = 3
vars.type = "test"
vars.notification = "test"
assign where host.vars.test_type == "simple"
......@@ -60,6 +64,7 @@ apply Service "test-random" {
check_command = "random"
vars.type = "test"
vars.notification = "test"
assign where host.vars.test_type == "simple"
......@@ -71,7 +76,31 @@ apply Service "test-random-hard" {
check_command = "random"
max_check_attempts = 1
vars.type = "test"
vars.notification = "test"
assign where host.vars.test_type == "simple"
}
apply Service "test-random-hard-expectation" {
import "generic-service"
check_command = "dummy"
max_check_attempts = 1
var dyn_output = "UNKNOWN: ??"
vars.dummy_text = function() use(dyn_output) { return dyn_output }
vars.dummy_state = function() use(dyn_output) {
var test = get_service(host.name, "test-random-hard").last_check_result
// service.vars.dummy_state = test.state
dyn_output = test.state + " " + test.output
return 3
}
vars.type = "expectation"
assign where host.vars.test_type == "simple"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment