Skip to content

Commit 76f8d57

Browse files
committed
CLI/Error: add error handling for malformed groups.conf (#379)
Handle configparser's exceptions in case of malformed clush.conf or groups.conf. Closes #379 Change-Id: Iffa3bf3f425affefd976a4c4f252a3dcee7fda1a
1 parent 7ea95c0 commit 76f8d57

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/ClusterShell/CLI/Error.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323

2424
from __future__ import print_function
2525

26+
try:
27+
import configparser
28+
except ImportError:
29+
# Python 2 compat
30+
import ConfigParser as configparser
31+
2632
import errno
2733
import logging
2834
import os.path
@@ -42,7 +48,8 @@
4248
from ClusterShell.Worker.EngineClient import EngineClientError
4349
from ClusterShell.Worker.Worker import WorkerError
4450

45-
GENERIC_ERRORS = (EngineNotSupportedError,
51+
GENERIC_ERRORS = (configparser.Error,
52+
EngineNotSupportedError,
4653
EngineClientError,
4754
NodeSetExternalError,
4855
NodeSetParseError,
@@ -88,6 +95,8 @@ def handle_generic_error(excobj, prog=os.path.basename(sys.argv[0])):
8895
print("%s: Group error: %s" % (prog, exc), file=sys.stderr)
8996
except TopologyError as exc:
9097
print("%s: TREE MODE: %s" % (prog, exc), file=sys.stderr)
98+
except configparser.Error as exc:
99+
print("%s: %s" % (prog, exc), file=sys.stderr)
91100
except (TypeError, WorkerError) as exc:
92101
print("%s: %s" % (prog, exc), file=sys.stderr)
93102
except (IOError, OSError) as exc: # see PEP 3151

tests/CLINodesetTest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,19 @@ def tearDown(self):
823823
def test_empty_groups_conf(self):
824824
"""test nodeset with empty groups.conf"""
825825
self._nodeset_t(["--list-all"], None, b"")
826+
827+
828+
class CLINodesetMalformedGroupsConf(CLINodesetTestBase):
829+
"""Unit test class for testing malformed groups.conf"""
830+
831+
def setUp(self):
832+
self.gconff = make_temp_file(b"[Main")
833+
set_std_group_resolver(GroupResolverConfig(self.gconff.name))
834+
835+
def tearDown(self):
836+
set_std_group_resolver(None)
837+
self.gconff = None
838+
839+
def test_malformed_groups_conf(self):
840+
"""test nodeset with malformed groups.conf"""
841+
self._nodeset_t(["--list-all"], None, b"", 1, b"'[Main'\n")

0 commit comments

Comments
 (0)