Add better distinction of error cases
Add a new NotFoundError exception for use internally, so we can track
specific failure cases.
Also add a new Error class as a central place to store our error
numbers consistently.
In the API protocol, add a "NOTFOUND" error string alongside "ERROR"
to help the admin interface and other callers distinguish error cases
better.
In the admin interface, actually return distinct non-zero errors in
failure cases. Previously, almost all failures would have returned
suceesfully to the calling shell.
Change-Id: Ie382b737a80b7cd41c551e3a4a2a7e0827260bdc
diff --git a/vland.py b/vland.py
index 0822af6..8c87d35 100755
--- a/vland.py
+++ b/vland.py
@@ -30,7 +30,7 @@
from config.config import VlanConfig
from db.db import VlanDB
from ipc.ipc import VlanIpc
-from errors import InputError, SocketError
+from errors import InputError, NotFoundError, SocketError
from util import VlanUtil
from visualisation.visualisation import Visualisation
@@ -148,6 +148,10 @@
print e
response['response'] = 'ERROR'
response['error'] = e.__str__()
+ except NotFoundError as e:
+ print e
+ response['response'] = 'NOTFOUND'
+ response['error'] = e.__str__()
# Next - simple queries about daemon state only. Should be safe!
if json_data['type'] == 'daemon_query':
@@ -159,6 +163,10 @@
print e
response['response'] = 'ERROR'
response['error'] = e.__str__()
+ except NotFoundError as e:
+ print e
+ response['response'] = 'NOTFOUND'
+ response['error'] = e.__str__()
# Next, calls that manipulate objects in the database only
# (switches and ports). These are safe and don't need actual
@@ -175,6 +183,10 @@
print e
response['response'] = 'ERROR'
response['error'] = e.__str__()
+ except NotFoundError as e:
+ print e
+ response['response'] = 'NOTFOUND'
+ response['error'] = e.__str__()
# Next, calls that may manipulate switch state *as well* as state
# in the database - changes to VLAN setup.
@@ -190,6 +202,10 @@
print e
response['response'] = 'ERROR'
response['error'] = e.__str__()
+ except NotFoundError as e:
+ print e
+ response['response'] = 'NOTFOUND'
+ response['error'] = e.__str__()
# Finally, IPC interface for more complex API calls.
# NOT IMPLEMENTED YET