Commit dc559dad authored by Łukasz Nowak's avatar Łukasz Nowak

standalone: Expose specific exceptions

Thanks to more specific exceptions the caller is able to understand what
exactly happened during processing, especially useful in case of the caller
uses testcase, and can sneak into real problems during setUpClass.
parent 9a7d24ae
......@@ -79,6 +79,21 @@ class SlapOSNodeCommandError(Exception):
)
@zope.interface.implementer(IException)
class SlapOSNodeSoftwareError(SlapOSNodeCommandError):
"""Exception raised when runing SlapOS Node software command failed.
"""
@zope.interface.implementer(IException)
class SlapOSNodeInstanceError(SlapOSNodeCommandError):
"""Exception raised when runing SlapOS Node instance command failed.
"""
@zope.interface.implementer(IException)
class SlapOSNodeReportError(SlapOSNodeCommandError):
"""Exception raised when runing SlapOS Node report command failed.
"""
@zope.interface.implementer(IException)
class PathTooDeepError(Exception):
"""Exception raised when path is too deep to create an unix socket.
......@@ -769,15 +784,18 @@ class StandaloneSlapOS(object):
running `slapos node software --all`.
Error cases:
* `SlapOSNodeCommandError` when buildout error while installing software.
* `SlapOSNodeSoftwareError` when buildout error while installing software.
* Unexpected `Exception` if unable to connect to embedded slap server.
"""
return self._runSlapOSCommand(
'slapos-node-software-all' if install_all else 'slapos-node-software',
max_retry=max_retry,
debug=debug,
error_lines=error_lines,
)
try:
return self._runSlapOSCommand(
'slapos-node-software-all' if install_all else 'slapos-node-software',
max_retry=max_retry,
debug=debug,
error_lines=error_lines,
)
except SlapOSNodeCommandError as e:
raise SlapOSNodeSoftwareError(*e.args)
def waitForInstance(self, max_retry=0, debug=False, error_lines=30):
"""Instantiate all partitions previously requested for start.
......@@ -790,15 +808,18 @@ class StandaloneSlapOS(object):
drop in a debugger session if error occurs.
Error cases:
* `SlapOSNodeCommandError` when buildout error while creating instances.
* `SlapOSNodeInstanceError` when buildout error while creating instances.
* Unexpected `Exception` if unable to connect to embedded slap server.
"""
return self._runSlapOSCommand(
'slapos-node-instance-all' if self._force_slapos_node_instance_all else 'slapos-node-instance',
max_retry=max_retry,
debug=debug,
error_lines=error_lines,
)
try:
return self._runSlapOSCommand(
'slapos-node-instance-all' if self._force_slapos_node_instance_all else 'slapos-node-instance',
max_retry=max_retry,
debug=debug,
error_lines=error_lines,
)
except SlapOSNodeCommandError as e:
raise SlapOSNodeInstanceError(*e.args)
def waitForReport(self, max_retry=0, debug=False, error_lines=30):
"""Destroy all partitions previously requested for destruction.
......@@ -811,15 +832,18 @@ class StandaloneSlapOS(object):
drop in a debugger session if error occurs.
Error cases:
* `SlapOSNodeCommandError` when buildout error while destroying instances.
* `SlapOSNodeReportError` when buildout error while destroying instances.
* Unexpected `Exception` if unable to connect to embedded slap server.
"""
return self._runSlapOSCommand(
'slapos-node-report',
max_retry=max_retry,
debug=debug,
error_lines=error_lines,
)
try:
return self._runSlapOSCommand(
'slapos-node-report',
max_retry=max_retry,
debug=debug,
error_lines=error_lines,
)
except SlapOSNodeCommandError as e:
raise SlapOSNodeReportError(*e.args)
def _runSlapOSCommand(
self, command, max_retry=0, debug=False, error_lines=30):
......
......@@ -44,7 +44,7 @@ from six.moves.configparser import ConfigParser
import psutil
from slapos.slap.standalone import StandaloneSlapOS
from slapos.slap.standalone import SlapOSNodeCommandError
from slapos.slap.standalone import SlapOSNodeSoftwareError
from slapos.slap.standalone import PartitionForwardConfiguration
from slapos.slap.standalone import PartitionForwardAsPartitionConfiguration
......@@ -401,16 +401,16 @@ class TestSlapOSStandaloneSoftware(SlapOSStandaloneTestCase):
f.flush()
self.standalone.supply(f.name)
with self.assertRaises(SlapOSNodeCommandError) as e:
with self.assertRaises(SlapOSNodeSoftwareError) as e:
self.standalone.waitForSoftware()
self.assertEqual(1, e.exception.args[0]['exitstatus'])
self.assertIn(
"Error: Non zero exit code (123) while running command.",
e.exception.args[0]['output'])
# SlapOSNodeCommandError.__str__ also displays output nicely
# SlapOSNodeSoftwareError.__str__ also displays output nicely
self.assertIn(
"SlapOSNodeCommandError exitstatus: 1 output:", str(e.exception))
"SlapOSNodeSoftwareError exitstatus: 1 output:", str(e.exception))
self.assertIn(
"Error: Non zero exit code (123) while running command.",
str(e.exception))
......
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