Add a test api to test repositories which are currenlty building.

This commit is contained in:
yackob03 2013-10-25 15:47:34 -04:00
parent ffc33e454c
commit 684ce83058
6 changed files with 29 additions and 7 deletions

View file

@ -2,16 +2,25 @@ import logging
from app import app as application from app import app as application
logging.basicConfig(**application.config['LOGGING_CONFIG'])
import endpoints.index import endpoints.index
import endpoints.api import endpoints.api
import endpoints.web import endpoints.web
import endpoints.tags import endpoints.tags
import endpoints.registry import endpoints.registry
logger = logging.getLogger(__name__)
if application.config.get('INCLUDE_TEST_ENDPOINTS', False):
logger.debug('Loading test endpoints.')
import endpoints.test
# Remove this for prod config # Remove this for prod config
application.debug = True application.debug = True
logging.basicConfig(**application.config['LOGGING_CONFIG'])
if __name__ == '__main__': if __name__ == '__main__':
application.run(port=5000, debug=True, host='0.0.0.0') application.run(port=5000, debug=True, host='0.0.0.0')

View file

@ -105,6 +105,7 @@ class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
} }
SEND_FILE_MAX_AGE_DEFAULT = 0 SEND_FILE_MAX_AGE_DEFAULT = 0
POPULATE_DB_TEST_DATA = True POPULATE_DB_TEST_DATA = True
INCLUDE_TEST_ENDPOINTS = True
class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL, class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL,

View file

@ -397,6 +397,8 @@ def get_repo_builds(namespace, repository):
'builds': [build_view(build) for build in builds] 'builds': [build_view(build) for build in builds]
}) })
abort(403) # Permissions denied
def role_view(repo_perm_obj): def role_view(repo_perm_obj):
return { return {

View file

@ -5,6 +5,7 @@ import os
import hashlib import hashlib
from datetime import datetime, timedelta from datetime import datetime, timedelta
from flask import url_for
import storage import storage
@ -95,6 +96,8 @@ def __generate_repository(user, name, description, is_public, permissions,
create_subtree(repo, structure, None) create_subtree(repo, structure, None)
return repo
if __name__ == '__main__': if __name__ == '__main__':
initialize_db() initialize_db()
@ -141,6 +144,12 @@ if __name__ == '__main__':
'Shared repository, another user can write.', False, 'Shared repository, another user can write.', False,
[(new_user_2, 'write')], (5, [], 'latest')) [(new_user_2, 'write')], (5, [], 'latest'))
__generate_repository(new_user_1, 'empty', building = __generate_repository(new_user_1, 'building',
'Empty repository with no images or tags.', False, 'Empty repository which is building.',
[], (0, [], None)) False, [], (0, [], None))
build = model.create_repository_build(building, '123-45-6789')
build.build_node_id = 1
build.phase = 'building'
build.status_url = 'http://localhost:5000/test/build/status'
build.save()

Binary file not shown.

View file

@ -115,12 +115,13 @@ def babysit_builder(request):
# wait for the job to be complete # wait for the job to be complete
status_url = start_build.headers['Location'] status_url = start_build.headers['Location']
repository_build.phase = 'building'
repository_build.status_url = status_url repository_build.status_url = status_url
repository_build.save() repository_build.save()
logger.debug('Waiting for job to be complete') logger.debug('Waiting for job to be complete')
status = get_status(status_url) status = get_status(status_url)
while status != 'error' and status != 'completed': while status != 'error' and status != 'complete':
logger.debug('Job status is: %s' % status) logger.debug('Job status is: %s' % status)
time.sleep(5) time.sleep(5)
status = get_status(status_url) status = get_status(status_url)
@ -129,7 +130,7 @@ def babysit_builder(request):
if status == 'error': if status == 'error':
repository_build.phase = 'error' repository_build.phase = 'error'
else: else:
repository_build.phase = 'completed' repository_build.phase = 'complete'
# clean up the DO node # clean up the DO node
logger.debug('Cleaning up DO node.') logger.debug('Cleaning up DO node.')