Skip to content

Commit 4c95d65

Browse files
author
Grégory Starck
committed
Update configuration template for server config
Server configuration file changed. Adapted the test template config file. Slightly adapted InfluxDbInstance.__init__() : The client have now to connect to the "webui_port".
1 parent ef27887 commit 4c95d65

File tree

3 files changed

+66
-159
lines changed

3 files changed

+66
-159
lines changed

tests/influxdb/client_test_with_server.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class InfluxDbInstance(object):
133133
in a temporary place, using a config file template.
134134
'''
135135

136-
def __init__(self, conf_template):
136+
def __init__(self, conf_template, udp_enabled=False):
137137
# create a temporary dir to store all needed files
138138
# for the influxdb server instance :
139139
self.temp_dir_base = tempfile.mkdtemp()
@@ -142,28 +142,28 @@ def __init__(self, conf_template):
142142
tempdir = self.temp_dir_influxdb = tempfile.mkdtemp(
143143
dir=self.temp_dir_base)
144144
# we need some "free" ports :
145-
self.broker_port = get_free_port()
146-
self.admin_port = get_free_port()
147-
self.udp_port = get_free_port()
148-
self.snapshot_port = get_free_port()
149-
150-
self.logs_file = os.path.join(self.temp_dir_base, 'logs.txt')
151-
152-
with open(conf_template) as fh:
153-
conf = fh.read().format(
154-
broker_port=self.broker_port,
155-
admin_port=self.admin_port,
156-
udp_port=self.udp_port,
157-
broker_raft_dir=os.path.join(tempdir, 'raft'),
158-
broker_node_dir=os.path.join(tempdir, 'db'),
159-
cluster_dir=os.path.join(tempdir, 'state'),
160-
logfile=self.logs_file,
161-
snapshot_port=self.snapshot_port,
162-
)
145+
146+
ports = dict(
147+
broker_port=get_free_port(),
148+
webui_port=get_free_port(),
149+
admin_port=get_free_port(),
150+
udp_port=get_free_port() if udp_enabled else -1,
151+
)
152+
153+
conf_data = dict(
154+
broker_raft_dir=os.path.join(tempdir, 'raft'),
155+
broker_node_dir=os.path.join(tempdir, 'db'),
156+
cluster_dir=os.path.join(tempdir, 'state'),
157+
logs_file=os.path.join(self.temp_dir_base, 'logs.txt'),
158+
udp_enabled='true' if udp_enabled else 'false',
159+
)
160+
conf_data.update(ports)
161+
self.__dict__.update(conf_data)
163162

164163
conf_file = os.path.join(self.temp_dir_base, 'influxdb.conf')
165164
with open(conf_file, "w") as fh:
166-
fh.write(conf)
165+
with open(conf_template) as fh_template:
166+
fh.write(fh_template.read().format(**conf_data))
167167

168168
# now start the server instance:
169169
proc = self.proc = subprocess.Popen(
@@ -182,8 +182,13 @@ def __init__(self, conf_template):
182182
# or you run a 286 @ 1Mhz ?
183183
try:
184184
while time.time() < timeout:
185-
if (is_port_open(self.broker_port)
185+
if (is_port_open(self.webui_port)
186186
and is_port_open(self.admin_port)):
187+
# it's hard to check if a UDP port is open..
188+
if udp_enabled:
189+
# so let's just sleep 0.5 sec in this case
190+
# to be sure that the server has open the port
191+
time.sleep(0.5)
187192
break
188193
time.sleep(0.5)
189194
if proc.poll() is not None:
@@ -192,13 +197,13 @@ def __init__(self, conf_template):
192197
proc.terminate()
193198
proc.wait()
194199
raise RuntimeError('Timeout waiting for influxdb to listen'
195-
' on its broker port')
200+
' on its ports (%s)' % ports)
196201
except RuntimeError as err:
197202
data = self.get_logs_and_output()
198203
data['reason'] = str(err)
199204
data['now'] = datetime.datetime.now()
200205
raise RuntimeError("%(now)s > %(reason)s. RC=%(rc)s\n"
201-
"stdout=%(out)r\nstderr=%(err)r\nlogs=%(logs)r"
206+
"stdout=%(out)s\nstderr=%(err)s\nlogs=%(logs)r"
202207
% data)
203208

204209
def get_logs_and_output(self):
@@ -225,9 +230,11 @@ def close(self, remove_tree=True):
225230

226231

227232
def _setup_influxdb_server(inst):
228-
inst.influxd_inst = InfluxDbInstance(inst.influxdb_template_conf)
233+
inst.influxd_inst = InfluxDbInstance(
234+
inst.influxdb_template_conf,
235+
udp_enabled=getattr(inst, 'influxdb_udp_enabled', False))
229236
inst.cli = InfluxDBClient('localhost',
230-
inst.influxd_inst.broker_port,
237+
inst.influxd_inst.webui_port,
231238
'root', '', database='db')
232239

233240

@@ -653,12 +660,14 @@ def test_tags_json_order(self):
653660
class UdpTests(ManyTestCasesWithServerMixin,
654661
unittest.TestCase):
655662

663+
influxdb_udp_enabled = True
664+
656665
influxdb_template_conf = os.path.join(THIS_DIR,
657-
'influxdb.udp_conf.template')
666+
'influxdb.conf.template')
658667

659668
def test_write_points_udp(self):
660669
cli = InfluxDBClient(
661-
'localhost', self.influxd_inst.broker_port,
670+
'localhost', self.influxd_inst.webui_port,
662671
'dont', 'care',
663672
database='db',
664673
use_udp=True, udp_port=self.influxd_inst.udp_port

tests/influxdb/influxdb.conf.template

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# that can be resolved here.
66
# hostname = ""
77
bind-address = "0.0.0.0"
8+
port = {webui_port}
89

910
# Once every 24 hours InfluxDB will report anonymous data to m.influxdb.com
1011
# The data includes raft id (random 8 bytes), os, arch and version
@@ -14,11 +15,6 @@ bind-address = "0.0.0.0"
1415
# Change this option to true to disable reporting.
1516
reporting-disabled = false
1617

17-
# Controls settings for initial start-up. Once a node a successfully started,
18-
# these settings are ignored.
19-
[initialization]
20-
join-urls = "" # Comma-delimited URLs, in the form http://host:port, for joining another cluster.
21-
2218
# Control authentication
2319
# If not set authetication is DISABLED. Be sure to explicitly set this flag to
2420
# true if you want authentication.
@@ -53,52 +49,57 @@ enabled = false
5349
#database = "collectd_database"
5450
#typesdb = "types.db"
5551

52+
# Configure the OpenTSDB input.
53+
[opentsdb]
54+
enabled = false
55+
#address = "0.0.0.0" # If not set, is actually set to bind-address.
56+
#port = 4242
57+
#database = "opentsdb_database"
58+
5659
# Configure UDP listener for series data.
5760
[udp]
58-
enabled = false
61+
enabled = {udp_enabled}
5962
#bind-address = "0.0.0.0"
6063
#port = 4444
64+
port = {udp_port}
6165

6266
# Broker configuration. Brokers are nodes which participate in distributed
6367
# consensus.
6468
[broker]
69+
enabled = true
6570
# Where the Raft logs are stored. The user running InfluxDB will need read/write access.
71+
#dir = "/var/opt/influxdb/raft"
6672
dir = "{broker_raft_dir}"
6773
port = {broker_port}
6874

6975
# Data node configuration. Data nodes are where the time-series data, in the form of
7076
# shards, is stored.
7177
[data]
72-
dir = "{broker_node_dir}"
73-
port = {broker_port}
78+
enabled = true
79+
#dir = "/var/opt/influxdb/db"
80+
dir = "{broker_node_dir}"
7481

75-
# Auto-create a retention policy when a database is created. Defaults to true.
76-
retention-auto-create = true
82+
# Auto-create a retention policy when a database is created. Defaults to true.
83+
retention-auto-create = true
7784

78-
# Control whether retention policies are enforced and how long the system waits between
79-
# enforcing those policies.
80-
retention-check-enabled = true
81-
retention-check-period = "10m"
85+
# Control whether retention policies are enforced and how long the system waits between
86+
# enforcing those policies.
87+
retention-check-enabled = true
88+
retention-check-period = "10m"
8289

83-
[cluster]
84-
# Location for cluster state storage. For storing state persistently across restarts.
85-
dir = "{cluster_dir}"
90+
# Configuration for snapshot endpoint.
91+
[snapshot]
92+
enabled = false # Enabled by default if not set.
93+
bind-address = "127.0.0.1"
94+
port = 8087
8695

8796
[logging]
88-
file = "{logfile}" # Leave blank to redirect logs to stderr.
8997
write-tracing = false # If true, enables detailed logging of the write system.
9098
raft-tracing = false # If true, enables detailed logging of Raft consensus.
9199

92-
# InfluxDB can store statistics about itself. This is useful for monitoring purposes.
93-
# This feature is disabled by default, but if enabled, these statistics can be queried
94-
# as any other data.
95-
[statistics]
100+
# InfluxDB can store statistical and diagnostic information about itself. This is useful for
101+
# monitoring purposes. This feature is disabled by default, but if enabled, these data can be
102+
# queried like any other data.
103+
[monitoring]
96104
enabled = false
97-
database = "internal" # The database to which the data is written.
98-
retention-policy = "default" # The retention policy within the database.
99105
write-interval = "1m" # Period between writing the data.
100-
101-
102-
[snapshot]
103-
bind-address = "127.0.0.1"
104-
port = {snapshot_port}

tests/influxdb/influxdb.udp_conf.template

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)