← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~alisonken1/openlp/windows_lo_fix into lp:openlp

 

Ken Roberts has proposed merging lp:~alisonken1/openlp/windows_lo_fix into lp:openlp.

Commit message:
Fix windows not naming localhost interface to lo


Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~alisonken1/openlp/windows_lo_fix/+merge/352333

- Rename localhost to lo if found in iterfaces
- Add check for lo not in interface list before trying to remove lo
- Add extra log debug info
- Add test to check for get_local_ip4() returning no interfaces

--------------------------------------------------------------------------------
lp:~alisonken1/openlp/windows_lo_fix (revision 2825)
https://ci.openlp.io/job/Branch-01-Pull/2562/                          [SUCCESS]
https://ci.openlp.io/job/Branch-02a-Linux-Tests/2460/                  [SUCCESS]
https://ci.openlp.io/job/Branch-02b-macOS-Tests/242/                   [SUCCESS]
https://ci.openlp.io/job/Branch-03a-Build-Source/149/                  [SUCCESS]
https://ci.openlp.io/job/Branch-03b-Build-macOS/135/                   [SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code-Analysis/1611/                [SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test-Coverage/1424/                [SUCCESS]
https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/330/                 [FAILURE]

-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~alisonken1/openlp/windows_lo_fix into lp:openlp.
=== modified file 'openlp/core/common/__init__.py'
--- openlp/core/common/__init__.py	2018-04-17 19:26:18 +0000
+++ openlp/core/common/__init__.py	2018-08-03 22:40:28 +0000
@@ -64,13 +64,17 @@
     log.debug('Getting local IPv4 interface(es) information')
     my_ip4 = {}
     for iface in QNetworkInterface.allInterfaces():
+        log.debug('Checking for isValid and flags == IsUP | IsRunning')
         if not iface.isValid() or not (iface.flags() & (QNetworkInterface.IsUp | QNetworkInterface.IsRunning)):
             continue
+        log.debug('Checking address(es) protocol')
         for address in iface.addressEntries():
             ip = address.ip()
             # NOTE: Next line will skip if interface is localhost - keep for now until we decide about it later
             # if (ip.protocol() == QAbstractSocket.IPv4Protocol) and (ip != QHostAddress.LocalHost):
+            log.debug('Checking for protocol == IPv4Protocol')
             if ip.protocol() == QAbstractSocket.IPv4Protocol:
+                log.debug('Getting interface information')
                 my_ip4[iface.name()] = {'ip': ip.toString(),
                                         'broadcast': address.broadcast().toString(),
                                         'netmask': address.netmask().toString(),
@@ -79,14 +83,21 @@
                                                                  ip.toIPv4Address()).toString()
                                         }
                 log.debug('Adding {iface} to active list'.format(iface=iface.name()))
+    if 'localhost' in my_ip4:
+        log.debug('Renaming windows localhost to lo')
+        my_ip4['lo'] = my_ip4['localhost']
+        my_ip4.pop('localhost')
+    if len(my_ip4) == 0:
+        log.warning('No active IPv4 network interfaces detected')
     if len(my_ip4) == 1:
         if 'lo' in my_ip4:
             # No active interfaces - so leave localhost in there
             log.warning('No active IPv4 interfaces found except localhost')
     else:
         # Since we have a valid IP4 interface, remove localhost
-        log.debug('Found at least one IPv4 interface, removing localhost')
-        my_ip4.pop('lo')
+        if 'lo' in my_ip4:
+            log.debug('Found at least one IPv4 interface, removing localhost')
+            my_ip4.pop('lo')
 
     return my_ip4
 

=== added file 'tests/functional/openlp_core/common/test_network_interfaces.py'
--- tests/functional/openlp_core/common/test_network_interfaces.py	1970-01-01 00:00:00 +0000
+++ tests/functional/openlp_core/common/test_network_interfaces.py	2018-08-03 22:40:28 +0000
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection                                      #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2017 OpenLP Developers                                   #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it     #
+# under the terms of the GNU General Public License as published by the Free  #
+# Software Foundation; version 2 of the License.                              #
+#                                                                             #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    #
+# more details.                                                               #
+#                                                                             #
+# You should have received a copy of the GNU General Public License along     #
+# with this program; if not, write to the Free Software Foundation, Inc., 59  #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
+###############################################################################
+"""
+Functional tests to test calls for network interfaces.
+"""
+from unittest import TestCase
+from unittest.mock import MagicMock, call, patch
+
+import openlp.core.common
+from openlp.core.common import get_local_ip4
+
+from tests.helpers.testmixin import TestMixin
+
+lo_address_attrs = {'isValid.return_value': True,
+                    'flags.return_value': True,
+                    'InterfaceFlags.return_value': True,
+                    'name.return_value': 'lo',
+                    'broadcast.toString.return_value': '127.0.0.255',
+                    'netmask.toString.return_value': '255.0.0.0',
+                    'prefixLength.return_value': 8,
+                    'ip.protocol.return_value': True}
+
+
+class TestInterfaces(TestCase, TestMixin):
+    """
+    A test suite to test out functions/methods that use network interface(s).
+    """
+    def setUp(self):
+        """
+        Create an instance and a few example actions.
+        """
+        self.build_settings()
+
+        self.ip4_lo_address = MagicMock()
+        self.ip4_lo_address.configure_mock(**lo_address_attrs)
+
+    def tearDown(self):
+        """
+        Clean up
+        """
+        self.destroy_settings()
+
+    @patch.object(openlp.core.common, 'log')
+    def test_ip4_no_interfaces(self, mock_log):
+        """
+        Test no interfaces available
+        """
+        # GIVEN: Test environment
+        call_warning = [call('No active IPv4 network interfaces detected')]
+
+        with patch('openlp.core.common.QNetworkInterface') as mock_newtork_interface:
+            mock_newtork_interface.allInterfaces.return_value = []
+
+            # WHEN: get_local_ip4 is called
+            ifaces = get_local_ip4()
+
+            # THEN: There should not be any interfaces detected
+            assert not ifaces, 'There should have been no active interfaces'
+            mock_log.warning.assert_has_calls(call_warning)


Follow ups