From 96e86fedb48a681dc6f61dedac5ed924ed397502 Mon Sep 17 00:00:00 2001 From: Joao Paulo Tavares Musico Date: Wed, 8 Jun 2022 20:43:15 +0000 Subject: [PATCH] Debian: Fix collectd service config on Debian Fix for collectd logs not being generated on Debian build install. Added python3 encoding changed ptp service name based on OS family Changed config file location and removed encoding changes not compatible with Python3 Test Plan: Debian PASS: build package and iso PASS: AIO-SX fresh install PASS: check no errors in collectd.log file related to collectd-extensions plugin Test Plan: Centos PASS: Apply same changes and restart collectd No errors in log Story: 2010079 Task: 45574 Depends-On: https://review.opendev.org/c/starlingx/stx-puppet/+/845173 Signed-off-by: Joao Paulo Tavares Musico Change-Id: I74896b14a31c567d8a8994fb8bbe3fc0a597824d --- collectd-extensions/debian/deb_folder/rules | 4 ++++ collectd-extensions/src/fm_notifier.py | 10 +++++++++- collectd-extensions/src/ntpq.py | 8 +++++++- collectd-extensions/src/ptp.py | 19 ++++++++++++++++--- collectd-extensions/src/service_res.py | 13 ++++++++++++- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/collectd-extensions/debian/deb_folder/rules b/collectd-extensions/debian/deb_folder/rules index 5230773..67ea7d9 100755 --- a/collectd-extensions/debian/deb_folder/rules +++ b/collectd-extensions/debian/deb_folder/rules @@ -11,6 +11,10 @@ export LOCAL_CONFIG_EXTENSIONS_DIR = $(ROOT)/opt/collectd/extensions/config dh $@ override_dh_install: + + # Adjustments in the configuration files for debian + sed -i '/Encoding "utf-8"/D' python_plugins.conf + install -m 755 -d $(ROOT)/etc install -m 755 -d $(LOCAL_UNIT_DIR) install -m 755 -d $(LOCAL_DEFAULT_PLUGIN_DIR) diff --git a/collectd-extensions/src/fm_notifier.py b/collectd-extensions/src/fm_notifier.py index 16644db..57045b9 100755 --- a/collectd-extensions/src/fm_notifier.py +++ b/collectd-extensions/src/fm_notifier.py @@ -87,6 +87,7 @@ import os import re import socket import collectd +import six from threading import RLock as Lock from oslo_utils import encodeutils from fm_api import constants as fm_constants @@ -1570,7 +1571,14 @@ def init_func(): # The path to where collectd is looking for its plugins is specified # at the end of the /etc/collectd.conf file. # Because so we search for the 'Include' label in reverse order. - for line in reversed(open("/etc/collectd.conf", 'r').readlines()): + # collectd.conf will be in different places based on OS family + if six.PY2: + # Centos + conf_dir = "/etc/collectd.conf" + else: + # Debian + conf_dir = "/etc/collectd/collectd.conf" + for line in reversed(open(conf_dir, 'r').readlines()): if line.startswith('Include'): plugin_path = line.split(' ')[1].strip("\n").strip('"') + '/' fmAlarmObject.plugin_path = plugin_path diff --git a/collectd-extensions/src/ntpq.py b/collectd-extensions/src/ntpq.py index 5ef55d7..3808820 100755 --- a/collectd-extensions/src/ntpq.py +++ b/collectd-extensions/src/ntpq.py @@ -63,6 +63,7 @@ import os import subprocess import uuid import collectd +import six from fm_api import constants as fm_constants from fm_api import fm_api import tsconfig.tsconfig as tsc @@ -709,7 +710,12 @@ def read_func(): return 0 # Do NTP Query - data = subprocess.check_output([PLUGIN_EXEC, PLUGIN_EXEC_OPTIONS]) + if six.PY2: + # Centos + data = subprocess.check_output([PLUGIN_EXEC, PLUGIN_EXEC_OPTIONS]) + else: + # Debian + data = subprocess.check_output([PLUGIN_EXEC, PLUGIN_EXEC_OPTIONS], encoding='utf-8') # Keep this FIT test code but make it commented out for security # diff --git a/collectd-extensions/src/ptp.py b/collectd-extensions/src/ptp.py index 467a9b1..b9d6dfc 100755 --- a/collectd-extensions/src/ptp.py +++ b/collectd-extensions/src/ptp.py @@ -36,6 +36,7 @@ import subprocess import tsconfig.tsconfig as tsc import plugin_common as pc import re +import six from fm_api import constants as fm_constants from fm_api import fm_api from glob import glob @@ -62,14 +63,27 @@ PLUGIN_TYPE = 'time_offset' PLUGIN_TYPE_INSTANCE = 'nsec' # Primary PTP service name -PLUGIN_SERVICE = 'ptp4l.service' +if six.PY2: + # Centos + PLUGIN_SERVICE = 'ptp4l.service' +else: + # Debian + PLUGIN_SERVICE = 'ptp4l@.service' # Plugin configuration file # # This plugin looks for the timestamping mode in the ptp4l config file. # time_stamping hardware # -PLUGIN_CONF_FILE = '/etc/ptp4l.conf' + +# ptp4l config file will be in different location based on OS family +if six.PY2: + # Centos + PLUGIN_CONF_FILE = '/etc/ptp4l.conf' +else: + # Debian + PLUGIN_CONF_FILE = '/etc/linuxptp/ptp4l.conf' + PLUGIN_CONF_TIMESTAMPING = 'time_stamping' @@ -1181,7 +1195,6 @@ def check_clock_class(instance): data = subprocess.check_output([PLUGIN_STATUS_QUERY_EXEC, '-f', conf_file, '-u', '-b', '0', 'GET GRANDMASTER_SETTINGS_NP']).decode() - # Save all parameters in an ordered dict m = OrderedDict() obj.resp = data.split('\n') diff --git a/collectd-extensions/src/service_res.py b/collectd-extensions/src/service_res.py index 978d517..e25f6d0 100644 --- a/collectd-extensions/src/service_res.py +++ b/collectd-extensions/src/service_res.py @@ -5,6 +5,7 @@ import collectd import os +import six import subprocess import plugin_common as pc from datetime import datetime @@ -154,7 +155,17 @@ def init_func(): def check_service_status(service): cmd = service["service_plugin_cmdline"] env = service["service_plugin_env"] - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, shell=True) + if six.PY2: + # Centos + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, shell=True) + else: + # Debian + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, shell=True, + encoding='utf-8') proc.wait() new_status = (proc.communicate()[0] or "").strip()