Separate the TC and PTL elections

Currently even if we have closed an election when we build the docs we
still determine the full name, email address and IRC nick for all
candidates for a series (i.e both PTL and TC candidates for Rocky while
only running the rocky TC election)

Stop doing that.  This means that we reduce the REST-API hits during doc
builds, generally speed up the docs generation and importantly allow us
to change the process from looking this up from git to probing the
OpenStack Foundation membership DB.

Adding a flag to state the election type (or phase) will also allow us
to, in future changes, auto-validate candidates and generally streamline
the process.

NOTE: This change also forces all calls to filter() to be "listified" to
work the same under py2 and py3

As you can see from the results below, before we were looking up PTL data
from git, which this change stops.  After this change the expected git
queries still happen:

Before:
[tony@thor election]$ time strace -fo ./strace -s200 tox -e docs
<SNIP>
___________________________________ summary ____________________________________
  docs: commands succeeded
  congratulations :)

real	1m21.627s
user	0m16.268s
sys	0m9.921s
[tony@thor election]$ grep -Erin '/usr/bin/git.*--follow' strace | wc -l
125
[tony@thor election]$ grep -Erin '/usr/bin/git.*--follow' strace | head -n1
395670:6892  execve("/usr/bin/git", ["git", "log", "--follow", "--format=%aE", "candidates/rocky/Barbican/alee.txt"], 0x56333426b590 /* 8 vars */ <unfinished ...>
After (PTL)
[tony@thor election]$ time strace -fo ./strace -s200 tox -e docs
<SNIP>
___________________________________ summary ____________________________________
  docs: commands succeeded
  congratulations :)

real	1m23.211s
user	0m17.283s
sys	0m10.573s
[tony@thor election]$ grep -Erin '/usr/bin/git.*--follow' strace | wc -l
125
After (TC / no TC candidates)
[tony@thor election]$ time strace -fo ./strace -s200 tox -e docs
<SNIP>
___________________________________ summary ____________________________________
  docs: commands succeeded
  congratulations :)

real	0m35.943s
user	0m9.443s
sys	0m5.897s
[tony@thor election]$ grep -Erin '/usr/bin/git.*--follow' strace | wc -l
0
After (TC / 1 fake TC candidate)
[tony@thor election]$ time strace -fo ./strace -s200 tox -e docs
<SNIP>
___________________________________ summary ____________________________________
  docs: commands succeeded
  congratulations :)

real	0m15.497s
user	0m9.623s
sys	0m5.991s
[tony@thor election]$ grep -Erin '/usr/bin/git.*--follow' strace | wc -l
2
[tony@thor election]$ grep -Erin '/usr/bin/git.*--follow' strace
397279:9143  execve("/usr/bin/git", ["git", "log", "--follow", "--format=%aE", "candidates/rocky/TC/tonyb.txt"], 0x55cfc3ca9590 /* 8 vars */ <unfinished ...>
397686:9144  execve("/usr/bin/git", ["git", "log", "--follow", "--format=%aE", "candidates/rocky/TC/tonyb.txt"], 0x55cfc3ca9590 /* 8 vars */ <unfinished ...>

Change-Id: I81fc2df78c48aea1b594a7c9f174eee32a7b4128
This commit is contained in:
Tony Breeds 2018-04-09 15:51:06 +10:00
parent 073d477941
commit 4d898fbb31
2 changed files with 18 additions and 2 deletions

View File

@ -1,5 +1,6 @@
---
release: rocky
election_type: tc
tag: 'apr-2018-elections'

View File

@ -190,19 +190,34 @@ def dir2name(name, projects):
def build_candidates_list(election=conf['release']):
def is_tc_election():
return conf.get('election_type', '').lower() == 'tc'
election_path = os.path.join(CANDIDATE_PATH, election)
if os.path.exists(election_path):
project_list = os.listdir(election_path)
else:
project_list = []
if is_tc_election():
project_list = list(filter(
lambda p: p in ['TC'],
project_list
))
else:
project_list = list(filter(
lambda p: p not in ['TC'],
project_list
))
project_list.sort()
candidates_lists = {}
for project in project_list:
project_prefix = os.path.join(CANDIDATE_PATH, election, project)
file_list = filter(
file_list = list(filter(
lambda x: x.endswith(".txt"),
os.listdir(project_prefix),
)
))
candidates_list = []
for candidate_file in file_list:
filepath = os.path.join(project_prefix, candidate_file)