Skip to content

Commit

Permalink
Fix atomic migrate test
Browse files Browse the repository at this point in the history
Signed-off-by: Shishir Mahajan <[email protected]>
  • Loading branch information
Shishir Mahajan committed Jan 14, 2016
1 parent 4566659 commit 4a5f0c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
46 changes: 26 additions & 20 deletions Atomic/Export.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ def export_docker(graph, export_location):
if not os.path.isdir(export_location):
os.makedirs(export_location)

try:
dangling_images = DOCKER_CLIENT.images(filters={"dangling":True}, quiet=True)
if any(dangling_images):
util.writeOut("There are dangling images in your system. Would you like atomic to prune them [y/N]")
choice = sys.stdin.read(1)
if choice.lower() == 'y':
util.writeOut("Deleting dangling images")
subprocess.check_call(["docker", "rmi", "-f"]+dangling_images)
else:
raise ValueError("Please delete dangling images before running atomic migrate export")

#Save the docker storage driver
storage_driver = DOCKER_CLIENT.info()["Driver"]
filed = open(export_location+"/info.txt", "w")
filed.write(storage_driver)
filed.close()

#export docker images
export_images(export_location)
#export docker containers
export_containers(graph, export_location)
#export docker volumes
export_volumes(graph, export_location)
except:
error = sys.exc_info()[0]
sys.exit(error)
storage_driver = DOCKER_CLIENT.info()["Driver"]
filed = open(export_location+"/info.txt", "w")
filed.write(storage_driver)
filed.close()

#export docker images
export_images(export_location)
#export docker containers
export_containers(graph, export_location)
#export docker volumes
export_volumes(graph, export_location)

util.writeOut("atomic export completed successfully")

Expand Down Expand Up @@ -79,7 +85,7 @@ def export_containers(graph, export_location):
util.writeOut("Exporting container: {0}".format(id[:12]))
subprocess.check_call([ATOMIC_LIBEXEC + '/migrate.sh',
'export',
'--container-id=' + id,
'--container-id=' + id[:12],
'--graph=' + graph,
'--export-location=' + export_location])

Expand All @@ -96,9 +102,9 @@ def export_volumes(graph, export_location):
os.makedirs(export_location + "/volumes")

util.writeOut("Exporting volumes")
tar_create(srcdir = graph + '/volumes',
destfile = export_location + '/volumes/volumeData.tar.gz')
tar_create(srcdir=graph + '/volumes',
destfile=export_location + '/volumes/volumeData.tar.gz')

if os.path.isdir(graph + "/vfs"):
tar_create(srcdir = graph + '/vfs',
destfile = export_location + '/volumes/vfsData.tar.gz')
tar_create(srcdir=graph + '/vfs',
destfile=export_location + '/volumes/vfsData.tar.gz')
10 changes: 6 additions & 4 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ container_export(){
echo $containerBaseImageID>>containerInfo.txt
echo $notruncContainerID>>containerInfo.txt
"$GOTAR" -cf container-metadata.tar $dockerRootDir/containers/$notruncContainerID 2> /dev/null
imageID=$(docker commit $containerID)||exit 1
imageName=$(echo $RANDOM)
docker commit $containerID $imageName 1>/dev/null||exit 1
mkdir -p $tmpDir/temp
docker save $imageID > $tmpDir/temp/image.tar||exit 1
docker save $imageName > $tmpDir/temp/image.tar||exit 1
$(cd $tmpDir/temp; "$GOTAR" -xf image.tar)
cd $tmpDir/temp/$imageID
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
rm -rf temp
docker rmi -f $imageID 1>/dev/null||exit 1
docker rmi -f $imageName 1>/dev/null||exit 1
}

container_import(){
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ trap cleanup EXIT
# at /var/lib/docker
atomic_migrate () {
setup
${ATOMIC} migrate export --dir "$(pwd)/migrate-dir"
echo 'y'|${ATOMIC} migrate export --dir "$(pwd)/migrate-dir"
switch_docker_storage
echo 'y'|${ATOMIC} migrate import --dir "$(pwd)/migrate-dir"
systemctl restart docker
Expand Down

0 comments on commit 4a5f0c1

Please sign in to comment.