def test_direct_linking(): with open("tests/stack-confs/direct-linking-stack-conf.yml") as stack_conf: stack_conf = StackConf(stack_conf) linked_services = linker.link_services(stack_conf.get('services'), "ec2") auth_plus = find_by_attr(linked_services, 'name', 'auth-plus') assert auth_plus.get( 'env')["CASSANDRA_HOST"] == "{{ groups.cassandra[0] }}"
def test_name_is_required(valid_service): with pytest.raises(SchemaError): conf = { 'security_groups': [{ 'description': 'A generated security group' }] } StackConf(merge_dicts(conf, valid_service))
def expand_stack(args): """Parse the stack file and expand it with the variables in the configuration :args: The argument array :return: The arguments, with a expanded and parsed stack""" args.stack = StackConf(args.stack, args.config) return args
def test_link_via_env(): stack_conf_file = "tests/stack-confs/auth-plus-linking-stack-conf.yml" with open(stack_conf_file) as stack_conf: stack_conf = StackConf(stack_conf) linked_services = linker.link_services(stack_conf.get('services'), "ec2") expected = { "CASSANDRA_PORT": 9042, "CASSANDRA_HOST": "{{ groups.haproxy[0] }}", "CASSANDRA_PORT_9042_TCP_ADDR": "{{ groups.haproxy[0] }}", "REDIS_PORT": 6379, "REDIS_HOST": "{{ groups.haproxy[0] }}", "REDIS_PORT_6379_TCP_ADDR": "{{ groups.haproxy[0] }}", "DEVICE_INFO_PORT": 9002, "DEVICE_INFO_HOST": "{{ groups.haproxy[0] }}", "DEVICE_INFO_PORT_9002_TCP_ADDR": "{{ groups.haproxy[0] }}" } auth_plus = find_by_attr(linked_services, 'name', 'auth-plus') assert auth_plus.get('env') == expected
def run_schema_error_test(stack): """ Generate a playbook from a stack conf, that is expected to raise an Exception """ with pytest.raises(SchemaError): with open(CONFIG, 'r') as configuration: config = LauncherConf(configuration) yaml.load(playbook_generate(StackConf(stack), config))
def test_scheduler_schema(): stack = { 'services': [{ 'name': 'test_service', 'repo': 'test/repo', 'schedule': [{ 'onboot': '2min', 'schedule': '5min', 'description': 'something' }] }] } with open(CONFIG, 'r') as configuration: config = LauncherConf(configuration) yaml.load(playbook_generate(StackConf(stack), config))
def run_generator_test(generator, stackfile, playbook, index=False, configfile=CONFIG): """ Run a test by comparing an expected playbook with one generated by the generator function """ with open(configfile) as launcher_conf: config = LauncherConf(launcher_conf) with open(stackfile) as stack_conf: stack = StackConf(stack_conf) generated_playbook = yaml.load(generator(stack, config)) expected_playbook = parse_yaml_config(playbook) if not index: assert generated_playbook == expected_playbook else: for i in index: assert generated_playbook[i] == expected_playbook[i]
def test_pull_is_valid(valid_service): StackConf(valid_service)
def test_direct_linking(): with open("tests/stack-confs/direct-linking-stack-conf.yml") as stack_conf: stack_conf = StackConf(stack_conf) linked_services = linker.link_services(stack_conf.get('services'), "ec2") auth_plus = find_by_attr(linked_services, 'name', 'auth-plus') assert auth_plus.get('env')["CASSANDRA_HOST"] == "{{ groups.cassandra[0] }}"
def test_link_retains_env_variables(): with open("tests/stack-confs/direct-linking-stack-conf.yml") as stack_conf: stack_conf = StackConf(stack_conf) linker.link_services(stack_conf.get('services'), "ec2") auth_plus = find_by_attr(stack_conf.get('services'), 'name', 'auth-plus') assert auth_plus.get('env')["ENV_VAR_THAT"] == "should_still_be_here"
def test_name_is_a_str(valid_security_group): with pytest.raises(SchemaError): conf = {'services': [{'repo': 'test'}]} StackConf(merge_dicts(conf, valid_security_group))
def test_attach_is_valid(valid_service): StackConf(valid_service)