Welcome to dcos-test-utils’s documentation!

dcos-test-utils is a package for comprehensive interaction with DC/OS including:

  • API client for making calls to DC/OS APIs
  • simple wrapper for managing and communicating with the binary dcos-cli
  • SSH client for simple one-off host-level changes
  • Advanced SSH client for parallelized asynchronous command chains

Getting Started

To get started writing code that leverages the DC/OS API, not much is needed:

from dcos_test_utils import dcos_api

dcos_api_session = dcos_api.DcosApiSession.create()
dcos_api_session.marathon.deploy_app({
     "id": "/sample_app",
     "cmd": "touch foobar && sleep 3600",
     "cpus": 0.5,
     "mem": 128.0,
     "instances": 1,
     "healthChecks": [
         {
             'protocol': 'COMMAND',
             'command': {'value': 'test -f foobar'},
             'gracePeriodSeconds': 10,
             'intervalSeconds': 5,
             'timeoutSeconds': 5,
             'maxConsecutiveFailures': 1,
         }
     ]
 }

r = dcos_api_session.get('/service/marathon/v2/apps')
assert len(r.json()) >= 1, 'No apps were found!'

If using a Mesosphere Enterprise DC/OS cluster, a different but functionally similar client is used:

from dcos_test_utils import enterprise

dcos_api_session = enterprise.EnterpriseApiSession.create()
r = dcos_api_session.secrets.get('/store')
assert r.json()['array'][0]['initialized']

To learn more about how to configure these sessions, see:

Using dcos-test-utils in pytest

This module includes a pytest plugin, pytest-dcos, which includes the boilerplate to create a session in tests via a fixture called dcos_api_session.

In your conftest.py file, include the following:

pytest_plugins = ["pytest-dcos"]

Now, there is no need for boilerplate to declare the client

def test_dcos_apps(dcos_api_sessoion):
    dcos_api_session.get('/').raise_for_status()

Note: this fixture introduces an additional environment variable called DCOS_ENTERPRISE which can be set to true or false (default to false)

For more advanced configuration at test time, this fixture can be overridden like so:

@pytest.fixture(scope='session')
def dcos_api_session(dcos_api_session_factory, user_config):
    """ Overrides the dcos_api_session fixture to use
    exhibitor settings currently used in the cluster
    """
    args = dcos_api_session_factory.get_args_from_env()

    exhibitor_admin_password = None
    if user_config['exhibitor_admin_password_enabled'] == 'true':
        exhibitor_admin_password = user_config['exhibitor_admin_password']

    api = dcos_api_session_factory(
        exhibitor_admin_password=exhibitor_admin_password,
        **args)
    api.wait_for_dcos()
    return api

Indices and tables