# Path: dcos_launch/util.py
# def get_temp_config_path(tmpdir, name, update: dict = None):
#     config = yaml.load(
#         pkg_resources.resource_string(dcos_launch.__name__, 'sample_configs/{}'.format(name)).decode('utf-8'))
#     if update is not None:
#         config.update(update)
#     new_config_path = tmpdir.join('my_config.yaml')
#     new_config_path.write(yaml.dump(config))
#     return str(new_config_path)
# 
# def stub(output):
#     def accept_any_args(*args, **kwargs):
#         return output
#     return accept_any_args


import functools
import json
import dcos_launch
import dcos_launch.cli
import dcos_launch.config
import dcos_launch.onprem
import dcos_launch.platforms
import dcos_test_utils
import dcos_test_utils.ssh_client
import pytest
from collections import namedtuple
from contextlib import contextmanager
from dcos_launch.util import get_temp_config_path, stub
from dcos_test_utils.helpers import Host
    monkeypatch.setattr(dcos_launch.gcp.OnPremLauncher, 'key_helper', lambda self: self.config.update(
        {'ssh_private_key': dcos_launch.util.MOCK_SSH_KEY_DATA, 'ssh_public_key': dcos_launch.util.MOCK_SSH_KEY_DATA}))
    monkeypatch.setattr(dcos_launch.gcp.OnPremLauncher, 'get_cluster_hosts',
                        lambda self: [mock_pub_priv_host] * (self.config['num_masters'] +
                                                             self.config['num_public_agents'] +
                                                             self.config['num_private_agents']))
    monkeypatch.setattr(dcos_launch.gcp.OnPremLauncher, 'get_bootstrap_host', lambda self: mock_pub_priv_host)


@pytest.fixture
def mocked_aws_cfstack_bare_cluster(monkeypatch, mock_ssh_client, mocked_aws_cf):
    monkeypatch.setattr(dcos_launch.platforms.aws.BareClusterCfStack, '__init__', stub(None))
    monkeypatch.setattr(dcos_launch.platforms.aws.BareClusterCfStack, 'delete', stub(None))
    monkeypatch.setattr(dcos_launch.aws.OnPremLauncher, 'get_onprem_cluster',
                        dcos_launch.onprem.AbstractOnpremLauncher.get_onprem_cluster)
    monkeypatch.setattr(
        dcos_launch.platforms.aws.BareClusterCfStack, 'get_cluster_host_ips', stub([mock_pub_priv_host] * 4))
    monkeypatch.setattr(dcos_launch.platforms.aws.BareClusterCfStack, 'get_bootstrap_ip', stub(mock_pub_priv_host))
    monkeypatch.setattr(
        dcos_launch.platforms.aws, 'fetch_stack', lambda stack_name,
        bw: dcos_launch.platforms.aws.BareClusterCfStack(stack_name, bw))


@pytest.fixture
def mocked_terraform(monkeypatch):
    monkeypatch.setenv('GCE_CREDENTIALS', '{"project_id":"foobar"}')


@pytest.fixture
def aws_cf_config_path(tmpdir, ssh_key_path, mocked_aws_cf):

# Path: dcos_launch/util.py
# def get_temp_config_path(tmpdir, name, update: dict = None):
#     config = yaml.load(
#         pkg_resources.resource_string(dcos_launch.__name__, 'sample_configs/{}'.format(name)).decode('utf-8'))
#     if update is not None:
#         config.update(update)
#     new_config_path = tmpdir.join('my_config.yaml')
#     new_config_path.write(yaml.dump(config))
#     return str(new_config_path)
# 
# def stub(output):
#     def accept_any_args(*args, **kwargs):
#         return output
#     return accept_any_args


# Path: test/conftest.py
import functools
import json
import dcos_launch
import dcos_launch.cli
import dcos_launch.config
import dcos_launch.onprem
import dcos_launch.platforms
import dcos_test_utils
import dcos_test_utils.ssh_client
import pytest
from collections import namedtuple
from contextlib import contextmanager
from dcos_launch.util import get_temp_config_path, stub
from dcos_test_utils.helpers import Host

    monkeypatch.setattr(dcos_launch.gcp.OnPremLauncher, 'key_helper', lambda self: self.config.update(
        {'ssh_private_key': dcos_launch.util.MOCK_SSH_KEY_DATA, 'ssh_public_key': dcos_launch.util.MOCK_SSH_KEY_DATA}))
    monkeypatch.setattr(dcos_launch.gcp.OnPremLauncher, 'get_cluster_hosts',
                        lambda self: [mock_pub_priv_host] * (self.config['num_masters'] +
                                                             self.config['num_public_agents'] +
                                                             self.config['num_private_agents']))
    monkeypatch.setattr(dcos_launch.gcp.OnPremLauncher, 'get_bootstrap_host', lambda self: mock_pub_priv_host)


@pytest.fixture
def mocked_aws_cfstack_bare_cluster(monkeypatch, mock_ssh_client, mocked_aws_cf):
    monkeypatch.setattr(dcos_launch.platforms.aws.BareClusterCfStack, '__init__', stub(None))
    monkeypatch.setattr(dcos_launch.platforms.aws.BareClusterCfStack, 'delete', stub(None))
    monkeypatch.setattr(dcos_launch.aws.OnPremLauncher, 'get_onprem_cluster',
                        dcos_launch.onprem.AbstractOnpremLauncher.get_onprem_cluster)
    monkeypatch.setattr(
        dcos_launch.platforms.aws.BareClusterCfStack, 'get_cluster_host_ips', stub([mock_pub_priv_host] * 4))
    monkeypatch.setattr(dcos_launch.platforms.aws.BareClusterCfStack, 'get_bootstrap_ip', stub(mock_pub_priv_host))
    monkeypatch.setattr(
        dcos_launch.platforms.aws, 'fetch_stack', lambda stack_name,
        bw: dcos_launch.platforms.aws.BareClusterCfStack(stack_name, bw))


@pytest.fixture
def mocked_terraform(monkeypatch):
    monkeypatch.setenv('GCE_CREDENTIALS', '{"project_id":"foobar"}')


@pytest.fixture
def aws_cf_config_path(tmpdir, ssh_key_path, mocked_aws_cf):

    return get_temp_config_path(tmpdir, 'aws-cf.yaml', update={'ssh_private_key_filename': ssh_key_path})