Let the server loop until artifacts exist
This commit is contained in:
1 parent
0a6d365174
commit
7d820d85d9
6 files changed
+120
-69
No files matched your search
@@ -19,6 +19,42 @@
|
|||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
import django.apps
|
import django.apps
|
||||||
|
import threading, time
|
||||||
|
|
||||||
|
class ArtifactWatcher(threading.Thread):
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
# Delay imports due to the app not having been loaded yet
|
||||||
|
import OpenBench.utils
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
|
for test in OpenBench.utils.get_awaiting_tests():
|
||||||
|
|
||||||
|
dev_has_all = test.dev.source.endswith('artifacts')
|
||||||
|
base_has_all = test.base.source.endswith('artifacts')
|
||||||
|
headers = OpenBench.utils.read_git_credentials(test.engine)
|
||||||
|
|
||||||
|
if headers and not dev_has_all:
|
||||||
|
test.dev.source, dev_has_all = OpenBench.utils.fetch_artifact_url(
|
||||||
|
test.dev.source, test.engine, headers, test.dev.sha)
|
||||||
|
test.dev.save()
|
||||||
|
|
||||||
|
if headers and not base_has_all:
|
||||||
|
test.base.source, base_has_all = OpenBench.utils.fetch_artifact_url(
|
||||||
|
test.base.source, test.engine, headers, test.base.sha)
|
||||||
|
test.base.save()
|
||||||
|
|
||||||
|
if dev_has_all and base_has_all:
|
||||||
|
test.awaiting = False
|
||||||
|
test.save()
|
||||||
|
|
||||||
class OpenbenchConfig(django.apps.AppConfig):
|
class OpenbenchConfig(django.apps.AppConfig):
|
||||||
|
|
||||||
name = 'OpenBench'
|
name = 'OpenBench'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
self.watcher = ArtifactWatcher().start()
|
||||||
@@ -129,6 +129,7 @@ class Test(Model):
|
|||||||
finished = BooleanField(default=False)
|
finished = BooleanField(default=False)
|
||||||
deleted = BooleanField(default=False)
|
deleted = BooleanField(default=False)
|
||||||
approved = BooleanField(default=False)
|
approved = BooleanField(default=False)
|
||||||
|
awaiting = BooleanField(default=False)
|
||||||
|
|
||||||
creation = DateTimeField(auto_now_add=True)
|
creation = DateTimeField(auto_now_add=True)
|
||||||
updated = DateTimeField(auto_now=True)
|
updated = DateTimeField(auto_now=True)
|
||||||
|
|||||||
+57
-55
@@ -77,22 +77,29 @@ def parseTimeControl(time_control):
|
|||||||
raise Exception('Unable to parse Time Control (%s)' % (time_control))
|
raise Exception('Unable to parse Time Control (%s)' % (time_control))
|
||||||
|
|
||||||
|
|
||||||
def getPendingTests():
|
def get_pending_tests():
|
||||||
pending = OpenBench.models.Test.objects.filter(approved=False)
|
t = OpenBench.models.Test.objects.filter(approved=False)
|
||||||
pending = pending.exclude(finished=True)
|
t = t.exclude(finished=True)
|
||||||
pending = pending.exclude(deleted=True)
|
t = t.exclude(deleted=True)
|
||||||
return pending.order_by('-creation')
|
return t.order_by('-creation')
|
||||||
|
|
||||||
def getActiveTests():
|
def get_active_tests():
|
||||||
active = OpenBench.models.Test.objects.filter(approved=True)
|
t = OpenBench.models.Test.objects.filter(approved=True)
|
||||||
active = active.exclude(finished=True)
|
t = t.exclude(awaiting=True)
|
||||||
active = active.exclude(deleted=True)
|
t = t.exclude(finished=True)
|
||||||
return active.order_by('-priority', '-currentllr')
|
t = t.exclude(deleted=True)
|
||||||
|
return t.order_by('-priority', '-currentllr')
|
||||||
|
|
||||||
def getCompletedTests():
|
def get_completed_tests():
|
||||||
completed = OpenBench.models.Test.objects.filter(finished=True)
|
t = OpenBench.models.Test.objects.filter(finished=True)
|
||||||
completed = completed.exclude(deleted=True)
|
t = t.exclude(deleted=True)
|
||||||
return completed.order_by('-updated')
|
return t.order_by('-updated')
|
||||||
|
|
||||||
|
def get_awaiting_tests():
|
||||||
|
t = OpenBench.models.Test.objects.filter(awaiting=True)
|
||||||
|
t = t.exclude(finished=True)
|
||||||
|
t = t.exclude(deleted=True)
|
||||||
|
return t.order_by('-creation')
|
||||||
|
|
||||||
|
|
||||||
def getRecentMachines(minutes=5):
|
def getRecentMachines(minutes=5):
|
||||||
@@ -149,11 +156,8 @@ def getEngine(source, name, sha, bench):
|
|||||||
return Engine.objects.create(name=name, source=source, sha=sha, bench=bench)
|
return Engine.objects.create(name=name, source=source, sha=sha, bench=bench)
|
||||||
|
|
||||||
|
|
||||||
def read_git_credentials(request):
|
def read_git_credentials(engine):
|
||||||
|
fname = 'credentials.%s' % (engine.replace(' ', '').lower())
|
||||||
engine = request.POST['enginename'].replace(' ', '').lower()
|
|
||||||
fname = 'credentials.%s' % (engine)
|
|
||||||
|
|
||||||
if os.path.exists(fname):
|
if os.path.exists(fname):
|
||||||
with open(fname) as fin:
|
with open(fname) as fin:
|
||||||
return { 'Authorization' : 'token %s' % fin.readlines()[0].rstrip() }
|
return { 'Authorization' : 'token %s' % fin.readlines()[0].rstrip() }
|
||||||
@@ -198,19 +202,19 @@ def collect_github_info(request, errors, field):
|
|||||||
## [C] Determine which, if any, credentials we want to pass along
|
## [C] Determine which, if any, credentials we want to pass along
|
||||||
|
|
||||||
# Private engines must have a token stored in credentials.enginename
|
# Private engines must have a token stored in credentials.enginename
|
||||||
if private and not (headers := read_git_credentials(request)):
|
if private and not (headers := read_git_credentials(request.POST['enginename'])):
|
||||||
errors.append('Server does not have access tokens for this engine')
|
errors.append('Server does not have access tokens for this engine')
|
||||||
return (None, None, None, None)
|
return (None, None)
|
||||||
|
|
||||||
# Do not allow private engines to use forked repos ( We don't have a token! )
|
# Do not allow private engines to use forked repos ( We don't have a token! )
|
||||||
if requests_illegal_fork(request):
|
if requests_illegal_fork(request):
|
||||||
errors.append('Forked Repositories are not allowed for Private engines')
|
errors.append('Forked Repositories are not allowed for Private engines')
|
||||||
return (None, None, None, None)
|
return (None, None)
|
||||||
|
|
||||||
# Avoid leaking our credentials to other websites
|
# Avoid leaking our credentials to other websites
|
||||||
if not base.startswith('https://api.github.com/'):
|
if not base.startswith('https://api.github.com/'):
|
||||||
errors.append('OpenBench may only reach Github\'s API')
|
errors.append('OpenBench may only reach Github\'s API')
|
||||||
return (None, None, None, None)
|
return (None, None)
|
||||||
|
|
||||||
## Step 2: Connect to the Github API for the given Branch or Commit SHA.
|
## Step 2: Connect to the Github API for the given Branch or Commit SHA.
|
||||||
## [A] We will attempt to parse the most recent commit message for a
|
## [A] We will attempt to parse the most recent commit message for a
|
||||||
@@ -230,53 +234,51 @@ def collect_github_info(request, errors, field):
|
|||||||
except: # Unable to connect for whatever reason
|
except: # Unable to connect for whatever reason
|
||||||
path = 'Commit Sha' if bysha else 'Branch'
|
path = 'Commit Sha' if bysha else 'Branch'
|
||||||
errors.append('{0} {1} could not be found'.format(path, branch))
|
errors.append('{0} {1} could not be found'.format(path, branch))
|
||||||
return (None, None, None, None)
|
return (None, None)
|
||||||
|
|
||||||
# Extract the bench from the web form, or from the commit message
|
# Extract the bench from the web form, or from the commit message
|
||||||
if not (bench := determine_bench(request, field, data['commit']['message'])):
|
if not (bench := determine_bench(request, field, data['commit']['message'])):
|
||||||
errors.append('Unable to parse a Bench for %s' % (branch))
|
errors.append('Unable to parse a Bench for %s' % (branch))
|
||||||
return (None, None, None, None)
|
return (None, None)
|
||||||
|
|
||||||
# Public Engines: Construct the .zip download and return everything
|
# Public Engines: Construct the .zip download and return everything
|
||||||
if not OPENBENCH_CONFIG['engines'][request.POST['enginename']]['private']:
|
if not OPENBENCH_CONFIG['engines'][request.POST['enginename']]['private']:
|
||||||
treeurl = data['commit']['tree']['sha'] + '.zip'
|
treeurl = data['commit']['tree']['sha'] + '.zip'
|
||||||
source = pathjoin(request.POST['source'], 'archive', treeurl).rstrip('/')
|
source = pathjoin(request.POST['source'], 'archive', treeurl).rstrip('/')
|
||||||
return (source, branch, data['sha'], bench)
|
return (source, branch, data['sha'], bench), True
|
||||||
|
|
||||||
## Step 3: Construct the URL for the API request to list all Artifacts
|
## Step 3: Construct the URL for the API request to list all Artifacts
|
||||||
## [A] OpenBench artifacts are always run via a file named openbench.yml
|
## [A] OpenBench artifacts are always run via a file named openbench.yml
|
||||||
## [B] These should contain combinations for windows/linux, avx2/avx512, popcnt/pext
|
## [B] These should contain combinations for windows/linux, avx2/avx512, popcnt/pext
|
||||||
## [C] If those artifacts do not exist, we cannot create the test.
|
## [C] If those artifacts are not found, we flag the test as awaiting, and try later.
|
||||||
|
|
||||||
try: # Fetch the run id for the openbench workflow for this comment
|
engine = request.POST['enginename']
|
||||||
|
url, has_all = fetch_artifact_url(base, engine, headers, data['sha'])
|
||||||
|
return (url, branch, data['sha'], bench), has_all
|
||||||
|
|
||||||
|
def fetch_artifact_url(base, engine, headers, sha):
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Fetch the run id for the openbench workflow for this comment
|
||||||
url = pathjoin(base, 'actions', 'workflows', 'openbench.yml', 'runs').rstrip('/')
|
url = pathjoin(base, 'actions', 'workflows', 'openbench.yml', 'runs').rstrip('/')
|
||||||
url += '?head_sha=%s' % (data['sha'])
|
url += '?head_sha=%s' % (sha)
|
||||||
run_id = requests.get(url=url, headers=headers).json()['workflow_runs'][0]['id']
|
run_id = requests.get(url=url, headers=headers).json()['workflow_runs'][0]['id']
|
||||||
|
|
||||||
except: # Unable to determine this for whatever reason
|
# Construct the final URL that will be used to look at artifacts
|
||||||
errors.append('Failed to idenftify the run_id associated with the OpenBench workflow')
|
|
||||||
return (None, None, None, None)
|
|
||||||
|
|
||||||
try: # Fetch the artifact list for the run_id we determined above
|
|
||||||
url = pathjoin(base, 'actions', 'runs', str(run_id), 'artifacts').rstrip('/')
|
url = pathjoin(base, 'actions', 'runs', str(run_id), 'artifacts').rstrip('/')
|
||||||
artifacts = requests.get(url=url, headers=headers).json()['artifacts']
|
artifacts = requests.get(url=url, headers=headers).json()['artifacts']
|
||||||
|
|
||||||
except: # Unable to fetch the list of artifacts for whatever reason
|
# Verify that all of the artifacts exist and are not expired
|
||||||
errors.append('Failed to get the Artifact List for run_id = %d' % (run_id))
|
available = [ f['name'] for f in artifacts if f['expired'] == False ]
|
||||||
return (None, None, None, None)
|
required = OPENBENCH_CONFIG['engines'][engine]['build']['artifacts']
|
||||||
|
has_all = all(['%s-%s' % (sha, name) in available for name in required])
|
||||||
|
|
||||||
# Verify that all of the artifacts exist and are not expired
|
# Return the URL iff we found them; otherwise base
|
||||||
available = [ f['name'] for f in artifacts if f['expired'] == False ]
|
return (url if has_all else base, has_all)
|
||||||
required = OPENBENCH_CONFIG['engines'][request.POST['enginename']]['build']['artifacts']
|
|
||||||
|
|
||||||
# Flag any and all missing artifacts
|
|
||||||
for name in required:
|
|
||||||
if '%s-%s' % (data['sha'], name) not in available:
|
|
||||||
errors.append('Missing Artifact (%s)' % (name))
|
|
||||||
|
|
||||||
# Return the API endpoint for artifacts, along with the usual rest
|
|
||||||
return (url, branch, data['sha'], bench)
|
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
# If anything goes wrong, retry later with the same base URL
|
||||||
|
return (base, False)
|
||||||
|
|
||||||
def verifyNewTest(request):
|
def verifyNewTest(request):
|
||||||
|
|
||||||
@@ -340,8 +342,8 @@ def createNewTest(request):
|
|||||||
errors = verifyNewTest(request)
|
errors = verifyNewTest(request)
|
||||||
if errors != []: return None, errors
|
if errors != []: return None, errors
|
||||||
|
|
||||||
devinfo = collect_github_info(request, errors, 'dev')
|
devinfo, dev_has_all = collect_github_info(request, errors, 'dev')
|
||||||
baseinfo = collect_github_info(request, errors, 'base')
|
baseinfo, base_has_all = collect_github_info(request, errors, 'base')
|
||||||
if errors != []: return None, errors
|
if errors != []: return None, errors
|
||||||
|
|
||||||
test = Test()
|
test = Test()
|
||||||
@@ -379,8 +381,9 @@ def createNewTest(request):
|
|||||||
if request.POST['basenetwork']:
|
if request.POST['basenetwork']:
|
||||||
test.basenetname = Network.objects.get(sha256=request.POST['basenetwork']).name
|
test.basenetname = Network.objects.get(sha256=request.POST['basenetwork']).name
|
||||||
|
|
||||||
test.dev = getEngine(*devinfo)
|
test.dev = getEngine(*devinfo)
|
||||||
test.base = getEngine(*baseinfo)
|
test.base = getEngine(*baseinfo)
|
||||||
|
test.awaiting = not (dev_has_all and base_has_all)
|
||||||
test.save()
|
test.save()
|
||||||
|
|
||||||
profile = Profile.objects.get(user=request.user)
|
profile = Profile.objects.get(user=request.user)
|
||||||
@@ -445,9 +448,8 @@ def getWorkload(user, request):
|
|||||||
|
|
||||||
def get_valid_workloads(machine, request):
|
def get_valid_workloads(machine, request):
|
||||||
|
|
||||||
# Skip finished tests
|
# Skip anything that is not running
|
||||||
tests = Test.objects.filter(finished=False)
|
tests = get_active_tests()
|
||||||
tests = tests.filter(deleted=False).filter(approved=True)
|
|
||||||
|
|
||||||
# Skip engines that the Machine cannot build
|
# Skip engines that the Machine cannot build
|
||||||
for engine in OPENBENCH_CONFIG['engines'].keys():
|
for engine in OPENBENCH_CONFIG['engines'].keys():
|
||||||
|
|||||||
+16
-13
@@ -238,16 +238,18 @@ def index(request, page=1, error=''):
|
|||||||
# #
|
# #
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
pending = OpenBench.utils.getPendingTests()
|
pending = OpenBench.utils.get_pending_tests()
|
||||||
active = OpenBench.utils.getActiveTests()
|
active = OpenBench.utils.get_active_tests()
|
||||||
completed = OpenBench.utils.getCompletedTests()
|
completed = OpenBench.utils.get_completed_tests()
|
||||||
|
awaiting = OpenBench.utils.get_awaiting_tests()
|
||||||
|
|
||||||
start, end, paging = OpenBench.utils.getPaging(completed, page, 'index')
|
start, end, paging = OpenBench.utils.getPaging(completed, page, 'index')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'error' : error, 'pending' : pending,
|
'pending' : pending, 'active' : active,
|
||||||
'active' : active, 'completed' : completed[start:end],
|
'completed' : completed[start:end], 'awaiting' : awaiting,
|
||||||
'paging' : paging, 'status' : OpenBench.utils.getMachineStatus(),
|
'paging' : paging, 'status' : OpenBench.utils.getMachineStatus(),
|
||||||
|
'error' : error,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'index.html', data)
|
return render(request, 'index.html', data)
|
||||||
@@ -261,7 +263,7 @@ def greens(request, page=1):
|
|||||||
# #
|
# #
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
completed = OpenBench.utils.getCompletedTests().filter(passed=True)
|
completed = OpenBench.utils.get_completed_tests().filter(passed=True)
|
||||||
start, end, paging = OpenBench.utils.getPaging(completed, page, 'greens')
|
start, end, paging = OpenBench.utils.getPaging(completed, page, 'greens')
|
||||||
|
|
||||||
data = {'completed' : completed[start:end], 'paging' : paging}
|
data = {'completed' : completed[start:end], 'paging' : paging}
|
||||||
@@ -323,17 +325,18 @@ def user(request, username, page=1):
|
|||||||
# #
|
# #
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
pending = OpenBench.utils.getPendingTests().filter(author=username)
|
pending = OpenBench.utils.get_pending_tests().filter(author=username)
|
||||||
active = OpenBench.utils.getActiveTests().filter(author=username)
|
active = OpenBench.utils.get_active_tests().filter(author=username)
|
||||||
completed = OpenBench.utils.getCompletedTests().filter(author=username)
|
completed = OpenBench.utils.get_completed_tests().filter(author=username)
|
||||||
|
awaiting = OpenBench.utils.get_awaiting_tests().filter(author=username)
|
||||||
|
|
||||||
url = 'user/{0}'.format(username)
|
url = 'user/{0}'.format(username)
|
||||||
start, end, paging = OpenBench.utils.getPaging(completed, page, url)
|
start, end, paging = OpenBench.utils.getPaging(completed, page, url)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'pending' : pending, 'active' : active,
|
'pending' : pending, 'active' : active,
|
||||||
'completed' : completed[start:end], 'paging' : paging,
|
'completed' : completed[start:end], 'awaiting' : awaiting,
|
||||||
'status' : OpenBench.utils.getMachineStatus(username),
|
'paging' : paging, 'status' : OpenBench.utils.getMachineStatus(username),
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'index.html', data)
|
return render(request, 'index.html', data)
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'OpenBench',
|
|
||||||
'OpenBench.templatetags',
|
'OpenBench.templatetags',
|
||||||
|
'OpenBench.apps.OpenbenchConfig',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@@ -16,6 +16,15 @@
|
|||||||
<tr class="table-spacer"><th></th></tr>
|
<tr class="table-spacer"><th></th></tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- Currently Awaiting tests (Waiting for Artifacts) -->
|
||||||
|
{% if awaiting %}
|
||||||
|
<tr><th colspan='6'>Awaiting Artifacts</th></tr>
|
||||||
|
{% for test in awaiting %}
|
||||||
|
{% include "OpenBench/Blocks/testsummary.html" %}
|
||||||
|
{% endfor %}
|
||||||
|
<tr class="table-spacer"><th></th></tr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<!-- Currently Running tests (Waiting to be completed) -->
|
<!-- Currently Running tests (Waiting to be completed) -->
|
||||||
{% if active %}
|
{% if active %}
|
||||||
<tr><th colspan='6'>Active {{status}}</th></tr>
|
<tr><th colspan='6'>Active {{status}}</th></tr>
|
||||||
|
|||||||
Reference in new issue
Block a user