From 76ae1cc975be029d483e54e689dcadf5750d4b5e Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 09:42:10 +0200 Subject: [PATCH 1/9] prune: always prune OSTree references 4abc3eb8c9c6ee9c3528a9bb0211a4b494c39876 changed this to be done only when there are Docker images that are pruned as well. Change it back to the previous behavior. Closes: https://github.com/projectatomic/atomic/issues/496 Signed-off-by: Giuseppe Scrivano --- Atomic/delete.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Atomic/delete.py b/Atomic/delete.py index 27cc2b4a..647b4173 100644 --- a/Atomic/delete.py +++ b/Atomic/delete.py @@ -35,6 +35,8 @@ def prune_images(self): """ enc = sys.getdefaultencoding() + self.syscontainers.prune_ostree_images() + results = self.d.images(filters={"dangling":True}, quiet=True) if len(results) == 0: return 0 @@ -42,7 +44,6 @@ def prune_images(self): for img in results: self.d.remove_image(img.decode(enc), force=True) util.write_out("Removed dangling Image {}".format(enc)) - self.syscontainers.prune_ostree_images() return 0 def _delete_remote(self, targets): From 2e81bc4249bb4b2443e78bf95e924334708f6559 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 10:17:35 +0200 Subject: [PATCH 2/9] syscontainers: use temporarily CLI ostree for checkouts This is required to process Docker whiteouts files in OSTree, which are not enabled by this patch. There is an issue in the way the RepoCheckoutOptions object is mapped by glib, as the C struct is using bit fields that are not supported by the introspection, so use the CLI version of OSTree for now. Signed-off-by: Giuseppe Scrivano --- Atomic/syscontainers.py | 46 ++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index ec198dda..aa8cc304 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -58,6 +58,28 @@ def __init__(self): def get_atomic_config_item(self, config_item): return util.get_atomic_config_item(config_item, atomic_config=self.atomic_config) + def _checkout_layer(self, repo, rootfs_fd, rootfs, rev): + OSTREE_SAFE_GLIB_REPO_CHECKOUT_OPTIONS = False + # There is an issue in the way the RepoCheckoutOptions is mapped by glib, as the C + # struct is using bit fields that are not supported by the introspection. + # Accessing .disable_fsync and .process_whiteouts thus results in a segfault in + # libostree. Re-enable this once it gets fixed. + if OSTREE_SAFE_GLIB_REPO_CHECKOUT_OPTIONS: + options = OSTree.RepoCheckoutOptions() + options.overwrite_mode = OSTree.RepoCheckoutOverwriteMode.UNION_FILES + options.process_whiteouts = True + repo.checkout_tree_at(options, rootfs_fd, rootfs, rev) + else: + util.check_call(["ostree", "--repo=%s" % self._get_ostree_repo_location(), + "checkout", + "--union", + "--whiteouts", + rev, + rootfs], + stdin=DEVNULL, + stdout=DEVNULL, + stderr=DEVNULL) + def set_args(self, args): self.args = args @@ -148,19 +170,17 @@ def _checkout_system_container(self, repo, name, img, deployment, upgrade, value rev = repo.resolve_rev(imagebranch, False)[1] manifest = SystemContainers._get_commit_metadata(repo, rev, "docker.manifest") - options = OSTree.RepoCheckoutOptions() - options.overwrite_mode = OSTree.RepoCheckoutOverwriteMode.UNION_FILES rootfs_fd = None try: rootfs_fd = os.open(rootfs, os.O_DIRECTORY) if manifest is None: - repo.checkout_tree_at(options, rootfs_fd, rootfs, rev) + self._checkout_layer(repo, rootfs_fd, rootfs, rev) else: layers = SystemContainers._get_layers_from_manifest(json.loads(manifest)) for layer in layers: rev_layer = repo.resolve_rev("%s%s" % (OSTREE_OCIIMAGE_PREFIX, layer.replace("sha256:", "")), False)[1] - repo.checkout_tree_at(options, rootfs_fd, rootfs, rev_layer) + self._checkout_layer(repo, rootfs_fd, rootfs, rev_layer) finally: if rootfs_fd: os.close(rootfs_fd) @@ -247,18 +267,20 @@ def _get_system_checkout_path(self): self.get_atomic_config_item(["checkout_path"]) or \ "/var/lib/containers/atomic" - def _get_ostree_repo(self): - if not OSTREE_PRESENT: - return None - + def _get_ostree_repo_location(self): if self.user: home_dir = os.getenv("HOME") - repo_location = os.path.expanduser("%s/ostree/repo" % home_dir) + return os.path.expanduser("%s/ostree/repo" % home_dir) else: - repo_location = os.environ.get("ATOMIC_OSTREE_REPO") or \ - self.get_atomic_config_item(["ostree_repository"]) or \ - "/ostree/repo" + return os.environ.get("ATOMIC_OSTREE_REPO") or \ + self.get_atomic_config_item(["ostree_repository"]) or \ + "/ostree/repo" + + def _get_ostree_repo(self): + if not OSTREE_PRESENT: + return None + repo_location = self._get_ostree_repo_location() repo = OSTree.Repo.new(Gio.File.new_for_path(repo_location)) # If the repository doesn't exist at the specified location, create it From bdec0f9fda7e00776a399880d3a1aaa19022af17 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 11:06:32 +0200 Subject: [PATCH 3/9] syscontainers: use syncfs for checkouts from OSTree By default OSTree uses `fsync' after each file is checked out. Disable `fsync' and use `syncfs' after every layer was checked out to the file system. Closes: https://github.com/projectatomic/atomic/issues/491 Signed-off-by: Giuseppe Scrivano --- Atomic/syscontainers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index aa8cc304..b11f6a1b 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -11,6 +11,7 @@ import subprocess import time from .client import AtomicDocker +from ctypes import cdll, CDLL try: import gi @@ -58,6 +59,20 @@ def __init__(self): def get_atomic_config_item(self, config_item): return util.get_atomic_config_item(config_item, atomic_config=self.atomic_config) + def _do_syncfs(self, rootfs, rootfs_fd): + # Fallback to sync --file-system if loading it from libc fails. + try: + cdll.LoadLibrary("libc.so.6") + libc = CDLL("libc.so.6") + if libc.syncfs(rootfs_fd) == 0: + return + except (NameError, AttributeError, OSError): + pass + + util.check_call(["sync", "--file-system", rootfs], stdin=DEVNULL, + stdout=DEVNULL, + stderr=DEVNULL) + def _checkout_layer(self, repo, rootfs_fd, rootfs, rev): OSTREE_SAFE_GLIB_REPO_CHECKOUT_OPTIONS = False # There is an issue in the way the RepoCheckoutOptions is mapped by glib, as the C @@ -68,12 +83,14 @@ def _checkout_layer(self, repo, rootfs_fd, rootfs, rev): options = OSTree.RepoCheckoutOptions() options.overwrite_mode = OSTree.RepoCheckoutOverwriteMode.UNION_FILES options.process_whiteouts = True + options.disable_fsync = True repo.checkout_tree_at(options, rootfs_fd, rootfs, rev) else: util.check_call(["ostree", "--repo=%s" % self._get_ostree_repo_location(), "checkout", "--union", "--whiteouts", + "--fsync=no", rev, rootfs], stdin=DEVNULL, @@ -181,6 +198,7 @@ def _checkout_system_container(self, repo, name, img, deployment, upgrade, value for layer in layers: rev_layer = repo.resolve_rev("%s%s" % (OSTREE_OCIIMAGE_PREFIX, layer.replace("sha256:", "")), False)[1] self._checkout_layer(repo, rootfs_fd, rootfs, rev_layer) + self._do_syncfs(rootfs, rootfs_fd) finally: if rootfs_fd: os.close(rootfs_fd) From b3db3c0dd89aa10b1ef6fb19a330b94b5a0b94a4 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 11:22:13 +0200 Subject: [PATCH 4/9] syscontainers: do not leave broken symlink on uninstall Use `os.path.lexists' to verify its presence. Delete the symlink before the deployments, so that the container doesn't look installed while its being deleted. Closes: https://github.com/projectatomic/atomic/issues/495 Signed-off-by: Giuseppe Scrivano --- Atomic/syscontainers.py | 5 ++--- tests/integration/test_system_containers.sh | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index b11f6a1b..9d7520c2 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -401,12 +401,11 @@ def uninstall_system_container(self, name): except subprocess.CalledProcessError: pass + if os.path.lexists("%s/%s" % (self._get_system_checkout_path(), name)): + os.unlink("%s/%s" % (self._get_system_checkout_path(), name)) for deploy in ["0", "1"]: if os.path.exists("%s/%s.%s" % (self._get_system_checkout_path(), name, deploy)): shutil.rmtree("%s/%s.%s" % (self._get_system_checkout_path(), name, deploy)) - if os.path.exists("%s/%s" % (self._get_system_checkout_path(), name)): - os.unlink("%s/%s" % (self._get_system_checkout_path(), name)) - if os.path.exists(os.path.join(SYSTEMD_UNIT_FILES_DEST, "%s.service" % name)): os.unlink(os.path.join(SYSTEMD_UNIT_FILES_DEST, "%s.service" % name)) diff --git a/tests/integration/test_system_containers.sh b/tests/integration/test_system_containers.sh index cf113d28..46081c75 100755 --- a/tests/integration/test_system_containers.sh +++ b/tests/integration/test_system_containers.sh @@ -104,6 +104,9 @@ ${ATOMIC} umount ${WORK_DIR}/mount ${ATOMIC} uninstall ${NAME} test \! -e /etc/systemd/system/${NAME}.service +test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME} +test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.0 +test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1 # check that there are not any "ociimage/" prefixed branch left after images prune ostree --repo=${ATOMIC_OSTREE_REPO} refs --delete "ociimage/atomic-test-system-latest" From 1dd00417ed2c6eeb19864e2fef0928981ccb4038 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 11:31:43 +0200 Subject: [PATCH 5/9] ps: do not raise an error on crashed containers Do not stop processing containers when encountering a container which was not started up correctly, so that has not runc state. Also fixes a "the JSON object must be str, not 'bytes'" error with Python3. Signed-off-by: Giuseppe Scrivano --- Atomic/ps.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Atomic/ps.py b/Atomic/ps.py index e9563b6e..d7588591 100644 --- a/Atomic/ps.py +++ b/Atomic/ps.py @@ -2,7 +2,9 @@ from . import util from . import Atomic +import subprocess from dateutil.parser import parse as dateparse +from . import atomic class Ps(Atomic): def ps(self): @@ -11,8 +13,11 @@ def ps(self): # Collect the system containers for i in self.syscontainers.get_system_containers(): container = i["Id"] - inspect_stdout = util.check_output(["runc", "state", container]) - ret = json.loads(inspect_stdout) + try: + inspect_stdout = util.check_output(["runc", "state", container], stderr=atomic.DEVNULL) + ret = json.loads(inspect_stdout.decode()) + except (subprocess.CalledProcessError): + continue status = ret["status"] if not self.args.all and status != "running": continue From 90aa5cbd1f07e247a50979eae8aae4dd507dc7e2 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 12:39:50 +0200 Subject: [PATCH 6/9] delete: support images from the OSTree repository Signed-off-by: Giuseppe Scrivano --- Atomic/delete.py | 19 +++++++++++-------- Atomic/syscontainers.py | 11 +++++++++++ tests/integration/test_system_containers.sh | 4 ++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Atomic/delete.py b/Atomic/delete.py index 647b4173..330601dc 100644 --- a/Atomic/delete.py +++ b/Atomic/delete.py @@ -73,12 +73,15 @@ def _delete_remote(self, targets): def _delete_local(self, targets): results = 0 for target in targets: - try: - self.d.remove_image(target) - except NotFound as e: - util.write_err("Failed to delete Image {}: {}".format(target, e)) - results = 2 - except APIError as e: - util.write_err("Failed operation for delete Image {}: {}".format(target, e)) - results = 2 + if self.syscontainers.has_system_container_image(target): + self.syscontainers.delete_image(target) + else: + try: + self.d.remove_image(target) + except NotFound as e: + util.write_err("Failed to delete Image {}: {}".format(target, e)) + results = 2 + except APIError as e: + util.write_err("Failed operation for delete Image {}: {}".format(target, e)) + results = 2 return results diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index 9d7520c2..04f22093 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -358,6 +358,17 @@ def get_system_containers(self): ret.append(container) return ret + def delete_image(self, image): + repo = self._get_ostree_repo() + if not repo: + return + imagebranch = SystemContainers._get_ostree_image_branch(image) + commit_rev = repo.resolve_rev(imagebranch, True) + if not commit_rev[1]: + return + ref = OSTree.parse_refspec(imagebranch) + repo.set_ref_immediate(ref[1], ref[2], None) + def get_system_images(self, repo=None): if repo is None: repo = self._get_ostree_repo() diff --git a/tests/integration/test_system_containers.sh b/tests/integration/test_system_containers.sh index 46081c75..5c48a2e7 100755 --- a/tests/integration/test_system_containers.sh +++ b/tests/integration/test_system_containers.sh @@ -109,8 +109,8 @@ test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.0 test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1 # check that there are not any "ociimage/" prefixed branch left after images prune -ostree --repo=${ATOMIC_OSTREE_REPO} refs --delete "ociimage/atomic-test-system-latest" -ostree --repo=${ATOMIC_OSTREE_REPO} refs --delete "ociimage/busybox-latest" +${ATOMIC} images delete -f atomic-test-system +${ATOMIC} images delete -f busybox ${ATOMIC} images prune OUTPUT=$(! ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep -c ociimage) if test $OUTPUT \!= 0; then From e7be3ebfc61f5f55ac74b53b697defd0bd2f3ff3 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 12:40:34 +0200 Subject: [PATCH 7/9] syscontainers: 'pull' always create the metadata commit If we had all the data layers, we would skip the creation of the metadata commit, so that the sequence: atomic images delete foo atomic images pull foo would not create the image foo to be again present in the repository, unless a prune would happen in between the two operations. Signed-off-by: Giuseppe Scrivano --- Atomic/syscontainers.py | 31 ++++++++++----------- tests/integration/test_system_containers.sh | 13 +++++++-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index 04f22093..ff1335d9 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -601,24 +601,23 @@ def _check_system_oci_image(self, repo, img, upgrade): missing_layers.append(layer) util.write_out("Missing layer %s" % layer) - if len(missing_layers) == 0: - return True - - layers_dir = self._skopeo_get_layers(img, missing_layers) + layers_dir = None try: - layers = {} - for root, _, files in os.walk(layers_dir): - for f in files: - if f.endswith(".tar"): - layer_file = os.path.join(root, f) - layer = f.replace(".tar", "") - if layer in missing_layers: - layers[layer] = layer_file - - if (len(layers)): - SystemContainers._import_layers_into_ostree(repo, imagebranch, manifest, layers) + layers_to_import = {} + if len(missing_layers): + layers_dir = self._skopeo_get_layers(img, missing_layers) + for root, _, files in os.walk(layers_dir): + for f in files: + if f.endswith(".tar"): + layer_file = os.path.join(root, f) + layer = f.replace(".tar", "") + if layer in missing_layers: + layers_to_import[layer] = layer_file + + SystemContainers._import_layers_into_ostree(repo, imagebranch, manifest, layers_to_import) finally: - shutil.rmtree(layers_dir) + if layers_dir: + shutil.rmtree(layers_dir) return True @staticmethod diff --git a/tests/integration/test_system_containers.sh b/tests/integration/test_system_containers.sh index 5c48a2e7..73aa05c8 100755 --- a/tests/integration/test_system_containers.sh +++ b/tests/integration/test_system_containers.sh @@ -28,8 +28,6 @@ docker save atomic-test-system > ${WORK_DIR}/atomic-test-system.tar ${ATOMIC} pull dockertar:/${WORK_DIR}/atomic-test-system.tar -${ATOMIC} pull docker.io/busybox - # Check that the branch is created in the OSTree repository ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep -q "ociimage/atomic-test-system-latest" @@ -108,6 +106,17 @@ test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME} test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.0 test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1 + +${ATOMIC} pull docker.io/busybox +ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep busybox +${ATOMIC} images delete -f busybox +OUTPUT=$(! ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep -c busybox) +if test $OUTPUT \!= 0; then + exit 1 +fi +${ATOMIC} pull docker.io/busybox +ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep busybox + # check that there are not any "ociimage/" prefixed branch left after images prune ${ATOMIC} images delete -f atomic-test-system ${ATOMIC} images delete -f busybox From 0c7f31de97f174040900b4d418c70a6ada509fc6 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 22 Jul 2016 13:57:19 +0200 Subject: [PATCH 8/9] tests: write to file before using grep It avoids some random SIGPIPEs during the tests Signed-off-by: Giuseppe Scrivano --- tests/integration/test_system_containers.sh | 43 ++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/tests/integration/test_system_containers.sh b/tests/integration/test_system_containers.sh index 73aa05c8..eeb47b9f 100755 --- a/tests/integration/test_system_containers.sh +++ b/tests/integration/test_system_containers.sh @@ -19,7 +19,9 @@ OUTPUT=$(/bin/true) # Skip the test if OSTree or runc are not installed, or atomic has not --install --system ostree --version &>/dev/null || exit 77 runc --version &>/dev/null || exit 77 -${ATOMIC} install --help 2>&1 | grep -q -- --system || exit 77 + +${ATOMIC} install --help 2>&1 > help.out +grep -q -- --system help.out || exit 77 export ATOMIC_OSTREE_REPO=${WORK_DIR}/repo export ATOMIC_OSTREE_CHECKOUT_PATH=${WORK_DIR}/checkout @@ -29,7 +31,8 @@ docker save atomic-test-system > ${WORK_DIR}/atomic-test-system.tar ${ATOMIC} pull dockertar:/${WORK_DIR}/atomic-test-system.tar # Check that the branch is created in the OSTree repository -ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep -q "ociimage/atomic-test-system-latest" +ostree --repo=${ATOMIC_OSTREE_REPO} refs > refs +grep -q "ociimage/atomic-test-system-latest" refs ${ATOMIC} images list > ${WORK_DIR}/images grep -q "atomic-test-system" ${WORK_DIR}/images @@ -53,15 +56,24 @@ trap teardown EXIT ${ATOMIC} --debug install --name=${NAME} --set=RECEIVER=${SECRET} --system oci:atomic-test-system -${ATOMIC} ps | grep -q "test-system" -${ATOMIC} ps --json | grep -q "test-system" -${ATOMIC} ps --all | grep -q "test-system" -${ATOMIC} ps --json --all | grep -q "test-system" -${ATOMIC} ps --filter id=test-system | grep -q "test-system" -${ATOMIC} ps --no-trunc | grep -q "test-system" -${ATOMIC} ps --quiet | grep -q "test-system" -${ATOMIC} ps -aq --no-trunc --filter id=test-system | grep -q "test-system" -if ${ATOMIC} ps -aq --no-trunc --filter id=non-existing-system | grep -q "test-system"; then +${ATOMIC} ps > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps --json > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps --all > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps --json --all > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps --filter id=test-system > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps --no-trunc > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps --quiet > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps -aq --no-trunc --filter id=test-system > ps.out +grep -q "test-system" ps.out +${ATOMIC} ps -aq --no-trunc --filter id=non-existing-system > ps.out +if grep -q "test-system" ps.out; then exit 1 fi @@ -108,9 +120,11 @@ test \! -e ${ATOMIC_OSTREE_CHECKOUT_PATH}/${NAME}.1 ${ATOMIC} pull docker.io/busybox -ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep busybox +ostree --repo=${ATOMIC_OSTREE_REPO} refs > refs +grep -q busybox refs ${ATOMIC} images delete -f busybox -OUTPUT=$(! ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep -c busybox) +ostree --repo=${ATOMIC_OSTREE_REPO} refs > refs +OUTPUT=$(! grep -c busybox refs) if test $OUTPUT \!= 0; then exit 1 fi @@ -121,7 +135,8 @@ ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep busybox ${ATOMIC} images delete -f atomic-test-system ${ATOMIC} images delete -f busybox ${ATOMIC} images prune -OUTPUT=$(! ostree --repo=${ATOMIC_OSTREE_REPO} refs | grep -c ociimage) +ostree --repo=${ATOMIC_OSTREE_REPO} refs > refs +OUTPUT=$(! grep -c ociimage refs) if test $OUTPUT \!= 0; then exit 1 fi From 0165fa5173cd458d7f28183f54c82d1eb85ca66a Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 26 Jul 2016 17:30:35 +0200 Subject: [PATCH 9/9] Revert "Migrate script should now work since we are after docker-1.10" It breaks the tests suite This reverts commit 7fcd49ebdd174960487dbaee4deafeaf79ae767d. --- migrate.sh | 34 +++++++++++++------------------ tests/integration/test_migrate.sh | 15 +++++++------- tests/test-images/Dockerfile.2 | 4 ++++ 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 tests/test-images/Dockerfile.2 diff --git a/migrate.sh b/migrate.sh index 8b3b73df..d26b3b43 100755 --- a/migrate.sh +++ b/migrate.sh @@ -130,20 +130,18 @@ container_export(){ echo $containerBaseImageID>>containerInfo.txt echo $notruncContainerID>>containerInfo.txt "$GOTAR" -cf container-metadata.tar $dockerRootDir/containers/$notruncContainerID 2> /dev/null - if [[ ! -z $(docker diff $containerID) ]];then - imageName=$(echo $RANDOM) - docker commit $containerID $imageName 1>/dev/null||exit 1 - mkdir -p $tmpDir/temp - docker save $imageName > $tmpDir/temp/image.tar||exit 1 - $(cd $tmpDir/temp; "$GOTAR" -xf image.tar) - diffLayerID=$(python -c 'import json; f=open("temp/repositories"); j=json.load(f); print(j[j.keys()[0]]["latest"])') - cd $tmpDir/temp/$diffLayerID - cp layer.tar $tmpDir/container-diff.tar - cd $tmpDir - /usr/bin/tar --delete -f container-diff.tar run/gotar 2>/dev/null || true - rm -rf temp - docker rmi -f $imageName 1>/dev/null||exit 1 - fi + imageName=$(echo $RANDOM) + docker commit $containerID $imageName 1>/dev/null||exit 1 + mkdir -p $tmpDir/temp + docker save $imageName > $tmpDir/temp/image.tar||exit 1 + $(cd $tmpDir/temp; "$GOTAR" -xf image.tar) + diffLayerID=$(python -c 'import json; f=open("temp/repositories"); j=json.load(f); print(j[j.keys()[0]]["latest"])') + cd $tmpDir/temp/$diffLayerID + cp layer.tar $tmpDir/container-diff.tar + cd $tmpDir + /usr/bin/tar --delete -f container-diff.tar run/gotar 2>/dev/null || true + rm -rf temp + docker rmi -f $imageName 1>/dev/null||exit 1 } container_import(){ @@ -186,12 +184,8 @@ container_import(){ fi cd $importPath/containers/migrate-$containerID - dockerBaseImageID=$(sed -n '2p' containerInfo.txt)||exit 1 - if [[ -f container-diff.tar ]];then - cat container-diff.tar|docker run -i -v "$GOTAR:/run/gotar" $dockerBaseImageID /run/gotar -xf - - else - docker run -i $dockerBaseImageID echo "container_import" - fi + dockerBaseImageID=$(sed -n '2p' containerInfo.txt)||exit 1 + cat container-diff.tar|docker run -i -v "$GOTAR:/run/gotar" $dockerBaseImageID /run/gotar -xf - newContainerID=$(docker ps -lq)||exit 1 newContainerName=$(docker inspect -f '{{.Name}}' $newContainerID)||exit 1 newNotruncContainerID=$(docker ps -aq --no-trunc|grep $newContainerID)||exit 1 diff --git a/tests/integration/test_migrate.sh b/tests/integration/test_migrate.sh index 2c3e19cf..57214291 100755 --- a/tests/integration/test_migrate.sh +++ b/tests/integration/test_migrate.sh @@ -2,6 +2,13 @@ set -euo pipefail IFS=$'\n\t' +#With the inclusion of this PR (https://github.com/projectatomic/atomic/pull/294) +#atomic storage export/import will only work with docker 1.10 support. +#Skip this test, until we move to docker 1.10. + +echo "WARNING: skipping test_migrate.sh since it is only supported with docker 1.10 onwards." +exit 0 + # # 'atomic storage' integration tests (non-live) # AUTHOR: Shishir Mahajan @@ -18,13 +25,7 @@ if [ "$init" != "systemd" ];then exit 0 fi -if ! systemctl is-active docker >/dev/null; then - echo "Docker daemon is not running" - exit 1 -fi - -pid=$(systemctl show -p MainPID docker.service) -dockerPid=$(echo ${pid#*=}) +dockerPid=$(ps -C docker -o pid=|xargs) dockerCmdline=$(cat /proc/$dockerPid/cmdline) if [[ $dockerCmdline =~ "-g=" ]] || [[ $dockerCmdline =~ "-g/" ]] || [[ $dockerCmdline =~ "--graph" ]];then echo "Docker is not located at the default (/var/lib/docker) root location. Skipping these tests." diff --git a/tests/test-images/Dockerfile.2 b/tests/test-images/Dockerfile.2 new file mode 100644 index 00000000..a63b9418 --- /dev/null +++ b/tests/test-images/Dockerfile.2 @@ -0,0 +1,4 @@ +FROM scratch +MAINTAINER "William Temple " + +LABEL "Name"="atomic-test-2"