Fix handling solar resource action run errors
Change-Id: I60975a50a370de0de408c1581dcd18b33bf325e0 Closes-bug: #1544544 Related-bug: #1544506
This commit is contained in:
parent
06e3069d2b
commit
3f75defff1
@ -14,21 +14,35 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
from functools import wraps
|
||||||
import tabulate
|
import tabulate
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from solar.cli.base import EGroup
|
||||||
from solar.cli import executors
|
from solar.cli import executors
|
||||||
from solar.core import actions
|
from solar.core import actions
|
||||||
from solar.core.log import log
|
|
||||||
from solar.core import resource as sresource
|
from solar.core import resource as sresource
|
||||||
from solar.core.resource import composer as cr
|
from solar.core.resource import composer as cr
|
||||||
from solar import errors
|
from solar import errors
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
class ResourceGroup(EGroup):
|
||||||
|
|
||||||
|
def error_wrapper(self, f):
|
||||||
|
@wraps(f)
|
||||||
|
def _in(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
except errors.SolarError as e:
|
||||||
|
if self.error_wrapper_enabled:
|
||||||
|
raise click.ClickException(str(e))
|
||||||
|
raise
|
||||||
|
return _in
|
||||||
|
|
||||||
|
|
||||||
|
@click.group(cls=ResourceGroup)
|
||||||
def resource():
|
def resource():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -48,11 +62,7 @@ def action(dry_run_mapping, dry_run, action, resource):
|
|||||||
)
|
)
|
||||||
|
|
||||||
r = sresource.load(resource)
|
r = sresource.load(resource)
|
||||||
try:
|
actions.resource_action(r, action)
|
||||||
actions.resource_action(r, action)
|
|
||||||
except errors.SolarError as e:
|
|
||||||
log.debug(e)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
click.echo('EXECUTED:')
|
click.echo('EXECUTED:')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user