Merge "Ignore snapshot downloading if snapshot generating task failed"
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from fuelclient.cli.actions.base import Action
|
||||
@@ -62,11 +63,19 @@ class SnapshotAction(Action):
|
||||
"Generating dump..."
|
||||
)
|
||||
snapshot_task.wait()
|
||||
download_snapshot_with_progress_bar(
|
||||
snapshot_task.connection.root + snapshot_task.data["message"],
|
||||
auth_token=APIClient.auth_token,
|
||||
directory=params.dir
|
||||
)
|
||||
|
||||
if snapshot_task.status == 'ready':
|
||||
download_snapshot_with_progress_bar(
|
||||
snapshot_task.connection.root + snapshot_task.data["message"],
|
||||
auth_token=APIClient.auth_token,
|
||||
directory=params.dir
|
||||
)
|
||||
elif snapshot_task.status == 'error':
|
||||
six.print_(
|
||||
"Snapshot generating task ended with error. Task message: {0}"
|
||||
.format(snapshot_task.data["message"]),
|
||||
file=sys.stderr
|
||||
)
|
||||
|
||||
def get_snapshot_config(self, params):
|
||||
"""Download default config for snapshot
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
|
||||
from fuelclient.tests.unit.v1 import base
|
||||
@@ -21,6 +22,12 @@ from fuelclient.tests.unit.v1 import base
|
||||
|
||||
class TestSnapshot(base.UnitTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSnapshot, self).setUp()
|
||||
|
||||
self.mtask = Mock(status='ready', data={'message': ''})
|
||||
self.mtask.connection = Mock(root='')
|
||||
|
||||
@patch('fuelclient.cli.actions.snapshot.SnapshotTask.get_default_config')
|
||||
@patch('sys.stdout')
|
||||
def test_get_default_config(self, mstdout, mconf):
|
||||
@@ -42,6 +49,8 @@ class TestSnapshot(base.UnitTestCase):
|
||||
mstdin.isatty.return_value = False
|
||||
mstdin.read.return_value = conf
|
||||
|
||||
mstart.return_value = self.mtask
|
||||
|
||||
self.execute(['fuel', 'snapshot'])
|
||||
|
||||
mstart.assert_called_once_with({'key': 'value'})
|
||||
@@ -62,6 +71,8 @@ class TestSnapshot(base.UnitTestCase):
|
||||
|
||||
mstdin.isatty.return_value = True
|
||||
|
||||
mstart.return_value = self.mtask
|
||||
|
||||
self.execute(['fuel', 'snapshot'])
|
||||
|
||||
mstart.assert_called_once_with({})
|
||||
@@ -69,3 +80,21 @@ class TestSnapshot(base.UnitTestCase):
|
||||
mock.ANY,
|
||||
auth_token='token123',
|
||||
directory='.')
|
||||
|
||||
@patch('fuelclient.cli.actions.snapshot.SnapshotTask.start_snapshot_task')
|
||||
@patch('sys.stdin')
|
||||
@patch('sys.stderr')
|
||||
def test_get_snapshot_when_task_is_failed(self, mstderr, mstdin, mstart):
|
||||
mstdin.isatty.return_value = True
|
||||
|
||||
mdata = {'message': 'mock task message'}
|
||||
self.mtask.status = 'error'
|
||||
self.mtask.data = mdata
|
||||
|
||||
mstart.return_value = self.mtask
|
||||
|
||||
self.execute(['fuel', 'snapshot'])
|
||||
|
||||
err_msg = ("Snapshot generating task ended with error. "
|
||||
"Task message: {0}".format(mdata['message']))
|
||||
mstderr.write.called_once_with(err_msg)
|
||||
|
||||
Reference in New Issue
Block a user