diff --git a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py index a7b0876..adc7a37 100644 --- a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py +++ b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py @@ -100,6 +100,9 @@ def _readConfig(): return None def _readLegacyNetworkConfig(): + if not os.path.exists(constants.legacyNetworkConfigFilePath): + return None + configParser = configparser.ConfigParser() configParser.read(constants.legacyNetworkConfigFilePath) try: @@ -111,7 +114,7 @@ def _readLegacyNetworkConfig(): } return networkConfig except KeyError as e: - logging.error("Error when reading network.conf (1)") + logging.error("Error when reading network.conf. It exists but is invalid.") logging.exception(e) return None diff --git a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/imageHelper.py b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/imageHelper.py index b8c176b..2212a5a 100644 --- a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/imageHelper.py +++ b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/imageHelper.py @@ -126,11 +126,13 @@ def _clearUserCache(unattended=False): if not _checkLoggedInUsers(): return False - realm.clearUserCache() + result = realm.clearUserCache() + if not result: + logging.error("Failed to clear user cache!") + return False logging.info("Done.") - - return realm.clearUserCache() + return True def _unmountAllCifsMounts(): logging.info("Unmounting all CIFS mounts!") diff --git a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/setup.py b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/setup.py index 2a03e79..836a7db 100644 --- a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/setup.py +++ b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/setup.py @@ -15,7 +15,8 @@ def setup(domain=None, user=None): """ logging.info('#### linuxmuster-linuxclient7 setup ####') - if not realm.clearUserCache(): + userCacheCleared = realm.clearUserCache() + if not userCacheCleared and isSetup(): return False if not _cleanOldDomainJoins(): diff --git a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_config.py b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_config.py index 576c224..edb4688 100644 --- a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_config.py +++ b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_config.py @@ -34,10 +34,23 @@ def test_network_both(): @mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf") @mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/does/not/exist/config.yml") -def test_network_none(): +@mock.patch("linuxmusterLinuxclient7.config.logging.exception") +def test_network_none(mockLoggingException): + # make sure that no confusing error message is logged when config file does not exist rc, networkConfig = config.network() assert not rc assert networkConfig is None + assert not mockLoggingException.called + +@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"{MOCK_FILE_PATH}/network.invalid.conf") +@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/does/not/exist/config.yml") +@mock.patch("linuxmusterLinuxclient7.config.logging.exception") +def test_network_legacy_invalid(mockLoggingException): + # make sure that an error message is logged when the legacy config file exists but is invalid + rc, networkConfig = config.network() + assert not rc + assert networkConfig is None + assert mockLoggingException.called @mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf") @mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"{MOCK_FILE_PATH}/config.invalid-network.yml")