Get the testlogs to correlate properly.
This commit is contained in:
parent
6fd343741b
commit
daec74bc25
3 changed files with 24 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):
|
||||
|
|
|
@ -11,10 +11,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 = [{
|
||||
|
@ -23,6 +24,7 @@ class TestBuildLogs(BuildLogs):
|
|||
}]
|
||||
self.request_counter = 0
|
||||
self._generate_logs()
|
||||
self._status = {}
|
||||
|
||||
def _generate_command(self):
|
||||
self.last_command += 1
|
||||
|
@ -48,7 +50,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))
|
||||
|
@ -60,13 +62,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': {},
|
||||
|
@ -85,18 +81,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()
|
||||
|
@ -109,7 +109,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()
|
||||
|
@ -118,7 +118,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()
|
||||
|
@ -127,10 +127,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