DC/OS E2E Python Library¶
DC/OS E2E is a tool for spinning up and managing DC/OS clusters in test environments.
It includes a library which is focused on helping you to write tests which require DC/OS clusters.
See the CLI documentation for information on CLI tools built with DC/OS E2E.
Installing DC/OS E2E¶
Requires Python 3.6+. To avoid interfering with your system’s Python, we recommend using a virtualenv.
Check the Python version:
python3 --version
On Fedora, install Python development requirements:
dnf install -y git python3-devel
On Ubuntu, install Python development requirements:
apt update -y && \
apt install -y software-properties-common && \
apt upgrade -y python-apt && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt update -y && \
apt upgrade -y gcc python3-dev python3.6-dev libffi-dev libssl-dev git python3-pip
Install dependencies, preferably in a virtual environment.
If you are not in a virtualenv, you may have to use sudo
before the following command, or --user
after install
.
pip3 install --upgrade git+https://github.com/|github-owner|/|github-repository|.git@|release|
Uninstall¶
To uninstall DC/OS E2E, run the following command:
pip3 uninstall -y dcos-e2e
Getting Started¶
To create a DC/OS Cluster
, you need a backend.
Backends are customizable, but for now let’s use a standard Docker backend.
Each backend has different system requirements.
See the Docker backend documentation for details of what is needed for the Docker backend.
from dcos_e2e.backends import Docker
from dcos_e2e.cluster import Cluster
cluster = Cluster(cluster_backend=Docker())
It is also possible to use Cluster
as a context manager.
Doing this means that the cluster is destroyed on exit.
To install DC/OS on a cluster, you need a DC/OS installer.
You can download one from the DC/OS releases page.
In this example we will use a open source DC/OS installer downloaded to /tmp/dcos_generate_config.sh
.
from pathlib import Path
oss_installer = Path('/tmp/dcos_generate_config.sh')
cluster.install_dcos_from_path(
dcos_installer=oss_installer,
dcos_config={
**cluster.base_config,
**{
'resolvers': ['8.8.8.8'],
},
}
ip_detect_path=Docker().ip_detect_path,
)
cluster.wait_for_dcos_oss()
With a Cluster
you can then run commands on arbitrary Node
s.
for master in cluster.masters:
result = master.run(args=['echo', '1'])
print(result.stdout)
There is much more that you can do with Cluster
s and Node
s, and there are other ways to create a cluster.