Skip to content

Commit

Permalink
export/import: don't hardcode paths
Browse files Browse the repository at this point in the history
We can't hardcode paths to /usr/libexec/atomic because we need the tests
to work without having to install atomic. We use an env var instead
which the test harness then overrides.
  • Loading branch information
jlebon committed Nov 26, 2015
1 parent 43370ce commit 139ccba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
11 changes: 7 additions & 4 deletions Atomic/Export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

DOCKER_CLIENT = docker.Client()

ATOMIC_LIBEXEC = os.environ.get('ATOMIC_LIBEXEC', '/usr/libexec/atomic')

def export_docker(graph, export_location):
"""
This is a wrapper function for exporting docker images, containers
Expand Down Expand Up @@ -93,10 +95,11 @@ def export_containers(graph, export_location):
split_containers.append(j["Id"])

for i in range(0, len(split_containers)):
util.writeOut("Exporting container ID:{0}".format(split_containers[i][:12]))
subprocess.check_call("/usr/libexec/atomic/migrate.sh export --container-id={0}"
" --graph={1} --export-location={2}"
.format(split_containers[i][:12], graph, export_location),
util.writeOut("Exporting container: {0}".format(split_containers[i][:12]))
subprocess.check_call("{0}/migrate.sh export --container-id={1}"
" --graph={2} --export-location={3}"
.format(ATOMIC_LIBEXEC, split_containers[i],
graph, export_location),
shell=True)

def export_volumes(graph, export_location):
Expand Down
11 changes: 7 additions & 4 deletions Atomic/Import.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from . import util


ATOMIC_LIBEXEC = os.environ.get('ATOMIC_LIBEXEC', '/usr/libexec/atomic')

def import_docker(graph, import_location):
"""
This is a wrapper function for importing docker images, containers
Expand Down Expand Up @@ -64,10 +66,11 @@ def import_containers(graph, import_location):
containers = subprocess.check_output("ls {0}/containers".format(import_location), shell=True)
split_containers = containers.split()
for i in split_containers:
util.writeOut("Importing container ID:{0}".format(i[8:]))
subprocess.check_call("/usr/libexec/atomic/migrate.sh import --container-id={0}"
" --graph={1} --import-location={2}"
.format(i[8:], graph, import_location), shell=True)
i = i[8:] # strip off the "migrate-"
util.writeOut("Importing container: {0}".format(i[:12]))
subprocess.check_call("{0}/migrate.sh import --container-id={1}"
" --graph={2} --import-location={3}"
.format(ATOMIC_LIBEXEC, i, graph, import_location), shell=True)

def import_volumes(graph, import_location):
"""
Expand Down
11 changes: 7 additions & 4 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# bash script to migrate containers from one backend storage to another.
set -e

ATOMIC_LIBEXEC="${ATOMIC_LIBEXEC-/usr/libexec/atomic}"
GOTAR="$ATOMIC_LIBEXEC/gotar"

main() {
if [ $(id -u) != 0 ];then
echo "Run 'migrate' as root user"
Expand Down Expand Up @@ -116,11 +119,11 @@ container_export(){
echo $dockerRootDir>containerInfo.txt
echo $containerBaseImageID>>containerInfo.txt
echo $notruncContainerID>>containerInfo.txt
/usr/libexec/atomic/gotar -cf container-metadata.tar $dockerRootDir/containers/$notruncContainerID 2> /dev/null
"$GOTAR" -cf container-metadata.tar $dockerRootDir/containers/$notruncContainerID 2> /dev/null
imageID=$(docker commit $containerID)||exit 1
mkdir -p $tmpDir/temp
docker save $imageID > $tmpDir/temp/image.tar||exit 1
$(cd $tmpDir/temp; /usr/libexec/atomic/gotar -xf image.tar)
$(cd $tmpDir/temp; "$GOTAR" -xf image.tar)
cd $tmpDir/temp/$imageID
cp layer.tar $tmpDir/container-diff.tar
cd $tmpDir
Expand Down Expand Up @@ -169,14 +172,14 @@ container_import(){

cd $importPath/containers/migrate-$containerID
dockerBaseImageID=$(sed -n '2p' containerInfo.txt)||exit 1
cat container-diff.tar|docker run -i -v /usr/libexec/atomic/gotar:/dev/shm/gotar $dockerBaseImageID /dev/shm/gotar -xf -
cat container-diff.tar|docker run -i -v "$GOTAR:/dev/shm/gotar" $dockerBaseImageID /dev/shm/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
cd $dockerRootDir/containers/$newNotruncContainerID
rm -rf *
cp $importPath/containers/migrate-$containerID/container-metadata.tar .
/usr/libexec/atomic/gotar -xf container-metadata.tar
"$GOTAR" -xf container-metadata.tar
rm container-metadata.tar
oldDockerRootDir=$(sed -n '1p' $importPath/containers/migrate-$containerID/containerInfo.txt)||exit 1
oldNotruncContainerID=$(sed -n '3p' $importPath/containers/migrate-$containerID/containerInfo.txt)||exit 1
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export PYTHONPATH=${PYTHONPATH:-$(pwd)}
export WORK_DIR=$(mktemp -p $(pwd) -d -t .tmp.XXXXXXXXXX)
export DOCKER=${DOCKER:-"/usr/bin/docker"}
export SECRET=`dd if=/dev/urandom bs=4096 count=1 2> /dev/null | sha256sum`
export ATOMIC_LIBEXEC="$(pwd)"

# This image contains the secret, so it needs to be rebuilt each time.
cat > tests/test-images/Dockerfile.secret <<EOF
Expand Down

0 comments on commit 139ccba

Please sign in to comment.