Exemple #1
0
def service_task_exec(service_name: str, task_name: str, cmd: str) -> Tuple[int, str, str]:
    """
    Invokes the given command on the named SDK service task via `dcos task exec`.
    : param service_name: Name of the service running the task.
    : param task_name: Name of task to run 'cmd' on.
    : param cmd: The command to execute.
    : return: a tuple consisting of the task exec's exit code, stdout, and stderr
              NOTE: The exit code only is only for whether the task exec call itself succeeded,
              NOT if the underlying command succeded! This is a side effect of how the CLI handles task exec.
              To check for errors in underlying commands, check stderr.
    """

    # Contrary to CLI's help text for 'dcos task exec':
    # - 'partial task ID' is only prefix/startswith matching, not 'contains' as the wording would imply.
    # - Regexes don't work at all.
    # Therefore, we need to provide a full TaskID prefix, including "servicename__taskname":
    task_id_prefix = "{}__{}__".format(sdk_utils.get_task_id_service_name(service_name), task_name)
    rc, stdout, stderr = _task_exec(task_id_prefix, cmd)

    if "Cannot find a task with ID containing" in stderr:
        # If the service is doing an upgrade test, the old version may not use prefixed task ids.
        # Get around this by trying again without the service name prefix in the task id.
        rc, stdout, stderr = _task_exec(task_name, cmd)

    return rc, stdout, stderr
Exemple #2
0
def service_task_exec(service_name: str, task_name: str,
                      cmd: str) -> Tuple[int, str, str]:
    """
    Invokes the given command on the named SDK service task via `dcos task exec`.
    : param service_name: Name of the service running the task.
    : param task_name: Name of task to run 'cmd' on.
    : param cmd: The command to execute.
    : return: a tuple consisting of the task exec's exit code, stdout, and stderr
              NOTE: The exit code only is only for whether the task exec call itself succeeded,
              NOT if the underlying command succeded! This is a side effect of how the CLI handles task exec.
              To check for errors in underlying commands, check stderr.
    """

    # Contrary to CLI's help text for 'dcos task exec':
    # - 'partial task ID' is only prefix/startswith matching, not 'contains' as the wording would imply.
    # - Regexes don't work at all.
    # Therefore, we need to provide a full TaskID prefix, including "servicename__taskname":
    task_id_prefix = "{}__{}__".format(
        sdk_utils.get_task_id_service_name(service_name), task_name)
    rc, stdout, stderr = _task_exec(task_id_prefix, cmd)

    if "Cannot find a task with ID containing" in stderr:
        # If the service is doing an upgrade test, the old version may not use prefixed task ids.
        # Get around this by trying again without the service name prefix in the task id.
        rc, stdout, stderr = _task_exec(task_name, cmd)

    return rc, stdout, stderr
def test_pod_status_one():
    foldered_name = sdk_utils.get_foldered_name(config.SERVICE_NAME)
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    jsonobj = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name, 'pod status --json hello-0', json=True)
    assert jsonobj['name'] == 'hello-0'
    assert len(jsonobj['tasks']) == 1
    task = jsonobj['tasks'][0]
    assert len(task) == 3
    assert re.match(sanitized_name + '__hello-0-server__[0-9a-f-]+', task['id'])
    assert task['name'] == 'hello-0-server'
    assert task['status'] == 'RUNNING'
def test_pod_status_one():
    foldered_name = sdk_utils.get_foldered_name(config.SERVICE_NAME)
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    jsonobj = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name, 'pod status --json hello-0', json=True)
    assert jsonobj['name'] == 'hello-0'
    assert len(jsonobj['tasks']) == 1
    task = jsonobj['tasks'][0]
    assert len(task) == 3
    assert re.match(sanitized_name + '__hello-0-server__[0-9a-f-]+', task['id'])
    assert task['name'] == 'hello-0-server'
    assert task['status'] == 'RUNNING'
def test_pod_status_one():
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    rc, stdout, _ = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name, "pod status --json hello-0")
    assert rc == 0, "Pod status failed"
    jsonobj = json.loads(stdout)
    assert jsonobj["name"] == "hello-0"
    assert len(jsonobj["tasks"]) == 1
    task = jsonobj["tasks"][0]
    assert len(task) == 3
    assert re.match(sanitized_name + "__hello-0-server__[0-9a-f-]+", task["id"])
    assert task["name"] == "hello-0-server"
    assert task["status"] == "RUNNING"
Exemple #6
0
def test_pod_status_one():
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    rc, stdout, _ = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name,
                                    "pod status --json hello-0")
    assert rc == 0, "Pod status failed"
    jsonobj = json.loads(stdout)
    assert jsonobj["name"] == "hello-0"
    assert len(jsonobj["tasks"]) == 1
    task = jsonobj["tasks"][0]
    assert len(task) == 3
    assert re.match(sanitized_name + "__hello-0-server__[0-9a-f-]+",
                    task["id"])
    assert task["name"] == "hello-0-server"
    assert task["status"] == "RUNNING"
def test_pod_status_all():
    foldered_name = sdk_utils.get_foldered_name(config.SERVICE_NAME)
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    jsonobj = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name, 'pod status --json', json=True)
    assert jsonobj['service'] == foldered_name
    for pod in jsonobj['pods']:
        assert re.match('(hello|world)', pod['name'])
        for instance in pod['instances']:
            assert re.match('(hello|world)-[0-9]+', instance['name'])
            for task in instance['tasks']:
                assert len(task) == 3
                assert re.match(sanitized_name + '__(hello|world)-[0-9]+-server__[0-9a-f-]+', task['id'])
                assert re.match('(hello|world)-[0-9]+-server', task['name'])
                assert task['status'] == 'RUNNING'
