Skip to content

Commit 67a20fd

Browse files
authored
Merge pull request #355 from Helene/conf_valid
Add validation for configuration empty values
2 parents 7846614 + 3b7c3e4 commit 67a20fd

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

source/confParser.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ def checkCAsettings(args):
9191
return True, ''
9292

9393

94+
def checkForInvalidsettings(args):
95+
if not all(args.values()):
96+
for key, value in args.items():
97+
if value is None or value == '':
98+
return False, MSG['InvalidConfigParm'].format(key)
99+
else:
100+
return True, ''
101+
102+
94103
def getSettings(argv):
95104
settings = {}
96105
args, msg = parse_cmd_args(argv)
@@ -102,6 +111,9 @@ def getSettings(argv):
102111
settings = vars(args)
103112
else:
104113
return None, msg
114+
valid, msg = checkForInvalidsettings(settings)
115+
if not valid:
116+
return None, msg
105117
# check application port
106118
valid, msg = checkApplicationPort(settings)
107119
if not valid:
@@ -127,7 +139,6 @@ def getSettings(argv):
127139

128140
def merge_defaults_and_args(defaults, args):
129141
'''merge default config parameters with input parameters from the command line'''
130-
brConfig = {}
131142
brConfig = dict(defaults)
132143
args = vars(args)
133144
brConfig.update({k: v for k, v in args.items() if v is not None and not (v == str(None))})
@@ -170,9 +181,9 @@ def readConfigFile(self, fileName):
170181
value = int(value)
171182
options[sect][name] = value
172183
except Exception as e:
173-
print(f"cannot read config file {fileName} Exception {e}")
184+
print(f"Error: Cannot read config file {fileName} Exception {e}")
174185
else:
175-
print(f"cannot find config file {fileName}")
186+
print(f"Error: Cannot find config file {fileName}")
176187
return options
177188

178189
def get_template_path(self):

source/config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ username = scale_admin
6565

6666
##################### GPFS Server ###############################################
6767
[server]
68-
# The ip address to bind to, empty will bind to all interfaces
68+
# The host name or ip address of the pmcollector node
6969
server = localhost
7070

7171
# The https port to use

source/messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'GroupByErr': 'In the current setup the group aggregation \'groupby\' is not possible.',
4545
'MetricErr': 'Metric {0} cannot be found. Please check if the corresponding sensor is configured',
4646
'InconsistentParams': 'Received parameters {} inconsistent with request parameters {}',
47+
'InvalidConfigParm': 'Configuration Parameter "{}" has not allowed value, quitting',
4748
'SensorDisabled': 'Sensor for metric {} is disabled',
4849
'SensorForceRawData': 'Sensor {} includes metrics type counter, which need to be collected as raw data',
4950
'EndpointNotSupported': 'Endpoint {} you try to access is not supported',

tests/test_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
def test_case01():
66
result = os.system('python ./source/zimonGrafanaIntf.py')
7-
assert result == 0
7+
assert result > 0
88

99

1010
def test_case02():
1111
result = os.system('python ./source/zimonGrafanaIntf.py -a 2')
12-
assert result == 0
12+
assert result > 0
1313

1414

1515
def test_case03():
@@ -19,7 +19,7 @@ def test_case03():
1919

2020
def test_case04():
2121
result = os.system('python ./source/zimonGrafanaIntf.py -c 10 -m "/opt/registry/certs"')
22-
assert result == 0
22+
assert result > 0
2323

2424

2525
def test_case05():

0 commit comments

Comments
 (0)