def start_zeroconf(): """ Start the Zeroconf service """ # When we're running tests, just skip this set up if this flag is set if Registry().get_flag('no_web_server'): return http_port = Settings().value('api/port') ws_port = Settings().value('api/websocket port') for name, interface in get_network_interfaces().items(): worker = ZeroconfWorker(interface['ip'], http_port, ws_port) run_thread(worker, 'api_zeroconf_{name}'.format(name=name))
def get_ip_address(self, ip_address): """ returns the IP address in dependency of the passed address ip_address == 0.0.0.0: return the IP address of the first valid interface else: return ip_address """ if ip_address == ZERO_URL: # In case we have more than one interface for _, interface in get_network_interfaces().items(): ip_address = interface['ip'] # We only want the first interface returned break return ip_address
def test_network_interfaces_no_interfaces(self, mock_log): """ Test no interfaces available """ # GIVEN: Test environment call_debug = [call('Getting local IPv4 interface(es) information')] call_warning = [call('No active IPv4 network interfaces detected')] # WHEN: get_network_interfaces() is called with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: mock_network_interface.allInterfaces.return_value = [] interfaces = get_network_interfaces() # THEN: There should not be any interfaces detected mock_log.debug.assert_has_calls(call_debug) mock_log.warning.assert_has_calls(call_warning) assert not interfaces, 'There should have been no active interfaces listed'
def test_network_interfaces_localhost(self, mock_log): """ Test get_network_interfaces() returns an empty dictionary if "localhost" is the only network interface """ # GIVEN: Test environment call_debug = [ call('Getting local IPv4 interface(es) information'), call('Filtering out interfaces we don\'t care about: localhost') ] # WHEN: get_network_interfaces() is called with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: mock_network_interface.allInterfaces.return_value = [self.fake_localhost] interfaces = get_network_interfaces() # THEN: There should be no interfaces mock_log.debug.assert_has_calls(call_debug) assert interfaces == {}, 'There should be no interfaces listed'
def test_network_interfaces_invalid(self, mock_log): """ Test get_network_interfaces() returns an empty dictionary when there are no valid interfaces """ # GIVEN: Test environment call_debug = [ call('Getting local IPv4 interface(es) information'), call('Checking for isValid and flags == IsUP | IsRunning') ] call_warning = [call('No active IPv4 network interfaces detected')] # WHEN: get_network_interfaces() is called with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: mock_network_interface.allInterfaces.return_value = [self.invalid_if] interfaces = get_network_interfaces() # THEN: There should be a fake 'eth25' interface mock_log.debug.assert_has_calls(call_debug) mock_log.warning.assert_has_calls(call_warning) assert interfaces == {}, 'There should not be any interfaces listed'
def test_network_interfaces_eth25(self, mock_log): """ Test get_network_interfaces() returns proper dictionary with 'eth25' """ # GIVEN: Test environment call_debug = [ call('Getting local IPv4 interface(es) information'), call('Checking for isValid and flags == IsUP | IsRunning'), call('Checking address(es) protocol'), call('Checking for protocol == IPv4Protocol'), call('Getting interface information'), call('Adding eth25 to active list') ] # WHEN: get_network_interfaces() is called with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: mock_network_interface.allInterfaces.return_value = [self.fake_address] interfaces = get_network_interfaces() # THEN: There should be a fake 'eth25' interface mock_log.debug.assert_has_calls(call_debug) assert interfaces == self.fake_address.fake_data