finish implementation of data generator presets, fix flake8

This commit is contained in:
AlanCoding 2017-01-03 09:09:43 -05:00
parent 8c05d7e968
commit 67686f640b
3 changed files with 32 additions and 41 deletions

View File

@ -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
# --------------------------------------

View File

@ -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

View File

@ -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