예제 #1
0
    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()
예제 #2
0
    def run(self):
        """
        Actual execution starts here
        """
        # Exit if the executor is not defined.
        execute = self.executor_data.get('executors', None)
        if execute is None:
            LOG.critical('Nothing to run')
            ha_infra.ha_exit(0)

        self.executor_threads = []
        # clean up the xterm paths
        if os.path.exists(self.infra_path):
            shutil.rmtree(self.infra_path)

        ha_infra.start_run_time = \
            utils.get_timestamp(complete_timestamp=True)

        user_env_pc = None
        if os.environ.get('PROMPT_COMMAND', None):
            # save the PROMPT_COMMAND to set xterm title for now
            user_env_pc = os.environ['PROMPT_COMMAND']
            del os.environ['PROMPT_COMMAND']

        for executor_index, executor_block in enumerate(execute):
            # Check whether the executor block needs to be repeated
            # process the repeat commandi
            if not executor_block:
                ha_infra.stop_run_time = \
                    utils.get_timestamp(complete_timestamp=True)
                LOG.info("******** Completing the execution ******** ")
                ha_infra.ha_exit(0)

            parallel = False
            repeat_count = 1
            LOG.info('Executing %s' % str(executor_index + 1))

            if 'repeat' in executor_block:
                repeat_count = executor_block.get('repeat', 1)
                executor_block.pop('repeat')

            use_sync = False
            if 'sync' in executor_block:
                LOG.info("Sync is requested within the block")
                use_sync = executor_block.get('sync', False)
                LOG.info("Use Sync %s", use_sync)

            ha_interval = None
            ha_start_delay = None
            if 'ha_interval' in executor_block:
                ha_interval = executor_block.get('ha_interval', None)
            if 'ha_start_delay' in executor_block:
                ha_start_delay = executor_block.get('ha_start_delay', None)
            disruption_count = 1
            if 'disruption_count' in executor_block:
                disruption_count = executor_block.get('disruption_count', None)

            LOG.info("Block will be repeated %s times", repeat_count)
            # Repeat count in each steps
            for i in range(repeat_count):
                LOG.info("******** Block Execution Count %s ********  ",
                         str(i + 1))
                # process the mdoe command
                if 'mode' in executor_block:
                    # if mode is parallel set parllel flag
                    if executor_block['mode'].lower() == 'parallel':
                        LOG.info('starting thread')
                        parallel = True
                    elif executor_block['mode'].lower() == 'sequence':
                        LOG.info('sequential execution')
                    else:
                        LOG.critical('Unsupported mode , '
                                     'must be either '
                                     '"parallel" or "sequence"')
                        ha_infra.ha_exit(0)
                    executor_block.pop('mode')

                # process the timer command
                if 'timer' in executor_block:
                    # TODO: pradeech
                    LOG.info('Timer....')
                    executor_block.pop('timer')

                try:
                    # Execute the command and the respective parameters
                    del self.executor_threads[:]

                    for step_action, nodes in executor_block.iteritems():
                        launched_process = 0
                        ha_infra.set_launched_process_count(launched_process)
                        self.execute_the_block(executor_index,
                                               nodes,
                                               step_action,
                                               ha_interval,
                                               ha_start_delay,
                                               disruption_count,
                                               parallel=parallel,
                                               use_sync=use_sync)

                    if self.executor_threads:
                        # start all the executor threads
                        [t.start() for t in self.executor_threads]
                        [t.join() for t in self.executor_threads]

                    ha_infra.display_infra_report()
                except NotImplementedError as runerror:
                    LOG.critical('Unable to execute %s - %s' % runerror,
                                 step_action)
                    ha_infra.ha_exit(0)

                except Exception as runerror:
                    LOG.critical('Unable to continue execution %s' %
                                 str(runerror))
                    ha_infra.ha_exit(0)

        LOG.info("******** Completing the executions ******** ")
        ha_infra.stop_run_time = \
            utils.get_timestamp(complete_timestamp=True)

        # clean up all the pipes
        for f in self.open_pipes:
            try:
                os.unlink(f)
            except:
                pass
        # restore the env variables
        if user_env_pc:
            os.environ['PROMPT_COMMAND'] = user_env_pc