def test_pod_status_all():
    foldered_name = sdk_utils.get_foldered_name(config.SERVICE_NAME)
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    jsonobj = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name, 'pod status --json', json=True)
    assert jsonobj['service'] == foldered_name
    for pod in jsonobj['pods']:
        assert re.match('(hello|world)', pod['name'])
        for instance in pod['instances']:
            assert re.match('(hello|world)-[0-9]+', instance['name'])
            for task in instance['tasks']:
                assert len(task) == 3
                assert re.match(sanitized_name + '__(hello|world)-[0-9]+-server__[0-9a-f-]+', task['id'])
                assert re.match('(hello|world)-[0-9]+-server', task['name'])
                assert task['status'] == 'RUNNING'
def service_task_exec(service_name: str, task_name: str, cmd: str, return_stderr_in_stdout: bool = False) -> tuple:
    """
    Invokes the given command on the named SDK service task via `dcos task exec`.
    :param service_name: Name of the service running the task.
    :param task_name: Name of task to run 'cmd' on.
    :param cmd: The command to execute.
    :return: a tuple consisting of the task exec's return code, stdout, and stderr
    """

    # Contrary to CLI's help text for 'dcos task exec':
    # - 'partial task ID' is only prefix/startswith matching, not 'contains' as the wording would imply.
    # - Regexes don't work at all.
    # Therefore, we need to provide a full TaskID prefix, including "servicename__taskname":
    task_id_prefix = '{}__{}__'.format(sdk_utils.get_task_id_service_name(service_name), task_name)

    return _task_exec(task_id_prefix, cmd, return_stderr_in_stdout)
Exemple #10
0
def service_task_exec(service_name: str, task_name: str, cmd: str, return_stderr_in_stdout: bool = False) -> tuple:
    """
    Invokes the given command on the named SDK service task via `dcos task exec`.
    :param service_name: Name of the service running the task.
    :param task_name: Name of task to run 'cmd' on.
    :param cmd: The command to execute.
    :return: a tuple consisting of the task exec's return code, stdout, and stderr
    """

    # Contrary to CLI's help text for 'dcos task exec':
    # - 'partial task ID' is only prefix/startswith matching, not 'contains' as the wording would imply.
    # - Regexes don't work at all.
    # Therefore, we need to provide a full TaskID prefix, including "servicename__taskname":
    task_id_prefix = '{}__{}__'.format(sdk_utils.get_task_id_service_name(service_name), task_name)

    return _task_exec(task_id_prefix, cmd, return_stderr_in_stdout)
def test_pod_status_all():
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    rc, stdout, _ = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name, "pod status --json")
    assert rc == 0, "Pod status failed"
    jsonobj = json.loads(stdout)
    assert jsonobj["service"] == foldered_name
    for pod in jsonobj["pods"]:
        assert re.match("(hello|world)", pod["name"])
        for instance in pod["instances"]:
            assert re.match("(hello|world)-[0-9]+", instance["name"])
            for task in instance["tasks"]:
                assert len(task) == 3
                assert re.match(
                    sanitized_name + "__(hello|world)-[0-9]+-server__[0-9a-f-]+", task["id"]
                )
                assert re.match("(hello|world)-[0-9]+-server", task["name"])
                assert task["status"] == "RUNNING"
Exemple #12
0
def test_pod_status_all():
    # /test/integration/hello-world => test.integration.hello-world
    sanitized_name = sdk_utils.get_task_id_service_name(foldered_name)
    rc, stdout, _ = sdk_cmd.svc_cli(config.PACKAGE_NAME, foldered_name,
                                    "pod status --json")
    assert rc == 0, "Pod status failed"
    jsonobj = json.loads(stdout)
    assert jsonobj["service"] == foldered_name
    for pod in jsonobj["pods"]:
        assert re.match("(hello|world)", pod["name"])
        for instance in pod["instances"]:
            assert re.match("(hello|world)-[0-9]+", instance["name"])
            for task in instance["tasks"]:
                assert len(task) == 3
                assert re.match(
                    sanitized_name +
                    "__(hello|world)-[0-9]+-server__[0-9a-f-]+", task["id"])
                assert re.match("(hello|world)-[0-9]+-server", task["name"])
                assert task["status"] == "RUNNING"
Exemple #13
0
def service_task_exec(service_name: str, task_name: str, cmd: str) -> tuple:
    """
    Invokes the given command on the named SDK service task via `dcos task exec`.
    :param service_name: Name of the service running the task.
    :param task_name: Name of task to run 'cmd' on.
    :param cmd: The command to execute.
    :return: a tuple consisting of the task exec's return code, stdout, and stderr
    """

    # Contrary to CLI's help text for 'dcos task exec':
    # - 'partial task ID' is only prefix/startswith matching, not 'contains' as the wording would imply.
    # - Regexes don't work at all.
    # Therefore, we need to provide a full TaskID prefix, including "servicename__taskname":
    task_id_prefix = '{}__{}__'.format(sdk_utils.get_task_id_service_name(service_name), task_name)
    rc, stdout, stderr = _task_exec(task_id_prefix, cmd)

    if 'Cannot find a task with ID containing' in stderr:
        # If the service is doing an upgrade test, the old version may not use prefixed task ids.
        # Get around this by trying again without the service name prefix in the task id.
        rc, stdout, stderr = _task_exec(task_name, cmd)

    return rc, stdout, stderr