This instance will be upgraded to Heptapod 0.25.0 (final) on 2021-09-22 at 15:00 UTC+2 (a few minutes of down time)

Commit 5ebef680 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

PAAS Runner: PAAS exceptions

This is an attempt to use a single, flexible, base class for
errors encountered while dealing with PAAS APIs.

Many, but not all interactions go through a transport layer
(usually HTTP, can also be Git), which has its own, meaningful,
set of error codes on top of potentially a different one in the
payload. That's why we have a "main" `code` and an optional
`transport_code` when distinction is useful.

Similarly, `action_details` can be a HTTP request body, maybe
something else, and in some cases, nothing.

Typically, the caller would know what to expect in context, while
an ultimate catcher in top loop wouldn't try to interpret too much.

--HG--
branch : heptapod
parent b9c87329fba3
......@@ -6,6 +6,34 @@
# SPDX-License-Identifier: GPL-3.0-or-later
class PaasError(RuntimeError):
"""Used for errors encountered on PAAS."""
def __init__(self, executor, action, code,
transport_code=None, # used when different from code
action_details=None,
error_details=None):
self.executor = executor
self.action = action
self.action_details = action_details
self.transport_code = transport_code
self.code = code
self.error_details = error_details
self.args = (executor, action, code)
class PaasProvisioningError(PaasError):
"""Used for errors encountered while provisioning on PAAS."""
class PaasResourceError(PaasError):
"""Errors encountered on an already provisioned PAAS resource."""
def __init__(self, resource_id, *args, **kwargs):
super(PaasResourceError, self).__init__(*args, **kwargs)
self.resource_id = resource_id
self.args = (resource_id, ) + self.args
class GitLabError(RuntimeError):
"""Used for errors encountered in interactions with GitLab."""
......
# Copyright 2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-3.0-or-later
from ..exceptions import (
PaasResourceError,
)
def test_paas_resource_error():
rid = 'xyz-1234-foo'
exc = PaasResourceError(executor='test-docker',
action='run',
code=137,
resource_id=rid,
error_details="Container got SIGKILLed",
)
# the args attribute is just because it is probably expected for
# a subclass of RuntimeError
assert exc.args == (rid, 'test-docker', 'run', 137)
# details are more clearly available as other instance attributes
assert exc.resource_id == rid
assert exc.code == 137
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