Commit 682b2e5f authored by Hilal Ozdemir's avatar Hilal Ozdemir

exit the program with an error code when fail

parent 37856d66
......@@ -25,6 +25,7 @@ Beiran Docker Plugin command line interface module
import asyncio
# import progressbar
import click
import sys
from tabulate import tabulate
from beiran_package_docker.util import DockerUtil
......@@ -69,7 +70,7 @@ async def _pull_with_progress(ctx, imagename, node, force):
err = update.get('error')
if err:
click.echo('An error occured while pulling the image. {}'.format(err))
return
return 1
if update.get('finished'):
click.echo("Image pulling process finished.")
is_finished = True
......@@ -79,6 +80,7 @@ async def _pull_with_progress(ctx, imagename, node, force):
if not is_finished:
click.echo('An error occured!')
return 1
async def _pull_with_progress_distributed(ctx, imagename, node, force):
"""Pull image with async client (distributed)"""
......@@ -96,7 +98,7 @@ async def _pull_with_progress_distributed(ctx, imagename, node, force):
except Exception as err: # pylint: disable=broad-except
click.echo('An exception is catched while requesting pull image!')
click.echo(str(err))
return
return 1
click.echo('Downloading layers...')
lastbar = None
......@@ -104,7 +106,7 @@ async def _pull_with_progress_distributed(ctx, imagename, node, force):
resp_err = data.get('error')
if resp_err:
click.echo('An error occured while pulling the image. {}'.format(resp_err))
return
return 1
if data.get('finished'):
if lastbar:
lastbar.seek_last_line()
......@@ -130,6 +132,7 @@ async def _pull_with_progress_distributed(ctx, imagename, node, force):
if lastbar:
lastbar.seek_last_line()
click.echo('An error occured!')
return 1
async def _pull_without_progress(ctx, imagename, node, wait, force, whole_image_only): # pylint: disable=too-many-arguments
"""Pull image with async client"""
......@@ -147,13 +150,13 @@ async def _pull_without_progress(ctx, imagename, node, wait, force, whole_image_
except Exception as err: # pylint: disable=broad-except
click.echo('An exception is catched while requesting pull image!')
click.echo(str(err))
return
return 1
async for data in json_streamer(resp.content, '$.status[::]'):
resp_err = data.get('error')
if resp_err:
click.echo('An error occured while pulling the image. {}'.format(resp_err))
return
return 1
if data.get('started'):
click.echo("Image pulling process started.")
if not wait:
......@@ -162,6 +165,7 @@ async def _pull_without_progress(ctx, imagename, node, wait, force, whole_image_
click.echo("Image pulling process finished.")
return
click.echo('An error occured while pulling image!')
return 1
@image.command('pull')
......@@ -188,12 +192,13 @@ def image_pull(ctx, node: str, wait: bool, force: bool, noprogress: bool,
if not noprogress:
if whole_image_only:
loop.run_until_complete(_pull_with_progress(ctx, imagename, node, force))
return_value = loop.run_until_complete(_pull_with_progress(ctx, imagename, node, force))
else:
loop.run_until_complete(_pull_with_progress_distributed(ctx, imagename, node, force))
return_value = loop.run_until_complete(_pull_with_progress_distributed(ctx, imagename, node, force))
else:
loop.run_until_complete(
return_value = loop.run_until_complete(
_pull_without_progress(ctx, imagename, node, wait, force, whole_image_only))
sys.exit(return_value)
# pylint: enable-msg=too-many-arguments
......
......@@ -5,7 +5,7 @@
[ "$status" -eq 0 ]
}
@test "pulling a non-existing image (with '--no-progress' option) prints error message" {
@test "pulling a non-existing image (with '--no-progress' option) exits with error code" {
run python -m beiran docker image pull a_non_existent_image --no-progress
[ "$status" -eq 0 ]
[ "$status" -eq 1 ]
}
......@@ -5,7 +5,7 @@
[ "$status" -eq 0 ]
}
@test "pulling a non-existing image (with '--wait' and '--no-progress' options) prints error message" {
@test "pulling a non-existing image (with '--wait' and '--no-progress' options) exits with error code" {
run python -m beiran docker image pull a_non_existent_image --wait --no-progress
[ "$status" -eq 0 ]
[ "$status" -eq 1 ]
}
......@@ -5,7 +5,7 @@
[ "$status" -eq 0 ]
}
@test "pulling a non-existing image prints error message" {
@test "pulling a non-existing image exits with error code" {
run python -m beiran docker image pull a_non_existent_image
[ "$status" -eq 0 ]
[ "$status" -eq 1 ]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment