"""Classes used by client.py""" # -*- coding: utf-8 -*- #Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import paramiko import time import string import os.path ID_RSA_PATH = '/home/opnfv/.ssh/id_rsa' SSH_KEYS_SCRIPT = '/home/opnfv/barometer/baro_utils/get_ssh_keys.sh' DEF_PLUGIN_INTERVAL = 10 COLLECTD_CONF = '/etc/collectd/collectd.conf' COLLECTD_CONF_DIR = '/etc/collectd/collectd.conf.d' class Node(object): """Node configuration class""" def __init__(self, attrs): self.__id = int(attrs[0]) self.__status = attrs[1] self.__name = attrs[2] self.__cluster = int(attrs[3]) if attrs[3] else None self.__ip = attrs[4] self.__mac = attrs[5] self.__roles = [x.strip(' ') for x in attrs[6].split(',')] self.__pending_roles = attrs[7] self.__online = int(attrs[8]) if attrs[3] and attrs[8]else None self.__group_id = int(attrs[9]) if attrs[3] else None def get_name(self): """Get node name""" return self.__name def get_id(self): """Get node ID""" return self.__id def get_ip(self): """Get node IP address""" return self.__ip def get_roles(self): """Get node roles""" return self.__roles class ConfigServer(object): """Class to get env configuration""" def __init__(self, host, user, logger, passwd=None): self.__host = host self.__user = user self.__passwd = passwd self.__priv_key = None self.__nodes = list() self.__logger = logger self.__private_key_file = ID_RSA_PATH if not os.path.isfile(self.__private_key_file): self.__logger.error( "Private key file '{}'".format(self.__private_key_file) + " not found. Please try to run {} script.".format(SSH_KEYS_SCRIPT)) raise IOError("Private key file '{}' not found.".format(self.__private_key_file)) # get list of available nodes ssh, sftp = self.__open_sftp_session(self.__host, self.__user, self.__passwd) attempt = 1 fuel_node_passed = False while (attempt <= 10) and not fuel_node_passed: stdin, stdout, stderr = ssh.exec_command("fuel node") stderr_lines = stderr.readlines() if stderr_lines: self.__logger.warning("'fuel node' command failed (try {}):".format(attempt)) for line in stderr_lines: self.__logger.debug(line.strip()) else: fuel_node_passed = True if attempt > 1: self.__logger.info("'fuel node' command passed (try {})".format(attempt)) attempt += 1 if not fuel_node_passed: self.__logger.error("'fuel node' command failed. This was the last try.") raise OSError("'fuel node' command failed. This was the last try.") node_table = stdout.readlines()\ # skip table title and parse table values for entry in node_table[2:]: self.__nodes.append(Node([str(x.strip(' \n')) for x in entry.split('|')])) def get_controllers(self): """Get list of controllers""" return [node for node in self.__nodes if 'controller' in node.get_roles()] def get_computes(self): """Get list of computes""" return [node for node in self.__nodes if 'compute' in node.get_roles()] def get_nodes(self): """Get list of nodes""" return self.__nodes def __open_sftp_session(self, host, user, passwd=None): """Connect to given host. Keyword arguments: host -- host to connect user -- user to use passwd -- password to use Return tuple of SSH and SFTP client instances. """ # create SSH client ssh = paramiko.SSHClient() ssh.set_missing_host_key_polic
---
docker_images:
  dovetail:
    domain: opnfv
    tag: latest
    store_name: image_dovetail.docker
  functest:
    domain: opnfv
    tag: latest
    store_name: image_functest.docker
  yardstick:
    domain: opnfv
    tag: latest
    store_name: image_yardstick.docker
  testapi:
    domain: opnfv
    tag: latest
    store_name: image_testapi.docker
  mongo:
    tag: 3.5
    store_name: image_mongo.docker
docker_save_path: /home/opnfv/dovetail/results/
comment_section = True error_plugins.append(( plugin, 'additional occurrence of plugin section found in ' + '{}, trying to comment it out.'.format(COLLECTD_CONF), False)) elif in_section > 0: if comment_section and '#' not in line: line = '#' + line if uncomment_section and '#' in line: line = line[line.rfind('#') + 1:] if '' in line: in_section -= 1 if in_section == 0: comment_section = False uncomment_section = False elif '' in line: self.__logger.error( 'Unexpected closure os plugin section on line' + ' {} in collectd.conf, matching section start not found.'.format( len(out_lines) + 1)) return False out_lines.append(line) if in_section > 0: self.__logger.error( 'Unexpected end of file collectd.conf, ' + 'closure of last plugin section not found.') return False out_lines = [ 'LoadPlugin {}\n'.format(plugin) for plugin in plugins_to_enable if plugin not in enabled_plugins] + out_lines for plugin in plugins_to_enable: if plugin not in enabled_plugins: error_plugins.append(( plugin, 'plugin not enabled in {}, trying to enable it.'.format(COLLECTD_CONF), False)) unenabled_sections = [ plugin for plugin in plugins_to_enable if plugin not in enabled_sections] if unenabled_sections: self.__logger.error('Plugin sections for following plugins not found: {}'.format( ', '.join(unenabled_sections))) return False config.close() if create_backup: self.__logger.info('Creating backup of collectd.conf...') config = sftp.open(COLLECTD_CONF + '.backup', mode='w') config.writelines(in_lines) config.close() self.__logger.info('Updating collectd.conf...') config = sftp.open(COLLECTD_CONF, mode='w') config.writelines(out_lines) config.close() diff_command = "diff {} {}.backup".format(COLLECTD_CONF, COLLECTD_CONF) stdin, stdout, stderr = ssh.exec_command(diff_command) self.__logger.debug(diff_command) for line in stdout.readlines(): self.__logger.debug(line.strip()) return True def restore_config(self, compute): """Restore collectd config file from backup on compute node. Keyword arguments: compute -- compute node instance """ ssh, sftp = self.__open_sftp_session(compute.get_ip(), 'root') self.__logger.info('Restoring config file from backup...') ssh.exec_command("cp {0} {0}.used".format(COLLECTD_CONF)) ssh.exec_command("cp {0}.backup {0}".format(COLLECTD_CONF)) def restart_collectd(self, compute): """Restart collectd on compute node. Keyword arguments: compute -- compute node instance Retrun tuple with boolean indicating success and list of warnings received during collectd start. """ def get_collectd_processes(ssh_session): """Get number of running collectd processes. Keyword arguments: ssh_session -- instance of SSH session in which to check for processes """ stdin, stdout, stderr = ssh_session.exec_command("pgrep collectd") return len(stdout.readlines()) ssh, sftp = self.__open_sftp_session(compute.get_ip(), 'root') self.__logger.info('Stopping collectd service...') stdout = self.execute_command("service collectd stop", ssh=ssh) time.sleep(10) if get_collectd_processes(ssh): self.__logger.error('Collectd is still running...') return False, [] self.__logger.info('Starting collectd service...') stdout = self.execute_command("service collectd start", ssh=ssh) time.sleep(10) warning = [output.strip() for output in stdout if 'WARN: ' in output] if get_collectd_processes(ssh) == 0: self.__logger.error('Collectd is still not running...') return False, warning return True, warning