Exemplo n.º 1
0
def add_package_repo(
        repo_name,
        repo_url,
        index=None,
        wait_for_package=None,
        expect_prev_version=None):
    """ Add a repository to the list of package sources

        :param repo_name: name of the repository to add
        :type repo_name: str
        :param repo_url: location of the repository to add
        :type repo_url: str
        :param index: index (precedence) for this repository
        :type index: int
        :param wait_for_package: the package whose version should change after the repo is added
        :type wait_for_package: str, or None

        :return: True if successful, False otherwise
        :rtype: bool
    """

    package_manager = _get_package_manager()
    if wait_for_package:
        prev_version = package_manager.get_package_version(wait_for_package, None)
    if not package_manager.add_repo(repo_name, repo_url, index):
        return False
    if wait_for_package:
        try:
            time_wait(lambda: package_version_changed_predicate(package_manager, wait_for_package, prev_version))
        except TimeoutExpired:
            return False
    return True
Exemplo n.º 2
0
def wait_for_service_tasks_all_unchanged(service_name,
                                         old_task_ids,
                                         task_predicate=None,
                                         timeout_sec=30):
    """ Returns after verifying that NONE of old_task_ids have been removed or replaced from the service

        :param service_name: the service name
        :type service_name: str
        :param old_task_ids: list of original task ids as returned by get_service_task_ids
        :type old_task_ids: [str]
        :param task_predicate: filter to use when searching for tasks
        :type task_predicate: func
        :param timeout_sec: duration to wait until assuming tasks are unchanged
        :type timeout_sec: int

        :return: the duration waited in seconds (the timeout value)
        :rtype: int
    """
    try:
        time_wait(lambda: tasks_missing_predicate(service_name, old_task_ids,
                                                  task_predicate),
                  timeout_seconds=timeout_sec)
        # shouldn't have exited successfully: raise below
    except TimeoutExpired:
        return timeout_sec  # no changes occurred within timeout, as expected
    raise DCOSException(
        "One or more of the following tasks were no longer found: {}".format(
            old_task_ids))
Exemplo n.º 3
0
def wait_for_service_endpoint(service_name, timeout_sec=120):
    """Checks the service url if available it returns true, on expiration
    it returns false"""

    master_count = len(get_all_masters())
    return time_wait(lambda: service_available_predicate(service_name),
                     timeout_seconds=timeout_sec,
                     required_consecutive_success_count=master_count)
Exemplo n.º 4
0
def remove_package_repo(repo_name, wait_for_package=None):
    """ Remove a repository from the list of package sources

        :param repo_name: name of the repository to remove
        :type repo_name: str
        :param wait_for_package: the package whose version should change after the repo is removed
        :type wait_for_package: str, or None

        :returns: True if successful, False otherwise
        :rtype: bool
    """

    package_manager = _get_package_manager()
    if wait_for_package:
        prev_version = package_manager.get_package_version(wait_for_package, None)
    if not package_manager.remove_repo(repo_name):
        return False
    if wait_for_package:
        try:
            time_wait(lambda: package_version_changed_predicate(package_manager, wait_for_package, prev_version))
        except TimeoutExpired:
            return False
    return True
Exemplo n.º 5
0
def wait_for_service_tasks_all_changed(service_name,
                                       old_task_ids,
                                       task_predicate=None,
                                       timeout_sec=120):
    """ Returns once ALL of old_task_ids have been replaced with new tasks

        :param service_name: the service name
        :type service_name: str
        :param old_task_ids: list of original task ids as returned by get_service_task_ids
        :type old_task_ids: [str]
        :param task_predicate: filter to use when searching for tasks
        :type task_predicate: func
        :param timeout_sec: duration to wait
        :type timeout_sec: int

        :return: the duration waited in seconds
        :rtype: int
    """
    return time_wait(lambda: tasks_all_replaced_predicate(
        service_name, old_task_ids, task_predicate),
                     timeout_seconds=timeout_sec)
Exemplo n.º 6
0
def wait_for_service_tasks_state(service_name,
                                 expected_task_count,
                                 expected_task_states,
                                 timeout_sec=120):
    """ Returns once the service has at least N tasks in one of the specified state(s)

        :param service_name: the service name
        :type service_name: str
        :param expected_task_count: the expected number of tasks in the specified state(s)
        :type expected_task_count: int
        :param expected_task_states: the expected state(s) for tasks to be in, e.g. 'TASK_RUNNING'
        :type expected_task_states: [str]
        :param timeout_sec: duration to wait
        :type timeout_sec: int

        :return: the duration waited in seconds
        :rtype: int
    """
    return time_wait(lambda: task_states_predicate(
        service_name, expected_task_count, expected_task_states),
                     timeout_seconds=timeout_sec)
Exemplo n.º 7
0
def wait_for_service_endpoint_removal(service_name, timeout_sec=120):
    """Checks the service url if it is removed it returns true, on expiration
    it returns false"""

    return time_wait(lambda: service_unavailable_predicate(service_name),
                     timeout_seconds=timeout_sec)
Exemplo n.º 8
0
def wait_for_mesos_task_removal(task_name, timeout_sec=120):
    return time_wait(lambda: mesos_task_not_present_predicate(task_name),
                     timeout_seconds=timeout_sec)
Exemplo n.º 9
0
def wait_for_mesos_endpoint(timeout_sec=timedelta(minutes=5).total_seconds()):
    """Checks the service url if available it returns true, on expiration
    it returns false"""

    return time_wait(lambda: mesos_available_predicate(),
                     timeout_seconds=timeout_sec)