コード例 #1
0
def test_missing_ami_setting(load_config_dict_mock, dbm):
    load_config_dict_mock.return_value = {}

    with dbm.session() as session:
        with pytest.raises(ConfigurationError):
            adapter = Aws()
            adapter.session = session

            adapter.getResourceAdapterConfig()
コード例 #2
0
def test_invalid_adapter_configuration(dbm):
    """Ensure exception is raissed from missing required settings"""

    with dbm.session() as session:
        with pytest.raises(ConfigurationError):
            with patch.object(
                    ResourceAdapter, '_load_config_from_database', return_value={}):
                adapter = Aws()
                adapter.session = session

                adapter.getResourceAdapterConfig()
コード例 #3
0
def test_invalid_settings(load_config_dict_mock, dbm):
    load_config_dict_mock.return_value = {
        'ami': 'ami-XXXXXXXX',
        'unrecognized': 'setting',
        'another_bad_setting': 'value',
    }

    with dbm.session() as session:
        with pytest.raises(ConfigurationError):
            adapter = Aws()
            adapter.session = session

            adapter.getResourceAdapterConfig()
コード例 #4
0
def test_use_instance_hostname(load_config_dict_mock, dbm):
    load_config_dict_mock.return_value = {
        'ami': 'ami-XXXXXX',
        'override_dns_domain': 'true',
        'dns_domain': 'cloud.example.com',
        'use_instance_hostname': 'false',
    }

    with dbm.session() as session:
        adapter = Aws()
        adapter.session = session

        result = adapter.getResourceAdapterConfig()

        assert result['dns_domain'] == 'cloud.example.com'
コード例 #5
0
def test_minimal_config(dbm, minimal_configDict):
    with dbm.session() as session:
        with patch.object(
                ResourceAdapter, '_load_config_from_database',
                return_value=minimal_configDict):
            adapter = Aws()
            adapter.session = session

            config = adapter.getResourceAdapterConfig()

            assert 'ami' in config

            assert config['ami'] == 'ami-XXXXXXXX'

            assert isinstance(config['override_dns_domain'], bool)

            assert not config['override_dns_domain']
コード例 #6
0
def test_override_dns_domain_enabled_with_dns_domain(dbm):
    configDict = {
        'ami': 'ami-XXXXXXXX',
        'override_dns_domain': 'true',
        'dns_domain': 'mydomain',
    }

    with dbm.session() as session:
        with patch.object(
                ResourceAdapter, '_load_config_from_database',
                return_value=configDict):
            adapter = Aws()
            adapter.session = session

            config = adapter.getResourceAdapterConfig()

            assert isinstance(config['override_dns_domain'], bool)

            assert config['override_dns_domain']

            assert config['dns_domain'] == 'mydomain'
コード例 #7
0
def test_override_dns_domain_enabled(dbm):
    configDict = {
        'ami': 'ami-XXXXXXXX',
        'override_dns_domain': 'true',
    }

    with dbm.session() as session:
        with patch.object(
                ResourceAdapter, '_load_config_from_database',
                return_value=configDict):
            adapter = Aws()
            adapter.session = session

            config = adapter.getResourceAdapterConfig()

            assert isinstance(config['override_dns_domain'], bool)

            assert config['override_dns_domain']

            # when 'dns_domain' is not specified in the resource adapter
            # configuration, the current private DNS zone is used. We don't
            # care what the value is as long as there is one.
            assert isinstance(config['dns_domain'], str)
            assert config['dns_domain']
コード例 #8
0
def test_defaults(load_config_dict_mock, dbm):
    load_config_dict_mock.return_value = {
        'ami': 'ami-XXXXXXXX',
    }

    with dbm.session() as session:
        adapter = Aws()
        adapter.session = session

        result = adapter.getResourceAdapterConfig()

        assert result['ami'] == 'ami-XXXXXXXX'

        assert result['use_instance_hostname']

        assert result['associate_public_ip_address']

        assert not result['cloud_init']

        assert not result.get('override_dns_domain', None)

        assert not result.get('use_domain_from_dhcp_option_set', None)

        assert result['region'] == 'us-east-1'