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 <joaopaulotavares.musico@windriver.com>
Change-Id: I74896b14a31c567d8a8994fb8bbe3fc0a597824d
This commit is contained in:
Joao Paulo Tavares Musico 2022-06-08 20:43:15 +00:00
parent b3c3cc8810
commit 96e86fedb4
5 changed files with 48 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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
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
#

View File

@ -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')

View File

@ -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()