Get the testlogs to correlate properly.

This commit is contained in:
yackob03 2014-02-11 12:09:59 -05:00
parent 6fd343741b
commit daec74bc25
3 changed files with 24 additions and 23 deletions

View file

@ -1,5 +1,4 @@
import logging import logging
import os
from app import app as application from app import app as application
from data.model import db as model_db from data.model import db as model_db

View file

@ -1,5 +1,4 @@
import logging import logging
import os
import logstash_formatter import logstash_formatter
from peewee import MySQLDatabase, SqliteDatabase from peewee import MySQLDatabase, SqliteDatabase
@ -93,7 +92,8 @@ class RedisBuildLogs(object):
class TestBuildLogs(object): class TestBuildLogs(object):
BUILDLOGS = TestBuildLogs('logs.quay.io') BUILDLOGS = TestBuildLogs('logs.quay.io', 'devtable', 'building',
'deadbeef-dead-beef-dead-beefdeadbeef')
class StripeTestConfig(object): class StripeTestConfig(object):

View file

@ -11,10 +11,11 @@ logger = logging.getLogger(__name__)
class TestBuildLogs(BuildLogs): class TestBuildLogs(BuildLogs):
TEST_BUILD_ID = 'deadbeef-dead-beef-dead-beefdeadbeef' def __init__(self, redis_host, namespace, repository, test_build_id):
def __init__(self, redis_host):
super(TestBuildLogs, self).__init__(redis_host) super(TestBuildLogs, self).__init__(redis_host)
self.namespace = namespace
self.repository = repository
self.test_build_id = test_build_id
self.last_command = 0 self.last_command = 0
self.logs = [self._generate_command()] self.logs = [self._generate_command()]
self.commands = [{ self.commands = [{
@ -23,6 +24,7 @@ class TestBuildLogs(BuildLogs):
}] }]
self.request_counter = 0 self.request_counter = 0
self._generate_logs() self._generate_logs()
self._status = {}
def _generate_command(self): def _generate_command(self):
self.last_command += 1 self.last_command += 1
@ -48,7 +50,7 @@ class TestBuildLogs(BuildLogs):
}) })
@staticmethod @staticmethod
def generate_image_completion(rand_func): def _generate_image_completion(rand_func):
images = {} images = {}
for image_id in range(rand_func.randint(1, 11)): for image_id in range(rand_func.randint(1, 11)):
total = int(math.pow(abs(rand_func.gauss(0, 1000)), 2)) total = int(math.pow(abs(rand_func.gauss(0, 1000)), 2))
@ -60,13 +62,7 @@ class TestBuildLogs(BuildLogs):
} }
return images return images
@staticmethod def _generate_fake_status(self):
def generate_fake_status():
response = {
'id': 'deadbeef-dead-beef-dead-beefdeadbeef',
'status': None,
}
random = SystemRandom() random = SystemRandom()
phases = { phases = {
'waiting': {}, 'waiting': {},
@ -85,18 +81,22 @@ class TestBuildLogs(BuildLogs):
'total_commands': 7, 'total_commands': 7,
'current_command': 7, 'current_command': 7,
'push_completion': random.random(), 'push_completion': random.random(),
'image_completion': TestBuildLogs.generate_image_completion(random), 'image_completion': self._generate_image_completion(random),
}, },
} }
phase = random.choice(phases.keys()) 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): 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 self.request_counter += 1
if self.request_counter % 10 == 0: if self.request_counter % 10 == 0:
self._generate_logs() self._generate_logs()
@ -109,7 +109,7 @@ class TestBuildLogs(BuildLogs):
end_index) end_index)
def get_commands(self, build_id): def get_commands(self, build_id):
if build_id == self.TEST_BUILD_ID: if build_id == self.test_build_id:
self.request_counter += 1 self.request_counter += 1
if self.request_counter % 10 == 0: if self.request_counter % 10 == 0:
self._generate_logs() self._generate_logs()
@ -118,7 +118,7 @@ class TestBuildLogs(BuildLogs):
return super(TestBuildLogs, self).get_commands(build_id) return super(TestBuildLogs, self).get_commands(build_id)
def get_last_command(self, 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 self.request_counter += 1
if self.request_counter % 10 == 0: if self.request_counter % 10 == 0:
self._generate_logs() self._generate_logs()
@ -127,10 +127,12 @@ class TestBuildLogs(BuildLogs):
return super(TestBuildLogs, self).get_last_command(build_id) return super(TestBuildLogs, self).get_last_command(build_id)
def get_status(self, 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 self.request_counter += 1
if self.request_counter % 10 == 0: if self.request_counter % 10 == 0:
self._generate_logs() self._generate_logs()
return self.generate_fake_status() last_status = self._status
self._status = self._generate_fake_status()
return last_status
else: else:
return super(TestBuildLogs, self).get_status(build_id) return super(TestBuildLogs, self).get_status(build_id)