Exemple #1
0
def alienvault_asynchronous_update(system_ip, only_feed=False, update_key=""):
    """Runs an asynchronous  alienvault update
    Args:
      system_ip (str): The system IP where we would like to run the alienvault-update
      only_feed (boolean): A boolean indicating whether we should update only the feed or not.
      update_key (str): Upgrade key.
    Returns:
      JobResult (dict): where obj['result'] == True if success or False otherwise.
    """
    running = exist_task_running(task_type='alienvault_asynchronous_update',
                                 current_task_request=current_task.request,
                                 param_to_compare=system_ip,
                                 argnum=0)
    if running:
        return JobResult(False, "An existing task running", "", "300090", system_ip=system_ip).serialize

    try:
        logger.info("Start asynchronous update <%s>" % system_ip)

        rt, error_str = ansible_run_async_update(system_ip, only_feed=only_feed, update_key=update_key)
        # When the task has been launched properly the error_str variable will contain the log file.
        if not rt:
            error_msg = "Something wrong happened while running the alienvault update %s" % error_str
            if 'unreachable' in error_msg:
                error_msg = 'System unreachable'
            return JobResult(False, error_msg, "", "300091", system_ip=system_ip).serialize
        logger.info(" alienvault-update <%s> waiting to finish...." % system_ip)
        time.sleep(1)  # Wait until the task is launched.
        n_process = 1
        while int(n_process) > 0:
            success, n_process = ansible_check_if_process_is_running(system_ip, error_str)
            time.sleep(1)

        flush_cache(namespace='system_packages')

        rt, log_file = ansible_get_asynchronous_command_log_file(system_ip, error_str)
        if not rt:
            return JobResult(
                False,
                "Something wrong happened while retrieving the alienvault-update log file: %s" % log_file,
                "", "300092", system_ip=system_ip).serialize
        rt, return_code_msg = ansible_check_asynchronous_command_return_code(system_ip, error_str+".rc")
        if not rt:
            error_msg = "Something wrong happened while retrieving the alienvault-return code <%s>" % return_code_msg
            error_id = "300093"
            if return_code_msg.startswith("Return code is different from 0"):
                return_code = return_code_msg.split("<")[1].split(">")[0]
                error_msg = SYSTEM_UPDATE_ERROR_STRINGS[return_code][1]
                error_id = SYSTEM_UPDATE_ERROR_STRINGS[return_code][0]

            return JobResult(False, error_msg, log_file, error_id, system_ip=system_ip).serialize
        logger.info("Running alienvault-update ... end %s - %s" % (rt, error_str))

    except Exception, e:
        logger.error("An error occurred running alienvault-update: %s, %s" % (str(e), traceback.format_exc()))
        return JobResult(False, "An error occurred running alienvault-update <%s>" % str(e), "", "300099").serialize
Exemple #2
0
def asynchronous_update(system_id, only_feed=False,update_key=""):
    """Launches an asynchronous update on the given system_ip

    Args:
      system_id (str): The system_id of the system to update.
      only_feed (boolean): A boolean to indicate that we need update only the feed.
    Returns:
      (boolean, str): A tuple containing the result of the execution

    Examples:
      >>> asynchronous_update("11111111-1111-1111-111111111111")
      (True,"/tmp/system_update.log")
    """
    (success, system_ip) = get_system_ip_from_system_id(system_id)
    if not success:
        return success, "[asynchronous_update] Error retrieving the system ip for the system id %s -> %s" % (system_ip, str(system_ip))
    return ansible_run_async_update(system_ip,only_feed=only_feed,update_key=update_key)
Exemple #3
0
 def test_0008(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_update(ossim_setup.get_general_admin_ip(), only_feed="aAAA")
     self.assertEqual(success, False)
Exemple #4
0
    def test_0001(self, mock_ansible_playbook):

        mock_ansible_playbook.return_value=[]
        success, response = ansible_run_async_update(ossim_setup.get_general_admin_ip())
        self.assertEqual(success, False)