Raise error if provided UID is not found in history

This commit is contained in:
Dmitry Shulyak 2015-09-28 16:52:54 +03:00
parent c7edbd466c
commit 6268b534ae
3 changed files with 18 additions and 3 deletions

View File

@ -16,6 +16,7 @@ import sys
import click
from solar import errors
from solar.core import testing
from solar.core import resource
from solar.system_log import change
@ -96,8 +97,10 @@ def history(n, d, s):
@changes.command()
@click.argument('uid')
def revert(uid):
change.revert(uid)
try:
change.revert(uid)
except errors.SolarError as er:
raise click.BadParameter(str(er))
@changes.command()
@click.option('--name', default=None)

View File

@ -26,6 +26,7 @@ from solar.events import api as evapi
from solar.interfaces import orm
from .consts import CHANGES
from solar.core.resource.resource import RESOURCE_STATE
from solar.errors import CannotFindID
db = get_db()
@ -128,9 +129,20 @@ def parameters(res, action, data):
def revert_uids(uids):
"""
:param uids: iterable not generator
"""
history = data.CL()
not_valid = []
for uid in uids:
if history.get(uid) is None:
not_valid.append(uid)
if not_valid:
raise CannotFindID('UIDS: {} not in history.'.format(not_valid))
for uid in uids:
item = history.get(uid)
if item.action == CHANGES.update.name:
_revert_update(item)
elif item.action == CHANGES.remove.name:

View File

@ -85,7 +85,7 @@ def test_revert_update_connected():
operations.move_to_commited(item.log_action)
to_revert.append(item.uid)
change.revert_uids(reversed(to_revert))
change.revert_uids(sorted(to_revert, reverse=True))
staged_log = change.stage_changes()
assert len(staged_log) == 2
for item in staged_log: