2013-10-10 03:52:28 +00:00
|
|
|
import logging
|
2014-01-13 21:32:51 +00:00
|
|
|
import json
|
2013-10-18 20:36:11 +00:00
|
|
|
import hashlib
|
2014-01-03 21:32:00 +00:00
|
|
|
import random
|
2014-06-27 23:18:27 +00:00
|
|
|
import calendar
|
2014-11-13 17:51:37 +00:00
|
|
|
import os
|
2015-08-12 20:39:32 +00:00
|
|
|
import argparse
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2016-06-17 17:52:27 +00:00
|
|
|
from datetime import datetime, timedelta, date
|
2018-04-06 17:48:01 +00:00
|
|
|
from peewee import SqliteDatabase
|
2015-07-15 21:25:41 +00:00
|
|
|
from itertools import count
|
2016-01-12 20:57:03 +00:00
|
|
|
from uuid import UUID, uuid4
|
2015-07-15 21:25:41 +00:00
|
|
|
from threading import Event
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
from email.utils import formatdate
|
2018-07-16 21:12:04 +00:00
|
|
|
from data.database import (db, all_models, Role, TeamRole, Visibility, LoginService,
|
2015-07-15 21:25:41 +00:00
|
|
|
BuildTriggerService, AccessTokenKind, LogEntryKind, ImageStorageLocation,
|
|
|
|
ImageStorageTransformation, ImageStorageSignatureKind,
|
2016-01-12 20:57:03 +00:00
|
|
|
ExternalNotificationEvent, ExternalNotificationMethod, NotificationKind,
|
2016-04-01 17:55:29 +00:00
|
|
|
QuayRegion, QuayService, UserRegion, OAuthAuthorizationCode,
|
2017-03-21 02:12:18 +00:00
|
|
|
ServiceKeyApprovalType, MediaType, LabelSourceType, UserPromptKind,
|
2018-07-16 21:12:04 +00:00
|
|
|
RepositoryKind, User, DisableReason, DeletedNamespace, appr_classes,
|
2018-10-30 15:35:31 +00:00
|
|
|
ApprTagKind, ApprBlobPlacementLocation, Repository, TagKind,
|
2018-11-05 18:03:08 +00:00
|
|
|
ManifestChild, TagToRepositoryTag, get_epoch_timestamp_ms)
|
2013-10-10 03:52:28 +00:00
|
|
|
from data import model
|
2019-01-08 19:03:28 +00:00
|
|
|
from data.logs_model import logs_model
|
2016-01-12 20:57:03 +00:00
|
|
|
from data.queue import WorkQueue
|
2018-08-27 19:01:27 +00:00
|
|
|
from data.registry_model import registry_model
|
2018-11-05 18:03:08 +00:00
|
|
|
from data.registry_model.registry_pre_oci_model import pre_oci_model
|
2016-01-12 20:57:03 +00:00
|
|
|
from app import app, storage as store, tf
|
2015-06-28 10:29:22 +00:00
|
|
|
from storage.basestorage import StoragePaths
|
2018-07-31 19:43:09 +00:00
|
|
|
from image.docker.schema1 import DOCKER_SCHEMA1_CONTENT_TYPES
|
2018-11-12 21:27:49 +00:00
|
|
|
from image.docker.schema2 import DOCKER_SCHEMA2_CONTENT_TYPES
|
2016-04-01 17:55:29 +00:00
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2015-04-13 17:31:07 +00:00
|
|
|
from workers import repositoryactioncounter
|
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
|
2013-10-19 00:18:23 +00:00
|
|
|
SAMPLE_DIFFS = ['test/data/sample/diffs/diffs%s.json' % i
|
|
|
|
for i in range(1, 10)]
|
2014-02-17 20:17:39 +00:00
|
|
|
|
2014-01-14 20:47:13 +00:00
|
|
|
SAMPLE_CMDS = [["/bin/bash"],
|
2014-01-13 21:32:51 +00:00
|
|
|
["/bin/sh", "-c",
|
|
|
|
"echo \"PasswordAuthentication no\" >> /etc/ssh/sshd_config"],
|
|
|
|
["/bin/sh", "-c",
|
|
|
|
"sed -i 's/#\\(force_color_prompt\\)/\\1/' /etc/skel/.bashrc"],
|
2014-01-14 20:28:24 +00:00
|
|
|
["/bin/sh", "-c", "#(nop) EXPOSE [8080]"],
|
2014-11-24 21:07:38 +00:00
|
|
|
["/bin/sh", "-c",
|
2014-01-14 20:47:13 +00:00
|
|
|
"#(nop) MAINTAINER Jake Moshenko <jake@devtable.com>"],
|
2014-01-13 21:32:51 +00:00
|
|
|
None]
|
2013-10-18 20:36:11 +00:00
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
REFERENCE_DATE = datetime(2013, 6, 23)
|
2013-11-08 03:43:43 +00:00
|
|
|
TEST_STRIPE_ID = 'cus_2tmnh3PkXQS8NG'
|
2013-10-18 22:28:37 +00:00
|
|
|
|
2014-11-13 17:51:37 +00:00
|
|
|
IS_TESTING_REAL_DATABASE = bool(os.environ.get('TEST_DATABASE_URI'))
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
|
2013-10-18 20:36:11 +00:00
|
|
|
def __gen_checksum(image_id):
|
2015-07-15 21:25:41 +00:00
|
|
|
csum = hashlib.md5(image_id)
|
|
|
|
return 'tarsum+sha256:' + csum.hexdigest() + csum.hexdigest()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
def __gen_image_id(repo, image_num):
|
2014-09-24 22:01:35 +00:00
|
|
|
str_to_hash = "%s/%s/%s" % (repo.namespace_user.username, repo.name, image_num)
|
2013-10-18 20:36:11 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
img_id = hashlib.md5(str_to_hash)
|
|
|
|
return img_id.hexdigest() + img_id.hexdigest()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
2014-10-07 20:40:44 +00:00
|
|
|
def __gen_image_uuid(repo, image_num):
|
|
|
|
str_to_hash = "%s/%s/%s" % (repo.namespace_user.username, repo.name, image_num)
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
img_uuid = hashlib.md5(str_to_hash)
|
|
|
|
return UUID(bytes=img_uuid.digest())
|
|
|
|
|
|
|
|
|
|
|
|
global_image_num = count()
|
2014-10-07 20:40:44 +00:00
|
|
|
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
def __create_subtree(with_storage, repo, structure, creator_username, parent, tag_map):
|
2013-10-10 04:40:07 +00:00
|
|
|
num_nodes, subtrees, last_node_tags = structure
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
# create the nodes
|
2015-07-15 21:25:41 +00:00
|
|
|
for model_num in range(num_nodes):
|
|
|
|
image_num = next(global_image_num)
|
2013-10-18 22:28:37 +00:00
|
|
|
docker_image_id = __gen_image_id(repo, image_num)
|
2015-07-15 21:25:41 +00:00
|
|
|
logger.debug('new docker id: %s', docker_image_id)
|
2013-10-18 20:36:11 +00:00
|
|
|
checksum = __gen_checksum(docker_image_id)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_image = model.image.find_create_or_link_image(docker_image_id, repo, None, {}, 'local_us')
|
2014-10-07 20:40:44 +00:00
|
|
|
new_image.storage.uuid = __gen_image_uuid(repo, image_num)
|
2014-06-11 19:37:45 +00:00
|
|
|
new_image.storage.uploading = False
|
2014-02-17 20:17:39 +00:00
|
|
|
new_image.storage.save()
|
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
# Write out a fake torrentinfo
|
|
|
|
model.storage.save_torrent_info(new_image.storage, 1, 'deadbeef')
|
|
|
|
|
2015-06-28 10:29:22 +00:00
|
|
|
# Write some data for the storage.
|
2016-02-24 21:01:27 +00:00
|
|
|
if with_storage or os.environ.get('WRITE_STORAGE_FILES'):
|
2015-06-28 10:29:22 +00:00
|
|
|
storage_paths = StoragePaths()
|
2015-10-22 20:59:28 +00:00
|
|
|
paths = [storage_paths.v1_image_layer_path]
|
2015-06-28 10:29:22 +00:00
|
|
|
|
|
|
|
for path_builder in paths:
|
|
|
|
path = path_builder(new_image.storage.uuid)
|
|
|
|
store.put_content('local_us', path, checksum)
|
|
|
|
|
2015-10-05 17:35:01 +00:00
|
|
|
new_image.security_indexed = False
|
2015-11-09 19:41:53 +00:00
|
|
|
new_image.security_indexed_engine = -1
|
2015-10-05 17:35:01 +00:00
|
|
|
new_image.save()
|
2015-06-28 10:29:22 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
creation_time = REFERENCE_DATE + timedelta(weeks=image_num) + timedelta(days=model_num)
|
2014-01-13 21:32:51 +00:00
|
|
|
command_list = SAMPLE_CMDS[image_num % len(SAMPLE_CMDS)]
|
|
|
|
command = json.dumps(command_list) if command_list else None
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
v1_metadata = {
|
|
|
|
'id': docker_image_id,
|
|
|
|
}
|
|
|
|
if parent is not None:
|
|
|
|
v1_metadata['parent'] = parent.docker_image_id
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_image = model.image.set_image_metadata(docker_image_id, repo.namespace_user.username,
|
|
|
|
repo.name, str(creation_time), 'no comment', command,
|
2015-09-28 19:56:24 +00:00
|
|
|
json.dumps(v1_metadata), parent)
|
2016-01-05 17:14:52 +00:00
|
|
|
new_image.storage.content_checksum = checksum
|
|
|
|
new_image.storage.save()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2014-10-02 14:46:20 +00:00
|
|
|
compressed_size = random.randrange(1, 1024 * 1024 * 1024)
|
2016-01-05 17:14:52 +00:00
|
|
|
model.storage.set_image_storage_metadata(docker_image_id, repo.namespace_user.username,
|
|
|
|
repo.name, compressed_size, int(compressed_size * 1.4))
|
2014-01-03 21:32:00 +00:00
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
parent = new_image
|
|
|
|
|
2013-10-10 04:40:07 +00:00
|
|
|
if last_node_tags:
|
|
|
|
if not isinstance(last_node_tags, list):
|
|
|
|
last_node_tags = [last_node_tags]
|
|
|
|
|
2018-08-27 19:01:27 +00:00
|
|
|
repo_ref = registry_model.lookup_repository(repo.namespace_user.username, repo.name)
|
2013-10-10 04:40:07 +00:00
|
|
|
for tag_name in last_node_tags:
|
2018-11-05 18:03:08 +00:00
|
|
|
adjusted_tag_name = tag_name
|
|
|
|
now_ms = None
|
|
|
|
if tag_name[0] == '#':
|
|
|
|
adjusted_tag_name = tag_name[1:]
|
|
|
|
now_ms = get_epoch_timestamp_ms() - 1000
|
|
|
|
|
|
|
|
new_tag = model.tag.create_or_update_tag(repo.namespace_user.username, repo.name,
|
|
|
|
adjusted_tag_name,
|
|
|
|
new_image.docker_image_id,
|
|
|
|
now_ms=now_ms)
|
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
derived = model.image.find_or_create_derived_storage(new_tag, 'squash', 'local_us')
|
|
|
|
model.storage.find_or_create_storage_signature(derived, 'gpg2')
|
2015-03-04 21:03:00 +00:00
|
|
|
|
2018-11-05 18:03:08 +00:00
|
|
|
tag = pre_oci_model.get_repo_tag(repo_ref, adjusted_tag_name)
|
|
|
|
assert tag._db_id == new_tag.id
|
|
|
|
assert pre_oci_model.backfill_manifest_for_tag(tag)
|
2015-07-15 21:25:41 +00:00
|
|
|
tag_map[tag_name] = new_tag
|
2015-04-15 19:21:09 +00:00
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
for subtree in subtrees:
|
2016-02-24 21:01:27 +00:00
|
|
|
__create_subtree(with_storage, repo, subtree, creator_username, new_image, tag_map)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
2016-04-05 19:32:47 +00:00
|
|
|
def __generate_service_key(kid, name, user, timestamp, approval_type, expiration=None,
|
2016-04-12 23:17:19 +00:00
|
|
|
metadata=None, service='sample_service', rotation_duration=None):
|
2016-04-07 00:03:04 +00:00
|
|
|
_, key = model.service_keys.generate_service_key(service, expiration, kid=kid,
|
2016-04-12 23:17:19 +00:00
|
|
|
name=name, metadata=metadata,
|
|
|
|
rotation_duration=rotation_duration)
|
2016-04-01 17:55:29 +00:00
|
|
|
|
2016-04-05 19:32:47 +00:00
|
|
|
if approval_type is not None:
|
2018-08-13 15:40:50 +00:00
|
|
|
model.service_keys.approve_service_key(key.kid, approval_type, notes='The **test** approval')
|
2016-04-05 19:32:47 +00:00
|
|
|
|
|
|
|
key_metadata = {
|
|
|
|
'kid': kid,
|
|
|
|
'preshared': True,
|
2016-04-07 00:03:04 +00:00
|
|
|
'service': service,
|
2016-04-05 19:32:47 +00:00
|
|
|
'name': name,
|
|
|
|
'expiration_date': expiration,
|
|
|
|
'auto_approved': True
|
|
|
|
}
|
2016-04-01 17:55:29 +00:00
|
|
|
|
2019-01-08 19:03:28 +00:00
|
|
|
logs_model.log_action('service_key_approve', None, performer=user,
|
|
|
|
timestamp=timestamp, metadata=key_metadata)
|
2016-04-01 17:55:29 +00:00
|
|
|
|
2019-01-08 19:03:28 +00:00
|
|
|
logs_model.log_action('service_key_create', None, performer=user,
|
|
|
|
timestamp=timestamp, metadata=key_metadata)
|
2016-04-01 17:55:29 +00:00
|
|
|
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
def __generate_repository(with_storage, user_obj, name, description, is_public, permissions, structure):
|
2015-07-15 21:25:41 +00:00
|
|
|
repo = model.repository.create_repository(user_obj.username, name, user_obj)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
if is_public:
|
2015-07-15 21:25:41 +00:00
|
|
|
model.repository.set_repository_visibility(repo, 'public')
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2013-10-12 01:28:02 +00:00
|
|
|
if description:
|
|
|
|
repo.description = description
|
|
|
|
repo.save()
|
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
for delegate, role in permissions:
|
2015-07-15 21:25:41 +00:00
|
|
|
model.permission.set_user_repo_permission(delegate.username, user_obj.username, name, role)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2014-01-20 22:38:33 +00:00
|
|
|
if isinstance(structure, list):
|
2015-07-15 21:25:41 +00:00
|
|
|
for leaf in structure:
|
2016-02-24 21:01:27 +00:00
|
|
|
__create_subtree(with_storage, repo, leaf, user_obj.username, None, {})
|
2014-01-20 22:38:33 +00:00
|
|
|
else:
|
2016-02-24 21:01:27 +00:00
|
|
|
__create_subtree(with_storage, repo, structure, user_obj.username, None, {})
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2013-10-25 19:47:34 +00:00
|
|
|
return repo
|
|
|
|
|
2014-01-31 01:57:40 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
db_initialized_for_testing = Event()
|
2014-01-31 01:57:40 +00:00
|
|
|
testcases = {}
|
|
|
|
|
|
|
|
def finished_database_for_testing(testcase):
|
|
|
|
""" Called when a testcase has finished using the database, indicating that
|
|
|
|
any changes should be discarded.
|
|
|
|
"""
|
2018-07-24 15:37:06 +00:00
|
|
|
testcases[testcase]['savepoint'].rollback()
|
2014-01-31 01:57:40 +00:00
|
|
|
testcases[testcase]['savepoint'].__exit__(True, None, None)
|
2018-07-24 15:37:06 +00:00
|
|
|
|
|
|
|
testcases[testcase]['transaction'].__exit__(True, None, None)
|
2014-01-31 01:57:40 +00:00
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
def setup_database_for_testing(testcase, with_storage=False, force_rebuild=False):
|
2014-01-31 01:57:40 +00:00
|
|
|
""" Called when a testcase has started using the database, indicating that
|
|
|
|
the database should be setup (if not already) and a savepoint created.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Sanity check to make sure we're not killing our prod db
|
2015-07-15 21:25:41 +00:00
|
|
|
if not IS_TESTING_REAL_DATABASE and not isinstance(db.obj, SqliteDatabase):
|
2014-01-31 01:57:40 +00:00
|
|
|
raise RuntimeError('Attempted to wipe production database!')
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
if not db_initialized_for_testing.is_set() or force_rebuild:
|
2014-11-24 21:07:38 +00:00
|
|
|
logger.debug('Setting up DB for testing.')
|
2014-01-31 01:57:40 +00:00
|
|
|
|
|
|
|
# Setup the database.
|
2016-11-30 21:54:04 +00:00
|
|
|
if os.environ.get('SKIP_DB_SCHEMA', '') != 'true':
|
|
|
|
wipe_database()
|
|
|
|
initialize_database()
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
populate_database(with_storage=with_storage)
|
2014-01-31 01:57:40 +00:00
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
models_missing_data = find_models_missing_data()
|
|
|
|
if models_missing_data:
|
|
|
|
raise RuntimeError('%s models are missing data: %s', len(models_missing_data),
|
|
|
|
models_missing_data)
|
|
|
|
|
2014-11-07 17:05:21 +00:00
|
|
|
# Enable foreign key constraints.
|
2014-11-13 17:51:37 +00:00
|
|
|
if not IS_TESTING_REAL_DATABASE:
|
2015-07-15 21:25:41 +00:00
|
|
|
db.obj.execute_sql('PRAGMA foreign_keys = ON;')
|
2014-11-07 17:05:21 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
db_initialized_for_testing.set()
|
2014-01-31 01:57:40 +00:00
|
|
|
|
2018-07-31 19:43:09 +00:00
|
|
|
# Initialize caches.
|
|
|
|
Repository.kind.get_id('image')
|
|
|
|
|
2014-01-31 01:57:40 +00:00
|
|
|
# Create a savepoint for the testcase.
|
|
|
|
testcases[testcase] = {}
|
2018-07-24 15:37:06 +00:00
|
|
|
testcases[testcase]['transaction'] = db.transaction()
|
|
|
|
testcases[testcase]['transaction'].__enter__()
|
2018-04-06 17:48:01 +00:00
|
|
|
|
|
|
|
testcases[testcase]['savepoint'] = db.savepoint()
|
2014-01-31 01:57:40 +00:00
|
|
|
testcases[testcase]['savepoint'].__enter__()
|
2013-10-01 18:14:39 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
def initialize_database():
|
2018-04-06 17:48:01 +00:00
|
|
|
db.create_tables(all_models)
|
2013-11-06 22:09:22 +00:00
|
|
|
|
|
|
|
Role.create(name='admin')
|
|
|
|
Role.create(name='write')
|
|
|
|
Role.create(name='read')
|
|
|
|
TeamRole.create(name='admin')
|
|
|
|
TeamRole.create(name='creator')
|
|
|
|
TeamRole.create(name='member')
|
|
|
|
Visibility.create(name='public')
|
|
|
|
Visibility.create(name='private')
|
2014-08-11 19:47:44 +00:00
|
|
|
|
|
|
|
LoginService.create(name='google')
|
2013-11-06 22:09:22 +00:00
|
|
|
LoginService.create(name='github')
|
2013-11-20 21:13:03 +00:00
|
|
|
LoginService.create(name='quayrobot')
|
2014-05-13 16:17:26 +00:00
|
|
|
LoginService.create(name='ldap')
|
2015-06-02 22:19:22 +00:00
|
|
|
LoginService.create(name='jwtauthn')
|
2015-07-13 09:34:32 +00:00
|
|
|
LoginService.create(name='keystone')
|
2015-09-04 20:14:46 +00:00
|
|
|
LoginService.create(name='dex')
|
2017-06-08 17:13:22 +00:00
|
|
|
LoginService.create(name='oidc')
|
2014-02-18 20:50:15 +00:00
|
|
|
|
|
|
|
BuildTriggerService.create(name='github')
|
2015-04-21 22:04:25 +00:00
|
|
|
BuildTriggerService.create(name='custom-git')
|
2015-04-24 19:13:08 +00:00
|
|
|
BuildTriggerService.create(name='bitbucket')
|
2015-05-02 21:54:48 +00:00
|
|
|
BuildTriggerService.create(name='gitlab')
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2015-02-17 17:35:16 +00:00
|
|
|
AccessTokenKind.create(name='build-worker')
|
|
|
|
AccessTokenKind.create(name='pushpull-token')
|
|
|
|
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='account_change_plan')
|
|
|
|
LogEntryKind.create(name='account_change_cc')
|
|
|
|
LogEntryKind.create(name='account_change_password')
|
|
|
|
LogEntryKind.create(name='account_convert')
|
|
|
|
|
|
|
|
LogEntryKind.create(name='create_robot')
|
|
|
|
LogEntryKind.create(name='delete_robot')
|
|
|
|
|
|
|
|
LogEntryKind.create(name='create_repo')
|
|
|
|
LogEntryKind.create(name='push_repo')
|
|
|
|
LogEntryKind.create(name='pull_repo')
|
|
|
|
LogEntryKind.create(name='delete_repo')
|
2014-02-28 05:12:09 +00:00
|
|
|
LogEntryKind.create(name='create_tag')
|
|
|
|
LogEntryKind.create(name='move_tag')
|
2014-01-06 20:20:58 +00:00
|
|
|
LogEntryKind.create(name='delete_tag')
|
2015-04-16 21:18:00 +00:00
|
|
|
LogEntryKind.create(name='revert_tag')
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='add_repo_permission')
|
|
|
|
LogEntryKind.create(name='change_repo_permission')
|
|
|
|
LogEntryKind.create(name='delete_repo_permission')
|
|
|
|
LogEntryKind.create(name='change_repo_visibility')
|
2017-04-15 12:26:33 +00:00
|
|
|
LogEntryKind.create(name='change_repo_trust')
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='add_repo_accesstoken')
|
|
|
|
LogEntryKind.create(name='delete_repo_accesstoken')
|
|
|
|
LogEntryKind.create(name='set_repo_description')
|
2014-02-25 19:11:20 +00:00
|
|
|
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='build_dockerfile')
|
|
|
|
|
|
|
|
LogEntryKind.create(name='org_create_team')
|
|
|
|
LogEntryKind.create(name='org_delete_team')
|
2014-08-15 21:47:43 +00:00
|
|
|
LogEntryKind.create(name='org_invite_team_member')
|
2014-09-08 21:20:01 +00:00
|
|
|
LogEntryKind.create(name='org_delete_team_member_invite')
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='org_add_team_member')
|
2014-08-18 21:24:00 +00:00
|
|
|
LogEntryKind.create(name='org_team_member_invite_accepted')
|
|
|
|
LogEntryKind.create(name='org_team_member_invite_declined')
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='org_remove_team_member')
|
|
|
|
LogEntryKind.create(name='org_set_team_description')
|
|
|
|
LogEntryKind.create(name='org_set_team_role')
|
2014-01-21 19:18:20 +00:00
|
|
|
|
2014-01-21 22:04:00 +00:00
|
|
|
LogEntryKind.create(name='create_prototype_permission')
|
|
|
|
LogEntryKind.create(name='modify_prototype_permission')
|
|
|
|
LogEntryKind.create(name='delete_prototype_permission')
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2014-02-25 19:11:20 +00:00
|
|
|
LogEntryKind.create(name='setup_repo_trigger')
|
2014-02-18 20:50:15 +00:00
|
|
|
LogEntryKind.create(name='delete_repo_trigger')
|
|
|
|
|
2014-03-20 19:46:13 +00:00
|
|
|
LogEntryKind.create(name='create_application')
|
|
|
|
LogEntryKind.create(name='update_application')
|
|
|
|
LogEntryKind.create(name='delete_application')
|
|
|
|
LogEntryKind.create(name='reset_application_client_secret')
|
|
|
|
|
2014-08-25 21:19:23 +00:00
|
|
|
# Note: These next two are deprecated.
|
2014-07-16 20:30:47 +00:00
|
|
|
LogEntryKind.create(name='add_repo_webhook')
|
|
|
|
LogEntryKind.create(name='delete_repo_webhook')
|
|
|
|
|
|
|
|
LogEntryKind.create(name='add_repo_notification')
|
|
|
|
LogEntryKind.create(name='delete_repo_notification')
|
2017-05-18 21:52:50 +00:00
|
|
|
LogEntryKind.create(name='reset_repo_notification')
|
2014-07-16 20:30:47 +00:00
|
|
|
|
2014-08-25 21:19:23 +00:00
|
|
|
LogEntryKind.create(name='regenerate_robot_token')
|
|
|
|
|
2014-10-29 19:42:44 +00:00
|
|
|
LogEntryKind.create(name='repo_verb')
|
|
|
|
|
2016-04-01 17:55:29 +00:00
|
|
|
LogEntryKind.create(name='service_key_create')
|
|
|
|
LogEntryKind.create(name='service_key_approve')
|
|
|
|
LogEntryKind.create(name='service_key_delete')
|
|
|
|
LogEntryKind.create(name='service_key_modify')
|
|
|
|
LogEntryKind.create(name='service_key_extend')
|
|
|
|
LogEntryKind.create(name='service_key_rotate')
|
|
|
|
|
2016-06-07 22:12:11 +00:00
|
|
|
LogEntryKind.create(name='take_ownership')
|
|
|
|
|
2016-07-18 22:20:00 +00:00
|
|
|
LogEntryKind.create(name='manifest_label_add')
|
|
|
|
LogEntryKind.create(name='manifest_label_delete')
|
|
|
|
|
2017-06-22 01:33:26 +00:00
|
|
|
LogEntryKind.create(name='change_tag_expiration')
|
2017-10-17 21:01:59 +00:00
|
|
|
LogEntryKind.create(name='toggle_repo_trigger')
|
2017-06-22 01:33:26 +00:00
|
|
|
|
2017-12-08 22:05:59 +00:00
|
|
|
LogEntryKind.create(name='create_app_specific_token')
|
|
|
|
LogEntryKind.create(name='revoke_app_specific_token')
|
|
|
|
|
2014-06-17 20:03:43 +00:00
|
|
|
ImageStorageLocation.create(name='local_eu')
|
|
|
|
ImageStorageLocation.create(name='local_us')
|
|
|
|
|
2018-05-24 21:54:51 +00:00
|
|
|
ApprBlobPlacementLocation.create(name='local_eu')
|
|
|
|
ApprBlobPlacementLocation.create(name='local_us')
|
|
|
|
|
2014-09-18 21:26:40 +00:00
|
|
|
ImageStorageTransformation.create(name='squash')
|
2015-01-13 22:46:11 +00:00
|
|
|
ImageStorageTransformation.create(name='aci')
|
2014-09-18 21:26:40 +00:00
|
|
|
|
2015-02-04 20:29:24 +00:00
|
|
|
ImageStorageSignatureKind.create(name='gpg2')
|
|
|
|
|
2014-07-18 02:51:58 +00:00
|
|
|
# NOTE: These MUST be copied over to NotificationKind, since every external
|
|
|
|
# notification can also generate a Quay.io notification.
|
2014-07-16 20:30:47 +00:00
|
|
|
ExternalNotificationEvent.create(name='repo_push')
|
2014-07-18 19:58:18 +00:00
|
|
|
ExternalNotificationEvent.create(name='build_queued')
|
2014-07-16 20:30:47 +00:00
|
|
|
ExternalNotificationEvent.create(name='build_start')
|
|
|
|
ExternalNotificationEvent.create(name='build_success')
|
2016-11-29 16:48:08 +00:00
|
|
|
ExternalNotificationEvent.create(name='build_cancelled')
|
2014-07-16 20:30:47 +00:00
|
|
|
ExternalNotificationEvent.create(name='build_failure')
|
2015-10-13 22:14:52 +00:00
|
|
|
ExternalNotificationEvent.create(name='vulnerability_found')
|
2014-07-16 20:30:47 +00:00
|
|
|
|
|
|
|
ExternalNotificationMethod.create(name='quay_notification')
|
|
|
|
ExternalNotificationMethod.create(name='email')
|
|
|
|
ExternalNotificationMethod.create(name='webhook')
|
|
|
|
|
2014-08-19 18:33:33 +00:00
|
|
|
ExternalNotificationMethod.create(name='flowdock')
|
2014-08-19 21:40:36 +00:00
|
|
|
ExternalNotificationMethod.create(name='hipchat')
|
2014-08-27 02:09:56 +00:00
|
|
|
ExternalNotificationMethod.create(name='slack')
|
2014-08-19 18:33:33 +00:00
|
|
|
|
2014-07-18 02:51:58 +00:00
|
|
|
NotificationKind.create(name='repo_push')
|
2014-07-18 19:58:18 +00:00
|
|
|
NotificationKind.create(name='build_queued')
|
2014-07-18 02:51:58 +00:00
|
|
|
NotificationKind.create(name='build_start')
|
|
|
|
NotificationKind.create(name='build_success')
|
2016-11-29 16:48:08 +00:00
|
|
|
NotificationKind.create(name='build_cancelled')
|
2014-07-18 02:51:58 +00:00
|
|
|
NotificationKind.create(name='build_failure')
|
2015-10-13 22:14:52 +00:00
|
|
|
NotificationKind.create(name='vulnerability_found')
|
2016-03-23 22:16:03 +00:00
|
|
|
NotificationKind.create(name='service_key_submitted')
|
2014-07-18 02:51:58 +00:00
|
|
|
|
|
|
|
NotificationKind.create(name='password_required')
|
|
|
|
NotificationKind.create(name='over_private_usage')
|
|
|
|
NotificationKind.create(name='expiring_license')
|
|
|
|
NotificationKind.create(name='maintenance')
|
2014-08-15 21:47:43 +00:00
|
|
|
NotificationKind.create(name='org_team_invite')
|
2014-07-18 02:51:58 +00:00
|
|
|
|
|
|
|
NotificationKind.create(name='test_notification')
|
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
QuayRegion.create(name='us')
|
|
|
|
QuayService.create(name='quay')
|
|
|
|
|
2016-07-18 22:20:00 +00:00
|
|
|
MediaType.create(name='text/plain')
|
|
|
|
MediaType.create(name='application/json')
|
2017-01-17 21:41:24 +00:00
|
|
|
MediaType.create(name='text/markdown')
|
2017-08-10 00:45:46 +00:00
|
|
|
MediaType.create(name='application/vnd.cnr.blob.v0.tar+gzip')
|
|
|
|
MediaType.create(name='application/vnd.cnr.package-manifest.helm.v0.json')
|
|
|
|
MediaType.create(name='application/vnd.cnr.package-manifest.kpm.v0.json')
|
|
|
|
MediaType.create(name='application/vnd.cnr.package-manifest.docker-compose.v0.json')
|
|
|
|
MediaType.create(name='application/vnd.cnr.package.kpm.v0.tar+gzip')
|
|
|
|
MediaType.create(name='application/vnd.cnr.package.helm.v0.tar+gzip')
|
|
|
|
MediaType.create(name='application/vnd.cnr.package.docker-compose.v0.tar+gzip')
|
|
|
|
MediaType.create(name='application/vnd.cnr.manifests.v0.json')
|
|
|
|
MediaType.create(name='application/vnd.cnr.manifest.list.v0.json')
|
2016-07-18 22:20:00 +00:00
|
|
|
|
2018-07-31 19:43:09 +00:00
|
|
|
for media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
|
|
|
|
MediaType.create(name=media_type)
|
|
|
|
|
2018-11-12 21:27:49 +00:00
|
|
|
for media_type in DOCKER_SCHEMA2_CONTENT_TYPES:
|
|
|
|
MediaType.create(name=media_type)
|
|
|
|
|
2016-07-18 22:20:00 +00:00
|
|
|
LabelSourceType.create(name='manifest')
|
|
|
|
LabelSourceType.create(name='api', mutable=True)
|
|
|
|
LabelSourceType.create(name='internal')
|
|
|
|
|
2016-09-08 22:43:50 +00:00
|
|
|
UserPromptKind.create(name='confirm_username')
|
2016-11-04 21:57:55 +00:00
|
|
|
UserPromptKind.create(name='enter_name')
|
|
|
|
UserPromptKind.create(name='enter_company')
|
2016-09-08 22:43:50 +00:00
|
|
|
|
2017-03-21 02:12:18 +00:00
|
|
|
RepositoryKind.create(name='image')
|
|
|
|
RepositoryKind.create(name='application')
|
|
|
|
|
2018-05-24 21:54:51 +00:00
|
|
|
ApprTagKind.create(name='tag')
|
|
|
|
ApprTagKind.create(name='release')
|
|
|
|
ApprTagKind.create(name='channel')
|
|
|
|
|
2017-10-17 21:01:59 +00:00
|
|
|
DisableReason.create(name='user_toggled')
|
2017-10-18 20:03:38 +00:00
|
|
|
DisableReason.create(name='successive_build_failures')
|
|
|
|
DisableReason.create(name='successive_build_internal_errors')
|
2017-10-17 21:01:59 +00:00
|
|
|
|
2018-10-29 19:37:33 +00:00
|
|
|
TagKind.create(name='tag')
|
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
|
|
|
|
def wipe_database():
|
|
|
|
logger.debug('Wiping all data from the DB.')
|
|
|
|
|
|
|
|
# Sanity check to make sure we're not killing our prod db
|
2015-07-15 21:25:41 +00:00
|
|
|
if not IS_TESTING_REAL_DATABASE and not isinstance(db.obj, SqliteDatabase):
|
2013-11-06 22:09:22 +00:00
|
|
|
raise RuntimeError('Attempted to wipe production database!')
|
|
|
|
|
2018-04-06 17:48:01 +00:00
|
|
|
db.drop_tables(all_models)
|
2013-11-06 22:09:22 +00:00
|
|
|
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
def populate_database(minimal=False, with_storage=False):
|
2013-11-06 22:09:22 +00:00
|
|
|
logger.debug('Populating the DB with test data.')
|
|
|
|
|
2017-04-24 19:52:50 +00:00
|
|
|
# Check if the data already exists. If so, we skip. This can happen between calls from the
|
|
|
|
# "old style" tests and the new py.test's.
|
|
|
|
try:
|
|
|
|
User.get(username='devtable')
|
|
|
|
logger.debug('DB already populated')
|
|
|
|
return
|
|
|
|
except User.DoesNotExist:
|
|
|
|
pass
|
|
|
|
|
2016-11-30 21:54:04 +00:00
|
|
|
# Note: databases set up with "real" schema (via Alembic) will not have these types
|
|
|
|
# type, so we it here it necessary.
|
|
|
|
try:
|
|
|
|
ImageStorageLocation.get(name='local_eu')
|
|
|
|
ImageStorageLocation.get(name='local_us')
|
|
|
|
except ImageStorageLocation.DoesNotExist:
|
|
|
|
ImageStorageLocation.create(name='local_eu')
|
|
|
|
ImageStorageLocation.create(name='local_us')
|
|
|
|
|
|
|
|
try:
|
|
|
|
NotificationKind.get(name='test_notification')
|
|
|
|
except NotificationKind.DoesNotExist:
|
|
|
|
NotificationKind.create(name='test_notification')
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_user_1 = model.user.create_user('devtable', 'password', 'jschorr@devtable.com')
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_1.verified = True
|
2014-01-10 17:39:23 +00:00
|
|
|
new_user_1.stripe_id = TEST_STRIPE_ID
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_1.save()
|
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
if minimal:
|
|
|
|
logger.debug('Skipping most db population because user requested mininal db')
|
|
|
|
return
|
|
|
|
|
2016-11-30 21:54:04 +00:00
|
|
|
UserRegion.create(user=new_user_1, location=ImageStorageLocation.get(name='local_us'))
|
2016-01-12 20:57:03 +00:00
|
|
|
model.release.set_region_release('quay', 'us', 'v0.1.2')
|
|
|
|
|
|
|
|
model.user.create_confirm_email_code(new_user_1, new_email='typo@devtable.com')
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
disabled_user = model.user.create_user('disabled', 'password', 'jschorr+disabled@devtable.com')
|
2015-05-11 21:13:42 +00:00
|
|
|
disabled_user.verified = True
|
|
|
|
disabled_user.enabled = False
|
|
|
|
disabled_user.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
dtrobot = model.user.create_robot('dtrobot', new_user_1)
|
2013-11-20 23:23:59 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_user_2 = model.user.create_user('public', 'password', 'jacob.moshenko@gmail.com')
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_2.verified = True
|
|
|
|
new_user_2.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_user_3 = model.user.create_user('freshuser', 'password', 'jschorr+test@devtable.com')
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_3.verified = True
|
|
|
|
new_user_3.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.user.create_robot('anotherrobot', new_user_3)
|
2014-03-27 22:33:13 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_user_4 = model.user.create_user('randomuser', 'password', 'no4@thanks.com')
|
2014-02-18 21:46:10 +00:00
|
|
|
new_user_4.verified = True
|
|
|
|
new_user_4.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_user_5 = model.user.create_user('unverified', 'password', 'no5@thanks.com')
|
2014-03-12 20:05:32 +00:00
|
|
|
new_user_5.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
reader = model.user.create_user('reader', 'password', 'no1@thanks.com')
|
2013-11-07 04:21:12 +00:00
|
|
|
reader.verified = True
|
|
|
|
reader.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
creatoruser = model.user.create_user('creator', 'password', 'noc@thanks.com')
|
2015-06-10 19:16:01 +00:00
|
|
|
creatoruser.verified = True
|
|
|
|
creatoruser.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
outside_org = model.user.create_user('outsideorg', 'password', 'no2@thanks.com')
|
2013-11-08 04:29:58 +00:00
|
|
|
outside_org.verified = True
|
|
|
|
outside_org.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.notification.create_notification('test_notification', new_user_1,
|
|
|
|
metadata={'some':'value',
|
|
|
|
'arr':[1, 2, 3],
|
|
|
|
'obj':{'a':1, 'b':2}})
|
2014-03-12 04:49:03 +00:00
|
|
|
|
2014-06-27 23:18:27 +00:00
|
|
|
from_date = datetime.utcnow()
|
|
|
|
to_date = from_date + timedelta(hours=1)
|
|
|
|
notification_metadata = {
|
|
|
|
'from_date': formatdate(calendar.timegm(from_date.utctimetuple())),
|
|
|
|
'to_date': formatdate(calendar.timegm(to_date.utctimetuple())),
|
|
|
|
'reason': 'database migration'
|
|
|
|
}
|
2015-08-12 20:39:32 +00:00
|
|
|
model.notification.create_notification('maintenance', new_user_1,
|
|
|
|
metadata=notification_metadata)
|
2014-06-27 23:18:27 +00:00
|
|
|
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_4, 'randomrepo', 'Random repo repository.', False,
|
2014-02-18 21:46:10 +00:00
|
|
|
[], (4, [], ['latest', 'prod']))
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
simple_repo = __generate_repository(with_storage, new_user_1, 'simple', 'Simple repository.', False,
|
2015-07-21 21:20:24 +00:00
|
|
|
[], (4, [], ['latest', 'prod']))
|
2016-07-18 22:20:00 +00:00
|
|
|
|
|
|
|
# Add some labels to the latest tag's manifest.
|
|
|
|
tag_manifest = model.tag.load_tag_manifest(new_user_1.username, 'simple', 'latest')
|
|
|
|
first_label = model.label.create_manifest_label(tag_manifest, 'foo', 'bar', 'manifest')
|
|
|
|
model.label.create_manifest_label(tag_manifest, 'foo', 'baz', 'api')
|
|
|
|
model.label.create_manifest_label(tag_manifest, 'anotherlabel', '1234', 'internal')
|
2017-03-08 21:25:14 +00:00
|
|
|
model.label.create_manifest_label(tag_manifest, 'jsonlabel', '{"hey": "there"}', 'internal')
|
2016-07-18 22:20:00 +00:00
|
|
|
|
|
|
|
label_metadata = {
|
|
|
|
'key': 'foo',
|
|
|
|
'value': 'bar',
|
|
|
|
'id': first_label.id,
|
|
|
|
'manifest_digest': tag_manifest.digest
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:03:28 +00:00
|
|
|
logs_model.log_action('manifest_label_add', new_user_1.username, performer=new_user_1,
|
|
|
|
timestamp=datetime.now(), metadata=label_metadata,
|
|
|
|
repository=tag_manifest.tag.repository)
|
2016-07-18 22:20:00 +00:00
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
model.blob.initiate_upload(new_user_1.username, simple_repo.name, str(uuid4()), 'local_us', {})
|
|
|
|
model.notification.create_repo_notification(simple_repo, 'repo_push', 'quay_notification', {}, {})
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'sharedtags',
|
2015-03-10 05:03:39 +00:00
|
|
|
'Shared tags repository',
|
|
|
|
False, [(new_user_2, 'read'), (dtrobot[0], 'read')],
|
|
|
|
(2, [(3, [], ['v2.0', 'v2.1', 'v2.2']),
|
|
|
|
(1, [(1, [(1, [], ['prod', '581a284'])],
|
|
|
|
['staging', '8423b58']),
|
|
|
|
(1, [], None)], None)], None))
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'history', 'Historical repository.', False,
|
2018-11-05 18:03:08 +00:00
|
|
|
[], (4, [(2, [], '#latest'), (3, [], 'latest')], None))
|
2015-03-04 21:03:00 +00:00
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'complex',
|
2013-11-06 22:09:22 +00:00
|
|
|
'Complex repository with many branches and tags.',
|
2014-04-03 03:33:58 +00:00
|
|
|
False, [(new_user_2, 'read'), (dtrobot[0], 'read')],
|
2013-11-06 22:09:22 +00:00
|
|
|
(2, [(3, [], 'v2.0'),
|
2018-04-02 18:16:43 +00:00
|
|
|
(1, [(1, [(2, [], ['prod'])],
|
2013-11-06 22:09:22 +00:00
|
|
|
'staging'),
|
|
|
|
(1, [], None)], None)], None))
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'gargantuan', None, False, [],
|
2013-11-06 22:09:22 +00:00
|
|
|
(2, [(3, [], 'v2.0'),
|
|
|
|
(1, [(1, [(1, [], ['latest', 'prod'])],
|
|
|
|
'staging'),
|
|
|
|
(1, [], None)], None),
|
|
|
|
(20, [], 'v3.0'),
|
|
|
|
(5, [], 'v4.0'),
|
|
|
|
(1, [(1, [], 'v5.0'), (1, [], 'v6.0')], None)],
|
|
|
|
None))
|
2014-07-15 19:13:58 +00:00
|
|
|
|
2017-04-17 18:34:43 +00:00
|
|
|
trusted_repo = __generate_repository(with_storage, new_user_1, 'trusted', 'Trusted repository.',
|
|
|
|
False, [], (4, [], ['latest', 'prod']))
|
|
|
|
trusted_repo.trust_enabled = True
|
|
|
|
trusted_repo.save()
|
|
|
|
|
2016-06-17 17:52:27 +00:00
|
|
|
publicrepo = __generate_repository(with_storage, new_user_2, 'publicrepo',
|
|
|
|
'Public repository pullable by the world.', True,
|
|
|
|
[], (10, [], 'latest'))
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, outside_org, 'coolrepo',
|
2014-02-18 21:46:10 +00:00
|
|
|
'Some cool repo.', False,
|
|
|
|
[],
|
|
|
|
(5, [], 'latest'))
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'shared',
|
2013-11-06 22:09:22 +00:00
|
|
|
'Shared repository, another user can write.', False,
|
2013-11-07 04:21:12 +00:00
|
|
|
[(new_user_2, 'write'), (reader, 'read')],
|
|
|
|
(5, [], 'latest'))
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2017-01-11 20:03:14 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'text-full-repo',
|
|
|
|
'This is a repository for testing text search', False,
|
|
|
|
[(new_user_2, 'write'), (reader, 'read')],
|
|
|
|
(5, [], 'latest'))
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
building = __generate_repository(with_storage, new_user_1, 'building',
|
2013-11-06 22:09:22 +00:00
|
|
|
'Empty repository which is building.',
|
2017-04-24 19:59:10 +00:00
|
|
|
False, [(new_user_2, 'write'), (reader, 'read')], (0, [], None))
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
new_token = model.token.create_access_token(building, 'write', 'build-worker')
|
2014-02-19 21:08:33 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
trigger = model.build.create_build_trigger(building, 'github', '123authtoken', new_user_1,
|
|
|
|
pull_robot=dtrobot[0])
|
2014-02-19 21:08:33 +00:00
|
|
|
trigger.config = json.dumps({
|
|
|
|
'build_source': 'jakedt/testconnect',
|
2014-02-24 21:18:14 +00:00
|
|
|
'subdir': '',
|
2017-03-21 21:24:11 +00:00
|
|
|
'dockerfile_path': 'Dockerfile',
|
|
|
|
'context': '/',
|
2014-02-19 21:08:33 +00:00
|
|
|
})
|
|
|
|
trigger.save()
|
|
|
|
|
2014-09-24 22:01:35 +00:00
|
|
|
repo = 'ci.devtable.com:5000/%s/%s' % (building.namespace_user.username, building.name)
|
2014-02-24 21:11:23 +00:00
|
|
|
job_config = {
|
|
|
|
'repository': repo,
|
|
|
|
'docker_tags': ['latest'],
|
|
|
|
'build_subdir': '',
|
2015-02-26 22:45:28 +00:00
|
|
|
'trigger_metadata': {
|
2015-06-02 19:32:28 +00:00
|
|
|
'commit': '3482adc5822c498e8f7db2e361e8d57b3d77ddd9',
|
2015-02-26 22:45:28 +00:00
|
|
|
'ref': 'refs/heads/master',
|
|
|
|
'default_branch': 'master'
|
|
|
|
}
|
2014-02-24 21:11:23 +00:00
|
|
|
}
|
2014-02-06 01:01:23 +00:00
|
|
|
|
2015-07-21 21:20:24 +00:00
|
|
|
model.repository.star_repository(new_user_1, simple_repo)
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
record = model.repository.create_email_authorization_for_repo(new_user_1.username, 'simple',
|
|
|
|
'jschorr@devtable.com')
|
2014-07-28 18:58:12 +00:00
|
|
|
record.confirmed = True
|
|
|
|
record.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.repository.create_email_authorization_for_repo(new_user_1.username, 'simple',
|
|
|
|
'jschorr+other@devtable.com')
|
2014-07-28 18:58:12 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
build2 = model.build.create_repository_build(building, new_token, job_config,
|
|
|
|
'68daeebd-a5b9-457f-80a0-4363b882f8ea',
|
|
|
|
'build-name', trigger)
|
2014-04-01 04:23:53 +00:00
|
|
|
build2.uuid = 'deadpork-dead-pork-dead-porkdeadpork'
|
|
|
|
build2.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
build3 = model.build.create_repository_build(building, new_token, job_config,
|
|
|
|
'f49d07f9-93da-474d-ad5f-c852107c3892',
|
|
|
|
'build-name', trigger)
|
2014-04-01 17:00:26 +00:00
|
|
|
build3.uuid = 'deadduck-dead-duck-dead-duckdeadduck'
|
|
|
|
build3.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
build1 = model.build.create_repository_build(building, new_token, job_config,
|
|
|
|
'701dcc3724fb4f2ea6c31400528343cd', 'build-name',
|
|
|
|
trigger)
|
|
|
|
build1.uuid = 'deadbeef-dead-beef-dead-beefdeadbeef'
|
|
|
|
build1.save()
|
2014-05-19 18:14:18 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
org = model.organization.create_organization('buynlarge', 'quay@devtable.com', new_user_1)
|
2013-11-08 03:43:43 +00:00
|
|
|
org.stripe_id = TEST_STRIPE_ID
|
|
|
|
org.save()
|
|
|
|
|
2016-01-21 20:40:51 +00:00
|
|
|
liborg = model.organization.create_organization('library', 'quay+library@devtable.com', new_user_1)
|
|
|
|
liborg.save()
|
|
|
|
|
2017-04-25 03:08:28 +00:00
|
|
|
titiorg = model.organization.create_organization('titi', 'quay+titi@devtable.com', new_user_1)
|
|
|
|
titiorg.save()
|
|
|
|
|
2017-02-22 20:23:52 +00:00
|
|
|
thirdorg = model.organization.create_organization('sellnsmall', 'quay+sell@devtable.com', new_user_1)
|
|
|
|
thirdorg.save()
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.user.create_robot('coolrobot', org)
|
2014-03-27 22:33:13 +00:00
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
oauth_app_1 = model.oauth.create_application(org, 'Some Test App', 'http://localhost:8000',
|
|
|
|
'http://localhost:8000/o2c.html',
|
|
|
|
client_id='deadbeef')
|
2014-03-14 22:57:28 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.oauth.create_application(org, 'Some Other Test App', 'http://quay.io',
|
|
|
|
'http://localhost:8000/o2c.html', client_id='deadpork',
|
|
|
|
description='This is another test application')
|
2014-03-12 16:37:06 +00:00
|
|
|
|
2014-03-25 00:57:02 +00:00
|
|
|
model.oauth.create_access_token_for_testing(new_user_1, 'deadbeef', 'repo:admin')
|
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
OAuthAuthorizationCode.create(application=oauth_app_1, code='Z932odswfhasdf1', scope='repo:admin',
|
|
|
|
data='{"somejson": "goeshere"}')
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.user.create_robot('neworgrobot', org)
|
2013-11-20 23:23:59 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
ownerbot = model.user.create_robot('ownerbot', org)[0]
|
|
|
|
creatorbot = model.user.create_robot('creatorbot', org)[0]
|
2015-06-10 19:16:01 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
owners = model.team.get_organization_team('buynlarge', 'owners')
|
2013-11-08 03:43:43 +00:00
|
|
|
owners.description = 'Owners have unfetterd access across the entire org.'
|
|
|
|
owners.save()
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
org_repo = __generate_repository(with_storage, org, 'orgrepo', 'Repository owned by an org.', False,
|
2015-07-15 21:25:41 +00:00
|
|
|
[(outside_org, 'read')], (4, [], ['latest', 'prod']))
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, org, 'anotherorgrepo', 'Another repository owned by an org.', False,
|
2015-07-15 21:25:41 +00:00
|
|
|
[], (4, [], ['latest', 'prod']))
|
2014-02-18 21:46:10 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
creators = model.team.create_team('creators', org, 'creator', 'Creators of orgrepo.')
|
2015-06-10 19:16:01 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
reader_team = model.team.create_team('readers', org, 'member', 'Readers of orgrepo.')
|
2016-01-12 20:57:03 +00:00
|
|
|
model.team.add_or_invite_to_team(new_user_1, reader_team, outside_org)
|
2015-07-15 21:25:41 +00:00
|
|
|
model.permission.set_team_repo_permission(reader_team.name, org_repo.namespace_user.username,
|
|
|
|
org_repo.name, 'read')
|
2015-06-10 19:16:01 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
model.team.add_user_to_team(new_user_2, reader_team)
|
|
|
|
model.team.add_user_to_team(reader, reader_team)
|
|
|
|
model.team.add_user_to_team(ownerbot, owners)
|
|
|
|
model.team.add_user_to_team(creatorbot, creators)
|
|
|
|
model.team.add_user_to_team(creatoruser, creators)
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2017-02-22 20:23:52 +00:00
|
|
|
sell_owners = model.team.get_organization_team('sellnsmall', 'owners')
|
|
|
|
sell_owners.description = 'Owners have unfettered access across the entire org.'
|
|
|
|
sell_owners.save()
|
|
|
|
|
|
|
|
model.team.add_user_to_team(new_user_4, sell_owners)
|
|
|
|
|
2017-02-23 19:41:27 +00:00
|
|
|
sync_config = {'group_dn': 'cn=Test-Group,ou=Users', 'group_id': 'somegroupid'}
|
2017-02-17 17:01:41 +00:00
|
|
|
synced_team = model.team.create_team('synced', org, 'member', 'Some synced team.')
|
2017-02-23 19:41:27 +00:00
|
|
|
model.team.set_team_syncing(synced_team, 'ldap', sync_config)
|
2017-02-17 17:01:41 +00:00
|
|
|
|
2017-02-22 20:23:52 +00:00
|
|
|
another_synced_team = model.team.create_team('synced', thirdorg, 'member', 'Some synced team.')
|
|
|
|
model.team.set_team_syncing(another_synced_team, 'ldap', {'group_dn': 'cn=Test-Group,ou=Users'})
|
|
|
|
|
2016-02-24 21:01:27 +00:00
|
|
|
__generate_repository(with_storage, new_user_1, 'superwide', None, False, [],
|
2014-01-20 22:48:25 +00:00
|
|
|
[(10, [], 'latest2'),
|
2015-07-15 21:25:41 +00:00
|
|
|
(2, [], 'latest3'),
|
|
|
|
(2, [(1, [], 'latest11'), (2, [], 'latest12')],
|
|
|
|
'latest4'),
|
|
|
|
(2, [], 'latest5'),
|
|
|
|
(2, [], 'latest6'),
|
|
|
|
(2, [], 'latest7'),
|
|
|
|
(2, [], 'latest8'),
|
|
|
|
(2, [], 'latest9'),
|
|
|
|
(2, [], 'latest10'),
|
|
|
|
(2, [], 'latest13'),
|
|
|
|
(2, [], 'latest14'),
|
|
|
|
(2, [], 'latest15'),
|
|
|
|
(2, [], 'latest16'),
|
|
|
|
(2, [], 'latest17'),
|
|
|
|
(2, [], 'latest18')])
|
|
|
|
|
|
|
|
model.permission.add_prototype_permission(org, 'read', activating_user=new_user_1,
|
|
|
|
delegate_user=new_user_2)
|
|
|
|
model.permission.add_prototype_permission(org, 'read', activating_user=new_user_1,
|
|
|
|
delegate_team=reader_team)
|
|
|
|
model.permission.add_prototype_permission(org, 'write', activating_user=new_user_2,
|
|
|
|
delegate_user=new_user_1)
|
2014-01-21 19:18:20 +00:00
|
|
|
|
2013-12-03 00:07:14 +00:00
|
|
|
today = datetime.today()
|
|
|
|
week_ago = today - timedelta(6)
|
|
|
|
six_ago = today - timedelta(5)
|
|
|
|
four_ago = today - timedelta(4)
|
2016-06-17 17:52:27 +00:00
|
|
|
yesterday = datetime.combine(date.today(), datetime.min.time()) - timedelta(hours=6)
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2016-04-05 19:32:47 +00:00
|
|
|
__generate_service_key('kid1', 'somesamplekey', new_user_1, today,
|
|
|
|
ServiceKeyApprovalType.SUPERUSER)
|
|
|
|
__generate_service_key('kid2', 'someexpiringkey', new_user_1, week_ago,
|
2016-04-13 17:59:07 +00:00
|
|
|
ServiceKeyApprovalType.SUPERUSER, today + timedelta(days=14))
|
2016-04-05 19:32:47 +00:00
|
|
|
|
|
|
|
__generate_service_key('kid3', 'unapprovedkey', new_user_1, today, None)
|
2016-04-01 17:55:29 +00:00
|
|
|
|
2016-04-05 19:32:47 +00:00
|
|
|
__generate_service_key('kid4', 'autorotatingkey', new_user_1, six_ago,
|
2016-04-13 17:59:07 +00:00
|
|
|
ServiceKeyApprovalType.KEY_ROTATION, today + timedelta(days=1),
|
2016-04-12 23:17:19 +00:00
|
|
|
rotation_duration=timedelta(hours=12).total_seconds())
|
|
|
|
|
2016-04-07 00:03:04 +00:00
|
|
|
__generate_service_key('kid5', 'key for another service', new_user_1, today,
|
2016-04-13 17:59:07 +00:00
|
|
|
ServiceKeyApprovalType.SUPERUSER, today + timedelta(days=14),
|
2016-04-07 00:03:04 +00:00
|
|
|
service='different_sample_service')
|
2016-04-01 17:55:29 +00:00
|
|
|
|
2016-04-27 21:44:59 +00:00
|
|
|
__generate_service_key('kid6', 'someexpiredkey', new_user_1, week_ago,
|
|
|
|
ServiceKeyApprovalType.SUPERUSER, today - timedelta(days=1))
|
|
|
|
|
|
|
|
__generate_service_key('kid7', 'somewayexpiredkey', new_user_1, week_ago,
|
|
|
|
ServiceKeyApprovalType.SUPERUSER, today - timedelta(days=30))
|
|
|
|
|
2016-05-31 20:48:19 +00:00
|
|
|
# Add the test pull key as pre-approved for local and unittest registry testing.
|
|
|
|
# Note: this must match the private key found in the local/test config.
|
|
|
|
_TEST_JWK = {
|
|
|
|
'e': 'AQAB',
|
|
|
|
'kty': 'RSA',
|
|
|
|
'n': 'yqdQgnelhAPMSeyH0kr3UGePK9oFOmNfwD0Ymnh7YYXr21VHWwyM2eVW3cnLd9KXywDFtGSe9oFDbnOuMCdUowdkBcaHju-isbv5KEbNSoy_T2Rip-6L0cY63YzcMJzv1nEYztYXS8wz76pSK81BKBCLapqOCmcPeCvV9yaoFZYvZEsXCl5jjXN3iujSzSF5Z6PpNFlJWTErMT2Z4QfbDKX2Nw6vJN6JnGpTNHZvgvcyNX8vkSgVpQ8DFnFkBEx54PvRV5KpHAq6AsJxKONMo11idQS2PfCNpa2hvz9O6UZe-eIX8jPo5NW8TuGZJumbdPT_nxTDLfCqfiZboeI0Pw'
|
|
|
|
}
|
|
|
|
|
|
|
|
key = model.service_keys.create_service_key('test_service_key', 'test_service_key', 'quay',
|
|
|
|
_TEST_JWK, {}, None)
|
|
|
|
|
2018-08-13 15:40:50 +00:00
|
|
|
model.service_keys.approve_service_key(key.kid, ServiceKeyApprovalType.SUPERUSER,
|
2016-05-31 20:48:19 +00:00
|
|
|
notes='Test service key for local/test registry testing')
|
|
|
|
|
2017-12-08 22:05:59 +00:00
|
|
|
# Add an app specific token.
|
|
|
|
token = model.appspecifictoken.create_token(new_user_1, 'some app')
|
|
|
|
token.token_code = 'test'
|
|
|
|
token.save()
|
|
|
|
|
2019-01-08 19:03:28 +00:00
|
|
|
logs_model.log_action('org_create_team', org.username, performer=new_user_1,
|
|
|
|
timestamp=week_ago, metadata={'team': 'readers'})
|
|
|
|
|
|
|
|
logs_model.log_action('org_set_team_role', org.username, performer=new_user_1,
|
|
|
|
timestamp=week_ago,
|
|
|
|
metadata={'team': 'readers', 'role': 'read'})
|
|
|
|
|
|
|
|
logs_model.log_action('create_repo', org.username, performer=new_user_1,
|
|
|
|
repository=org_repo, timestamp=week_ago,
|
|
|
|
metadata={'namespace': org.username, 'repo': 'orgrepo'})
|
|
|
|
|
|
|
|
logs_model.log_action('change_repo_permission', org.username,
|
|
|
|
performer=new_user_2, repository=org_repo,
|
|
|
|
timestamp=six_ago,
|
|
|
|
metadata={'username': new_user_1.username,
|
|
|
|
'repo': 'orgrepo', 'role': 'admin'})
|
|
|
|
|
|
|
|
logs_model.log_action('change_repo_permission', org.username,
|
|
|
|
performer=new_user_1, repository=org_repo,
|
|
|
|
timestamp=six_ago,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo', 'role': 'read'})
|
|
|
|
|
|
|
|
logs_model.log_action('add_repo_accesstoken', org.username, performer=new_user_1,
|
|
|
|
repository=org_repo, timestamp=four_ago,
|
|
|
|
metadata={'repo': 'orgrepo', 'token': 'deploytoken'})
|
|
|
|
|
|
|
|
logs_model.log_action('push_repo', org.username, performer=new_user_2,
|
|
|
|
repository=org_repo, timestamp=today,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo'})
|
|
|
|
|
|
|
|
logs_model.log_action('pull_repo', org.username, performer=new_user_2,
|
|
|
|
repository=org_repo, timestamp=today,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo'})
|
|
|
|
|
|
|
|
logs_model.log_action('pull_repo', org.username, repository=org_repo,
|
|
|
|
timestamp=today,
|
|
|
|
metadata={'token': 'sometoken', 'token_code': 'somecode',
|
|
|
|
'repo': 'orgrepo'})
|
|
|
|
|
|
|
|
logs_model.log_action('delete_tag', org.username, performer=new_user_2,
|
|
|
|
repository=org_repo, timestamp=today,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo', 'tag': 'sometag'})
|
|
|
|
|
|
|
|
logs_model.log_action('pull_repo', org.username, repository=org_repo,
|
|
|
|
timestamp=today,
|
|
|
|
metadata={'token_code': 'somecode', 'repo': 'orgrepo'})
|
|
|
|
|
|
|
|
logs_model.log_action('pull_repo', new_user_2.username, repository=publicrepo,
|
|
|
|
timestamp=yesterday,
|
|
|
|
metadata={'token_code': 'somecode', 'repo': 'publicrepo'})
|
|
|
|
|
|
|
|
logs_model.log_action('build_dockerfile', new_user_1.username, repository=building,
|
|
|
|
timestamp=today,
|
|
|
|
metadata={'repo': 'building', 'namespace': new_user_1.username,
|
|
|
|
'trigger_id': trigger.uuid, 'config': json.loads(trigger.config),
|
|
|
|
'service': trigger.service.name})
|
2014-02-25 23:22:55 +00:00
|
|
|
|
2017-01-17 21:41:24 +00:00
|
|
|
model.message.create([{'content': 'We love you, Quay customers!', 'severity': 'info',
|
|
|
|
'media_type': 'text/plain'}])
|
|
|
|
|
|
|
|
model.message.create([{'content': 'This is a **development** install of Quay',
|
|
|
|
'severity': 'warning', 'media_type': 'text/markdown'}])
|
2016-10-07 19:56:58 +00:00
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
fake_queue = WorkQueue('fakequeue', tf)
|
|
|
|
fake_queue.put(['canonical', 'job', 'name'], '{}')
|
|
|
|
|
2016-11-08 23:27:12 +00:00
|
|
|
model.user.create_user_prompt(new_user_4, 'confirm_username')
|
2016-09-08 22:43:50 +00:00
|
|
|
|
2017-03-17 17:51:45 +00:00
|
|
|
while True:
|
|
|
|
to_count = model.repositoryactioncount.find_uncounted_repository()
|
|
|
|
if not to_count:
|
|
|
|
break
|
|
|
|
|
|
|
|
model.repositoryactioncount.count_repository_actions(to_count)
|
|
|
|
model.repositoryactioncount.update_repository_score(to_count)
|
2015-04-13 17:31:07 +00:00
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
|
2019-01-03 18:50:43 +00:00
|
|
|
WHITELISTED_EMPTY_MODELS = ['DeletedNamespace', 'LogEntry', 'LogEntry2', 'ManifestChild',
|
2019-01-02 18:29:35 +00:00
|
|
|
'NamespaceGeoRestriction']
|
2018-02-23 21:45:16 +00:00
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
def find_models_missing_data():
|
2018-02-23 21:45:16 +00:00
|
|
|
# As a sanity check we are going to make sure that all db tables have some data, unless explicitly
|
|
|
|
# whitelisted.
|
2016-01-12 20:57:03 +00:00
|
|
|
models_missing_data = set()
|
|
|
|
for one_model in all_models:
|
2018-07-16 21:12:04 +00:00
|
|
|
if one_model in appr_classes:
|
2017-03-16 20:37:16 +00:00
|
|
|
continue
|
|
|
|
|
2016-01-12 20:57:03 +00:00
|
|
|
try:
|
|
|
|
one_model.select().get()
|
|
|
|
except one_model.DoesNotExist:
|
2018-02-23 21:45:16 +00:00
|
|
|
if one_model.__name__ not in WHITELISTED_EMPTY_MODELS:
|
|
|
|
models_missing_data.add(one_model.__name__)
|
2016-01-12 20:57:03 +00:00
|
|
|
|
|
|
|
return models_missing_data
|
|
|
|
|
|
|
|
|
2013-10-01 18:14:39 +00:00
|
|
|
if __name__ == '__main__':
|
2015-08-12 20:39:32 +00:00
|
|
|
parser = argparse.ArgumentParser(description='Initialize the test database.')
|
|
|
|
parser.add_argument('--simple', action='store_true')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2017-02-23 20:01:37 +00:00
|
|
|
log_level = os.environ.get('LOGGING_LEVEL', getattr(logging, app.config['LOGGING_LEVEL']))
|
2014-05-01 23:44:28 +00:00
|
|
|
logging.basicConfig(level=log_level)
|
2014-07-07 19:35:29 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
if not IS_TESTING_REAL_DATABASE and not isinstance(db.obj, SqliteDatabase):
|
2014-07-07 19:35:29 +00:00
|
|
|
raise RuntimeError('Attempted to initialize production database!')
|
|
|
|
|
2017-02-22 22:55:17 +00:00
|
|
|
if os.environ.get('SKIP_DB_SCHEMA', '').lower() != 'true':
|
|
|
|
initialize_database()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
populate_database(args.simple)
|
2016-01-12 20:57:03 +00:00
|
|
|
|
|
|
|
if not args.simple:
|
|
|
|
models_missing_data = find_models_missing_data()
|
|
|
|
if models_missing_data:
|
|
|
|
logger.warning('The following models do not have any data: %s', models_missing_data)
|