Exemple #1
0
def test_get_config(load_path_mock):
    with env(), util.tempdir() as tempdir:
        os.environ.pop('DCOS_CONFIG', None)
        os.environ[constants.DCOS_DIR_ENV] = tempdir

        # no config file of any type
        # this should create the global config
        config.get_config()
        global_toml = os.path.join(tempdir, "dcos.toml")
        load_path_mock.assert_called_once_with(global_toml, False)
        load_path_mock.reset_mock()

        # create old global config toml
        global_toml = create_global_config(tempdir)
        config.get_config()
        load_path_mock.assert_called_once_with(global_toml, False)
        load_path_mock.reset_mock()

        # clusters dir, no clusters
        _create_clusters_dir(tempdir)
        config.get_config()
        load_path_mock.assert_called_once_with(global_toml, False)
        load_path_mock.reset_mock()

        cluster_id = "fake-cluster"
        cluster_path = add_cluster_dir(cluster_id, tempdir)
        cluster_toml = os.path.join(cluster_path, "dcos.toml")
        config.get_config(True)
        load_path_mock.assert_called_with(cluster_toml, True)
def test_get_config(load_path_mock):
    with env(), util.tempdir() as tempdir:
        os.environ.pop('DCOS_CONFIG', None)
        os.environ[constants.DCOS_DIR_ENV] = tempdir

        # no config file of any type
        with pytest.raises(DCOSException) as e:
            config.get_config()

        msg = ("No cluster is attached. "
               "Please run `dcos cluster attach <cluster-name>`")
        assert str(e.value) == msg
        load_path_mock.assert_not_called()

        # create old global config toml
        global_toml = create_global_config(tempdir)
        config.get_config()
        load_path_mock.assert_called_once_with(global_toml, False)

        # clusters dir, no clusters
        _create_clusters_dir(tempdir)
        with pytest.raises(DCOSException) as e:
            config.get_config()
        assert str(e.value) == msg

        cluster_id = "fake-cluster"
        cluster_path = add_cluster_dir(cluster_id, tempdir)
        cluster_toml = os.path.join(cluster_path, "dcos.toml")
        config.get_config(True)
        load_path_mock.assert_any_call(cluster_toml, True)
def test_move_to_cluster_config(mock_get, mock_config):
    with env(), util.tempdir() as tempdir:
        os.environ[constants.DCOS_DIR_ENV] = tempdir

        create_global_config(tempdir)
        mock_config.return_value = "fake-url"

        cluster_id = "fake"
        mock_resp = mock.Mock()
        mock_resp.json.return_value = {"CLUSTER_ID": cluster_id}
        mock_get.return_value = mock_resp

        assert config.get_config_dir_path() == tempdir
        cluster.move_to_cluster_config()

        clusters_path = os.path.join(tempdir, constants.DCOS_CLUSTERS_SUBDIR)
        assert os.path.exists(clusters_path)
        cluster_path = os.path.join(clusters_path, cluster_id)
        assert os.path.exists(os.path.join(cluster_path, "dcos.toml"))
        assert os.path.exists(
            os.path.join(cluster_path, constants.DCOS_CLUSTER_ATTACHED_FILE))
Exemple #4
0
def test_uses_deprecated_config():
    with env(), util.tempdir() as tempdir:
        os.environ.pop('DCOS_CONFIG', None)
        os.environ[constants.DCOS_DIR_ENV] = tempdir
        assert config.get_config_dir_path() == tempdir

        # create old global config toml
        global_toml = create_global_config(tempdir)
        assert config.get_global_config_path() == global_toml
        assert config.uses_deprecated_config() is True

        # create clusters subdir
        _create_clusters_dir(tempdir)
        assert config.uses_deprecated_config() is False