def test_seeds_references_dont_error(self): # If a node doesn't have a seed environment/node, then no jinja # templates that rely on properties on those should raise errors. All # values will be None environments = { NeckbeardLoader.VERSION_OPTION: '0.1', 'test1': { 'name': 'test1', 'aws_nodes': { 'ec2': { 'web0': { "name": "web0", "unique_id": "web0-{{ node.scaling_index }}", "env_constant": "{{ seed_environment.constants.foo }}", # NOQA "env_secret": "{{ seed_environment.secrets.foo }}", "env_name": "{{ seed_environment.name }}", "node_foo": "{{ seed_node.foo }}", }, }, }, }, } configuration = ConfigurationManager( environments=environments, scaling_backend=MaxScalingBackend(), ) expanded_configuration = configuration.get_environment_config( 'test1', ) expected = { 'ec2': { 'web0-0': { "name": "web0", "unique_id": "web0-0", "env_constant": "", "env_secret": "", "env_name": "", "node_foo": "", }, }, } self.assertEqual(expanded_configuration, expected)
def test_environment_configuration(self): # Integration test for full environment configuration parsing secrets = { NeckbeardLoader.VERSION_OPTION: '0.1', 'environments': { 'test1': { 'foo': 'v_secret1', }, 'test2': { 'foo': 'v_secret2', }, }, } constants = { NeckbeardLoader.VERSION_OPTION: '0.1', 'environments': { 'test1': { 'foo': 'v_foo1', }, 'test2': { 'foo': 'v_foo2', }, }, } environments = { NeckbeardLoader.VERSION_OPTION: '0.1', 'test1': { 'name': 'test1', 'seed_environment_name': 'test2', 'aws_nodes': { 'ec2': { 'web0': { "name": "web0", "unique_id": "web0-{{ node.scaling_index }}", "node_template_name": "web", "seed": { "name": "web", }, "service_addons": { "redis": { "foo": "web0", }, }, }, 'web1': { "name": "web1", "unique_id": "web1-{{ node.scaling_index }}", "node_template_name": "web", "seed": { "name": "web", }, "service_addons": { "redis": { "foo": "web1", }, }, "scaling": { "minimum": 1, "maximum": 2, }, }, }, }, }, 'test2': { 'name': 'test2', 'aws_nodes': { 'ec2': { 'web': { "name": "web", "unique_id": "web-{{ node.scaling_index }}", }, }, }, }, } node_templates = { 'ec2': { "web": { NeckbeardLoader.VERSION_OPTION: '0.1', "resource_type": "ec2", "node_template_name": "web", "defaults": { "service_addons": { "redis": { "foo": "overridden", "from_template": "v_from_template", }, "celery": { "celerybeat": True, }, }, "constant_foo": "{{ environment.constants.foo }}", "secret_foo": "{{ environment.secrets.foo }}", "s_const_foo": "{{ seed_environment.constants.foo }}", "s_secret_foo": "{{ seed_environment.secrets.foo }}", }, "required_overrides": {}, }, }, } configuration = ConfigurationManager( constants=constants, secrets=secrets, secrets_tpl={}, environments=environments, node_templates=node_templates, scaling_backend=MaxScalingBackend(), ) expanded_configuration = configuration.get_environment_config( 'test1', ) expected = { "ec2": { 'web0-0': { "name": "web0", "unique_id": "web0-0", "node_template_name": "web", "seed": { "name": "web", }, "service_addons": { "redis": { "foo": "web0", "from_template": "v_from_template", }, "celery": { "celerybeat": True, }, }, "constant_foo": "v_foo1", "secret_foo": "v_secret1", "s_const_foo": "v_foo2", "s_secret_foo": "v_secret2", }, 'web1-0': { "name": "web1", "unique_id": "web1-0", "node_template_name": "web", "seed": { "name": "web", }, "service_addons": { "redis": { "foo": "web1", "from_template": "v_from_template", }, "celery": { "celerybeat": True, }, }, "scaling": { "minimum": 1, "maximum": 2, }, "constant_foo": "v_foo1", "secret_foo": "v_secret1", "s_const_foo": "v_foo2", "s_secret_foo": "v_secret2", }, 'web1-1': { "name": "web1", "unique_id": "web1-1", "node_template_name": "web", "seed": { "name": "web", }, "service_addons": { "redis": { "foo": "web1", "from_template": "v_from_template", }, "celery": { "celerybeat": True, }, }, "scaling": { "minimum": 1, "maximum": 2, }, "constant_foo": "v_foo1", "secret_foo": "v_secret1", "s_const_foo": "v_foo2", "s_secret_foo": "v_secret2", }, }, } # Ensure all of the unique nodes exist actual_unique_ids = expanded_configuration['ec2'].keys() for unique_id in expected['ec2'].keys(): self.assertTrue( unique_id in actual_unique_ids, msg="%s not in ec2 resources. Actuals: %s" % ( unique_id, actual_unique_ids, ), ) # Test that the individual configurations actually match for unique_id in expected['ec2'].keys(): self.assertDictEqual( expanded_configuration['ec2'][unique_id], expected['ec2'][unique_id], msg="Config doesn't match for %s" % unique_id, )
def test_config_data_types(self): # Lists, dictionaries, integers, strings, booleans and floats should # all be valid configuration values environments = { NeckbeardLoader.VERSION_OPTION: '0.1', 'test1': { 'name': 'test1', 'aws_nodes': { 'ec2': { 'web0': { "name": "web0", "unique_id": "web0-{{ node.scaling_index }}", "service_addons": { "list": [ "item1", 1, 1.0, True, None, ], "unicode": u'unicode', "int": 1, "float": 110.05, "bool": False, "none": None, }, }, }, }, }, } configuration = ConfigurationManager( environments=environments, scaling_backend=MaxScalingBackend(), ) expanded_configuration = configuration.get_environment_config( 'test1', ) expected = { 'ec2': { 'web0-0': { "name": "web0", "unique_id": "web0-0", "service_addons": { "list": [ "item1", 1, 1.0, True, None, ], "unicode": u'unicode', "int": 1, "float": 110.05, "bool": False, "none": None, }, }, }, } self.assertEqual(expanded_configuration, expected)