Randomize the diffs a little bit better.

This commit is contained in:
yackob03 2013-10-18 18:28:37 -04:00
parent e3bb9165e3
commit 0565871ee6
42 changed files with 161550 additions and 176153 deletions

View file

@ -4,7 +4,7 @@ import shutil
import os
import hashlib
from datetime import datetime
from datetime import datetime, timedelta
import storage
@ -24,41 +24,45 @@ SAMPLE_DIFFS = [
'test/data/sample/diffs/diffs3.json',
]
REFERENCE_DATE = datetime(2013, 6, 23)
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
def __gen_image_id(repo, image_num):
str_to_hash = "%s/%s/%s" % (repo.namespace, repo.name, image_num)
h = hashlib.md5(str_to_hash)
return h.hexdigest()
global_image_num = [0]
def create_subtree(repo, structure, parent):
num_nodes, subtrees, last_node_tags = structure
# create the nodes
for i in range(num_nodes):
docker_image_id = __gen_image_id(repo)
image_num = global_image_num[0]
global_image_num[0] += 1
docker_image_id = __gen_image_id(repo, image_num)
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)
creation_time = REFERENCE_DATE + timedelta(days=image_num)
new_image = model.set_image_metadata(docker_image_id, repo.namespace,
repo.name, str(datetime.now()),
repo.name, str(creation_time),
'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)]
docker_image_id)
source_diff = SAMPLE_DIFFS[image_num % len(SAMPLE_DIFFS)]
with open(source_diff, 'r') as source_file:
store.stream_write(diff_path, source_file)

Binary file not shown.