def any_changed_state(state, *args): from comitup.states import dns_names from comitup import mdns interesting_states = PASS_STATES + FAIL_STATES if state in interesting_states: mdns.clear_entries() mdns.add_hosts(dns_names)
def test_avahi_clear_entries(avahi_fxt): isempty = Mock(return_value=False) mdns.group = Mock() mdns.group.IsEmpty = isempty mdns.clear_entries() assert isempty.called assert mdns.group.Reset.called assert mdns.establish_group.called assert not mdns.log.called
def hotspot_pass(): log.debug("Activating mdns") # IP tolerance for PI 2 for _ in range(5): log.debug("states: Calling nm.get_active_ip()") ip = nm.get_active_ip(modemgr.get_state_device('HOTSPOT')) if ip: mdns.clear_entries() mdns.add_hosts(dns_names) break time.sleep(1)
def connected_start(): global conn_list # IP tolerance for PI 2 for _ in range(5): log.debug("states: Calling nm.get_active_ip()") ip = nm.get_active_ip(modemgr.get_state_device('CONNECTED')) if ip: mdns.clear_entries() mdns.add_hosts(dns_names) break time.sleep(1) conn_list = []
def connecting_start(): global conn_list mdns.clear_entries() if conn_list: log.debug("states: Calling nm.disconnect()") nm.disconnect(modemgr.get_state_device('CONNECTING')) conn = conn_list.pop(0) log.info('Attempting connection to %s' % conn) activate_connection(conn, 'CONNECTING') else: set_state('HOTSPOT')
def hotspot_start(): global conn_list log.info("Activating hotspot") hs_ssid = dns_to_conn(dns_names[0]) log.debug("states: Calling nm.get_active_ssid()") if hs_ssid != nm.get_active_ssid(modemgr.get_state_device('HOTSPOT')): mdns.clear_entries() conn_list = [] activate_connection(hs_ssid, 'HOTSPOT') else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass)
def hotspot_start(dummy: int) -> None: global conn_list log.info("Activating hotspot") if startup: mdns.clear_entries() mdns.add_hosts(dns_names) hs_ssid: str = dns_to_conn(dns_names[0]) if startup and modemgr.get_mode() == modemgr.SINGLE_MODE: log.debug("Passing on hotspot connection for now") timeout_add(100, fake_hs_pass, state_id) elif hs_ssid != nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")): conn_list = [] log.debug("Activating connection {}".format(hs_ssid)) activate_connection(hs_ssid, "HOTSPOT") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass, state_id)
def hotspot_start(): global conn_list log.info("Activating hotspot") hs_ssid = dns_to_conn(dns_names[0]) # if we are in two-wifi device mode, skip the reconnect if possible, # to avoid kicking some clients off log.debug("states: Calling nm.get_active_ssid()") if hs_ssid != nm.get_active_ssid(modemgr.get_state_device('HOTSPOT')): mdns.clear_entries() conn_list = [] # tolerate Raspberry Pi 2 try: activate_connection(hs_ssid, 'HOTSPOT') except DBusException: log.warn("Error connecting hotspot") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass)
def connecting_start(): global conn_list mdns.clear_entries() if conn_list: log.debug("states: Calling nm.disconnect()") nm.disconnect(modemgr.get_state_device('CONNECTING')) conn = conn_list.pop(0) log.info('Attempting connection to %s' % conn) activate_connection(conn, 'CONNECTING') else: # Give NetworkManager a chance to update the access point list try: # todo - clean this up log.debug("states: Calling nm.deactivate_connection()") nm.deactivate_connection(modemgr.get_state_device('CONNECTING')) except DBusException: pass time.sleep(5) set_state('HOTSPOT')
def test_avahi_clear_fail(warn, avahi_fxt): mdns.group = None mdns.clear_entries()
def reset_mdns(): mdns.clear_entries() mdns.add_hosts(dns_names)