Example #1
0
def process_inotify_event(event, services_by_dependencies, soa_dir,
                          synapse_service_dir):
    filename = event[3].decode()
    log.debug('process_inotify_event on {}'.format(filename))

    service_instance, suffix = os.path.splitext(filename)
    if suffix != '.json':
        return

    services_to_update = services_by_dependencies.get(service_instance, ())
    if not services_to_update:
        return

    # filter active_service_groups() down to just the names in services_to_update
    service_groups = {
        service_group: macs
        for service_group, macs in firewall.active_service_groups().items()
        if service_group in services_to_update
    }

    try:
        with firewall.firewall_flock():
            firewall.ensure_service_chains(service_groups, soa_dir,
                                           synapse_service_dir)

        for service_to_update in services_to_update:
            log.debug('Updated {}'.format(service_to_update))
    except TimeoutError as e:
        log.error(
            'Unable to update firewalls for {} because time-out obtaining flock: {}'
            .format(
                service_groups.keys(),
                e,
            ), )
Example #2
0
def test_active_service_groups(mock_service_config, mock_services_running_here):
    assert firewall.active_service_groups() == {
        firewall.ServiceGroup("example_happyhour", "main"): {
            "02:42:a9:fe:00:00",
            "02:42:a9:fe:00:01",
        },
        firewall.ServiceGroup("example_happyhour", "batch"): {"02:42:a9:fe:00:02"},
        firewall.ServiceGroup("my_cool_service", "web"): {
            "02:42:a9:fe:00:03",
            "02:42:a9:fe:00:04",
        },
    }
Example #3
0
def test_active_service_groups(mock_service_config, mock_services_running_here):
    assert firewall.active_service_groups() == {
        firewall.ServiceGroup('example_happyhour', 'main'): {
            '02:42:a9:fe:00:00',
            '02:42:a9:fe:00:01',
        },
        firewall.ServiceGroup('example_happyhour', 'batch'): {
            '02:42:a9:fe:00:02',
        },
        firewall.ServiceGroup('my_cool_service', 'web'): {
            '02:42:a9:fe:00:03',
            '02:42:a9:fe:00:04',
        },
    }