import ha_engine.ha_infra as common LOG = common.ha_logging(__name__) class BaseRunner(object): def __init__(self, input_args): self.ha_report = [] self.input_args = {} if input_args: self.set_input_arguments(input_args) def set_input_arguments(self, input_args): self.input_args = input_args LOG.info("Self, input %s ", str(self.input_args)) def get_input_arguments(self): return self.input_args def execute(self, sync=None, finish_execution=None): raise NotImplementedError('Subclass should implement this method') def setup(self): raise NotImplementedError('Subclass should implement this method') def teardown(self): raise NotImplementedError('Subclass should implement this method') def is_module_exeution_completed(self, finish_exection):
import threading import multiprocessing import subprocess import inspect from ha_engine import ha_parser from ha_engine import ha_infra import os import shutil import utils.utils as utils LOG = ha_infra.ha_logging(__name__) class HAExecutor(object): infra_path = "/tmp/ha_infra/" xterm_position = { 'monitors': ["100x35+100+" + str(int(i * 100) + (i * 100)) for i in range(10)], 'disruptors': ["100x35-100+" + str(int(100) + (i * 100)) for i in range(10)], 'runners': ["100x35-100-" + str(int(100) + (i * 100)) for i in range(10)] } xterm_bg = { 'disruptors': 'DarkGray', 'monitors': 'MintCream', 'runners': 'LightCyan1' } def __init__(self, parser): """
def start(self, sync=None, finish_execution=None, args=None): ''' Required start method to implement for the class. ''' # Parse user data and Initialize. self.finish_execution = finish_execution data = self.get_input_arguments() self.loglevel = data['ansible'].get("loglevel", "DEBUG") self.frequency = data['ansible'].get('frequency', 5) self.max_hist_size = data['ansible'].get('max_hist', 25) self.dockerized = data['ansible'].get('dockerized', False) global LOG LOG = infra.ha_logging(__name__, level=self.loglevel) print "ANSIBLE LOG LEVEL: ", self.loglevel LOG.debug("User data: %s", data) # Get MariaDB Username/pass self.mariadb_user = None self.mariadb_password = None mariadb_info = data['ansible'].get('mariadb', None) if mariadb_info is not None: self.mariadb_user = data['ansible']['mariadb'].get('user', None) self.mariadb_password = data['ansible']['mariadb'].get('password', None) self.ansirunner = None setup_file = "../../configs/openstack_config.yaml" self.ansiresults = collections.deque(maxlen=self.max_hist_size) self.inventory = ConfigHelper(host_file=setup_file) LOG.debug("parsed data: ", self.inventory.parsed_data) host_list = self.inventory.get_host_list() host_ip_list = self.inventory.get_host_ip_list() control_ip_list = self.inventory.get_host_ip_list(role='controller') compute_ip_list = self.inventory.get_host_ip_list(role='compute') remote_user = self.inventory.get_host_username(host_list[0]) LOG.debug("Inventory: [all: %s], [control: %s] [compute: %s]", host_ip_list, control_ip_list, compute_ip_list) LOG.debug("Remote user: "******"Waiting for Runner Notification") infra.wait_for_notification(sync) infra.display_on_terminal(self, "Received notification from Runner") while infra.is_execution_completed(self.finish_execution) is False: #################################################### # Ansible Monitoring Loop. #################################################### ts_results = [] ts = utils.get_timestamp(complete_timestamp=True) ts_results.append({'name': 'ts', 'ts': ts}) msg = "=" * 50 + "\n" + "Timestamp: " + ts infra.display_on_terminal(self, msg) # Ping and SSH Check. host_ip_list = self.inventory.get_host_ip_list() ansi_results = self.ansible_ssh_ping_check(host_ip_list, remote_user) ts_results.append(ansi_results) # Process check. for service in SERVICE_LIST: host_ip_list = self.inventory.get_host_ip_list(role=service['role']) ansi_results = self.ansible_check_process(host_ip_list, remote_user, service['service']) ts_results.append(ansi_results) # RabbitMQ Check. host_ip_list = self.inventory.get_host_ip_list(role='controller') ansi_results = self.ansible_check_rabbitmq(host_ip_list, remote_user) ts_results.append(ansi_results) # MariaDB Check. ansi_results = self.ansible_check_mariadb(host_ip_list, remote_user) ts_results.append(ansi_results) # Add the ts results to main result list. self.ansiresults.append(ts_results) time.sleep(self.frequency) # Generate Summary Reports self.display_ansible_summary_report() self.display_asible_process_report() infra.display_infra_report() self.generate_graphs_output()
from disruptors.baseDisruptor import BaseDisruptor import ha_engine.ha_infra as infra from ha_engine.ha_constants import HAConstants from utils import utils import time LOG = infra.ha_logging(__name__) class NodeDisruptor(BaseDisruptor): report_headers = ['state', 'type', 'uptime'] ha_report = [] sync = None finish_execution = None def node_disruption(self, sync=None, finish_execution=None): self.sync = sync self.finish_execution = finish_execution infra.display_on_terminal(self, "Entering Node Disruption plugin") table_name = "Node Disruption" infra.create_report_table(self, table_name) infra.add_table_headers(self, table_name, ["Node", "IP", "TimeStamp", "Status of Disruption"]) infra.display_on_terminal(self, "Entering Process Disruption plugin") input_args_dict = self.get_input_arguments() node_name = input_args_dict.keys()[0] input_args = input_args_dict.get(node_name, None)
from optparse import OptionParser from ha_engine.ha_parser import HAParser from ha_engine.ha_executor import HAExecutor import ha_engine.ha_infra as common LOG = common.ha_logging(__name__) def main(config_file): parser = HAParser(config_file) executor = HAExecutor(parser) executor.run() if __name__ == '__main__': parser = OptionParser() parser.add_option("-f", "--file", dest="config_file", action="store", type="string") (options, args) = parser.parse_args() config_file = options.config_file main(config_file)