from fb_tools.errors import HandlerError, ExpectedHandlerError, CommandNotFoundError
-from fb_tools.handling_obj import HandlingObject
+from fb_tools.handling_obj import HandlingObject, CalledProcessError
from fb_tools.handler import BaseHandler
from .xlate import XLATOR
-__version__ = '3.2.3'
+__version__ = '3.3.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
print()
LOG.info(_("Executing {!r} ...").format('terraform init'))
cmd = [str(self.terraform_cmd), 'init']
- result = self.run(
- cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True)
+ try:
+ result = self.run(
+ cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True)
+ except CalledProcessError as e:
+ msg = _("Error on executing {cmd!r}: return value {v}.").format(
+ cmd=e.cmd, v=e.returncode)
+ if e.stdout:
+ msg += '\nOutput: {}'.format(e.stdout)
+ if e.stderr:
+ msg += '\nError message: {}'.format(e.stderr)
+ raise ExpectedHandlerError(msg)
LOG.debug(_("Completed process:") + "\n" + str(result))
if self.existing_vms:
dc=self.vsphere[vs_name].dc, f=self.vsphere[vs_name].dc_obj.vm_folder,
p=vm.path, n=vm.name)
cmd = [str(self.terraform_cmd), 'import', vm_obj, path]
- result = self.run(
- cmd, may_simulate=True, timeout=tf_timeout,
- stdout=PIPE, stderr=PIPE, check=True)
+ try:
+ result = self.run(
+ cmd, may_simulate=True, timeout=tf_timeout,
+ stdout=PIPE, stderr=PIPE, check=True)
+ except CalledProcessError as e:
+ msg = _("Error on executing {cmd!r}: return value {v}.").format(
+ cmd=e.cmd, v=e.returncode)
+ if e.stdout:
+ msg += '\nOutput: {}'.format(e.stdout)
+ if e.stderr:
+ msg += '\nError message: {}'.format(e.stderr)
+ raise ExpectedHandlerError(msg)
+
LOG.debug(_("Completed process:") + "\n" + str(result))
print()
LOG.info(_("Executing {!r} ...").format('terraform plan'))
cmd = [str(self.terraform_cmd), 'plan']
- result = self.run(
- cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True)
+ try:
+ result = self.run(
+ cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True)
+ except CalledProcessError as e:
+ msg = _("Error on executing {cmd!r}: return value {v}.").format(
+ cmd=e.cmd, v=e.returncode)
+ if e.stdout:
+ msg += '\nOutput: {}'.format(e.stdout)
+ if e.stderr:
+ msg += '\nError message: {}'.format(e.stderr)
+ raise ExpectedHandlerError(msg)
LOG.debug(_("Completed process:") + "\n" + str(result))
goto = Path(os.path.relpath(self.project_dir, self.start_dir))