Skip to content

Commit dca281d

Browse files
authored
Test: add extra behaviour to testing suite (#209)
* add extra behavior to testing suite This commit adds one more option to running the test suite, to instruct it to rewrite the config file of an existing ES bundle. This is just a convenience option. * address review comments - s/rezet/full*reset - improve help message format.
1 parent d1392c7 commit dca281d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

test/integration/elasticsearch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def _fetch_elasticsearch(self, version, dest_dir):
140140

141141
return dest_file
142142

143-
def _update_es_yaml(self, es_dir):
143+
def _update_es_yaml(self, es_dir, append=True):
144144
yaml = os.path.join(es_dir, "config", "elasticsearch.yml")
145-
with open(yaml, mode="a", newline="\n") as f:
145+
with open(yaml, mode="a" if append else "w", newline="\n") as f:
146146
f.write("#\n# ODBC Integration Test\n#\n")
147147
f.write("xpack.security.enabled: True\n")
148148
f.write("http.port: %s\n" % self._port) # don't bind on next avail port
@@ -259,7 +259,7 @@ def spawn(self, version, root_dir=None, ephemeral=False):
259259
self._start_elasticsearch(es_dir)
260260
self._enable_xpack(es_dir)
261261

262-
def reset(self, es_dir):
262+
def reset(self, es_dir, reset_conf=False):
263263
# make sure there's no instance running
264264
try:
265265
if self.is_listening():
@@ -277,6 +277,8 @@ def reset(self, es_dir):
277277
else:
278278
os.remove(path)
279279

280+
if reset_conf:
281+
self._update_es_yaml(es_dir, False)
280282
self._start_elasticsearch(es_dir)
281283
self._enable_xpack(es_dir)
282284

test/integration/ites.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def ites(args):
2121

2222
# create a running instance of Elasticsearch if needed
2323
if args.url is None:
24-
if args.es_reset:
25-
es_dir = os.path.abspath(args.es_reset)
26-
es.reset(es_dir)
24+
es_reset = args.es_full_reset or args.es_reset
25+
if es_reset:
26+
es_dir = os.path.abspath(es_reset)
27+
es.reset(es_dir, args.es_full_reset is not None)
2728
else:
2829
assert(args.root_dir)
2930
root_dir = os.path.abspath(args.root_dir)
@@ -79,7 +80,9 @@ def main():
7980
stage_grp = parser.add_mutually_exclusive_group()
8081
stage_grp.add_argument("-r", "--root-dir", help="Root directory to [temporarily] stage Elasticsearch into.")
8182
stage_grp.add_argument("-s", "--es-reset", help="Path to an already configured Elasticsearch folder to "
82-
"use; data directory content will be removed; 'ephemeral' will be ignored.")
83+
"use; data directory content will be removed; 'ephemeral' will be ignored.", dest="ES_DIR")
84+
stage_grp.add_argument("-S", "--es-full-reset", help="Path to the Elasticsearch folder; config file and data "
85+
"directory content will be removed; 'ephemeral' will be ignored.", dest="ES_DIR")
8386
stage_grp.add_argument("-p", "--url", help="Use a pre-staged and running Elasticsearch instance. If no URL is "
8487
"provided, %s is assumed." % Elasticsearch.ES_BASE_URL, nargs="?", const="")
8588

@@ -103,10 +106,10 @@ def main():
103106
"default.")
104107

105108
args = parser.parse_args()
106-
if not (args.root_dir or args.es_reset or args.url is not None):
109+
if not (args.root_dir or args.es_reset or args.es_full_reset or args.url is not None):
107110
parser.error("no Elasticsearch instance or root/staged directory provided.")
108111

109-
if not (args.driver or args.version or args.es_reset or args.url is not None):
112+
if not (args.driver or args.version or args.es_reset or args.es_full_reset or args.url is not None):
110113
parser.error("don't know what Elasticsearch version to test against.")
111114

112115
if args.driver and args.dsn and "Driver=" in args.dsn:

0 commit comments

Comments
 (0)