From 9ebb8b20b7503194a09b83a3e7cb580bf132b765 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Fri, 19 Feb 2021 20:57:48 +0000 Subject: [PATCH] Ansible for collectd * Intended to replace puppet implementation * Molecule tests included Change-Id: Ib75702bf17a76cae3a811db503d3365e6aacf663 --- doc/source/roles/role-tripleo_collectd.rst | 6 + .../roles/tripleo_collectd/defaults/main.yml | 228 ++++++++++++++++++ .../files/openstack-healthcheck.conf | 2 + .../roles/tripleo_collectd/meta/main.yml | 33 +++ .../molecule/amqp_connection/converge.yml | 35 +++ .../molecule/amqp_connection/molecule.yml | 59 +++++ .../molecule/amqp_connection/verify.yml | 28 +++ .../amqp_default_interval/converge.yml | 37 +++ .../amqp_default_interval/molecule.yml | 59 +++++ .../molecule/amqp_default_interval/verify.yml | 36 +++ .../molecule/collectd_connection/converge.yml | 43 ++++ .../molecule/collectd_connection/molecule.yml | 85 +++++++ .../molecule/collectd_connection/verify.yml | 98 ++++++++ .../molecule/common/Dockerfile | 36 +++ .../molecule/common/prepare.yml | 59 +++++ .../molecule/common/requirements.yml | 7 + .../molecule/common/verify.yml | 89 +++++++ .../molecule/default/converge.yml | 33 +++ .../molecule/default/molecule.yml | 65 +++++ .../molecule/default/verify.yml | 39 +++ .../molecule/enable_libpodstats/converge.yml | 34 +++ .../molecule/enable_libpodstats/molecule.yml | 59 +++++ .../molecule/enable_libpodstats/verify.yml | 52 ++++ .../molecule/enable_sensubility/converge.yml | 18 ++ .../molecule/enable_sensubility/molecule.yml | 59 +++++ .../molecule/enable_sensubility/verify.yml | 61 +++++ .../molecule/enable_sqlalchemy/converge.yml | 34 +++ .../molecule/enable_sqlalchemy/molecule.yml | 59 +++++ .../enable_sqlalchemy/requirements.yml | 7 + .../molecule/enable_sqlalchemy/verify.yml | 46 ++++ .../molecule/enable_stf/converge.yml | 34 +++ .../molecule/enable_stf/molecule.yml | 59 +++++ .../molecule/enable_stf/verify.yml | 36 +++ .../tasks/configure_collectd.yml | 226 +++++++++++++++++ .../tasks/configure_healthcheck.yml | 47 ++++ .../tasks/configure_host_software.yml | 22 ++ .../tasks/create_persistent_directories.yml | 30 +++ .../roles/tripleo_collectd/tasks/main.yml | 33 +++ .../templates/collectd-sensubility.conf.j2 | 52 ++++ .../roles/tripleo_collectd/vars/main.yml | 50 ++++ zuul.d/molecule.yaml | 10 + 41 files changed, 2105 insertions(+) create mode 100644 doc/source/roles/role-tripleo_collectd.rst create mode 100644 tripleo_ansible/roles/tripleo_collectd/defaults/main.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/files/openstack-healthcheck.conf create mode 100644 tripleo_ansible/roles/tripleo_collectd/meta/main.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/common/Dockerfile create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/common/prepare.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/common/requirements.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/common/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/default/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/default/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/default/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/requirements.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/verify.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/tasks/configure_collectd.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/tasks/configure_healthcheck.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/tasks/configure_host_software.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/tasks/create_persistent_directories.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/tasks/main.yml create mode 100644 tripleo_ansible/roles/tripleo_collectd/templates/collectd-sensubility.conf.j2 create mode 100644 tripleo_ansible/roles/tripleo_collectd/vars/main.yml diff --git a/doc/source/roles/role-tripleo_collectd.rst b/doc/source/roles/role-tripleo_collectd.rst new file mode 100644 index 000000000..1f3b29fd6 --- /dev/null +++ b/doc/source/roles/role-tripleo_collectd.rst @@ -0,0 +1,6 @@ +======================= +Role - tripleo_collectd +======================= + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo_collectd diff --git a/tripleo_ansible/roles/tripleo_collectd/defaults/main.yml b/tripleo_ansible/roles/tripleo_collectd/defaults/main.yml new file mode 100644 index 000000000..b6673e535 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/defaults/main.yml @@ -0,0 +1,228 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# Corresponds to MetricsQdrPort in THT +# Service name or port number on which the qdrouterd will accept connections. +metrics_qdr_port: 5666 + +# Corresponds to MetricsQdrUsername in THT +# Username which should be used to authenticate to the deployed qdrouterd. +metrics_qdr_username: guest + +# Corresponds to MetricsQdrPassword in THT +# Password which should be used to authenticate to the deployed qdrouterd. +metrics_qdr_password: guest + +# Corresponds to MonitoringSubscriptionCollectd in THT +tripleo_collectd_monitoring_subscription: overcloud-collectd + +# Corresponds to CollectdConnectionType in THT +# Define which write plugin should collectd use. Currently supported are 'amqp1', +# 'network' and 'gnocchi'. +tripleo_collectd_connection_type: amqp1 + +# Corresponds to CollectdDefaultPollingInterval in THT +# Controls how often registered read functions are called and with that the +# resolution of the collected data. This value can be overridden per plugin(per +# role) by setting "::collectd::plugin::::interval" key in +# ExtraConfig(ExtraConfig). +tripleo_collectd_default_polling_interval: 120 + +# Corresponds to CollectdDefaultPlugins in THT +# List of collectd plugins to activate on all overcloud hosts. See the +# documentation for the puppet-collectd module for a list plugins supported by +# the module (https://github.com/voxpupuli/puppet-collectd). Set this key to +# override the default list of plugins. Use CollectdExtraPlugins if you want to +# load additional plugins without overriding the defaults. +tripleo_collectd_default_plugins: ['cpu', 'df', 'disk', 'hugepages', 'interface', 'load', 'memory', 'processes', 'unixsock', 'uptime'] + +# Corresponds to CollectdExtraPlugins in THT +# List of collectd plugins to activate on all overcloud hosts. See the +# documentation for the puppet-collectd module for a list plugins supported by +# the module (https://github.com/voxpupuli/puppet-collectd). Set this key to load +# plugins in addition to those in CollectdDefaultPlugins. +tripleo_collectd_extra_plugins: [] + +# Corresponds to CollectdServer in THT +# Address of remote collectd server to which we will send metrics. +tripleo_collectd_server: + +# Corresponds to CollectdServerPort in THT +# Port on remote collectd server to which we will send metrics. +tripleo_collectd_server_port: 25826 + +# Corresponds to CollectdUsername in THT +# Username for authenticating to the remote collectd server. The default is to +# not configure any authentication. +tripleo_collectd_username: + +# Corresponds to CollectdPassword in THT +# Password for authenticating to the remote collectd server. The default is to +# not configure any authentication. +tripleo_collectd_password: + +# Corresponds to CollectdSecurityLevel in THT +# Security level setting for remote collectd connection. If it is set to Sign or +# Encrypt the CollectdPassword and CollectdUsername parameters need to be set. +tripleo_collectd_security_level: None + +# Corresponds to EnableSQLAlchemyCollectd in THT +# Set to true to enable the SQLAlchemy-collectd server plugin +tripleo_collectd_enable_sqlalchemy: false + +# Corresponds to CollectdSQLAlchemyLogMessages in THT +# set to "debug" to enable message logging. +tripleo_collectd_sqlalchemy_log_messages: info + +# Corresponds to CollectdSQLAlchemyBindHost in THT +# hostname for SQLAlchemy-collectd plugin to bind on. defaults to localhost. +tripleo_collectd_sqlalchemy_bind_host: localhost + +# Corresponds to CollectdAmqpHost in THT +# Hostname or IP address of the AMQP 1.0 intermediary. +tripleo_collectd_amqp_host: nil + +# Corresponds to CollectdAmqpPort in THT +# Service name or port number on which the AMQP 1.0 intermediary accepts +# connections. This argument must be a string, even if the numeric form is used. +tripleo_collectd_amqp_port: 5666 + +# Corresponds to CollectdAmqpUser in THT +# User part of credentials used to authenticate to the AMQP 1.0 intermediary. +tripleo_collectd_amqp_user: guest + +# Corresponds to CollectdAmqpPassword in THT +# Password part of credentials used to authenticate to the AMQP 1.0 intermediary. +tripleo_collectd_amqp_password: guest + +# Corresponds to CollectdAmqpTransportName in THT +# Name of the AMQP 1.0 transport. +tripleo_collectd_amqp_transport_name: metrics + +# Corresponds to CollectdAmqpAddress in THT +# This option specifies the prefix for the send-to value in the message. +tripleo_collectd_amqp_address: collectd + +# Corresponds to CollectdAmqpInstances in THT +# Hash of hashes. Each inner hash represent Instance block in plugin +# configuration file. Key of outter hash represents instance name. The 'address' +# value concatenated with the 'name' given will be used as the send-to address +# for communications over the messaging link. +tripleo_collectd_amqp_instances: {} + +# Corresponds to CollectdAmqpRetryDelay in THT +# When the AMQP 1.0 connection is lost, defines the time in seconds to wait +# before attempting to reconnect. +tripleo_collectd_amqp_retry_delay: 1 + +# Corresponds to CollectdAmqpInterval in THT +# Interval on which metrics should be sent to AMQP intermediary. If not set the +# default for all collectd plugins is used. +tripleo_collectd_amqp_interval: -666 + +# Corresponds to CollectdAmqpSendQueueLimit in THT +# Number of data sets to be kept in memory, older sets will be discarded, +# if set to -1, this feature is disabled. +tripleo_collectd_amqp_send_queue_limit: -1 + +# Corresponds to CollectdEnableSensubility in THT +# Set to true if sensubility should be executed by exec plugin. +tripleo_collectd_enable_sensubility: false + +# Corresponds to CollectdSensubilityExecSudoRule in THT +# Given rule will be created in /etc/sudoers.d for sensubility to enable it +# calling restricted commands via sensubility executor. +tripleo_collectd_sensubility_exec_sudo_rule: '' + +# Corresponds to CollectdSensubilityLogLevel in THT +# Use for override the default logging level (WARNING). +tripleo_collectd_sensubility_log_level: WARNING + +# Corresponds to CollectdSensubilityConnection in THT +# URL to Sensu sever side +tripleo_collectd_sensubility_connection: amqp://sensu:sensu@localhost:5672//sensu + +tripleo_collectd_sensubility_subscriptions: [] + +# Corresponds to CollectdSensubilityKeepaliveInterval in THT +# Interval in seconds for sending keepalive messages to Sensu server side. +tripleo_collectd_sensubility_keepalive_interval: 20 + +# Corresponds to CollectdSensubilityTmpDir in THT +# Path to temporary directory which is used for creation of check scripts. +tripleo_collectd_sensubility_tmp_dir: /var/tmp/collectd-sensubility-checks + +# Corresponds to CollectdSensubilityShellPath in THT +# Path to shell used for executing check scripts. +tripleo_collectd_sensubility_shell_path: /usr/bin/sh + +# Corresponds to CollectdSensubilityWorkerCount in THT +# Number of goroutines spawned for executing check scripts. +tripleo_collectd_sensubility_worker_count: 2 + +# Corresponds to CollectdSensubilityChecks in THT +# JSON formated definition of standalone checks to be scheduled on client side. +tripleo_collectd_sensubility_checks: {} + +# Corresponds to CollectdSensubilityTransport in THT +# Bus type for sent data. Options are 'sensu' (rabbitmq) and 'amqp1' +tripleo_collectd_sensubility_transport: sensu + +# Corresponds to CollectdSensubilityResultsChannel in THT +# AMQP1 channel address +tripleo_collectd_sensubility_results_channel: 'collectd/notify' + +# Corresponds to CollectdEnableContainerHealthCheck in THT +# Set to false if container health check should not be defined and attached to +# CollectdEnableContainerHealthCheck. +tripleo_collectd_enable_container_health_check: true + +# Corresponds to CollectdContainerHealthCheckCommand in THT +# The command to be run by sensubility when the health check is enabled. +# Defaults to a script that is expected to be placed by TripleO at the given +# location. +tripleo_collectd_container_health_check_command: /scripts/collectd_check_health.py + +# Corresponds to CollectdContainerHealthCheckInterval in THT +# The frequency in seconds the docker health check is executed. +tripleo_collectd_container_health_check_interval: 10 + +# Corresponds to CollectdContainerHealthCheckHandlers in THT +# The Sensu event handler to use for events created by the docker health check. +tripleo_collectd_container_health_check_handlers: [] + +# Corresponds to CollectdContainerHealthCheckOccurrences in THT +# The number of event occurrences before sensu-plugin-aware handler should take +# action. +tripleo_collectd_container_health_check_occurrences: 3 + +# Corresponds to CollectdContainerHealthCheckRefresh in THT +# The number of seconds sensu-plugin-aware handlers should wait before taking +# second action. +tripleo_collectd_container_health_check_refresh: 90 + +# Corresponds to EnableSTF in THT +# Set to true to enable configuration for STF client. +tripleo_collectd_enable_stf: false + +# Corresponds to CollectdEnableMcelog in THT +# Set to true to enable mcelog +tripleo_collectd_enable_mcelog: false + +# Corresponds to CollectdEnableLibpodstats in THT +# Set to true if collectd should run the libpodstats plugin +tripleo_collectd_enable_libpodstats: false diff --git a/tripleo_ansible/roles/tripleo_collectd/files/openstack-healthcheck.conf b/tripleo_ansible/roles/tripleo_collectd/files/openstack-healthcheck.conf new file mode 100644 index 000000000..0a8d86b2a --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/files/openstack-healthcheck.conf @@ -0,0 +1,2 @@ +if ($programname startswith 'podman' and ($msg contains 'container exec' or $msg contains 'healthy')) or ($programname startswith 'systemd' and $msg contains 'podman healthcheck run') then -/var/log/containers/collectd/healthchecks.stdout +& stop diff --git a/tripleo_ansible/roles/tripleo_collectd/meta/main.yml b/tripleo_ansible/roles/tripleo_collectd/meta/main.yml new file mode 100644 index 000000000..f13c43396 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/meta/main.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +galaxy_info: + author: OpenStack + description: TripleO OpenStack Role -- tripleo_collectd + company: Red Hat + license: Apache-2.0 + min_ansible_version: 2.9 + platforms: + - name: CentOS + versions: + - 7 + - 8 + + galaxy_tags: + - tripleo + +dependencies: [] diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/converge.yml new file mode 100644 index 000000000..f7ddcc2ad --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/converge.yml @@ -0,0 +1,35 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: all + tasks: + - name: "Set up expected THT vars" + set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + + - name: "Use the tripleo_collectd role to configure collectd to export metrics to amqp" + include_role: + name: "{{ playbook_dir }}/../../../tripleo_collectd" + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + # This is not the right things to put here... need to check tripleo_collectd + tripleo_collectd_connection_type: 'amqp1' diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/molecule.yml new file mode 100644 index 000000000..1914fedc7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/molecule.yml @@ -0,0 +1,59 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/verify.yml new file mode 100644 index 000000000..2a5be3257 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_connection/verify.yml @@ -0,0 +1,28 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- import_playbook: ../common/verify.yml + +- name: Verify + hosts: all + tasks: + - name: "Get amqp conf" + stat: + path: "{{ collectd_conf_output_dir }}/amqp1.conf" + register: amqp_conf + failed_when: + - not amqp_conf.stat.exists diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/converge.yml new file mode 100644 index 000000000..b4b1fc67f --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/converge.yml @@ -0,0 +1,37 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: all + tasks: + - name: "Set up expected THT vars" + set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + + - name: "Use tripleo_collectd to configure collectd using the default interval for amqp" + include_role: + name: "{{ playbook_dir }}/../../../tripleo_collectd" + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + tripleo_collectd_amqp_host: collectd-test + # This is not the right things to put here... need to check tripleo_collectd + tripleo_collectd_connection_type: 'amqp1' + tripleo_collectd_amqp_interval: -666 diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/molecule.yml new file mode 100644 index 000000000..1914fedc7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/molecule.yml @@ -0,0 +1,59 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/verify.yml new file mode 100644 index 000000000..e820c20c0 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/amqp_default_interval/verify.yml @@ -0,0 +1,36 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- import_playbook: ../common/verify.yml + +- name: Verify + hosts: all + tasks: + - name: "Get amqp conf" + stat: + path: "{{ collectd_conf_output_dir }}/amqp1.conf" + register: amqp_conf + failed_when: + - not amqp_conf.stat.exists + + - name: "Check that default interval was unchanged" + command: + grep "Interval" {{ collectd_conf_output_dir }}/amqp1.conf + register: interval + changed_when: false + failed_when: + - ( interval.stdout | length != 0 ) or ( interval.stderr_lines | length != 0 ) diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/converge.yml new file mode 100644 index 000000000..cb34f4b40 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/converge.yml @@ -0,0 +1,43 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: collectd-test + tasks: + - name: "Use tripleo_collectd to configure collectd to sent metrics using the network plugin" + include_role: + name: "{{ playbook_dir }}/../../../tripleo_collectd" + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + tripleo_collectd_connection_type: 'network' + tripleo_collectd_server: '192.168.42.2' + +- name: Converge collectd-server + hosts: collectd-server + tasks: + - name: "Configure collectd on the server to receive metrics" + include_role: + name: collectd_config + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + collectd_plugin_network_listen: + - address: "192.168.42.2" + collectd_plugins: + - logfile + - network + - unixsock diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/molecule.yml new file mode 100644 index 000000000..222ba7b08 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/molecule.yml @@ -0,0 +1,85 @@ +--- +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + docker_networks: + - name: collectd + ipam_config: + - subnet: "192.168.42.0/24" + gateway: "192.168.42.254" + networks: + - name: collectd + ipv4_address: "192.168.42.1" + - name: collectd-server + hostname: collectd-server + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: + - host + networks: + - name: collectd + ipv4_address: "192.168.42.2" + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - verify + - destroy + - cleanup diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/verify.yml new file mode 100644 index 000000000..1565bdc93 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/collectd_connection/verify.yml @@ -0,0 +1,98 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# TODO: Reconsider this later, but it seems like a bad fit right now, since +# there are two hosts in the scenario, and this relies on there being one, and +# using podman +# - import_playbook: ../common/verify.yml +- name: Verify collectd-test + hosts: collectd-test + tasks: + - name: "Check that network.conf exists" + stat: + path: "{{ collectd_conf_output_dir }}/network.conf" + register: network_conf + failed_when: + - not network_conf.stat.exists + + - name: "Get the network.conf is configuration" + slurp: + path: "{{ collectd_conf_output_dir }}/network.conf" + register: network_conf + + - name: "Check the contents of network.conf" + assert: + that: + - '"" in network_conf.content | b64decode' + - '"SecurityLevel \"None\"" in network_conf.content | b64decode' + - not "Username" in network_conf.content | b64decode + - not "Password" in network_conf.content | b64decode + fail_msg: "Incorrect contents in network.conf: {{ network_conf.content | b64decode }}" + +- name: "(Re)start collectd service" + hosts: + - all + tasks: + - name: "Kill running collectd process" + command: + pkill -e -c collectd + ignore_errors: true + changed_when: false + + - name: "Start collectd" + command: + /usr/sbin/collectd -C /etc/collectd.conf + changed_when: false + +- name: Verify collectd-server + hosts: collectd-server + tasks: + - name: Check for files in conf output dir + find: + paths: /etc/collectd.d + patterns: '*.conf' + register: output + failed_when: + - output.files | length == 0 + + - name: "Check for collectd.conf" + find: + paths: /etc/ + patterns: collectd.conf + register: conf + failed_when: + - conf.files | length != 1 + + - name: "Check for metrics received by the collectd server" + command: + collectdctl -s /var/run/collectd-socket listval + retries: 3 + delay: 5 + register: plugins + until: plugins.stdout_lines | length > 0 + changed_when: false + failed_when: + - ( plugins.stderr | length > 0 ) or ( plugins.rc != 0 ) + + - name: "Make sure the metrics on collectd-server are from collectd-test" + shell: | + set -o pipefail + collectdctl -s /var/run/collectd-socket listval | grep ^collectd-test/ | wc -l + register: test_plugins + changed_when: false + failed_when: + - plugins.stdout_lines | length != test_plugins.stdout | int diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/common/Dockerfile b/tripleo_ansible/roles/tripleo_collectd/molecule/common/Dockerfile new file mode 100644 index 000000000..a80f24a51 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/common/Dockerfile @@ -0,0 +1,36 @@ +# Molecule managed +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install sudo python*-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/common/prepare.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/common/prepare.yml new file mode 100644 index 000000000..6e7d9f073 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/common/prepare.yml @@ -0,0 +1,59 @@ +--- +# Copyright 2020 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Prepare + hosts: all + tasks: + - name: "Enable delorean repos" + command: | + dnf config-manager --add-repo https://trunk.rdoproject.org/centos{{ ansible_facts['distribution_major_version'] }}/current/delorean.repo + + - name: "Install tripleo-repos" + package: + name: "python*tripleo-repos" + state: present + + - name: "Set-up tripleo-repos" + command: | + tripleo-repos -b master current-tripleo + + - name: "Install collectd plugin packages" + package: + name: + - collectd + - collectd-amqp1 + - collectd-disk + - collectd-hugepages + # for collectdctl + - collectd-utils + # enable_stf + - collectd-connectivity + - collectd-ipmi + - collectd-procevent + - collectd-rdt + # enable_sqlalchemy + - collectd-python + - python3-sqlalchemy-collectd + # libpodstats + - collectd-libpod-stats + state: present + + - name: "Create a directory for the log file" + file: + path: /var/log/collectd/ + state: directory + mode: 0766 diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/common/requirements.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/common/requirements.yml new file mode 100644 index 000000000..0cfeb1600 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/common/requirements.yml @@ -0,0 +1,7 @@ +--- +roles: + - src: git+https://github.com/infrawatch/functional-tests + name: functional_tests + + - src: git+http://github.com/infrawatch/collectd-config-ansible-role + name: collectd_config diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/common/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/common/verify.yml new file mode 100644 index 000000000..ad5871781 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/common/verify.yml @@ -0,0 +1,89 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: "Common Verify tasks" + hosts: all + tasks: + - name: Check for files in conf output dir + find: + paths: "{{ collectd_conf_output_dir }}" + patterns: '*.conf' + register: plugins + failed_when: + - plugins.files | length == 0 + + - name: "Check for collectd.conf" + stat: + path: "{{ collectd_conf_output_dir }}/../collectd.conf" + register: conf + failed_when: + - not conf.stat.exists + + - name: "Check what plugins were enabled." + command: | + ls {{ collectd_conf_output_dir }} + register: plugins + changed_when: false + failed_when: > + ( plugins.stdout_lines | length < 1 ) or + ( 'logfile.conf' not in plugins.stdout_lines ) + + - name: "Debug -- list of plugins, one per line" + debug: + var: plugins.stdout_lines + + - name: "(Re)start collectd service" + block: + - name: "Kill running collectd process" + command: + pkill -e -c collectd + ignore_errors: true + + - name: "Start collectd" + command: + /usr/sbin/collectd -C /etc/collectd.conf + + - name: "Get logfile path" + shell: | + set -o pipefail + grep "File" {{ collectd_conf_output_dir }}/logfile.conf | awk '{ print $NF }' + register: logfile_path + changed_when: false + + - name: "Make sure there is a directory for the logfile to live in since collectd doesn't seem to create this by default" + stat: + path: "{{ logfile_path.stdout | regex_replace('\"', '') | dirname }}" + register: logfile_stat + failed_when: + - not logfile_stat.stat.exists + + - name: "Make sure the logfile is created" + stat: + path: "{{ logfile_path.stdout | regex_replace('\"', '') }}" + register: logfile_stat + failed_when: + - not logfile_stat.stat.exists + +- hosts: localhost + tasks: + - name: "Run the collectd test from STF functional-tests" + include_role: + name: functional_tests + tasks_from: test_collectd + vars: + collectd_container_name: 'collectd-test' + container_bin: "{{ lookup('env', 'CONTAINER_BIN') | default('podman', True) }}" diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/default/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/default/converge.yml new file mode 100644 index 000000000..d10c09ae5 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/default/converge.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: all + tasks: + - name: "Set up expected THT vars" + set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + + - name: "Use tripleo_collectd to configure collectd with defaults" + include_role: + name: "{{ playbook_dir }}/../../../tripleo_collectd" + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/default/molecule.yml new file mode 100644 index 000000000..a77f0085a --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/default/molecule.yml @@ -0,0 +1,65 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + verify: ../common/verify.yml + +lint: | + ansible-lint **/*.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + name: default + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/default/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/default/verify.yml new file mode 100644 index 000000000..18cb55ee9 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/default/verify.yml @@ -0,0 +1,39 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- import_playbook: ../common/verify.yml + +- name: Verify + hosts: all + tasks: + - name: "Check that the right plugins are enabled" + stat: + path: "{{ collectd_conf_output_dir }}/{{ item }}.conf" + register: conf + failed_when: + - not conf.stat.exists + loop: + - cpu + - df + - disk + - hugepages + - interface + - load + - memory + - processes + - unixsock + - uptime diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/converge.yml new file mode 100644 index 000000000..ee5513c50 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/converge.yml @@ -0,0 +1,34 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: all + tasks: + - set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + fqdn_ctlplane: "standalone.ctlplane.localdomain" + + - name: "Use tripleo_collectd to configure collectd with defaults" + include_role: + name: '{{ playbook_dir }}/../../../tripleo_collectd' + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d" + tripleo_collectd_enable_libpodstats: true diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/molecule.yml new file mode 100644 index 000000000..1914fedc7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/molecule.yml @@ -0,0 +1,59 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/verify.yml new file mode 100644 index 000000000..0478f927f --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_libpodstats/verify.yml @@ -0,0 +1,52 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- import_playbook: ../common/verify.yml + +- name: "Verify collectd libpodstats plugin" + hosts: all + tasks: + - name: Check that the libpodstats conf file exists + stat: + path: '/etc/collectd.d/libpodstats.conf' + register: output + failed_when: + - not output.stat.exists + + - name: Get contents of libpodstats.conf + slurp: + src: /etc/collectd.d/libpodstats.conf + register: libpodstats_conf + failed_when: + - not 'LoadPlugin "libpodstats"' in libpodstats_conf.content | b64decode + - not '' in libpodstats_conf.content | b64decode + - not '' in libpodstats_conf.content | b64decode + + - name: "Check that the TypesDB has been updated" + slurp: + src: /etc/collectd.conf + register: output + failed_when: + - not "TypesDB \"/etc/collectd.d/types.db.libpodstats\"" in output.content | b64decode + + - name: "Check that the contents of types.db.libpodstats are as expected" + slurp: + src: /etc/collectd.d/types.db.libpodstats + register: typesdb + failed_when: + - not "pod_cpu percent:GAUGE:0:100.1, time:DERIVE:0:U" in typesdb.content | b64decode + - not "pod_memory value:GAUGE:0:281474976710656" in typesdb.content | b64decode diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/converge.yml new file mode 100644 index 000000000..bc8c32a85 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/converge.yml @@ -0,0 +1,18 @@ +--- +- name: Converge + hosts: all + tasks: + - set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + fqdn_ctlplane: "standalone.ctlplane.localdomain" + + - include_role: + name: '{{ playbook_dir }}/../../../tripleo_collectd' + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + tripleo_collectd_enable_sensubility: true + tripleo_collectd_sensubility_exec_sudo_rule: "collectd ALL = NOPASSWD: ALL" diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/molecule.yml new file mode 100644 index 000000000..1914fedc7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/molecule.yml @@ -0,0 +1,59 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/verify.yml new file mode 100644 index 000000000..a6777ba5e --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sensubility/verify.yml @@ -0,0 +1,61 @@ +--- +- import_playbook: ../common/verify.yml + +- name: "Verify collectd exec plugin" + hosts: all + tasks: + - name: "Check that the exec plugin config file exists" + stat: + path: '/etc/collectd.d/exec.conf' + register: output + failed_when: + - not output.stat.exists + + - name: "Get contents of exec file" + slurp: + path: /etc/collectd.d/exec.conf + register: exec_conf + failed_when: + - '"Exec \"collectd:collectd\" \"collectd-sensubility\"" not in exec_conf.content | b64decode' + + - name: Check that the sensubility file exists + stat: + path: '/etc/collectd-sensubility.conf' + register: output + failed_when: + - not output.stat.exists + + - name: "Get contents of the generated collectd-sensubility file" + slurp: + src: /etc/collectd-sensubility.conf + register: sensubility_conf + + - name: "Show the contents of generated collectd-sensubility file" + debug: + msg: "{{ sensubility_conf.content | b64decode }}" + + - name: "Check the contents of generated collectd-sensubility.conf file" + assert: + that: + - '"connection=amqp://sensu:sensu@localhost:5672//sensu" in sensubility_conf.content | b64decode' + - '"client_name=standalone.ctlplane.localdomain" in sensubility_conf.content | b64decode' + - '"client_address=10.0.0.42" in sensubility_conf.content | b64decode' + - '"keepalive_interval=20" in sensubility_conf.content | b64decode' + - '"tmp_base_dir=/var/tmp/collectd-sensubility-checks" in sensubility_conf.content | b64decode' + - '"shell_path=/usr/bin/sh" in sensubility_conf.content | b64decode' + - '"worker_count=2" in sensubility_conf.content | b64decode' + success_msg: "Expected content found in collectd-sensubility.conf" + + - name: "Check that the sensubility sudoers file has been created" + stat: + path: /etc/sudoers.d/sensubility_collectd + register: sudoer_file + failed_when: + - not sudoer_file.stat.exists + + - name: "Check that the sensubility sudoers file has been populated" + slurp: + src: /etc/sudoers.d/sensubility_collectd + register: sensubility_sudoers + failed_when: + - 'not "collectd ALL = NOPASSWD: ALL" in sensubility_sudoers.content | b64decode' diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/converge.yml new file mode 100644 index 000000000..a7511b18f --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/converge.yml @@ -0,0 +1,34 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: all + tasks: + - name: "Set up expected THT vars" + set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + + - name: "Include tripleo-collectd-ansible-role" + include_role: + name: '{{ playbook_dir }}/../../../tripleo_collectd' + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + tripleo_collectd_enable_sqlalchemy: true diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/molecule.yml new file mode 100644 index 000000000..1914fedc7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/molecule.yml @@ -0,0 +1,59 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/requirements.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/requirements.yml new file mode 100644 index 000000000..a3f7ceafa --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/requirements.yml @@ -0,0 +1,7 @@ +--- +- src: git+https://github.com/infrawatch/functional-tests + name: functional_tests + +- src: git+http://github.com/infrawatch/collectd-config-ansible-role + name: collectd_config + version: plugin/python diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/verify.yml new file mode 100644 index 000000000..1c02407b9 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_sqlalchemy/verify.yml @@ -0,0 +1,46 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- import_playbook: ../common/verify.yml + +- name: Verify + hosts: all + tasks: + - name: "Make sure python.conf exists" + stat: + path: "{{ collectd_conf_output_dir }}/python.conf" + register: python_conf + failed_when: + - not python_conf.stat.exists + + - name: "Get contents of python.conf" + slurp: + path: "{{ collectd_conf_output_dir }}/python.conf" + register: python_conf + + - name: "Check that the config imports sqlalchemy" + assert: + that: + - '"Import \"sqlalchemy_collectd.server.plugin\"" in python_conf.content | b64decode' + fail_msg: "SQLAlchemy is not imported by python config" + + - name: "Check that collectd_sqlalchemy is configured as expected" + assert: + that: + - '"" in python_conf.content | b64decode' + - '"listen \"localhost\" 25827" in python_conf.content | b64decode' + - '"loglevel \"info\"" in python_conf.content | b64decode' diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/converge.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/converge.yml new file mode 100644 index 000000000..2e33e6578 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/converge.yml @@ -0,0 +1,34 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Converge + hosts: all + tasks: + - name: "Set up expected THT vars" + set_fact: + tripleo_role_name: "SomeRole" + service_net_map: + some_role_metrics_qdr_network: "ctlplane" + ctlplane_ip: "10.0.0.42" + + - name: "Include tripleo-collectd-ansible-role" + include_role: + name: "{{ playbook_dir }}/../../../tripleo_collectd" + tasks_from: configure_collectd + vars: + collectd_conf_output_dir: "/etc/collectd.d/" + tripleo_collectd_enable_stf: true diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/molecule.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/molecule.yml new file mode 100644 index 000000000..1914fedc7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/molecule.yml @@ -0,0 +1,59 @@ +--- +driver: + name: podman + +platforms: + - name: collectd-test + hostname: collectd-test + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: ../common/Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + CONTAINER_BIN: podman + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + collectd-test: + ansible_python_interpreter: /usr/bin/python3 + host_vars: + collectd-test: + collectd_conf_output_dir: "/etc/collectd.d/" + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_FILTER_PLUGINS: "${ANSIBLE_FILTER_PLUGINS:-\ + /usr/share/ansible/plugins/filter}" + playbooks: + prepare: ../common/prepare.yml + +verifier: + name: ansible + +dependency: + name: galaxy + options: + role-file: molecule/common/requirements.yml + +scenario: + test_sequence: + - destroy + - dependency + - create + - prepare + - converge + - check + - verify + - destroy diff --git a/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/verify.yml b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/verify.yml new file mode 100644 index 000000000..d0ca74309 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/molecule/enable_stf/verify.yml @@ -0,0 +1,36 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- import_playbook: ../common/verify.yml + +- name: Verify + hosts: all + tasks: + - name: "Check that the right plugins are enabled" + stat: + path: "{{ collectd_conf_output_dir }}/{{ item }}.conf" + register: conf + failed_when: + - not conf.stat.exists + loop: + - cpu + - df + - load + - connectivity + - intel_rdt + - ipmi + - procevent diff --git a/tripleo_ansible/roles/tripleo_collectd/tasks/configure_collectd.yml b/tripleo_ansible/roles/tripleo_collectd/tasks/configure_collectd.yml new file mode 100644 index 000000000..6d974b0ef --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/tasks/configure_collectd.yml @@ -0,0 +1,226 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: "Create initial plugins list and other vars for collectd_config" + set_fact: + collectd_plugins: "{{ tripleo_collectd_default_plugins | union(tripleo_collectd_extra_plugins) | union(['logfile']) | unique }}" + collectd_interval: "{{ tripleo_collectd_default_polling_interval }}" + +- name: "Enable read plugins for STF" + when: + - tripleo_collectd_enable_stf | bool + set_fact: + collectd_plugins: "{{ collectd_plugins | union(['cpu', 'df', 'load', 'connectivity', 'intel_rdt', 'ipmi', 'procevent']) | unique }}" + +- name: Set up amqp connection to collectd + when: + - tripleo_collectd_connection_type == 'amqp1' + block: + - name: "Enable amqp1 plugin and configure transport, address, instances and retry_delay" + set_fact: + collectd_plugins: "{{ collectd_plugins | union(['amqp1']) | unique }}" + collectd_plugin_amqp1_transport: "{{ tripleo_collectd_amqp_transport_name }}" + collectd_plugin_amqp1_address: "{{ tripleo_collectd_amqp_address }}" + collectd_plugin_amqp1_instances: "{{ tripleo_collectd_amqp_instances }}" + collectd_plugin_amqp1_retry_delay: "{{ tripleo_collectd_amqp_retry_delay }}" + + - name: "Set the interval for the amqp1 plugin" + when: + - tripleo_collectd_amqp_interval | int != -666 + set_fact: + collectd_plugin_amqp1_interval: "{{ tripleo_collectd_amqp_interval }}" + + - name: "Set amqp send_queue_limit" + when: + - tripleo_collectd_amqp_send_queue_limit != -1 + set_fact: + collectd_plugin_amqp1_send_queue_limit: "{{ tripleo_collectd_amqp_send_queue_limit }}" + + - name: "Use the default values for the AMQP connection" + when: + - tripleo_collectd_amqp_host == 'nil' + set_fact: + collectd_plugin_amqp1_host: "{{ lookup('vars', service_net_map[(tripleo_role_name + 'MetricsQdrNetwork') | snake_case] + '_ip' ) }}" + collectd_plugin_amqp1_port: "{{ metrics_qdr_port }}" + collectd_plugin_amqp1_user: "{{ metrics_qdr_username }}" + collectd_plugin_amqp1_password: "{{ metrics_qdr_password }}" + + - name: "Set up user-defined amqp connection" + when: + - tripleo_collectd_amqp_host != 'nil' + set_fact: + collectd_plugin_amqp1_host: "{{ tripleo_collectd_amqp_host }}" + collectd_plugin_amqp1_port: "{{ tripleo_collectd_amqp_port }}" + collectd_plugin_amqp1_user: "{{ tripleo_collectd_amqp_user }}" + collectd_plugin_amqp1_password: "{{ tripleo_collectd_amqp_password }}" + +- name: Set up collectd connection to external collectd instance + when: + - tripleo_collectd_connection_type == 'network' + block: + - name: "Add network to the list of plugins to enable" + set_fact: + collectd_plugins: "{{ collectd_plugins | union(['network']) | unique }}" + + - name: "Create the collectd network config." + when: + - tripleo_collectd_server | length > 0 + block: + - name: "Populate the initial config for network server." + set_fact: + collectd_plugin_network_server: + name: "{{ tripleo_collectd_server }}" + port: "{{ tripleo_collectd_server_port | default(omit) }}" + username: "{{ tripleo_collectd_username | default(omit) }}" + password: "{{ tripleo_collectd_password | default(omit) }}" + securitylevel: "{{ tripleo_collectd_security_level | default(omit) }}" + + - name: "Filter out the empty string values from the network server config" + set_fact: + collectd_plugin_network_server: + - '{{ collectd_plugin_network_server | dict2items | rejectattr("value", "equalto", "") | list | items2dict }}' + +- name: Enable sqlalchemy + when: + - tripleo_collectd_enable_sqlalchemy | bool + set_fact: + collectd_plugins: "{{ collectd_plugins | union(['python']) | unique }}" + collectd_plugin_python_modules: "{{ collectd_plugin_python_module | default({}) | combine( { + 'sqlalchemy': { + 'config': { + 'listen': [tripleo_collectd_sqlalchemy_bind_host, 25827], + 'loglevel': tripleo_collectd_sqlalchemy_log_messages + }, + 'module_import': 'sqlalchemy_collectd.server.plugin' + }}) }}" + +- name: "Configure collectd to run collectd-sensubility via collectd-exec" + when: + - tripleo_collectd_enable_sensubility | bool + block: + - name: Set-up sensubility config for exec + set_fact: + sensubility_exec: + - user: collectd + group: collectd + exec: "collectd-sensubility" + + - name: Configure the exec plugin + set_fact: + collectd_plugins: "{{ collectd_plugins | union(['exec']) | unique }}" + collectd_plugin_exec_exec: "{{ ( collectd_plugin_exec_exec | default([]) ) | union( sensubility_exec ) }}" + + - name: "Update sudoers file" + when: + - (tripleo_collectd_sensubility_exec_sudo_rule | length > 0 ) | default(false) + block: + - name: "Set sudoers path" + set_fact: + sensubility_sudoers_file: "{{ collectd_conf_output_dir }}/../sudoers.d/sensubility_collectd" + + - name: "Create sudoers.d if it does not exist" + file: + path: "{{ sensubility_sudoers_file | dirname }}" + mode: 0750 + state: directory + + - name: "Populate the file in {{ sensubility_sudoers_file }}" + copy: + content: "{{ tripleo_collectd_sensubility_exec_sudo_rule }}" + dest: "{{ sensubility_sudoers_file }}" + mode: 0440 + validate: 'visudo -c -f %s' + + - name: "Set up the healthcheck check" + when: + - tripleo_collectd_enable_container_health_check | bool + set_fact: + healthcheck_check: + check-container-health: + standalone: true + command: "{{ tripleo_collectd_container_health_check_command }}" + interval: "{{ tripleo_collectd_container_health_check_interval }}" + handlers: "{{ tripleo_collectd_container_health_check_handlers }}" + occurences: "{{ tripleo_collectd_container_health_check_occurrences }}" + refresh: "{{ tripleo_collectd_container_health_check_refresh }}" + + - name: "Set the values for collectd-sensubility.conf" + set_fact: + collectd_sensubility_log_file: "/var/log/collectd/sensubility.log" + collectd_sensubility_log_level: "{{ tripleo_collectd_sensubility_log_level }}" + collectd_sensubility_transport: "{{ tripleo_collectd_sensubility_transport }}" + collectd_sensubility_connection: "{{ tripleo_collectd_sensubility_connection }}" + collectd_sensubility_subscriptions: "{{ tripleo_collectd_sensubility_subscriptions }}" + collectd_sensubility_keepalive_interval: "{{ tripleo_collectd_sensubility_keepalive_interval }}" + collectd_sensubility_tmp_dir: "{{ tripleo_collectd_sensubility_tmp_dir }}" + collectd_sensubility_shell_path: "{{ tripleo_collectd_sensubility_shell_path }}" + collectd_sensubility_worker_count: "{{ tripleo_collectd_sensubility_worker_count }}" + collectd_sensubility_amqp_port: "{{ tripleo_collectd_amqp_port }}" + collectd_sensubility_results_channel: "{{ tripleo_collectd_sensubility_results_channel }}" + collectd_sensubility_results_format: 'smartgateway' + collectd_sensubility_client_name: "{{ lookup('vars', 'fqdn_' + service_net_map[ (tripleo_role_name + 'MetricsQdrNetwork' )| snake_case] ) }}" + collectd_sensubility_client_address: "{{ lookup('vars', service_net_map[( tripleo_role_name + 'MetricsQdrNetwork') | snake_case ] + '_ip' ) }}" + collectd_sensubility_checks: "{{ tripleo_collectd_sensubility_checks | combine(healthcheck_check | default({})) }}" + + - name: "Create directory for collectd-sensubility.conf" + file: + path: "{{ collectd_conf_output_dir }}/../" + mode: 0750 + state: directory + + - name: "Render collectd-sensubility template in {{ collectd_conf_output_dir }}/../" + template: + src: collectd-sensubility.conf.j2 + dest: "{{ collectd_conf_output_dir }}/../collectd-sensubility.conf" + mode: 0644 + +- name: "Configure collectd to run libpodstats" + when: + - tripleo_collectd_enable_libpodstats + block: + - set_fact: + typesdb_libpodstats: + name: "libpodstats" + path: "{{ collectd_conf_output_dir }}" + types: + pod_cpu: + - ds_type: 'GAUGE' + min: 0 + max: 100.1 + ds_name: 'percent' + - ds_type: 'DERIVE' + min: 0 + max: 'U' + ds_name: 'time' + pod_memory: + - ds_type: 'GAUGE' + min: 0 + max: 281474976710656 + ds_name: 'value' + - set_fact: + collectd_plugins: "{{ collectd_plugins | union(['libpodstats']) | unique }}" + collectd_typesdb_extra: "{{ collectd_typesdb_extra | default([]) | union([typesdb_libpodstats]) }}" + +- name: "Generate the collectd config files" + include_role: + name: collectd_config + +- name: "Update config file path" + replace: + path: "{{ collectd_conf_output_dir }}/../collectd.conf" + regexp: "^(.*){{ collectd_conf_output_dir }}/(.*)$" + replace: '\1/etc/collectd.d/\2' diff --git a/tripleo_ansible/roles/tripleo_collectd/tasks/configure_healthcheck.yml b/tripleo_ansible/roles/tripleo_collectd/tasks/configure_healthcheck.yml new file mode 100644 index 000000000..3a0ddb91d --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/tasks/configure_healthcheck.yml @@ -0,0 +1,47 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: Check if rsyslog exists + shell: systemctl list-unit-files --type=service | grep -q rsyslog + register: rsyslog_config + failed_when: + - rsyslog_config.rc == 2 +- name: Configure if we can + when: + - rsyslog_config is changed + - rsyslog_config.rc == 0 + block: + - name: Log healthchecks in dedicated file + when: + - tripleo_collectd_enable_sensubility | bool + register: logconfig_add + copy: + dest: /etc/rsyslog.d/ + src: files/openstack-healthcheck.conf + - name: Remove healthcheck log + when: + - not tripleo_collectd_enable_sensubility | bool + register: logconfig_rm + file: + path: /etc/rsyslog.d/openstack-healthcheck.conf + state: absent + - name: Reload rsyslogd if needed + when: + - logconfig_add is changed or logconfig_rm is changed + service: + name: rsyslog + state: restarted diff --git a/tripleo_ansible/roles/tripleo_collectd/tasks/configure_host_software.yml b/tripleo_ansible/roles/tripleo_collectd/tasks/configure_host_software.yml new file mode 100644 index 000000000..4f36e9d59 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/tasks/configure_host_software.yml @@ -0,0 +1,22 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: import provision_mcelog + import_role: + name: tripleo_provision_mcelog + when: + - tripleo_collectd_enable_mcelog | bool diff --git a/tripleo_ansible/roles/tripleo_collectd/tasks/create_persistent_directories.yml b/tripleo_ansible/roles/tripleo_collectd/tasks/create_persistent_directories.yml new file mode 100644 index 000000000..108c3f588 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/tasks/create_persistent_directories.yml @@ -0,0 +1,30 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +- name: create persistent directories + file: + path: "{{ item.path }}" + state: directory + setype: "{{ item.setype }}" + mode: "{{ item.mode }}" + with_items: + - path: /var/log/containers/collectd + setype: container_file_t + mode: '0750' + - path: "{{ collectd_conf_output_dir }}" + setype: container_file_t + mode: '0750' diff --git a/tripleo_ansible/roles/tripleo_collectd/tasks/main.yml b/tripleo_ansible/roles/tripleo_collectd/tasks/main.yml new file mode 100644 index 000000000..dbff8b0ba --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/tasks/main.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# "tripleo_collectd" will search for and load any operating system variable file + +# found within the "vars/" path. If no OS files are found the task will skip. +- name: Gather variables for each operating system + include_vars: "{{ item }}" + with_first_found: + - skip: true + files: + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml" + - "{{ ansible_facts['os_family'] | lower }}.yml" + tags: + - always diff --git a/tripleo_ansible/roles/tripleo_collectd/templates/collectd-sensubility.conf.j2 b/tripleo_ansible/roles/tripleo_collectd/templates/collectd-sensubility.conf.j2 new file mode 100644 index 000000000..4a86ac8fa --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/templates/collectd-sensubility.conf.j2 @@ -0,0 +1,52 @@ +[default] +{% if collectd_sensubility_log_file is defined %} +log_file={{ collectd_sensubility_log_file }} +{% endif %} +{% if collectd_sensubility_log_level is defined %} +log_level={{ collectd_sensubility_log_level }} +{% endif %} + +[sensu] +{% if collectd_sensubility_transport == 'sensu' %} +{% if collectd_sensubility_connection is defined %} +connection={{ collectd_sensubility_connection }} +{% endif %} +subscriptions={{ collectd_sensubility_subscriptions | default([]) | join(',') }} +{% if collectd_sensubility_client_name is defined %} +client_name={{ collectd_sensubility_client_name }} +{% endif %} +{% if collectd_sensubility_client_address is defined %} +client_address={{ collectd_sensubility_client_address }} +{% endif %} +{% endif %} +{% if collectd_sensubility_keepalive_interval is defined %} +keepalive_interval={{ collectd_sensubility_keepalive_interval }} +{% endif %} +{% if collectd_sensubility_tmp_dir is defined %} +tmp_base_dir={{ collectd_sensubility_tmp_dir }} +{% endif %} +{% if collectd_sensubility_shell_path is defined %} +shell_path={{ collectd_sensubility_shell_path }} +{% endif %} +{% if collectd_sensubility_worker_count is defined %} +worker_count={{ collectd_sensubility_worker_count }} +{% endif %} +{% if collectd_sensubility_checks is defined %} +checks={{ collectd_sensubility_checks | to_json }} +{% endif %} + +[amqp1] +{% if collectd_sensubility_transport == 'amqp1' %} +{% if collectd_sensubility_client_address is defined and collectd_sensubility_amqp_port is defined %} +connection=amqp://{{ collectd_sensubility_client_address }}:{{ collectd_sensubility_amqp_port }} +{% endif %} +{% if collectd_sensubility_results_channel is defined %} +results_channel={{ collectd_sensubility_results_channel }} +{% endif %} +{% if collectd_sensubility_client_name is defined %} +client_name={{ collectd_sensubility_client_name }} +{% endif %} +{% if collectd_sensubility_results_format is defined %} +results_format={{ collectd_sensubility_results_format }} +{% endif %} +{% endif %} diff --git a/tripleo_ansible/roles/tripleo_collectd/vars/main.yml b/tripleo_ansible/roles/tripleo_collectd/vars/main.yml new file mode 100644 index 000000000..4f0632871 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_collectd/vars/main.yml @@ -0,0 +1,50 @@ +--- +# Copyright 2021 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# Vars to be passed to the collectd_config role +collectd_conf_output_dir: "/var/lib/config-data/ansible-generated/collectd/etc/collectd.d" + +# TODO: Add actions for these to collectd-config-ansible-role +# - collectd::manage_repo: false +# collectd::purge: true +# collectd::recurse: true +# collectd::purge_config: true +# collectd::minimum_version: "5.7" + +# Plugin configuration +collectd_plugin_cpu_reportbycpu: true +collectd_plugin_cpu_reportbystate: true +collectd_plugin_cpu_reportnumcpu: false +collectd_plugin_cpu_valuespercentage: true + +collectd_plugin_df_fstypes: + - 'xfs' +collectd_plugin_df_ignoreselected: true +collectd_plugin_df_reportbydevice: true + +collectd_plugin_load_reportrelative: true + +collectd_plugin_logfile_file: /var/log/collectd/collectd.log + +collectd_plugin_unixsock_socketgroup: root +collectd_plugin_unixsock_socketfile: /run/collectd-socket +collectd_plugin_unixsock_delete_socket: true + +collectd_plugin_virt_connection: "qemu:///system" +collectd_plugin_virt_extrastats: >- + "pcpu cpu_util vcpupin vcpu memory disk disk_err disk_allocation disk_capacity disk_physical domain_state job_stats_background perf" +collectd_plugin_virt_hostnameformat: "hostname" diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 5b80d233a..88a5cd577 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -16,6 +16,7 @@ - tripleo-ansible-centos-8-molecule-tripleo_ceph_run_ansible - tripleo-ansible-centos-8-molecule-tripleo_cephadm - tripleo-ansible-centos-8-molecule-tripleo_clients_install + - tripleo-ansible-centos-8-molecule-tripleo_collectd - tripleo-ansible-centos-8-molecule-tripleo_config - tripleo-ansible-centos-8-molecule-tripleo_container_image_build - tripleo-ansible-centos-8-molecule-tripleo_container_image_prepare @@ -73,6 +74,7 @@ - tripleo-ansible-centos-8-molecule-tripleo_ceph_run_ansible - tripleo-ansible-centos-8-molecule-tripleo_cephadm - tripleo-ansible-centos-8-molecule-tripleo_clients_install + - tripleo-ansible-centos-8-molecule-tripleo_collectd - tripleo-ansible-centos-8-molecule-tripleo_config - tripleo-ansible-centos-8-molecule-tripleo_container_image_build - tripleo-ansible-centos-8-molecule-tripleo_container_image_prepare @@ -131,6 +133,7 @@ - tripleo-ansible-centos-8-molecule-tripleo_ceph_run_ansible - tripleo-ansible-centos-8-molecule-tripleo_cephadm - tripleo-ansible-centos-8-molecule-tripleo_clients_install + - tripleo-ansible-centos-8-molecule-tripleo_collectd - tripleo-ansible-centos-8-molecule-tripleo_config - tripleo-ansible-centos-8-molecule-tripleo_container_image_build - tripleo-ansible-centos-8-molecule-tripleo_container_image_prepare @@ -258,6 +261,13 @@ parent: tripleo-ansible-centos-8-base vars: tripleo_role_name: tripleo_clients_install +- job: + files: + - ^tripleo_ansible/roles/tripleo_collectd/.* + name: tripleo-ansible-centos-8-molecule-tripleo_collectd + parent: tripleo-ansible-centos-8-base + vars: + tripleo_role_name: tripleo_collectd - job: files: - ^tripleo_ansible/roles/tripleo_config/.*