예제 #3
0
    def run(self):
        """
        Actual execution starts here
        """
        # Exit if the executor is not defined.
        execute = self.executor_data.get('executors', None)
        if execute is None:
            LOG.critical('Nothing to run')
            ha_infra.ha_exit(0)

        self.executor_threads = []
        # clean up the xterm paths
        if os.path.exists(self.infra_path):
            shutil.rmtree(self.infra_path)

        ha_infra.start_run_time = \
            utils.get_timestamp(complete_timestamp=True)

        user_env_pc = None
        if os.environ.get('PROMPT_COMMAND', None):
            # save the PROMPT_COMMAND to set xterm title for now
            user_env_pc = os.environ['PROMPT_COMMAND']
            del os.environ['PROMPT_COMMAND']

        for executor_index, executor_block in enumerate(execute):
                # Check whether the executor block needs to be repeated
                # process the repeat commandi
                if not executor_block:
                    ha_infra.stop_run_time = \
                        utils.get_timestamp(complete_timestamp=True)
                    LOG.info("******** Completing the execution ******** ")
                    ha_infra.ha_exit(0)

                parallel = False
                repeat_count = 1
                LOG.info('Executing %s' % str(executor_index+1))

                if 'repeat' in executor_block:
                    repeat_count = executor_block.get('repeat', 1)
                    executor_block.pop('repeat')

                use_sync = False
                if 'sync' in executor_block:
                    LOG.info("Sync is requested within the block")
                    use_sync = executor_block.get('sync', False)
                    LOG.info("Use Sync %s", use_sync)

                ha_interval = None
                ha_start_delay = None
                if 'ha_interval' in executor_block:
                    ha_interval = executor_block.get('ha_interval', None)
                if 'ha_start_delay' in executor_block:
                    ha_start_delay = executor_block.get('ha_start_delay', None)
                disruption_count = 1 
                if 'disruption_count' in executor_block:
                    disruption_count = executor_block.get('disruption_count',
                                                          None)
                 
                LOG.info("Block will be repeated %s times", repeat_count)
                # Repeat count in each steps
                for i in range(repeat_count):
                    LOG.info("******** Block Execution Count %s ********  ",
                             str(i+1))
                    # process the mdoe command
                    if 'mode' in executor_block:
                        # if mode is parallel set parllel flag
                        if executor_block['mode'].lower() == 'parallel':
                            LOG.info('starting thread')
                            parallel = True
                        elif executor_block['mode'].lower() == 'sequence':
                            LOG.info('sequential execution')
                        else:
                            LOG.critical('Unsupported mode , '
                                         'must be either '
                                         '"parallel" or "sequence"')
                            ha_infra.ha_exit(0)
                        executor_block.pop('mode')

                    # process the timer command
                    if 'timer' in executor_block:
                        # TODO: pradeech
                        LOG.info('Timer....')
                        executor_block.pop('timer')

                    try:
                        # Execute the command and the respective parameters
                        del self.executor_threads[:]

                        for step_action, nodes in executor_block.iteritems():
                            launched_process = 0
                            ha_infra.set_launched_process_count(
                                launched_process)
                            self.execute_the_block(executor_index,
                                                   nodes,
                                                   step_action,
                                                   ha_interval,
						   ha_start_delay,
                                                   disruption_count,
                                                   parallel=parallel,
                                                   use_sync=use_sync)

                        if self.executor_threads:
                            # start all the executor threads
                            [t.start() for t in self.executor_threads]
                            [t.join() for t in self.executor_threads]

                        ha_infra.display_infra_report()
                    except NotImplementedError as runerror:
                        LOG.critical('Unable to execute %s - %s'
                                     % runerror, step_action)
                        ha_infra.ha_exit(0)

                    except Exception as runerror:
                        LOG.critical('Unable to continue execution %s'
                                     % str(runerror))
                        ha_infra.ha_exit(0)

        LOG.info("******** Completing the executions ******** ")
        ha_infra.stop_run_time = \
            utils.get_timestamp(complete_timestamp=True)

        # clean up all the pipes
        for f in self.open_pipes:
	    try:
                os.unlink(f)
            except: 
		pass
        # restore the env variables
        if user_env_pc:
            os.environ['PROMPT_COMMAND'] = user_env_pc