Merge "Configure the node service checks based on Hiera"

This commit is contained in:
Jenkins 2015-10-23 12:34:18 +00:00 committed by Gerrit Code Review
commit 1a1f45524d
8 changed files with 664 additions and 131 deletions

View File

@ -66,85 +66,46 @@ class { 'lma_infra_alerting::nagios::contact':
require => Class['lma_infra_alerting'],
}
$nodes_hash = hiera('nodes', {})
$primary_controller_nodes = filter_nodes($nodes_hash,'role','primary-controller')
$controller_nodes = filter_nodes($nodes_hash,'role','controller')
$all_controller_nodes = concat($primary_controller_nodes, $controller_nodes)
$compute_nodes = filter_nodes($nodes_hash,'role','compute')
$cinder_nodes = filter_nodes($nodes_hash,'role','cinder')
$base_os_nodes = filter_nodes($nodes_hash,'role','base-os')
$osd_nodes = filter_nodes($nodes_hash, 'role', 'ceph-osd')
$influxdb_nodes = filter_nodes($nodes_hash, 'role', 'influxdb_grafana')
$es_kibana_nodes = filter_nodes($nodes_hash, 'role', 'elasticsearch_kibana')
$all_nodes = {}
if !empty($all_controller_nodes){
$all_nodes['controller'] = $all_controller_nodes
if $lma_collector['node_cluster_roles'] {
$node_cluster_roles = $lma_collector['node_cluster_roles']
} else {
$node_cluster_roles = []
}
if $lma_collector['node_cluster_alarms'] {
$node_cluster_alarms = $lma_collector['node_cluster_alarms']
} else {
$node_cluster_alarms = []
}
if !empty($compute_nodes){
$all_nodes['compute'] = $compute_nodes
}
if !empty($cinder_nodes){
$all_nodes['cinder'] = $cinder_nodes
}
if !empty($base_os_nodes){
$all_nodes['base-os'] = $base_os_nodes
}
if !empty($osd_nodes){
$all_nodes['ceph-osd'] = $osd_nodes
}
if !empty($influxdb_nodes){
$all_nodes['influxdb_grafana'] = $influxdb_nodes
}
if !empty($es_kibana_nodes){
$all_nodes['elasticsearch_kibana'] = $es_kibana_nodes
# The private network exists only when the GRE segmentation is used
# FIXME(pasquier-s): should check for VxLAN too
$network_config = hiera('quantum_settings')
$segmentation_type = $network_config['L2']['segmentation_type']
if $segmentation_type == 'gre' {
$private_network = true
} else {
$private_network = false
}
if !empty($all_nodes){ # allow to deploy one node with this plugin's role
class { 'lma_infra_alerting::nagios::hosts':
hosts => $all_nodes,
host_name_key => 'name',
host_address_key => 'internal_address',
host_display_name_keys => ['name', 'user_node_name'],
host_custom_vars_keys => ['internal_address', 'private_address',
'public_address', 'storage_address',
'fqdn', 'role'],
require => Class[lma_infra_alerting],
}
# Nodes have private IPs only with GRE segmentation
$network_config = hiera('quantum_settings')
$segmentation_type = $network_config['L2']['segmentation_type']
if $segmentation_type == 'gre' {
$private_network = true
} else {
$private_network = false
}
# Configure SSH checks
lma_infra_alerting::nagios::check_ssh { 'management':
hostgroups => keys($all_nodes),
require => Class[lma_infra_alerting::nagios::hosts],
}
lma_infra_alerting::nagios::check_ssh { 'storage':
hostgroups => keys($all_nodes),
custom_var_address => 'storage_address',
require => Class[lma_infra_alerting::nagios::hosts],
}
if $private_network {
lma_infra_alerting::nagios::check_ssh { 'private':
hostgroups => keys($all_nodes),
custom_var_address => 'private_address',
require => Class[lma_infra_alerting::nagios::hosts],
}
}
$nodes = hiera('nodes', {})
class { 'lma_infra_alerting::nagios::hosts':
hosts => $nodes,
host_name_key => 'name',
host_address_key => 'internal_address',
role_key => 'role',
host_display_name_keys => ['name', 'user_node_name'],
host_custom_vars_keys => ['internal_address', 'private_address',
'public_address', 'storage_address',
'fqdn', 'role'],
private_network => $private_network,
node_cluster_roles => $node_cluster_roles,
node_cluster_alarms => $node_cluster_alarms,
require => Class['lma_infra_alerting'],
}
$influxdb_nodes = filter_nodes($nodes, 'role', 'influxdb_grafana')
$es_kibana_nodes = filter_nodes($nodes, 'role', 'elasticsearch_kibana')
# Configure Grafana and InfluxDB checks
if ! empty($influxdb_nodes){
lma_infra_alerting::nagios::check_http { 'Grafana':
@ -153,7 +114,7 @@ if ! empty($influxdb_nodes){
url => '/login',
custom_var_address => 'internal_address',
string_expected_in_content => 'grafana',
require => Class[lma_infra_alerting::nagios::hosts],
require => Class['lma_infra_alerting::nagios::hosts'],
}
lma_infra_alerting::nagios::check_http { 'InfluxDB':
host_name => $influxdb_nodes[0]['name'],
@ -162,7 +123,7 @@ if ! empty($influxdb_nodes){
custom_var_address => 'internal_address',
string_expected_in_status => '204 No Content',
string_expected_in_headers => 'X-Influxdb-Version',
require => Class[lma_infra_alerting::nagios::hosts],
require => Class['lma_infra_alerting::nagios::hosts'],
}
}

View File

@ -0,0 +1,100 @@
# Copyright 2015 Mirantis, 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.
#
module Puppet::Parser::Functions
newfunction(:afds_to_nagios_services, :type => :rvalue, :doc => <<-EOS
Returns a hash that can be used to create/update nagios::service resources.
It expects 5 arguments:
1. An array of nodes, each node being described as a hash.
2. The key containing the node's name.
3. The key containing the node's role.
4. The mapping between clusters and node's roles
4. The mapping between cluster and the AFD alarms
*Examples:*
$hash = afds_to_nagios_services(
[{'name' => 'node-1', role => 'primary-controller'}, {'name' => 'node-2', role => 'controller'}],
'name', 'role',
[{'control_nodes' => ['primary-controller', 'controller']}],
[{'control_nodes' => [{'cpu' => ['alarm1']}, {'fs' => ['alarm1']}]}]
)
Would return:
{
'control_nodes.cpu, control_nodes.fs checks for node-1' => {
'hostname' => 'node-1',
'services' => ['control_nodes.cpu', 'control_nodes.fs'],
},
}
EOS
) do |arguments|
raise(Puppet::ParseError, "afds_to_nagios_services(): Wrong number of arguments " +
"given (#{arguments.size} expecting 5") if arguments.size != 5
nodes = arguments[0]
raise(Puppet::ParseError, "arg0 isn't an array!") if ! nodes.is_a?(Array)
name_key = arguments[1]
role_key = arguments[2]
role_to_cluster = arguments[3]
raise(Puppet::ParseError, "arg3 isn't an array!") if ! role_to_cluster.is_a?(Array)
afds = arguments[4]
raise(Puppet::ParseError, "arg4 isn't an array!") if ! afds.is_a?(Array)
result = {}
# collect the cluster memberships for every node
node_clusters = {}
nodes.each do |node|
node_name = node[name_key]
unless node_clusters.has_key?(node_name) then
node_clusters[node_name] = Set.new([])
end
role_to_cluster.each do |x|
x.each do |cluster, roles|
node_clusters[node_name] << cluster if roles.include?(node[role_key])
end
end
end
# collect the AFDs associated to the node using its cluster memberships
node_clusters.each do |node, clusters|
clusters << "default" if clusters.empty?
node_services = {}
clusters.each do |cluster|
afds.each do |x|
(x[cluster] || []).each do |y|
y.keys.sort.each do |source|
node_services["#{node}.#{cluster}.#{source}"] = "#{ cluster }.#{ source }".gsub(/\s+/, '_')
end
end
end
end
unless node_services.empty? then
result["#{ clusters.to_a.sort.join(', ') } checks for #{ node }"] = {
'hostname' => node,
'services' => node_services
}
end
end
return result
end
end

View File

@ -1,28 +1,63 @@
# Copyright 2015 Mirantis, 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.
#
module Puppet::Parser::Functions
newfunction(:nodes_to_nagios_hostgroups, :type => :rvalue, :doc => <<-EOS
Return a Hash grouped by role with all attributes matching
Nagios_Hostgroup resource properties (for nagios::hostgroup type).
{
'controller' => {
'properties' => {
'members' => 'node-1,node-2',
},
},
}
Returns a hash that can be used to create/update nagios::hostgroup resources.
Nagios hostgroups are mapped to the roles defined in the current environment.
It expects 3 arguments:
1. An array of nodes, each node being described as a hash.
2. The key containing the node's name.
3. The key containing the node's role.
*Examples:*
$hash = nodes_to_nagios_hostgroups(
[{'name' => 'node-1', role => 'controller'}, {'name' => 'node-2', role => 'controller'}],
'name', 'role'
)
Would return:
{'controller' => {'properties' => {'members' => 'node-1,node-2'}}}
EOS
) do |arguments|
raise(Puppet::ParseError, "nodes_to_nagios_hostgroups(): Wrong number of arguments " +
"given (#{arguments.size} for 2") if arguments.size < 2
"given (#{arguments.size} for 3") if arguments.size != 3
hash = arguments[0]
raise(Puppet::ParseError, "not a hash!") if ! hash.is_a?(Hash)
nodes = arguments[0]
raise(Puppet::ParseError, "arg0 is not an array!") if ! nodes.is_a?(Array)
name_key = arguments[1]
role_key = arguments[2]
result = {}
hash.each do |group, nodes|
result[group] = {'properties' => {'members' => nodes.collect{|x| x[name_key]}.sort().join(',') }}
roles = Set.new([])
nodes.each do |node|
roles << node[role_key]
end
roles.each do |role|
result[role] = {
'properties' => {
'members' => nodes.select{|x| x[role_key] == role}.collect{|x| x[name_key]}.sort().join(','),
}
}
end
return result
end
end

View File

@ -1,21 +1,72 @@
# Copyright 2015 Mirantis, 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.
#
module Puppet::Parser::Functions
newfunction(:nodes_to_nagios_hosts, :type => :rvalue, :doc => <<-EOS
Return a Hash grouped by host_name with all attributes matching
Nagios_Host resource properties (for nagios::host type).
{
'node-1' => {
'properties' => { .. nagios_host properties .. },
'custom_vars' => { .. nagios_host custom variables .. },
},
}
Returns a hash that can be used to create/update nagios::host resources.
It expects 5 arguments:
1. An array of nodes, each node being described as a hash.
2. The key containing the node's name.
3. The key containing the node's IP address.
4. The list of keys that will be used to build the node's display name.
5. The list of keys that will be used to build the node's custom variables.
*Examples:*
$hash = nodes_to_nagios_hostgroups(
[{'name' => 'node-1', role => 'controller', 'internal_address' => '10.20.0.5', 'user_node_name' => 'foo'},
{'name' => 'node-2', role => 'compute', 'internal_address' => '10.20.0.4', 'storage_address' => '10.20.2.4', 'user_node_name' => 'bar'},
{'name' => 'node-2', role => 'cinder', 'internal_address' => '10.20.0.4', 'storage_address' => '10.20.2.4', 'user_node_name' => 'bar'}],
'name',
'internal_address',
['name', 'user_node_name'],
['storage_address']
)
Would return:
{
'node-1' => {
'properties' => {
'address' => '10.20.0.5',
'display_name' => 'node-1_foo'
'alias' => 'node-1_foo'
},
'custom_vars' => {
'_storage_address' => ''
}
},
'node-2' => {
'properties' => {
'address' => '10.20.0.4',
'display_name' => 'node-2_bar'
'alias' => 'node-2_bar'
},
'custom_vars' => {
'_storage_address' => '10.20.2.4'
}
},
}
EOS
) do |arguments|
raise(Puppet::ParseError, "nodes_to_nagios_hosts(): Wrong number of arguments " +
"given (#{arguments.size} for 4") if arguments.size < 4
"given (#{arguments.size} expecting 5") if arguments.size != 5
hash = arguments[0]
raise(Puppet::ParseError, "not a hash!") if ! hash.is_a?(Hash)
nodes = arguments[0]
raise(Puppet::ParseError, "arg0 isn't a array!") if ! nodes.is_a?(Array)
name_key = arguments[1]
ip_key = arguments[2]
@ -23,26 +74,40 @@ module Puppet::Parser::Functions
custom_vars_keys = arguments[4] or []
result = {}
hash.each do |role, nodes|
nodes.each do |value|
ip = value[ip_key]
name = value[name_key]
display_name = display_name_keys.collect{ |x| value[x] }.join('_')
if ! result[name] then
result[name] = {
custom_vars = {}
nodes.each do |node|
node_name = node[name_key]
unless result.has_key?(node_name) then
display_name = display_name_keys.collect{ |x| node[x] }.join('_')
result[node_name] = {
'properties' => {
'address' => ip,
# Note: due to incompatible behavior between ruby 1.8.7 and 1.9.3
# the select method return an Array or a Hash.
'hostgroups' => Hash[hash.select{|k,v| v.count{|n| n[name_key] == name} > 0 }].keys(),
'display_name' => display_name,
'alias' => display_name,
'address' => node[ip_key],
'display_name' => display_name,
'alias' => display_name,
},
'custom_vars' => Hash[*custom_vars_keys.collect{|x| ["_#{x}", value[x]]}.flatten()],
'custom_vars' => {}
}
end
end
custom_vars[node_name] = {}
custom_vars_keys.each do |x|
custom_vars[node_name][x] = Set.new([node[x] || ''])
end
else
custom_vars_keys.each do |x|
custom_vars[node_name][x] << node[x] if node[x]
end
end
end
result.each_key do |node_name|
custom_vars[node_name].each_pair do |k,v|
unless v.empty? then
result[node_name]['custom_vars']["_#{k}"] = v.to_a.join(',')
end
end
end
return result
end
end
end

View File

@ -29,23 +29,23 @@ class lma_infra_alerting::nagios::hosts (
$host_address_key = undef,
$host_display_name_keys = [],
$host_custom_vars_keys = [],
$role_key = undef,
$private_network = false,
$node_cluster_roles = [],
$node_cluster_alarms = [],
){
include lma_infra_alerting::params
validate_hash($hosts)
validate_string($host_name_key, $host_address_key)
validate_array($host_display_name_keys, $host_custom_vars_keys)
validate_array($hosts, $host_display_name_keys, $host_custom_vars_keys)
$nagios_hosts = nodes_to_nagios_hosts(
$hosts,
$host_name_key,
$host_address_key,
$host_display_name_keys,
$host_custom_vars_keys)
$nagios_hostgroups = nodes_to_nagios_hostgroups($hosts, $host_name_key)
$default = {
$nagios_hosts = nodes_to_nagios_hosts($hosts,
$host_name_key,
$host_address_key,
$host_display_name_keys,
$host_custom_vars_keys)
$host_defaults = {
ensure => $ensure,
prefix => $lma_infra_alerting::params::nagios_config_filename_prefix,
defaults => {
@ -56,12 +56,40 @@ class lma_infra_alerting::nagios::hosts (
use => $lma_infra_alerting::params::nagios_generic_host_template,
}
}
create_resources(nagios::host, $nagios_hosts, $host_defaults)
$hg_default = {
$nagios_hostgroups = nodes_to_nagios_hostgroups($hosts,
$host_name_key,
$role_key)
$hostgroup_defaults = {
prefix => $lma_infra_alerting::params::nagios_config_filename_prefix,
ensure => $ensure,
}
create_resources(nagios::hostgroup, $nagios_hostgroups, $hostgroup_defaults)
create_resources(nagios::hostgroup, $nagios_hostgroups, $hg_default)
create_resources(nagios::host, $nagios_hosts, $default)
# Configure AFD-based service checks
$afd_services = afds_to_nagios_services($hosts,
$host_name_key,
$role_key,
$node_cluster_roles,
$node_cluster_alarms)
$afd_service_defaults = {'notifications_enabled' => 0}
create_resources(lma_infra_alerting::nagios::services, $afd_services, $afd_service_defaults)
# Configure SSH checks
lma_infra_alerting::nagios::check_ssh { 'management':
hostgroups => keys($nagios_hostgroups),
}
lma_infra_alerting::nagios::check_ssh { 'storage':
hostgroups => keys($nagios_hostgroups),
custom_var_address => 'storage_address',
}
if $private_network {
lma_infra_alerting::nagios::check_ssh { 'private':
hostgroups => keys($nagios_hostgroups),
custom_var_address => 'private_address',
}
}
}

View File

@ -0,0 +1,132 @@
# Copyright 2015 Mirantis, 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.
#
require 'spec_helper'
describe 'afds_to_nagios_services' do
all_nodes = [
{"fqdn" => "node-1.test.domain.local",
"internal_address" => "10.109.2.5",
"internal_netmask" => "255.255.255.0",
"name" => "node-1",
"role" => "influxdb_grafana",
"storage_address" => "10.109.4.2",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "1",
"uid" => "1",
"user_node_name" => "slave-03_alerting"},
{"fqdn" => "node-1.test.domain.local",
"internal_address" => "10.109.2.5",
"internal_netmask" => "255.255.255.0",
"name" => "node-1",
"role" => "infrastructure_alerting",
"storage_address" => "10.109.4.2",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "1",
"uid" => "1",
"user_node_name" => "slave-03_alerting"},
{"fqdn" => "node-3.test.domain.local",
"internal_address" => "10.109.2.4",
"internal_netmask" => "255.255.255.0",
"name" => "node-3",
"public_address" => "10.109.1.4",
"public_netmask" => "255.255.255.0",
"role" => "primary-controller",
"storage_address" => "10.109.4.3",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "3",
"uid" => "3",
"user_node_name" => "slave-01_controller"},
{"fqdn" => "node-4.test.domain.local",
"internal_address" => "10.109.2.7",
"internal_netmask" => "255.255.255.0",
"name" => "node-4",
"role" => "elasticsearch_kibana",
"storage_address" => "10.109.4.5",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "4",
"uid" => "4",
"user_node_name" => "Untitled (79:a7)"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-2",
"role" => "cinder",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-2",
"role" => "compute",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"}
]
role_to_cluster = [
{"controller" => ["primary-controller", "controller"]},
{"compute" => ["compute"]},
{"storage" => ["cinder", "ceph-osd"]}
]
afds = [
{"controller" => [
{"system" => ["cpu-critical-controller", "cpu-warning-controller"]},
{"fs" => ["fs-critical", "fs-warning"]}]},
{"compute" => [
{"system" => ["cpu-critical-compute", "cpu-warning-compute"]},
{"fs" => ["fs-critical", "fs-critical-compute", "fs-warning"]}]},
{"storage" => [
{"system" => ["cpu-critical-storage", "cpu-warning-storage"]},
{"fs" => ["fs-critical-storage", "fs-warning-storage"]}]},
{"default" => [
{"cpu" => ["cpu-critical-default"]},
{"fs" => ["fs-critical", "fs-warning"]}]}
]
describe 'with argumentss' do
it { should run.with_params(all_nodes, 'name', 'role', role_to_cluster, afds).and_return(
{"default checks for node-1" => {
"hostname" => "node-1",
"services" => {
"node-1.default.cpu" => "default.cpu",
"node-1.default.fs" => "default.fs",
}},
"controller checks for node-3" => {
"hostname" => "node-3",
"services" => {
"node-3.controller.fs" => "controller.fs",
"node-3.controller.system" => "controller.system"
}},
"default checks for node-4" => {
"hostname" => "node-4",
"services" => {
"node-4.default.cpu" => "default.cpu",
"node-4.default.fs" => "default.fs"
}},
"compute, storage checks for node-2" => {
"hostname" => "node-2",
"services" => {
"node-2.compute.fs" => "compute.fs",
"node-2.compute.system" => "compute.system",
"node-2.storage.fs" => "storage.fs",
"node-2.storage.system" => "storage.system"
}}})
}
end
end

View File

@ -0,0 +1,109 @@
# Copyright 2015 Mirantis, 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.
#
require 'spec_helper'
describe 'nodes_to_nagios_hostgroups' do
describe 'with empty node list' do
it { should run.with_params([], 'name', 'role').and_return({}) }
end
describe 'with node list' do
nodes = [
{"fqdn" => "node-1.test.domain.local",
"internal_address" => "10.109.2.5",
"internal_netmask" => "255.255.255.0",
"name" => "node-1",
"role" => "influxdb_grafana",
"storage_address" => "10.109.4.2",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "1",
"uid" => "1",
"user_node_name" => "slave-03_alerting"},
{"fqdn" => "node-1.test.domain.local",
"internal_address" => "10.109.2.5",
"internal_netmask" => "255.255.255.0",
"name" => "node-1",
"role" => "infrastructure_alerting",
"storage_address" => "10.109.4.2",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "1",
"uid" => "1",
"user_node_name" => "slave-03_alerting"},
{"fqdn" => "node-3.test.domain.local",
"internal_address" => "10.109.2.4",
"internal_netmask" => "255.255.255.0",
"name" => "node-3",
"public_address" => "10.109.1.4",
"public_netmask" => "255.255.255.0",
"role" => "primary-controller",
"storage_address" => "10.109.4.3",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "3",
"uid" => "3",
"user_node_name" => "slave-01_controller"},
{"fqdn" => "node-4.test.domain.local",
"internal_address" => "10.109.2.7",
"internal_netmask" => "255.255.255.0",
"name" => "node-4",
"role" => "elasticsearch_kibana",
"storage_address" => "10.109.4.5",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "4",
"uid" => "4",
"user_node_name" => "Untitled (79:a7)"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-2",
"role" => "cinder",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-2",
"role" => "compute",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-9",
"role" => "compute",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"}
]
it { should run.with_params(nodes, 'name', 'role').and_return(
{"influxdb_grafana" => { "properties" => {"members" => "node-1"}},
"infrastructure_alerting" => { "properties" => {"members" => "node-1"}},
"primary-controller" => { "properties" => {"members" => "node-3"}},
"elasticsearch_kibana" => { "properties" => {"members" => "node-4"}},
"cinder" => { "properties" => {"members" => "node-2"}},
"compute" => { "properties" => {"members" => "node-2,node-9"}}}
)}
end
end

View File

@ -0,0 +1,103 @@
# Copyright 2015 Mirantis, 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.
#
require 'spec_helper'
describe 'nodes_to_nagios_hosts' do
nodes = [
{"fqdn" => "node-1.test.domain.local",
"internal_address" => "10.109.2.5",
"internal_netmask" => "255.255.255.0",
"name" => "node-1",
"role" => "influxdb_grafana",
"storage_address" => "10.109.4.2",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "1",
"uid" => "1",
"user_node_name" => "slave-03_alerting"},
{"fqdn" => "node-1.test.domain.local",
"internal_address" => "10.109.2.5",
"internal_netmask" => "255.255.255.0",
"name" => "node-1",
"role" => "infrastructure_alerting",
"storage_address" => "10.109.4.2",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "1",
"uid" => "1",
"user_node_name" => "slave-03_alerting"},
{"fqdn" => "node-3.test.domain.local",
"internal_address" => "10.109.2.4",
"internal_netmask" => "255.255.255.0",
"name" => "node-3",
"public_address" => "10.109.1.4",
"public_netmask" => "255.255.255.0",
"role" => "primary-controller",
"storage_address" => "10.109.4.3",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "3",
"uid" => "3",
"user_node_name" => "slave-01_controller"},
{"fqdn" => "node-4.test.domain.local",
"internal_address" => "10.109.2.7",
"internal_netmask" => "255.255.255.0",
"name" => "node-4",
"role" => "elasticsearch_kibana",
"storage_address" => "10.109.4.5",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "4",
"uid" => "4",
"user_node_name" => "Untitled (79:a7)"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-2",
"role" => "cinder",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"},
{"fqdn" => "node-2.test.domain.local",
"internal_address" => "10.109.2.6",
"internal_netmask" => "255.255.255.0",
"name" => "node-2",
"role" => "compute",
"storage_address" => "10.109.4.4",
"storage_netmask" => "255.255.255.0",
"swift_zone" => "2",
"uid" => "2",
"user_node_name" => "slave-02_compute_cinder"}
]
describe 'with valid arguments' do
it { should run.with_params(nodes, 'name', 'internal_address',
['name', 'user_node_name'],
['fqdn']).and_return({
"node-1" => {
"properties" => {"address" => "10.109.2.5", "display_name" => "node-1_slave-03_alerting", "alias" => "node-1_slave-03_alerting"},
"custom_vars" => {"_fqdn" => "node-1.test.domain.local"}},
"node-3" => {
"properties" => {"address" => "10.109.2.4", "display_name" => "node-3_slave-01_controller", "alias" => "node-3_slave-01_controller"},
"custom_vars" => {"_fqdn" => "node-3.test.domain.local"}},
"node-4" => {
"properties" => {"address" => "10.109.2.7", "display_name" => "node-4_Untitled (79:a7)", "alias" => "node-4_Untitled (79:a7)"},
"custom_vars" => {"_fqdn" => "node-4.test.domain.local"}},
"node-2" => {
"properties" => {"address" => "10.109.2.6", "display_name" => "node-2_slave-02_compute_cinder", "alias" => "node-2_slave-02_compute_cinder"},
"custom_vars" => {"_fqdn" => "node-2.test.domain.local"}}
})
}
end
end