We are introducing a new subcommand for managing your clusters. Configuring your CLI to talk to your cluster is a single command now `dcos cluster setup`. Moreover, the CLI can now be aware of multiple clusters with cluster specific configuration managed by the CLI. Subcommands will be installed for the current "attached" cluster only. To install a subcommand for all your configured clusters, use `--global`. Note that `DCOS_CONFIG` environment variable will not take effect in "cluster" mode since we are now managing different clusters in the CLI.
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import contextlib
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from dcos import constants, util
|
|
from dcos.errors import DCOSException
|
|
|
|
|
|
def test_open_file():
|
|
path = 'nonexistant_file_name.txt'
|
|
with pytest.raises(DCOSException) as excinfo:
|
|
with util.open_file(path):
|
|
pass
|
|
assert 'Error opening file [{}]: No such file or directory'.format(path) \
|
|
in str(excinfo.value)
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def env():
|
|
"""Context manager for altering env vars in tests """
|
|
|
|
try:
|
|
old_env = dict(os.environ)
|
|
yield
|
|
finally:
|
|
os.environ.clear()
|
|
os.environ.update(old_env)
|
|
|
|
|
|
def add_cluster_dir(cluster_id, dcos_dir):
|
|
clusters_dir = os.path.join(dcos_dir, constants.DCOS_CLUSTERS_SUBDIR)
|
|
util.ensure_dir_exists(clusters_dir)
|
|
|
|
cluster_path = os.path.join(clusters_dir, cluster_id)
|
|
util.ensure_dir_exists(cluster_path)
|
|
|
|
os.path.join(cluster_path, "dcos.toml")
|
|
return cluster_path
|
|
|
|
|
|
def create_global_config(dcos_dir):
|
|
global_toml = os.path.join(dcos_dir, "dcos.toml")
|
|
util.ensure_file_exists(global_toml)
|
|
return global_toml
|