From 55533bc1c9c714000b4fa5c578928d727da368fd Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Tue, 2 Jun 2015 19:17:10 +0200 Subject: [PATCH] Fail early when the settings aren't valid This change adds a post-deployment task that verifies that the plugin configuration matches with the configuration of the environment. The task checks that when using local Elasticsearch and InfluxDB nodes, these nodes exist effectively in the deployed environment. The goal is to stop the deployment as soon as possible if the configuration isn't valid. This couldn't be done in a pre-deployment task because Hiera isn't available at this stage. Change-Id: I318a214407a9e287f8376ec32907300bea554781 --- .../check_environment_configuration.pp | 64 +++++++++++++++++++ tasks.yaml | 8 +++ 2 files changed, 72 insertions(+) create mode 100644 deployment_scripts/puppet/manifests/check_environment_configuration.pp diff --git a/deployment_scripts/puppet/manifests/check_environment_configuration.pp b/deployment_scripts/puppet/manifests/check_environment_configuration.pp new file mode 100644 index 000000000..da5d9728a --- /dev/null +++ b/deployment_scripts/puppet/manifests/check_environment_configuration.pp @@ -0,0 +1,64 @@ +# 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. +# +# This manifest is only executed on the primrary-controller to verify that the +# plugin's configuration matches with the environment. + +$lma_collector = hiera('lma_collector') + +$elasticsearch_mode = $lma_collector['elasticsearch_mode'] +if $elasticsearch_mode == 'local' { + # Check that the Elasticsearch-Kibana node exists in the environment + $es_node_name = $lma_collector['elasticsearch_node_name'] + $es_nodes = filter_nodes(hiera('nodes'), 'user_node_name', $es_node_name) + if size($es_nodes) < 1 { + fail("Could not find node '${es_node_name}' in the environment") + } + + # Check that the Elasticsearch-Kibana plugin is enabled for that environment + # and that the node names match + $elasticsearch_kibana = hiera('elasticsearch_kibana', false) + if ! $elasticsearch_kibana { + fail('Could not get the Elasticsearch parameters. The Elasticsearch-Kibana plugin is probably not installed.') + } + elsif ! $elasticsearch_kibana['metadata']['enabled'] { + fail('Could not get the Elasticsearch parameters. The Elasticsearch-Kibana plugin is probably not enabled for this environment.') + } + elsif $elasticsearch_kibana['node_name'] != $es_node_name { + fail('Node name settings don\'t match between the LMA collector and Elasticsearch-Kibana plugins.') + } +} + +$influxdb_mode = $lma_collector['influxdb_mode'] +if $influxdb_mode == 'local' { + # Check that the InfluxDB-Grafana node exists in the environment + $influxdb_node_name = $lma_collector['influxdb_node_name'] + $influxdb_nodes = filter_nodes(hiera('nodes'), 'user_node_name', $influxdb_node_name) + if size($influxdb_nodes) < 1 { + fail("Could not find node '${influxdb_node_name}' in the environment") + } + + # Check that the InfluxDB-Grafana plugin is enabled for that environment + # and that the node names match + $influxdb_grafana = hiera('influxdb_grafana', false) + if ! $influxdb_grafana { + fail('Could not get the InfluxDB parameters. The InfluxDB-Grafana plugin is probably not installed.') + } + elsif ! $influxdb_grafana['metadata']['enabled'] { + fail('Could not get the InfluxDB parameters. The InfluxDB-Grafana plugin is probably not enabled for this environment.') + } + elsif $influxdb_grafana['node_name'] != $influxdb_node_name { + fail('Node name settings don\'t match between the LMA collector and InfluxDB-Grafana plugins.') + } +} diff --git a/tasks.yaml b/tasks.yaml index 9d53bcace..df94eea3c 100644 --- a/tasks.yaml +++ b/tasks.yaml @@ -1,3 +1,11 @@ +- role: ['primary-controller'] + stage: post_deployment + type: puppet + parameters: + puppet_manifest: puppet/manifests/check_environment_configuration.pp + puppet_modules: puppet/modules + timeout: 300 + - role: '*' stage: post_deployment type: puppet