+ def is_libpqos_on_node(self, compute):
+ """Check whether libpqos is present on compute node"""
+ ssh, sftp = self.__open_sftp_session(
+ compute.get_ip(), 'root', 'opnfvapex')
+ stdin, stdout, stderr = \
+ ssh.exec_command("ls /usr/local/lib/ | grep libpqos")
+ output = stdout.readlines()
+ for lib in output:
+ if 'libpqos' in lib:
+ return True
+ return False
+
+ def check_gnocchi_plugin_included(self, compute):
+ """Check if gnocchi plugin is included in collectd.conf file.
+ If not, try to enable it.
+
+ Keyword arguments:
+ compute -- compute node instance
+
+ Return boolean value whether gnocchi plugin is included
+ or it's enabling was successful.
+ """
+ ssh, sftp = self.__open_sftp_session(
+ compute.get_ip(), 'root', 'opnfvapex')
+ try:
+ config = sftp.open(COLLECTD_CONF, mode='r')
+ except IOError:
+ self.__logger.error(
+ 'Cannot open {} on node {}'.format(
+ COLLECTD_CONF, compute.get_name()))
+ return False
+ in_lines = config.readlines()
+ out_lines = in_lines[:]
+ include_section_indexes = [
+ (start, end) for start in range(len(in_lines))
+ for end in range(len(in_lines))
+ if (start < end)
+ and '<Include' in in_lines[start]
+ and COLLECTD_CONF_DIR in in_lines[start]
+ and '#' not in in_lines[start]
+ and '</Include>' in in_lines[end]
+ and '#' not in in_lines[end]
+ and len([
+ i for i in in_lines[start + 1: end]
+ if 'Filter' in i and '*.conf' in i and '#' not in i]) > 0]
+ if len(include_section_indexes) == 0:
+ out_lines.append('<Include "{}">\n'.format(COLLECTD_CONF_DIR))
+ out_lines.append(' Filter "*.conf"\n')
+ out_lines.append('</Include>\n')
+ config.close()
+ config = sftp.open(COLLECTD_CONF, mode='w')
+ config.writelines(out_lines)
+ config.close()
+ self.__logger.info('Creating backup of collectd.conf...')
+ config = sftp.open(COLLECTD_CONF + '.backup', mode='w')
+ config.writelines(in_lines)
+ config.close()
+ return True
+