Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Make ContainerManagerError inherit from RemoteProcedureCallError.
Browse files Browse the repository at this point in the history
So it can be re-raised and caught by name on the client-side.
  • Loading branch information
mbarnes authored and ashcrow committed Mar 2, 2017
1 parent 39c6e52 commit 095017a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
19 changes: 19 additions & 0 deletions src/commissaire/bus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ def __init__(self, message, model=None, data={}):
super().__init__(message, code, data)


class ContainerManagerError(RemoteProcedureCallError):
"""
Exception class for container manager errors.
"""
def __init__(self, message, data={}):
"""
Creates a ContainerManagerError instance.
:param message: Error message
:type message: str
:param data: Additional error data
:type data: dict
"""
code = C.JSONRPC_ERRORS['CONTAINER_MANAGER_ERROR']
super().__init__(message, code, data)


class BusMixin:
"""
Common methods for classes which utilize the Commissaire bus.
Expand Down Expand Up @@ -170,6 +187,8 @@ def request(self, routing_key, params={}, **kwargs):
data = error_data.get('data', {})
if code == C.JSONRPC_ERRORS['STORAGE_LOOKUP_ERROR']:
raise StorageLookupError(message, data=data)
elif code == C.JSONRPC_ERRORS['CONTAINER_MANAGER_ERROR']:
raise ContainerManagerError(message, data=data)
else:
raise RemoteProcedureCallError(message, code, data)

Expand Down
1 change: 1 addition & 0 deletions src/commissaire/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

# These map to Exception classes
'STORAGE_LOOKUP_ERROR': -20000,
'CONTAINER_MANAGER_ERROR': -20001,

# Custom codes
'NOT_FOUND': 404,
Expand Down
17 changes: 5 additions & 12 deletions src/commissaire/containermgr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
import logging


class ContainerManagerError(Exception):
"""
Base Exception class for ContainerManager related errors.
"""
pass


class ContainerManagerBase(object): # pragma: no cover
"""
Base class for all container managers.
Expand All @@ -48,7 +41,7 @@ def node_registered(self, address):
:param address: Address of the node
:type address: str
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
raise NotImplementedError(
'ContainerManagerBase().node_registered() must be overridden.')
Expand All @@ -59,7 +52,7 @@ def register_node(self, address):
:param address: Address of the node
:type address: str
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
raise NotImplementedError(
'ContainerManagerBase().register_node() must be overridden.')
Expand All @@ -70,7 +63,7 @@ def remove_node(self, address):
:param address: Address of the node
:type address: str
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
raise NotImplementedError(
'ContainerManagerBase().remove_node() must be overridden.')
Expand All @@ -79,7 +72,7 @@ def remove_all_nodes(self):
"""
Removes all nodes from the container manager.
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
raise NotImplementedError(
'ContainerManagerBase().remove_all_nodes() must be overridden.')
Expand All @@ -92,7 +85,7 @@ def get_node_status(self, address):
:type address: str
:returns: Status of the node according to the container manager
:rtype: dict
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
raise NotImplementedError(
'ContainerManagerBase().get_node_status() must be overridden.')
14 changes: 7 additions & 7 deletions src/commissaire/containermgr/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

from urllib.parse import urljoin, urlparse

from commissaire.containermgr import (
ContainerManagerBase, ContainerManagerError)
from commissaire.bus import ContainerManagerError
from commissaire.containermgr import ContainerManagerBase
from commissaire.util.config import ConfigurationError


Expand Down Expand Up @@ -209,7 +209,7 @@ def register_node(self, name):
:param name: The name of the node.
:type name: str
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
part = '/nodes'

Expand All @@ -236,7 +236,7 @@ def remove_node(self, name):
:param name: The name of the node.
:type name: str
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
part = '/nodes/{}'.format(name)

Expand All @@ -253,7 +253,7 @@ def remove_all_nodes(self):
"""
Removes all nodes from the Kubernetes Container Manager.
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
resp = self._delete('/nodes')
if resp.status_code != 200:
Expand All @@ -270,7 +270,7 @@ def node_registered(self, name):
:param name: The name of the node.
:type name: str
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
part = '/nodes/{0}'.format(name)
resp = self._get(part)
Expand All @@ -290,7 +290,7 @@ def get_node_status(self, name, raw=False):
:type raw: bool
:returns: The response back from kubernetes.
:rtype: dict
:raises: commissaire.containermgr.ContainerManagerError
:raises: commissaire.bus.ContainerManagerError
"""
part = '/nodes/{}'.format(name)
resp = self._get(part)
Expand Down
3 changes: 2 additions & 1 deletion test/test_containermgr_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

from . import TestCase, mock

from commissaire.containermgr import ContainerManagerError, kubernetes
from commissaire.bus import ContainerManagerError
from commissaire.containermgr import kubernetes
from commissaire.util.config import ConfigurationError


Expand Down

0 comments on commit 095017a

Please sign in to comment.