Merge branch 'bobthe' of https://bitbucket.org/yackob03/quay into bobthe
This commit is contained in:
commit
9616c32409
5 changed files with 27 additions and 23 deletions
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
from app import app as application
|
||||
from data.model import db as model_db
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
import logstash_formatter
|
||||
|
||||
from peewee import MySQLDatabase, SqliteDatabase
|
||||
|
@ -93,7 +92,8 @@ class RedisBuildLogs(object):
|
|||
|
||||
|
||||
class TestBuildLogs(object):
|
||||
BUILDLOGS = TestBuildLogs('logs.quay.io')
|
||||
BUILDLOGS = TestBuildLogs('logs.quay.io', 'devtable', 'building',
|
||||
'deadbeef-dead-beef-dead-beefdeadbeef')
|
||||
|
||||
|
||||
class StripeTestConfig(object):
|
||||
|
|
|
@ -215,6 +215,8 @@ class RepositoryBuild(BaseModel):
|
|||
resource_key = CharField()
|
||||
tag = CharField()
|
||||
phase = CharField(default='waiting')
|
||||
started = DateTimeField(default=datetime.now)
|
||||
|
||||
|
||||
|
||||
class QueueItem(BaseModel):
|
||||
|
|
|
@ -1147,6 +1147,7 @@ def build_status_view(build_obj):
|
|||
return {
|
||||
'id': build_obj.uuid,
|
||||
'phase': build_obj.phase,
|
||||
'started': build_obj.started,
|
||||
'status': status,
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,11 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class TestBuildLogs(BuildLogs):
|
||||
TEST_BUILD_ID = 'deadbeef-dead-beef-dead-beefdeadbeef'
|
||||
|
||||
def __init__(self, redis_host):
|
||||
def __init__(self, redis_host, namespace, repository, test_build_id):
|
||||
super(TestBuildLogs, self).__init__(redis_host)
|
||||
self.namespace = namespace
|
||||
self.repository = repository
|
||||
self.test_build_id = test_build_id
|
||||
self.last_command = 0
|
||||
self.logs = [self._generate_command()]
|
||||
self.commands = [{
|
||||
|
@ -24,6 +25,7 @@ class TestBuildLogs(BuildLogs):
|
|||
}]
|
||||
self.request_counter = 0
|
||||
self._generate_logs()
|
||||
self._status = {}
|
||||
|
||||
def _get_random_command(self):
|
||||
COMMANDS = ['FROM', 'MAINTAINER', 'RUN', 'CMD', 'EXPOSE', 'ENV', 'ADD',
|
||||
|
@ -61,7 +63,7 @@ class TestBuildLogs(BuildLogs):
|
|||
})
|
||||
|
||||
@staticmethod
|
||||
def generate_image_completion(rand_func):
|
||||
def _generate_image_completion(rand_func):
|
||||
images = {}
|
||||
for image_id in range(rand_func.randint(1, 11)):
|
||||
total = int(math.pow(abs(rand_func.gauss(0, 1000)), 2))
|
||||
|
@ -73,13 +75,7 @@ class TestBuildLogs(BuildLogs):
|
|||
}
|
||||
return images
|
||||
|
||||
@staticmethod
|
||||
def generate_fake_status():
|
||||
response = {
|
||||
'id': 'deadbeef-dead-beef-dead-beefdeadbeef',
|
||||
'status': None,
|
||||
}
|
||||
|
||||
def _generate_fake_status(self):
|
||||
random = SystemRandom()
|
||||
phases = {
|
||||
'waiting': {},
|
||||
|
@ -98,18 +94,22 @@ class TestBuildLogs(BuildLogs):
|
|||
'total_commands': 7,
|
||||
'current_command': 7,
|
||||
'push_completion': random.random(),
|
||||
'image_completion': TestBuildLogs.generate_image_completion(random),
|
||||
'image_completion': self._generate_image_completion(random),
|
||||
},
|
||||
}
|
||||
|
||||
phase = random.choice(phases.keys())
|
||||
response['phase'] = phase
|
||||
response['status'] = (phases[phase])
|
||||
|
||||
return response
|
||||
from data import model
|
||||
build_obj = model.get_repository_build(self.namespace, self.repository,
|
||||
self.test_build_id)
|
||||
build_obj.phase = phase
|
||||
build_obj.save()
|
||||
|
||||
return phases[phase]
|
||||
|
||||
def get_log_entries(self, build_id, start_index, end_index):
|
||||
if build_id == self.TEST_BUILD_ID:
|
||||
if build_id == self.test_build_id:
|
||||
self.request_counter += 1
|
||||
if self.request_counter % 10 == 0:
|
||||
self._generate_logs()
|
||||
|
@ -122,7 +122,7 @@ class TestBuildLogs(BuildLogs):
|
|||
end_index)
|
||||
|
||||
def get_commands(self, build_id):
|
||||
if build_id == self.TEST_BUILD_ID:
|
||||
if build_id == self.test_build_id:
|
||||
self.request_counter += 1
|
||||
if self.request_counter % 10 == 0:
|
||||
self._generate_logs()
|
||||
|
@ -131,7 +131,7 @@ class TestBuildLogs(BuildLogs):
|
|||
return super(TestBuildLogs, self).get_commands(build_id)
|
||||
|
||||
def get_last_command(self, build_id):
|
||||
if build_id == self.TEST_BUILD_ID:
|
||||
if build_id == self.test_build_id:
|
||||
self.request_counter += 1
|
||||
if self.request_counter % 10 == 0:
|
||||
self._generate_logs()
|
||||
|
@ -140,10 +140,12 @@ class TestBuildLogs(BuildLogs):
|
|||
return super(TestBuildLogs, self).get_last_command(build_id)
|
||||
|
||||
def get_status(self, build_id):
|
||||
if build_id == self.TEST_BUILD_ID:
|
||||
if build_id == self.test_build_id:
|
||||
self.request_counter += 1
|
||||
if self.request_counter % 10 == 0:
|
||||
self._generate_logs()
|
||||
return self.generate_fake_status()
|
||||
last_status = self._status
|
||||
self._status = self._generate_fake_status()
|
||||
return last_status
|
||||
else:
|
||||
return super(TestBuildLogs, self).get_status(build_id)
|
||||
|
|
Reference in a new issue