File tree Expand file tree Collapse file tree 4 files changed +89
-20
lines changed
Expand file tree Collapse file tree 4 files changed +89
-20
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ ##############################################################################
3+ # Copyright 2019 IBM Corp.
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+ ##############################################################################
17+
18+ Created on Apr 4, 2017
19+
20+ @author: HWASSMAN
21+ '''
22+ import os
23+ import sys
24+ sys .path .insert (0 , os .path .abspath (os .path .dirname (__file__ )))
Original file line number Diff line number Diff line change 2424import os
2525import logging .handlers
2626from messages import MSG
27+ import configparser
2728
2829
2930def findKeyFile (path ):
@@ -42,6 +43,19 @@ def findCertFile(path):
4243 return None
4344
4445
46+ def parse_defaults_from_config_file (fileName = 'config.ini' ):
47+ defaults = {}
48+ dirname , filename = os .path .split (os .path .abspath (__file__ ))
49+ conf_file = os .path .join (dirname , fileName )
50+ if os .path .isfile (conf_file ):
51+ config = configparser .ConfigParser ()
52+ config .read (conf_file )
53+ for sect in config .sections ():
54+ for name , value in config .items (sect ):
55+ defaults [name ] = value
56+ return defaults
57+
58+
4559def parse_cmd_args (argv ):
4660 '''parse input parameters'''
4761
Original file line number Diff line number Diff line change 1+ # #################### Grafana Connection Defaults ############################
2+ [connection]
3+ # port number the bridge listening on for Grafana data requests
4+ # 4242 - for HTTP connections
5+ # 8443 - for HTTPS connections
6+ # (Default: 4242)
7+ port = 4242
8+
9+ # ################################### Grafana Generic OAuth ####################
10+ [tls]
11+ # Directory path of tls key and cert file location
12+ # tlsKeyPath = /etc/bridge_cert/
13+
14+ #
15+ # tlsKeyFile = privkey.pem
16+
17+ #
18+ # tlsCertFile = cert.pem
19+
20+ # ################################### GPFS Server ##############################
21+ [server]
22+ # The ip address to bind to, empty will bind to all interfaces
23+ server = localhost
24+
25+ # The http port to use
26+ serverPort = 9084
27+
28+ # ################################### Logging ##################################
29+ [logging]
30+ # Directory where the bridge can store logs
31+ logPath = /var/log/ibm_bridge_for_grafana
32+
33+ # log level 10 (DEBUG), 20 (INFO), 30 (WARN), 40 (ERROR) (Default: 20)
34+ logLevel = 20
35+
36+ # Log file name (Default: zserver.log)
37+ logFile = zserver.log
Original file line number Diff line number Diff line change 1- import os
1+ from source . confParser import parse_defaults_from_config_file
22
33
44def test_case01 ():
5- result = os .system ("python ./source/zimonGrafanaIntf.py" )
6- assert result == 0
7-
5+ result = parse_defaults_from_config_file ()
6+ assert isinstance (result , dict )
87
98def test_case02 ():
10- result = os .system ("python ./source/zimonGrafanaIntf.py --port 4242" )
11- assert result == 0
12-
9+ result = parse_defaults_from_config_file ()
10+ assert len (result .keys ()) > 0
1311
1412def test_case03 ():
15- result = os .system ("python ./source/zimonGrafanaIntf.py -c 10" )
16- assert result == 0
17-
13+ result = parse_defaults_from_config_file ()
14+ elements = list (result .keys ())
15+ mandatoryItems = ['port' ,'serverport' ]
16+ assert all (item in elements for item in mandatoryItems )
1817
1918def test_case04 ():
20- result = os . system ( "python ./source/zimonGrafanaIntf.py --port 8443" )
21- assert result > 0
22-
19+ result = parse_defaults_from_config_file ( )
20+ value = int ( result [ 'port' ])
21+ assert value == 4242
2322
2423def test_case05 ():
25- result = os .system ('python ./source/zimonGrafanaIntf.py --port 8443 --tlsKeyPath "/tmp"' )
26- assert result > 0
27-
28-
29- def test_case06 ():
30- result = os .system ('python ./source/zimonGrafanaIntf.py -a 2' )
31- assert result > 0
24+ result = parse_defaults_from_config_file ()
25+ assert int (result ['port' ]) == 4242 and int (result ['serverport' ]) == 9084
You can’t perform that action at this time.
0 commit comments