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.get_config()
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.get_config()
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.get_config()
def test_get_user_data( load_config_dict_mock, get_config_path_mock): \ # pylint: disable=unused-argument """ Use mock data to expand SETTINGS macro """ file_contents = ''' #!/usr/bin/env python ### SETTINGS def main(): pass if __name__ == '__main__': main() ''' fp = io.StringIO(file_contents) adapter = Aws() config = adapter.get_config() result = adapter._Aws__get_user_data_script(fp, config) assert result and isinstance(result, str) assert get_config_path_mock.called_with('blah.txt')
def test_expand_cloud_init_user_data_template( load_config_dict_mock, get_config_path_mock): \ # pylint: disable=unused-argument """ Load sample data as Jinja2 template """ tmpl = ''' #!/usr/bin/env python installer = '{{ installer }}' def main(): pass if __name__ == '__main__': main() ''' adapter = Aws() config = adapter.get_config() result = adapter.expand_cloud_init_user_data_template( config, template=Template(tmpl)) assert result and isinstance(result, str) assert get_config_path_mock.called_with('notblah.txt')
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.get_config() assert result['dns_domain'] == 'cloud.example.com'
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.get_config() assert 'ami' in config assert config['ami'] == 'ami-XXXXXXXX' assert isinstance(config['override_dns_domain'], bool) assert not config['override_dns_domain']
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.get_config() assert isinstance(config['override_dns_domain'], bool) assert config['override_dns_domain'] assert config['dns_domain'] == 'mydomain'
def test_get_user_data_with_node( load_config_dict_mock, get_config_path_mock): \ # pylint: disable=unused-argument """ Use mock data to expand SETTINGS macro """ file_contents = ''' #!/usr/bin/env python ### SETTINGS def main(): pass if __name__ == '__main__': main() ''' fp = io.StringIO(file_contents) adapter = Aws() config = adapter.get_config() class DummyNode: def __init__(self, name): self.name = name node = DummyNode('mynode.example.com') result = adapter._Aws__get_user_data_script(fp, config, node=node) assert result and isinstance(result, str) assert get_config_path_mock.called_with('blah.txt')
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.get_config() 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']
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.get_config() 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'