From 7541b40e39368084d8aed51665f4b6566c53383c Mon Sep 17 00:00:00 2001 From: John Browning Date: Fri, 12 Aug 2016 10:29:27 -0400 Subject: [PATCH] Added check for ceilometerdb size Also includes the new ini reader module from Tomas Sedovic Change-Id: Icdd28c18aee7bb0f96d01e194f17de5eee164ba6 --- validations/ceilometerdb-size.yaml | 23 ++++++++++++ validations/library/ini.py | 60 ++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 validations/ceilometerdb-size.yaml create mode 100644 validations/library/ini.py diff --git a/validations/ceilometerdb-size.yaml b/validations/ceilometerdb-size.yaml new file mode 100644 index 000000000..15964c7aa --- /dev/null +++ b/validations/ceilometerdb-size.yaml @@ -0,0 +1,23 @@ +--- +- hosts: undercloud + vars: + metadata: + name: Ceilometer Database Size Check + description: > + The undercloud's ceilometer database can grow to a substantial size + if metering_time_to_live and event_time_to_live is set to -1 (infinite). + We check each setting and fail if -1 is set. + groups: + - pre-deployment + ttl_value: "-1" + metering_ttl_check: "metering_time_to_live" + event_ttl_check: "event_time_to_live" + tasks: + - name: Check ceilomter.conf for a -1 TTL setting + become: true + ini: path=/etc/ceilometer/ceilometer.conf section=database key={{ item }} + register: config_result + with_items: + - "{{ metering_ttl_check }}" + - "{{ event_ttl_check }}" + failed_when: "'{{ ttl_value }}' in config_result.value" diff --git a/validations/library/ini.py b/validations/library/ini.py new file mode 100644 index 000000000..f5b36c7ba --- /dev/null +++ b/validations/library/ini.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +# -*- coding: utf-8 -*- +# 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. + +# Ansible module to read a value from an Ini file. +# Usage: +# - ini: path=/path/to/file.ini section=default key=something +# register: my_ini +# +# This will read the `path/to/file.ini` file and read the `Hello!` value under: +# [default] +# something = Hello! +# +# You can register the result and use it later with `{{ my_ini.value }}` + +import ConfigParser +from os import path + +from ansible.module_utils.basic import * # NOQA + + +def main(): + module = AnsibleModule(argument_spec=dict( + path=dict(required=True, type='str'), + section=dict(required=True, type='str'), + key=dict(required=True, type='str'), + )) + + ini_file_path = module.params.get('path') + + if path.exists(ini_file_path) and path.isfile(ini_file_path): + config = ConfigParser.SafeConfigParser() + config.read(ini_file_path) + + try: + value = config.get(module.params.get('section'), + module.params.get('key')) + except ConfigParser.Error as e: + module.fail_json(msg=e.message) + + module.exit_json(changed=False, value=value) + else: + module.fail_json(msg="Could not open the ini file: '{}'" + .format(ini_file_path)) + + +if __name__ == '__main__': + main()