Skip to content

Commit 5fe3ed2

Browse files
committed
create config file with default config settings
1 parent ee520c1 commit 5fe3ed2

File tree

4 files changed

+89
-20
lines changed

4 files changed

+89
-20
lines changed

source/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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__)))

source/confParser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import logging.handlers
2626
from messages import MSG
27+
import configparser
2728

2829

2930
def 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+
4559
def parse_cmd_args(argv):
4660
'''parse input parameters'''
4761

source/config.ini

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

tests/test_params.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
import os
1+
from source.confParser import parse_defaults_from_config_file
22

33

44
def 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

98
def 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

1412
def 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

1918
def 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

2423
def 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

0 commit comments

Comments
 (0)