generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make image archive/save idempotent, using image id as key
- Loading branch information
Showing
6 changed files
with
26,026 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,3 +134,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# PyCharm | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2022 Red Hat | Ansible | ||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
import os.path | ||
import pytest | ||
import tempfile | ||
|
||
from ansible_collections.community.docker.plugins.modules.docker_image import archived_image_id | ||
|
||
from .test_resources.docker_image_load.busybox_latest import busybox_latest_tar_bytes | ||
from .test_resources.docker_image_load.hello_world_latest import hello_world_latest_tar_bytes | ||
|
||
|
||
@pytest.mark.parametrize('fn, expected_id', [ | ||
( | ||
busybox_latest_tar_bytes, | ||
'9d5226e6ce3fb6aee2822206a5ef85f38c303d2b37bfc894b419fca2c0501269' | ||
), | ||
( | ||
hello_world_latest_tar_bytes, | ||
'feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412' | ||
), | ||
]) | ||
def test_archived_image_id_extracts(fn, expected_id): | ||
tar_bytes = fn() | ||
|
||
file_name = tempfile.mkstemp(suffix='.tar')[1] | ||
|
||
with open(file_name, 'wb') as f: | ||
f.write(tar_bytes) | ||
|
||
image_id = archived_image_id(file_name) | ||
|
||
assert image_id == expected_id | ||
|
||
os.remove(file_name) | ||
|
||
|
||
def test_archived_image_id_extracts_nothing_when_file_not_present(): | ||
full_name = os.path.join(os.path.split(__file__)[0], 'does-not-exist.tar') | ||
|
||
image_id = archived_image_id(full_name) | ||
|
||
assert image_id is None | ||
|
||
|
||
def test_archived_image_id_raises_when_file_not_a_tar(): | ||
from ansible_collections.community.docker.plugins.modules.docker_image import ImageArchiveInvalidException | ||
|
||
try: | ||
archived_image_id(__file__) | ||
raise AssertionError("Should have failed") | ||
except ImageArchiveInvalidException: | ||
pass |
Oops, something went wrong.