|
import copy
|
|
import sys
|
|
|
|
from add_remove_utils import (
|
|
git_info,
|
|
cleanup,
|
|
ensure_empty,
|
|
DESTINATION_REPO,
|
|
get_repo_content_count,
|
|
get_units_by_type,
|
|
copy_by_content_pk,
|
|
rm_by_content_pk,
|
|
TAGS,
|
|
MANIFEST_LISTS_NO_SHARED_MANIFESTS,
|
|
MANIFEST_LISTS_SHARING_MANIFESTS,
|
|
MANIFESTS_NO_SHARED_BLOBS,
|
|
MANIFESTS_WITH_SHARED_BLOBS,
|
|
)
|
|
|
|
|
|
def main():
|
|
git_info()
|
|
cleanup()
|
|
test_tags()
|
|
test_manifest_lists()
|
|
test_manifest_lists_with_shared_manifests()
|
|
test_remove_one_manifest_list_with_shared_manifests()
|
|
test_manifests()
|
|
test_manifests_with_shared_blobs()
|
|
test_remove_one_manifest_with_shared_blobs()
|
|
test_blobs()
|
|
test_mixed_types_no_sharing()
|
|
test_mixed_types_with_sharing()
|
|
test_tags_in_manifest_lists_out()
|
|
#
|
|
|
|
def test_tags():
|
|
print("**********************************************************")
|
|
print(" tags in tags out ")
|
|
print("Behavior: Adding tags is recursive. Removing tags is not.")
|
|
print("add/remove the same tags will leave the referenced content")
|
|
print("int the repo.")
|
|
print
|
|
print("Cannot check for symmetry, just ensure behavior is the same")
|
|
print("between this branch and the previous branch.")
|
|
print("**********************************************************")
|
|
ensure_empty()
|
|
copy_by_content_pk('docker_tag', TAGS)
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
expected_counts = {u'docker_blob': 66, u'docker_tag': 10, u'docker_manifest_list': 4,
|
|
u'docker_manifest': 35}
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
sys.exit(1)
|
|
|
|
# Another query because the tag ids new destination are new.
|
|
tags_in_dest = get_units_by_type(DESTINATION_REPO, 'docker_tag')
|
|
expected_after_remove = copy.deepcopy(expected_counts)
|
|
expected_after_remove.pop('docker_tag')
|
|
|
|
rm_by_content_pk(tags_in_dest)
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
if expected_after_remove != after_remove:
|
|
print("Expected:" + str(expected_after_remove))
|
|
print("Actual:" + str(after_remove))
|
|
raise Exception("remove")
|
|
|
|
cleanup()
|
|
print("--------------------------------------------------------------PASS")
|
|
|
|
|
|
def test_manifest_lists():
|
|
print("**********************************************************")
|
|
print(" manifest list no shared manifests ")
|
|
print("Behavior: Adding manifest lists is recursive and removing is ")
|
|
print("symmetrical")
|
|
print
|
|
print("Check for symmetry. After removal, repo should be empty.")
|
|
print("**********************************************************")
|
|
|
|
ensure_empty()
|
|
|
|
copy_by_content_pk('docker_manifest_list', MANIFEST_LISTS_NO_SHARED_MANIFESTS)
|
|
expected_counts = {u'docker_blob': 112, u'docker_manifest_list': 8, u'docker_manifest': 56}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("COPY")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
# sys.exit(1)
|
|
|
|
rm_by_content_pk(MANIFEST_LISTS_NO_SHARED_MANIFESTS)
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
if after_remove:
|
|
print("REMOVE DIDNT WORK RIGHT")
|
|
print("Expected:" + str({}))
|
|
print("Actual:" + str(after_remove))
|
|
sys.exit(1)
|
|
|
|
cleanup()
|
|
print("--------------------------------------------------------------PASS")
|
|
|
|
|
|
def test_remove_one_manifest_list_with_shared_manifests():
|
|
print("**********************************************************")
|
|
print(" Add 2 Manifest lists with some common manifests, remove 1 ")
|
|
print
|
|
print(" set(B_ml.manifests) - set(A_ml.manifests) should remain")
|
|
print("**********************************************************")
|
|
""
|
|
ensure_empty()
|
|
|
|
copy_by_content_pk('docker_manifest_list', MANIFEST_LISTS_SHARING_MANIFESTS)
|
|
expected_counts = {u'docker_blob': 26, u'docker_manifest_list': 2, u'docker_manifest': 13}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
sys.exit(1)
|
|
|
|
# TODO on 2-master, removing all the manifest_lists leaves behind 2 manifests and 4 blobs.
|
|
# TODO on 2-master, removing each manifest_list one at a time works as expected
|
|
# for manifest_list in MANIFEST_LISTS_SHARING_MANIFESTS:
|
|
# rm_by_content_pk([manifest_list])
|
|
rm_by_content_pk([MANIFEST_LISTS_SHARING_MANIFESTS[0]])
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
expected_after_remove = {u'docker_blob': 14, u'docker_manifest_list': 1, u'docker_manifest': 7}
|
|
if expected_after_remove != after_remove:
|
|
print("REMOVE DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_after_remove))
|
|
print("Actual:" + str(after_remove))
|
|
print("-------------------------------------------------------------- NEEDS INVESTIGATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
|
cleanup()
|
|
return
|
|
|
|
cleanup()
|
|
print("--------------------------------------------------------------PASS")
|
|
|
|
|
|
def test_manifest_lists_with_shared_manifests():
|
|
print("**********************************************************")
|
|
print(" Add 2 Manifest lists with some common manifests, remove both")
|
|
print
|
|
print(" set(B_ml.manifests).intersect(set(A_ml.manifests)) should remain")
|
|
print("**********************************************************")
|
|
|
|
ensure_empty()
|
|
|
|
copy_by_content_pk('docker_manifest_list', MANIFEST_LISTS_SHARING_MANIFESTS)
|
|
expected_counts = {u'docker_blob': 26, u'docker_manifest_list': 2, u'docker_manifest': 13}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
sys.exit(1)
|
|
|
|
# TODO on 2-master, removing all the manifest_lists leaves behind 2 manifests and 4 blobs.
|
|
# TODO on 2-master, removing each manifest_list one at a time works as expected
|
|
# for manifest_list in MANIFEST_LISTS_SHARING_MANIFESTS:
|
|
# rm_by_content_pk([manifest_list])
|
|
rm_by_content_pk(MANIFEST_LISTS_SHARING_MANIFESTS)
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
if after_remove:
|
|
print("REMOVE DIDNT WORK RIGHT")
|
|
print("Expected:" + str({}))
|
|
print("Actual:" + str(after_remove))
|
|
print("--------------------------------------------------------------EXPECTED ON 2-master **FAILED**")
|
|
cleanup()
|
|
return
|
|
|
|
cleanup()
|
|
print("--------------------------------------------------------------PASS")
|
|
|
|
|
|
def test_manifests():
|
|
print("**********************************************************")
|
|
print(" manifests in/out no shared ")
|
|
print("Behavior: Adding manifest is recursive and removing is ")
|
|
print("symmetrical")
|
|
print
|
|
print("Check for symmetry. After removal, repo should be empty.")
|
|
print("**********************************************************")
|
|
|
|
ensure_empty()
|
|
|
|
copy_by_content_pk('docker_manifest', MANIFESTS_NO_SHARED_BLOBS)
|
|
expected_counts = {u'docker_blob': 14, u'docker_manifest': 7}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
sys.exit(1)
|
|
|
|
rm_by_content_pk(MANIFESTS_NO_SHARED_BLOBS)
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
if after_remove:
|
|
print("REMOVE DIDNT WORK RIGHT")
|
|
print("Expected:" + str({}))
|
|
print("Actual:" + str(after_remove))
|
|
print("-------------------------------------------------------------- NEEDS INVESTIGATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
|
print("THis may be an expected bug on 2-master. after_remove will be {} if removed one at a time. NEEDS INVESTIGATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
|
cleanup()
|
|
return
|
|
|
|
cleanup()
|
|
print("--------------------------------------------------------------PASS")
|
|
|
|
|
|
def test_remove_one_manifest_with_shared_blobs():
|
|
print("--------------------------------------------------------------NOTIMPLEMENTED **FAILED**")
|
|
|
|
|
|
def test_manifests_with_shared_blobs():
|
|
print("--------------------------------------------------------------NOTIMPLEMENTED **FAILED**")
|
|
|
|
|
|
def test_blobs():
|
|
print("--------------------------------------------------------------NOTIMPLEMENTED **FAILED**")
|
|
|
|
|
|
def test_mixed_types_no_sharing():
|
|
print("**********************************************************")
|
|
print(" [tags + manifest list + manifests ] NO SHARING ")
|
|
print("**********************************************************")
|
|
|
|
ensure_empty()
|
|
copy_by_content_pk('docker_tag', TAGS)
|
|
copy_by_content_pk(
|
|
'docker_manifest_list',
|
|
MANIFEST_LISTS_NO_SHARED_MANIFESTS
|
|
)
|
|
copy_by_content_pk(
|
|
'docker_manifest',
|
|
MANIFESTS_NO_SHARED_BLOBS
|
|
)
|
|
expected_counts = {u'docker_blob': 168, u'docker_tag': 10, u'docker_manifest_list': 12,
|
|
u'docker_manifest': 87}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
print("TODO----------------------------------------------------------")
|
|
# sys.exit(1)
|
|
|
|
# Another query because the tag ids new destination are new.
|
|
tags_in_dest = get_units_by_type(DESTINATION_REPO, 'docker_tag')
|
|
|
|
# 2-master
|
|
# expected_counts = {u'docker_blob': 73, u'docker_manifest_list': 4, u'docker_manifest': 37}
|
|
# flattened-queries
|
|
expected_counts = {u'docker_blob': 66, u'docker_manifest_list': 4, u'docker_manifest': 35}
|
|
|
|
rm_by_content_pk(
|
|
tags_in_dest + MANIFEST_LISTS_NO_SHARED_MANIFESTS + MANIFESTS_NO_SHARED_BLOBS,
|
|
)
|
|
|
|
# TODO this will make 2-master pass
|
|
# for pk in tags_in_dest + MANIFEST_LISTS_NO_SHARED_MANIFESTS + MANIFESTS_NO_SHARED_BLOBS:
|
|
# rm_by_content_pk([pk])
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
|
|
if after_remove != expected_counts:
|
|
print("REMOVE DIDNT WORK RIGHT.")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(after_remove))
|
|
print("--------------------------------------------------------------EXPECTED ON 2-master **FAILED**")
|
|
cleanup()
|
|
return
|
|
|
|
cleanup()
|
|
print("--------------------------------------------------------------PASS")
|
|
|
|
|
|
def test_mixed_types_with_sharing():
|
|
print("**********************************************************")
|
|
print(" [tags + manifest list + manifests ] UNITS SHARE OTHER UNITS ")
|
|
print("**********************************************************")
|
|
|
|
ensure_empty()
|
|
copy_by_content_pk('docker_tag', TAGS)
|
|
copy_by_content_pk(
|
|
'docker_manifest_list',
|
|
MANIFEST_LISTS_NO_SHARED_MANIFESTS + MANIFEST_LISTS_SHARING_MANIFESTS,
|
|
)
|
|
copy_by_content_pk(
|
|
'docker_manifest',
|
|
MANIFESTS_NO_SHARED_BLOBS + MANIFESTS_WITH_SHARED_BLOBS,
|
|
)
|
|
expected_counts = {u'docker_blob': 195, u'docker_tag': 10, u'docker_manifest_list': 14,
|
|
u'docker_manifest': 103}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
# sys.exit(1)
|
|
print("TODO 00000-currently difficult to tell what this count should be00000")
|
|
print("TODO XXXXXXXX- one strategy:rm one at a time on 2-master, should be rightXXXXXXX")
|
|
|
|
# Another query because the tag ids new destination are new.
|
|
tags_in_dest = get_units_by_type(DESTINATION_REPO, 'docker_tag')
|
|
|
|
# 2-master
|
|
# expected_counts = {u'docker_blob': 73, u'docker_manifest_list': 4, u'docker_manifest': 37}
|
|
# flattened-queries
|
|
expected_counts = {u'docker_blob': 66, u'docker_manifest_list': 4, u'docker_manifest': 35}
|
|
|
|
rm_by_content_pk(
|
|
tags_in_dest + MANIFEST_LISTS_NO_SHARED_MANIFESTS + MANIFEST_LISTS_SHARING_MANIFESTS +
|
|
MANIFESTS_NO_SHARED_BLOBS + MANIFESTS_WITH_SHARED_BLOBS
|
|
)
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
|
|
if after_remove != expected_counts:
|
|
print("REMOVE DIDNT WORK RIGHT. ---------------Expected on 2-master-------------")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(after_remove))
|
|
print("--------------------------------------------------------------EXPECTED ON 2-master **FAILED**")
|
|
cleanup()
|
|
return
|
|
|
|
print("--------------------------------------------------------------PASS")
|
|
cleanup()
|
|
|
|
|
|
def test_tags_in_manifest_lists_out():
|
|
print("**********************************************************")
|
|
print(" tags in manifest_lists out")
|
|
print(" DOES NOT REMOVE THE TAGS UNLESS UNLINKED")
|
|
print("**********************************************************")
|
|
|
|
ensure_empty()
|
|
copy_by_content_pk('docker_tag', TAGS)
|
|
expected_counts = {u'docker_blob': 66, u'docker_tag': 10, u'docker_manifest_list': 4,
|
|
u'docker_manifest': 35}
|
|
content_counts = get_repo_content_count(DESTINATION_REPO)
|
|
if content_counts != expected_counts:
|
|
print("COPY DIDNT WORK RIGHT")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(content_counts))
|
|
# sys.exit(1)
|
|
print("TODO 00000-currently difficult to tell what this count should be00000")
|
|
print("TODO XXXXXXXX- one strategy:rm one at a time on 2-master, should be rightXXXXXXX")
|
|
|
|
# Another query because the tag ids new destination are new.
|
|
manifest_lists_in_dest = get_units_by_type(DESTINATION_REPO, 'docker_manifest_list')
|
|
|
|
# 2-master
|
|
# expected_counts = {u'docker_blob': 73, u'docker_manifest_list': 4, u'docker_manifest': 37}
|
|
# flattened-queries
|
|
expected_counts = {u'docker_blob': 8, u'docker_tag': 5, u'docker_manifest': 5}
|
|
# rm_by_content_pk(manifest_lists_in_dest)
|
|
for ml in manifest_lists_in_dest:
|
|
rm_by_content_pk([ml])
|
|
after_remove = get_repo_content_count(DESTINATION_REPO)
|
|
|
|
if after_remove != expected_counts:
|
|
print("REMOVE DIDNT WORK RIGHT. ---------------Expected on 2-master-------------")
|
|
print("Expected:" + str(expected_counts))
|
|
print("Actual:" + str(after_remove))
|
|
print("--------------------------------------------------------------EXPECTED ON 2-master **FAILED**")
|
|
cleanup()
|
|
return
|
|
|
|
print("--------------------------------------------------------------PASS")
|
|
cleanup()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|