~lazypower/charms/trusty/haproxy/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

[sidnei] Fix tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
342
342
 
343
343
 
344
344
def parse_services_yaml(services, yaml_data):
345
 
    for service in yaml.safe_load(yaml_data):
 
345
    yaml_services = yaml.safe_load(yaml_data)
 
346
    if yaml_services is None:
 
347
        return services
 
348
 
 
349
    for service in yaml_services:
346
350
        service_name = service["service_name"]
347
351
        if not services:
348
352
            # 'None' is used as a marker for the first service defined, which
365
369
 
366
370
        services[service_name] = merge_service(
367
371
            services.get(service_name, {}), service)
 
372
 
368
373
    return services
369
374
 
370
375
 
435
440
 
436
441
    # Augment services_dict with service definitions from relation data.
437
442
    relation_data = relations_of_type("reverseproxy")
 
443
 
438
444
    for relation_info in relation_data:
439
445
        if "services" in relation_info:
440
446
            services_dict = parse_services_yaml(services_dict,
444
450
        log("No services configured, exiting.")
445
451
        return
446
452
 
447
 
    relation_data = relations_of_type("reverseproxy")
448
 
 
449
453
    for relation_info in relation_data:
450
454
        unit = relation_info['__unit__']
451
455
 
785
789
 
786
790
 
787
791
def notify_relation(relation, changed=False, relation_ids=None):
788
 
    config_data = config_get()
789
792
    default_host = get_hostname()
790
793
    default_port = 80
791
794
 
809
812
        if len(service_names) == 1:
810
813
            service_name = service_names.pop()
811
814
        elif len(service_names) > 1:
812
 
            log("Remote units requested than a single service name."
 
815
            log("Remote units requested more than a single service name."
813
816
                "Falling back to default host/port.")
814
817
 
815
818
        if service_name is not None:
822
825
            my_host = default_host
823
826
            my_port = default_port
824
827
 
 
828
        all_services = ""
 
829
        services_dict = create_services()
 
830
        if services_dict is not None:
 
831
            all_services = yaml.safe_dump(sorted(services_dict.itervalues()))
 
832
 
825
833
        relation_set(relation_id=rid, port=str(my_port),
826
834
                     hostname=my_host,
827
 
                     all_services=config_data['services'])
 
835
                     all_services=all_services)
828
836
 
829
837
 
830
838
def notify_website(changed=False, relation_ids=None):