Skip to content

Commit c422c87

Browse files
committed
Tests: Update data update tests to handle new test data format (#715)
All test parquet data are stored under tests/data/parquet now instead of being broken up further into subdirs belonging to different namespaces. The main reason for this change was to enable testing of remote DB use as well. However, with this change, we had not fixed the test update code that enabled us to update or add new test data. This patch fixes that. Signed-off-by: Dinesh Dutt <[email protected]>
1 parent aa326b6 commit c422c87

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ markers =
116116
parsing
117117

118118
# namespaces/nosses
119+
broken
119120
cumulus
120121
eos
121122
ios

tests/integration/test_update_data.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import glob
33
import shutil
4+
from pathlib import Path
45
import sys
56
from subprocess import check_output, check_call, CalledProcessError, STDOUT
67
import time
@@ -193,13 +194,23 @@ def vagrant_setup():
193194
vagrant_down()
194195

195196

196-
def git_del_dir(folder):
197-
'''Del git dir'''
198-
if os.path.isdir(folder):
197+
def git_rm_old_files(namespace):
198+
'''Del old files from namespace'''
199+
nsdirs = Path('tests/data/parquet/').glob(f'**/namespace={namespace}')
200+
for folder in nsdirs:
199201
try:
200-
check_call(['git', 'rm', '-rf', folder])
202+
check_call(['git', 'rm', '-rf', str(folder)])
201203
except CalledProcessError:
202-
shutil.rmtree(folder)
204+
shutil.rmtree(str(folder))
205+
206+
207+
def git_rm_input_dir(dstdir):
208+
'''Delete the input dir provided'''
209+
if os.path.isdir(dstdir):
210+
try:
211+
check_call(['git', 'rm', '-rf', dstdir])
212+
except CalledProcessError:
213+
shutil.rmtree(dstdir)
203214

204215

205216
def update_sqcmds(files, data_dir=None, namespace=None):
@@ -219,7 +230,7 @@ def update_sqcmds(files, data_dir=None, namespace=None):
219230
def update_input_data(root_dir, nos, scenario, input_path):
220231
'''Update collected raw data used for tests'''
221232
dst_dir = f'{root_dir}/tests/integration/sqcmds/{nos}-input/{scenario}/'
222-
git_del_dir(dst_dir)
233+
git_rm_input_dir(dst_dir)
223234
copytree(f'{input_path}/suzieq-input', dst_dir)
224235

225236

@@ -275,20 +286,22 @@ def test_update_cumulus_multidc_data(self, tmp_path):
275286
orig_dir, tmp_path)
276287

277288
dst_dir = f'{orig_dir}/tests/data/parquet'
278-
git_del_dir(dst_dir)
279-
copytree(f'{tmp_path}/parquet-out', dst_dir)
280-
shutil.rmtree(f'{tmp_path}/parquet-out')
289+
git_rm_old_files('ospf-ibgp')
290+
git_rm_old_files('dual-evpn')
291+
git_rm_old_files('ospf-single')
292+
copytree(f'{tmp_path}/parquet', dst_dir)
293+
shutil.rmtree(f'{tmp_path}/parquet')
281294

282295
update_data(
283296
'dual-bgp',
284297
f'{orig_dir}/tests/integration/sqcmds/cumulus-input/dual-bgp',
285298
orig_dir, tmp_path)
286299

287300
dst_dir = f'{orig_dir}/tests/data/parquet'
288-
git_del_dir(dst_dir)
301+
git_rm_old_files('dual-bgp')
289302

290-
copytree(f'{tmp_path}/parquet-out', dst_dir)
291-
shutil.rmtree(f'{tmp_path}/parquet-out')
303+
copytree(f'{tmp_path}/parquet', dst_dir)
304+
shutil.rmtree(f'{tmp_path}/parquet')
292305

293306
# update the samples data with updates from the newly collected data
294307

@@ -303,9 +316,9 @@ def _update_test_data_common_fn(self, nos, tmp_path, device_cnt):
303316
orig_dir, tmp_path, number_of_devices=device_cnt)
304317

305318
dst_dir = f'{orig_dir}/tests/data/parquet'
306-
git_del_dir(dst_dir)
307-
copytree(f'{tmp_path}/parquet-out', dst_dir)
308-
shutil.rmtree(f'{tmp_path}/parquet-out')
319+
git_rm_old_files(nos)
320+
copytree(f'{tmp_path}/parquet', dst_dir)
321+
shutil.rmtree(f'{tmp_path}/parquet')
309322

310323
# update the samples data with updates from the newly collected data
311324

@@ -357,6 +370,15 @@ def test_update_vmx_data(self, tmp_path):
357370
'''Update test data for VMX'''
358371
self._update_test_data_common_fn('vmx', tmp_path, '5')
359372

373+
@pytest.mark.test_update
374+
@pytest.mark.update_data
375+
@pytest.mark.broken
376+
@pytest.mark.skipif(not os.environ.get('SUZIEQ_POLLER', None),
377+
reason='Not updating data')
378+
def test_update_broken_data(self, tmp_path):
379+
'''Update test data for mixed sim, from Rick'''
380+
self._update_test_data_common_fn('broken', tmp_path, '14')
381+
360382

361383
tests = [
362384
['bgp', 'numbered'],
@@ -421,7 +443,7 @@ def _gather_cndcn_data(topology, proto, scenario, input_path):
421443
os.chdir(path + '/topologies')
422444
dst_dir = f'{orig_dir}/tests/integration/all_cndcn/{name}-input'
423445
gather_data(topology, proto, scenario, name, orig_dir, input_path)
424-
git_del_dir(dst_dir)
446+
git_rm_input_dir(dst_dir)
425447
copytree(f'{input_path}/suzieq-input', dst_dir)
426448
os.chdir(orig_dir)
427449

@@ -440,19 +462,19 @@ def _update_cndcn_data(topology, proto, scenario, tmp_path):
440462
if not os.path.isdir(f'{parquet_dir}/{name}'):
441463
os.mkdir(f'{parquet_dir}/{name}')
442464

443-
copytree(f"{tmp_path}/parquet-out",
444-
f"{parquet_dir}/{name}/parquet-out/")
465+
copytree(f"{tmp_path}/parquet",
466+
f"{parquet_dir}/{name}/parquet/")
445467

446468
if os.environ.get('UPDATE_SQCMDS', None):
447469
update_sqcmds(glob.glob(f'{cndcn_samples_dir}/{name}-samples/*.yml'),
448-
data_dir=f"{parquet_dir}/{name}/parquet-out",
470+
data_dir=f"{parquet_dir}/{name}/parquet",
449471
namespace=name)
450472

451473

452474
def _test_data(topology, proto, scenario, testvar):
453475
# pylint: disable=redefined-outer-name
454476
name = f'{topology}_{proto}_{scenario}'
455-
testvar['data-directory'] = f"{parquet_dir}/{name}/parquet-out"
477+
testvar['data-directory'] = f"{parquet_dir}/{name}/parquet"
456478
dummy_config = load_sq_config(
457479
config_file=conftest.create_dummy_config_file())
458480
_test_sqcmds(dummy_config, testvar)

0 commit comments

Comments
 (0)