github.com/uber/kraken@v0.1.4/test/python/test_docker.py (about) 1 # Copyright (c) 2016-2019 Uber Technologies, Inc. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 from __future__ import absolute_import 15 16 import time 17 18 from conftest import ( 19 TEST_IMAGE, 20 TEST_IMAGE_2, 21 ) 22 23 24 def test_proxy_push_and_pull(proxy): 25 proxy.push(TEST_IMAGE) 26 27 proxy.pull(TEST_IMAGE) 28 29 30 def test_proxy_pull_after_data_loss(proxy): 31 proxy.push(TEST_IMAGE) 32 33 proxy.restart(wipe_disk=True) 34 35 proxy.pull(TEST_IMAGE) 36 37 38 def test_agent_pull(proxy, agent): 39 proxy.push(TEST_IMAGE) 40 41 agent.pull(TEST_IMAGE) 42 43 44 def test_agent_preload(proxy, agent_factory): 45 proxy.push(TEST_IMAGE) 46 47 with agent_factory.create(with_docker_socket=True) as agent: 48 agent.preload(TEST_IMAGE) 49 50 51 def test_proxy_list_repository_tags(proxy, build_index): 52 tags = {'0001', '0002', '0003'} 53 for tag in tags: 54 proxy.push_as(TEST_IMAGE, tag) 55 56 # Push a separate image to ensure we scope by repo properly. 57 proxy.push_as(TEST_IMAGE_2, '0004') 58 59 repo = TEST_IMAGE.split(':')[0] 60 61 assert sorted(proxy.list(repo)) == sorted(tags) 62 63 # Make sure old build-index endpoint still works. 64 assert sorted(build_index.list_repo(repo)) == sorted(tags) 65 66 67 def test_proxy_catalog(proxy): 68 # Push a few tags to make sure we deduplicate repos. 69 for tags in {'0001', '0002', '0003'}: 70 proxy.push(TEST_IMAGE) 71 proxy.push(TEST_IMAGE_2) 72 73 repos = map(lambda img: img.split(':')[0], (TEST_IMAGE, TEST_IMAGE_2)) 74 75 assert sorted(proxy.catalog()) == sorted(repos) 76 77 78 def test_docker_image_distribution_high_availability(testfs, proxy, origin_cluster, build_index, 79 agent_factory): 80 # This is a long test for ensuring high availability during the entire docker 81 # image distribution flow. 82 83 # PART 1: Backend storage is unavailable. We should still be able to upload 84 # and distribute builds by relying on on-disk caches. 85 86 testfs.stop() 87 88 proxy.push(TEST_IMAGE) 89 90 # Must be able to survive soft restarts on our components. Ensures everything 91 # is properly stored on disk. 92 93 for origin in origin_cluster: 94 origin.restart() 95 96 build_index.restart() 97 98 with agent_factory.create() as agent: 99 agent.pull(TEST_IMAGE) 100 101 # PART 2: Backend storage is back online. Tags and blobs should automatically 102 # persist to backend storage, and we should survive total data loss by 103 # recovering data from backend storage. 104 105 testfs.start() 106 107 time.sleep(3) 108 109 # Tags and blobs should be backed up by now. Wipe all disks. 110 111 for origin in origin_cluster: 112 origin.restart(wipe_disk=True) 113 114 build_index.restart(wipe_disk=True) 115 116 with agent_factory.create() as agent: 117 agent.pull(TEST_IMAGE)