Check in diffs for the test db. Try to make the test db identifiers predictable.
This commit is contained in:
parent
4514f5a969
commit
3d0b165de9
71 changed files with 434170 additions and 11 deletions
43
initdb.py
43
initdb.py
|
@ -1,26 +1,42 @@
|
|||
import logging
|
||||
import string
|
||||
import shutil
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
from random import SystemRandom
|
||||
from datetime import datetime
|
||||
|
||||
import storage
|
||||
|
||||
from data.database import initialize_db
|
||||
from data import model
|
||||
from app import app
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
store = storage.load()
|
||||
logging.basicConfig(**app.config['LOGGING_CONFIG'])
|
||||
|
||||
|
||||
def __gen_hex_id(length=64):
|
||||
random = SystemRandom()
|
||||
return ''.join([random.choice('abcdef' + string.digits)
|
||||
for x in range(length)])
|
||||
SAMPLE_DIFFS = [
|
||||
'test/data/sample/diffs/diffs.json',
|
||||
'test/data/sample/diffs/diffs2.json',
|
||||
'test/data/sample/diffs/diffs3.json',
|
||||
]
|
||||
|
||||
|
||||
def __gen_checksum():
|
||||
return 'tarsum+sha256:' + __gen_hex_id(64)
|
||||
def __gen_checksum(image_id):
|
||||
h = hashlib.md5(image_id)
|
||||
return 'tarsum+sha256:' + h.hexdigest()
|
||||
|
||||
|
||||
global_image_num = [0]
|
||||
def __gen_image_id(repo):
|
||||
str_to_hash = "%s/%s/%s" % (repo.namespace, repo.name, global_image_num[0])
|
||||
global_image_num[0] += 1
|
||||
|
||||
h = hashlib.md5(str_to_hash)
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def create_subtree(repo, structure, parent):
|
||||
|
@ -28,8 +44,9 @@ def create_subtree(repo, structure, parent):
|
|||
|
||||
# create the nodes
|
||||
for i in range(num_nodes):
|
||||
docker_image_id = __gen_hex_id()
|
||||
checksum = __gen_checksum()
|
||||
docker_image_id = __gen_image_id(repo)
|
||||
logger.debug('new docker id: %s' % docker_image_id)
|
||||
checksum = __gen_checksum(docker_image_id)
|
||||
|
||||
new_image = model.create_image(docker_image_id, repo)
|
||||
model.set_image_checksum(docker_image_id, repo, checksum)
|
||||
|
@ -38,6 +55,14 @@ def create_subtree(repo, structure, parent):
|
|||
repo.name, str(datetime.now()),
|
||||
'no comment', parent)
|
||||
|
||||
# Populate the diff file
|
||||
diff_path = store.image_file_diffs_path(repo.namespace, repo.name,
|
||||
docker_image_id)
|
||||
source_diff = SAMPLE_DIFFS[i % len(SAMPLE_DIFFS)]
|
||||
|
||||
with open(source_diff, 'r') as source_file:
|
||||
store.stream_write(diff_path, source_file)
|
||||
|
||||
parent = new_image
|
||||
|
||||
if last_node_tags:
|
||||
|
|
Reference in a new issue