Skip to content

Commit 704da0e

Browse files
committed
Fix: Don't show confusing logs
1 parent 5c846a2 commit 704da0e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def _readConfig():
100100
return None
101101

102102
def _readLegacyNetworkConfig():
103+
if not os.path.exists(constants.legacyNetworkConfigFilePath):
104+
return None
105+
103106
configParser = configparser.ConfigParser()
104107
configParser.read(constants.legacyNetworkConfigFilePath)
105108
try:
@@ -111,7 +114,7 @@ def _readLegacyNetworkConfig():
111114
}
112115
return networkConfig
113116
except KeyError as e:
114-
logging.error("Error when reading network.conf (1)")
117+
logging.error("Error when reading network.conf. It exists but is invalid.")
115118
logging.exception(e)
116119
return None
117120

usr/lib/python3/dist-packages/linuxmusterLinuxclient7/tests/test_config.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,23 @@ def test_network_both():
3434

3535
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf")
3636
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/does/not/exist/config.yml")
37-
def test_network_none():
37+
@mock.patch("linuxmusterLinuxclient7.config.logging.exception")
38+
def test_network_none(mockLoggingException):
39+
# make sure that no confusing error message is logged when config file does not exist
3840
rc, networkConfig = config.network()
3941
assert not rc
4042
assert networkConfig is None
43+
assert not mockLoggingException.called
44+
45+
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"{MOCK_FILE_PATH}/network.invalid.conf")
46+
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"/does/not/exist/config.yml")
47+
@mock.patch("linuxmusterLinuxclient7.config.logging.exception")
48+
def test_network_legacy_invalid(mockLoggingException):
49+
# make sure that an error message is logged when the legacy config file exists but is invalid
50+
rc, networkConfig = config.network()
51+
assert not rc
52+
assert networkConfig is None
53+
assert mockLoggingException.called
4154

4255
@mock.patch("linuxmusterLinuxclient7.config.constants.legacyNetworkConfigFilePath", f"/does/not/exist/network.conf")
4356
@mock.patch("linuxmusterLinuxclient7.config.constants.configFilePath", f"{MOCK_FILE_PATH}/config.invalid-network.yml")

0 commit comments

Comments
 (0)