Skip to content

Commit 43550b3

Browse files
author
Grégory Starck
committed
Revert "Revert "Sync tests against last master update""
This reverts commit d3bb67d.
1 parent ec4fdcf commit 43550b3

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
@@ -130,7 +130,7 @@ class InfluxDbInstance(object):
130130
in a temporary place, using a config file template.
131131
'''
132132

133-
def __init__(self, conf_template):
133+
def __init__(self, conf_template, udp_enabled=False):
134134
# create a temporary dir to store all needed files
135135
# for the influxdb server instance :
136136
self.temp_dir_base = tempfile.mkdtemp()
@@ -139,28 +139,28 @@ def __init__(self, conf_template):
139139
tempdir = self.temp_dir_influxdb = tempfile.mkdtemp(
140140
dir=self.temp_dir_base)
141141
# we need some "free" ports :
142-
self.broker_port = get_free_port()
143-
self.admin_port = get_free_port()
144-
self.udp_port = get_free_port()
145-
self.snapshot_port = get_free_port()
146-
147-
self.logs_file = os.path.join(self.temp_dir_base, 'logs.txt')
148-
149-
with open(conf_template) as fh:
150-
conf = fh.read().format(
151-
broker_port=self.broker_port,
152-
admin_port=self.admin_port,
153-
udp_port=self.udp_port,
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-
logfile=self.logs_file,
158-
snapshot_port=self.snapshot_port,
159-
)
142+
143+
ports = dict(
144+
broker_port=get_free_port(),
145+
webui_port=get_free_port(),
146+
admin_port=get_free_port(),
147+
udp_port=get_free_port() if udp_enabled else -1,
148+
)
149+
150+
conf_data = dict(
151+
broker_raft_dir=os.path.join(tempdir, 'raft'),
152+
broker_node_dir=os.path.join(tempdir, 'db'),
153+
cluster_dir=os.path.join(tempdir, 'state'),
154+
logs_file=os.path.join(self.temp_dir_base, 'logs.txt'),
155+
udp_enabled='true' if udp_enabled else 'false',
156+
)
157+
conf_data.update(ports)
158+
self.__dict__.update(conf_data)
160159

161160
conf_file = os.path.join(self.temp_dir_base, 'influxdb.conf')
162161
with open(conf_file, "w") as fh:
163-
fh.write(conf)
162+
with open(conf_template) as fh_template:
163+
fh.write(fh_template.read().format(**conf_data))
164164

165165
# now start the server instance:
166166
proc = self.proc = subprocess.Popen(
@@ -179,8 +179,13 @@ def __init__(self, conf_template):
179179
# or you run a 286 @ 1Mhz ?
180180
try:
181181
while time.time() < timeout:
182-
if (is_port_open(self.broker_port)
182+
if (is_port_open(self.webui_port)
183183
and is_port_open(self.admin_port)):
184+
# it's hard to check if a UDP port is open..
185+
if udp_enabled:
186+
# so let's just sleep 0.5 sec in this case
187+
# to be sure that the server has open the port
188+
time.sleep(0.5)
184189
break
185190
time.sleep(0.5)
186191
if proc.poll() is not None:
@@ -189,13 +194,13 @@ def __init__(self, conf_template):
189194
proc.terminate()
190195
proc.wait()
191196
raise RuntimeError('Timeout waiting for influxdb to listen'
192-
' on its broker port')
197+
' on its ports (%s)' % ports)
193198
except RuntimeError as err:
194199
data = self.get_logs_and_output()
195200
data['reason'] = str(err)
196201
data['now'] = datetime.datetime.now()
197202
raise RuntimeError("%(now)s > %(reason)s. RC=%(rc)s\n"
198-
"stdout=%(out)r\nstderr=%(err)r\nlogs=%(logs)r"
203+
"stdout=%(out)s\nstderr=%(err)s\nlogs=%(logs)r"
199204
% data)
200205

201206
def get_logs_and_output(self):
@@ -222,9 +227,11 @@ def close(self, remove_tree=True):
222227

223228

224229
def _setup_influxdb_server(inst):
225-
inst.influxd_inst = InfluxDbInstance(inst.influxdb_template_conf)
230+
inst.influxd_inst = InfluxDbInstance(
231+
inst.influxdb_template_conf,
232+
udp_enabled=getattr(inst, 'influxdb_udp_enabled', False))
226233
inst.cli = InfluxDBClient('localhost',
227-
inst.influxd_inst.broker_port,
234+
inst.influxd_inst.webui_port,
228235
'root', '', database='db')
229236

230237

@@ -637,12 +644,14 @@ def test_query_multiple_series(self):
637644
class UdpTests(ManyTestCasesWithServerMixin,
638645
unittest.TestCase):
639646

647+
influxdb_udp_enabled = True
648+
640649
influxdb_template_conf = os.path.join(THIS_DIR,
641-
'influxdb.udp_conf.template')
650+
'influxdb.conf.template')
642651

643652
def test_write_points_udp(self):
644653
cli = InfluxDBClient(
645-
'localhost', self.influxd_inst.broker_port,
654+
'localhost', self.influxd_inst.webui_port,
646655
'dont', 'care',
647656
database='db',
648657
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy