From 67686f640be8a40a01292ba8b12afb4bf8e079c8 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Tue, 3 Jan 2017 09:09:43 -0500 Subject: [PATCH] finish implementation of data generator presets, fix flake8 --- Makefile | 3 +- tools/data_generators/load_presets.py | 26 ----------- .../rbac_dummy_data_generator.py | 44 +++++++++++++------ 3 files changed, 32 insertions(+), 41 deletions(-) delete mode 100644 tools/data_generators/load_presets.py diff --git a/Makefile b/Makefile index 41e2bb70cc..0679a11911 100644 --- a/Makefile +++ b/Makefile @@ -507,11 +507,12 @@ test_tox: test_jenkins : test_coverage # Make fake data +DATA_GEN_PRESET = "" bulk_data: @if [ "$(VENV_BASE)" ]; then \ . $(VENV_BASE)/tower/bin/activate; \ fi; \ - $(PYTHON) tools/data_generators/rbac_dummy_data_generator.py + $(PYTHON) tools/data_generators/rbac_dummy_data_generator.py --preset=$(DATA_GEN_PRESET) # l10n TASKS # -------------------------------------- diff --git a/tools/data_generators/load_presets.py b/tools/data_generators/load_presets.py deleted file mode 100644 index 7461dc067b..0000000000 --- a/tools/data_generators/load_presets.py +++ /dev/null @@ -1,26 +0,0 @@ -import os - -preset = 'medium' - -presets_filename = os.path.abspath(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'presets.tsv')) - -with open(presets_filename) as f: - text = f.read() - -split_lines = [line.split('\t') for line in text.split('\n')] -keys = split_lines[0][1:] - -try: - col = keys.index(preset) -except ValueError: - raise Exception('Preset %s data set not found, options are %s' % (preset, keys)) - -options = {cols[0]: cols[col+1] for cols in split_lines} - -print ' text ' -print text - -print ' options ' -print options diff --git a/tools/data_generators/rbac_dummy_data_generator.py b/tools/data_generators/rbac_dummy_data_generator.py index 046e4d851c..dbbb5f4aa2 100755 --- a/tools/data_generators/rbac_dummy_data_generator.py +++ b/tools/data_generators/rbac_dummy_data_generator.py @@ -84,7 +84,22 @@ options = vars(options) if options['preset']: - pass + # Read the numbers of resources from presets file, if provided + presets_filename = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), 'presets.tsv')) + + with open(presets_filename) as f: + text = f.read() + + split_lines = [line.split('\t') for line in text.split('\n')] + keys = split_lines[0][1:] + + try: + col = keys.index(options['preset']) + except ValueError: + raise Exception('Preset "%s" dataset not found, options are %s' % (options['preset'], keys)) + + options.update({cols[0]: cols[col + 1] for cols in split_lines}) n_organizations = int(options['organizations']) @@ -163,6 +178,7 @@ class Rollback(Exception): def mock_save(self, *args, **kwargs): return super(PrimordialModel, self).save(*args, **kwargs) + PrimordialModel.save = mock_save @@ -334,17 +350,17 @@ try: project, _ = Project.objects.get_or_create( name='%s Project %d Org %d' % (prefix, project_id, org_idx), organization=org, - defaults=dict(created_by=next(creator_gen), - modified_by=next(modifier_gen), - scm_url='https://github.com/jlaska/ansible-playbooks.git', - scm_type='git', - playbook_files=[ - "check.yml", "debug-50.yml", "debug.yml", "debug2.yml", - "debug_extra_vars.yml", "dynamic_inventory.yml", - "environ_test.yml", "fail_unless.yml", "pass_unless.yml", - "pause.yml", "ping-20.yml", "ping.yml", - "setfact_50.yml", "vault.yml" - ]) + defaults=dict( + created_by=next(creator_gen), modified_by=next(modifier_gen), + scm_url='https://github.com/jlaska/ansible-playbooks.git', + scm_type='git', + playbook_files=[ + "check.yml", "debug-50.yml", "debug.yml", "debug2.yml", + "debug_extra_vars.yml", "dynamic_inventory.yml", + "environ_test.yml", "fail_unless.yml", "pass_unless.yml", + "pause.yml", "ping-20.yml", "ping.yml", + "setfact_50.yml", "vault.yml" + ]) ) projects.append(project) if org_idx == 0 and i == 0: @@ -567,7 +583,7 @@ try: print('# Adding labels to job templates') jt_idx = 0 - for n in spread(n_labels*7, n_job_templates): + for n in spread(n_labels * 7, n_job_templates): jt = job_templates[jt_idx] if not jt._is_new: continue @@ -578,7 +594,7 @@ try: print('# Adding labels to workflow job templates') wfjt_idx = 0 - for n in spread(n_labels*3, n_wfjts): + for n in spread(n_labels * 3, n_wfjts): wfjt = wfjts[wfjt_idx] if not jt._is_new: continue