def alienvault_asynchronous_reconfigure(system_ip, new_system_ip): """Runs an asynchronous alienvault reconfig Args: system_ip (str): The system IP where we would like to run the alienvault-reconfig system_ip (str): The new system admin IP. This is used for the case of changing the ansible IP Returns: success (boolean): True if success false otherwise , job_log=job_log """ running = exist_task_running(task_type='alienvault_asynchronous_reconfigure', current_task_request=current_task.request, param_to_compare=system_ip, argnum=0) if running: return JobResult(False, "An existing task running", "", "0").serialize try: logger.info("Start asynchronous reconfigure <%s>" % system_ip) (success, log_file) = ansible_run_async_reconfig(system_ip) if not success: logger.error("Error running alienvault reconfig: %s" % log_file) return JobResult(False, "Something wrong happend while running alienvault reconfig %s" % log_file, log_file, "0").serialize logger.info("reconfigure <%s> waiting to finish...." % system_ip) # Wait until the task is launched. time.sleep(1) # Wait until the process is finished n_process = 1 while n_process > 0: (success, n_process) = ansible_check_if_process_is_running(system_ip, log_file) if not success: if new_system_ip is not None and system_ip != new_system_ip: system_ip = new_system_ip else: logger.error("Cannot retrieve the process status from %s" % system_ip) return JobResult(False, "Cannot retrieve the process status from %s" % system_ip, log_file, "0").serialize time.sleep(1) logger.info("Running alienvault-reconfig ... end %s - %s" % (success, log_file)) # Get the log file (success, log_file_path) = ansible_get_asynchronous_command_log_file(system_ip, log_file) if not success: return JobResult(False, "Something wrong happened while retrieving the alienvault-reconfig log file %s" % log_file_path, log_file, "0").serialize # Get the return code success, return_code_msg = ansible_check_asynchronous_command_return_code(system_ip, log_file + ".rc") if not success: logger.error("Something wrong happened while retrieving the alienvault-reconfig return code %s" % return_code_msg) return JobResult(False, "Something wrong happened while retrieving the return code %s" % return_code_msg, log_file, "0").serialize except Exception, e: logger.error("An error occurred running alienvault-reconfig: %s, %s" % (str(e), traceback.format_exc())) return JobResult(False, "An error occurred running alienvault-reconfig: %s" % (str(e)), "", "0").serialize
def asynchronous_reconfigure(system_id): """Launches an asynchronous reconfigure on the given system_ip Args: system_id (str): The system_id of the system to configure. Returns: (boolean, str): A tuple containing the result of the execution Examples: >>> asynchronous_reconfigure("88888888-8888-8888-888888888888") (True,"/tmp/system_reconfigure.log" """ (success, system_ip) = get_system_ip_from_system_id(system_id) if not success: return success, "[asynchronous_reconfigure] Error retrieving the system ip for the system id %s -> %s" % (system_ip, str(system_ip)) return ansible_run_async_reconfig(system_ip)
def test_0019(self, mock_ansible_playbook): # {'172.17.2.101': {'unreachable': 0, 'skipped': 4, 'ok': 3, 'changed': 0, 'failures': 0}} # {'172.17.2.102': {'unreachable': 1, 'skipped': 0, 'ok': 0, 'changed': 0, 'failures': 0}} mock_ansible_playbook.return_value=None success, response = ansible_run_async_reconfig(ossim_setup.get_general_admin_ip()) self.assertEqual(success, False)
def test_0010(self, mock_ansible_playbook): mock_ansible_playbook.return_value=[] success, response = ansible_run_async_reconfig(ossim_setup.get_general_admin_ip()) self.assertEqual(success, False)
def alienvault_asynchronous_reconfigure(system_ip, new_system_ip): """Runs an asynchronous alienvault reconfig Args: system_ip (str): The system IP where we would like to run the alienvault-reconfig system_ip (str): The new system admin IP. This is used for the case of changing the ansible IP Returns: success (boolean): True if success false otherwise , job_log=job_log """ running = exist_task_running( task_type='alienvault_asynchronous_reconfigure', current_task_request=current_task.request, param_to_compare=system_ip, argnum=0) if running: return JobResult(False, "An existing task running", "", "0").serialize try: logger.info("Start asynchronous reconfigure <%s>" % system_ip) (success, log_file) = ansible_run_async_reconfig(system_ip) if not success: logger.error("Error running alienvault reconfig: %s" % log_file) return JobResult( False, "Something wrong happend while running alienvault reconfig %s" % log_file, log_file, "0").serialize logger.info("reconfigure <%s> waiting to finish...." % system_ip) # Wait until the task is launched. time.sleep(1) # Wait until the process is finished n_process = 1 while n_process > 0: (success, n_process) = ansible_check_if_process_is_running( system_ip, log_file) if not success: if new_system_ip is not None and system_ip != new_system_ip: system_ip = new_system_ip else: logger.error("Cannot retrieve the process status from %s" % system_ip) return JobResult( False, "Cannot retrieve the process status from %s" % system_ip, log_file, "0").serialize time.sleep(1) logger.info("Running alienvault-reconfig ... end %s - %s" % (success, log_file)) # Get the log file (success, log_file_path) = ansible_get_asynchronous_command_log_file( system_ip, log_file) if not success: return JobResult( False, "Something wrong happened while retrieving the alienvault-reconfig log file %s" % log_file_path, log_file, "0").serialize # Get the return code success, return_code_msg = ansible_check_asynchronous_command_return_code( system_ip, log_file + ".rc") if not success: logger.error( "Something wrong happened while retrieving the alienvault-reconfig return code %s" % return_code_msg) return JobResult( False, "Something wrong happened while retrieving the return code %s" % return_code_msg, log_file, "0").serialize except Exception, e: logger.error("An error occurred running alienvault-reconfig: %s, %s" % (str(e), traceback.format_exc())) return JobResult( False, "An error occurred running alienvault-reconfig: %s" % (str(e)), "", "0").serialize