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_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 link_via_haproxy(service, services): """ creates a dict of env vars for haproxy linking :service: a Service object :service: array of Service objects :returns: Dict """ new_env = {} for link in service.get('links'): parsed_link_name = link.split("[direct]") direct = True if len(parsed_link_name) > 1 else False link_name = parsed_link_name[0] linked_service = find_by_attr(services, 'name', link_name) linked_port = linked_service.get('advertised_port') new_env.update(generate_env_vars(link_name, linked_port, direct)) return new_env
def create_migration(self, service): """ return migration tasks. :service: a service object :returns: string """ migrations = "\n" if service.get('migrations').get('cql', None) is not None: files = service.get('migrations')['cql'] if service.get('links'): host = "local" else: host = find_by_attr(self.stack.data['services'], 'name', 'cassandra').get('host') + '[0]' migrations += apply_template('cql_migration.yml', service=service, files=files, host=host) return migrations
def add_logging_to_nodes(nodes): """ adds logging services to nodes :nodes: list of nodes :returns: None """ logging_master = find_by_attr(nodes, 'logging_master', True) master_logging_services = ['elasticsearch', 'logstash', 'logspout', 'kibana'] for i in xrange(len(nodes)): if nodes[i] == logging_master: logging_services = master_logging_services else: logging_services = ['logspout'] nodes[i].set('services', prepend(nodes[i].get('services'), logging_services))
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"