Commit df02b63f authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] stats-httpd returns the 404 status code if the specified module

name or item name is incorrect

create a new exception StatsHttpdDataError which is an exception due
to the data specified to the stats daemon
parent f8a64959
......@@ -125,13 +125,14 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
# Couldn't find HOST
self.send_error(404)
return None
except StatsHttpdError as err:
except StatsHttpdDataError as err:
# Couldn't find neither specified module name nor
# specified item name
if str(err).startswith('Stats module: specified arguments are incorrect:'):
self.send_error(404)
else:
self.send_error(500)
self.send_error(404)
logger.error(STATHTTPD_SERVER_ERROR, err)
return None
except StatsHttpdError as err:
self.send_error(500)
logger.error(STATHTTPD_SERVER_ERROR, err)
return None
else:
......@@ -171,6 +172,12 @@ class StatsHttpdError(Exception):
main routine."""
pass
class StatsHttpdDataError(Exception):
"""Exception class for StatsHttpd class. The reason seems to be
due to the data. It is intended to be thrown from the the
StatsHttpd object to the HttpHandler object or main routine."""
pass
class StatsHttpd:
"""The main class of HTTP server of HTTP/XML interface for
statistics module. It handles HTTP requests, and command channel
......@@ -384,7 +391,7 @@ class StatsHttpd:
if rcode == 0:
return value
else:
raise StatsHttpdError("Stats module: %s" % str(value))
raise StatsHttpdDataError("Stats module: %s" % str(value))
def get_stats_spec(self, owner=None, name=None):
"""Requests statistics data to the Stats daemon and returns
......@@ -405,7 +412,7 @@ class StatsHttpd:
if rcode == 0:
return value
else:
raise StatsHttpdError("Stats module: %s" % str(value))
raise StatsHttpdDataError("Stats module: %s" % str(value))
except (isc.cc.session.SessionTimeout,
isc.cc.session.SessionError) as err:
raise StatsHttpdError("%s: %s" %
......
......@@ -483,26 +483,26 @@ class TestHttpHandler(unittest.TestCase):
# failure case(Stats replies an error)
self.stats.mccs.set_command_handler(
lambda cmd, args: \
isc.config.ccsession.create_answer(1, "I have an error.")
isc.config.ccsession.create_answer(1, "specified arguments are incorrect: I have an error.")
)
# request XML
self.client.putrequest('GET', stats_httpd.XML_URL_PATH)
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 500)
self.assertEqual(response.status, 404)
# request XSD
self.client.putrequest('GET', stats_httpd.XSD_URL_PATH)
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 500)
self.assertEqual(response.status, 404)
# request XSL
self.client.putrequest('GET', stats_httpd.XSL_URL_PATH)
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 500)
self.assertEqual(response.status, 404)
def test_do_HEAD(self):
self.client.putrequest('HEAD', stats_httpd.XML_URL_PATH)
......@@ -547,12 +547,18 @@ class TestHttpServer(unittest.TestCase):
class TestStatsHttpdError(unittest.TestCase):
"""Tests for StatsHttpdError exception"""
def test_raises(self):
def test_raises1(self):
try:
raise stats_httpd.StatsHttpdError('Nothing')
except stats_httpd.StatsHttpdError as err:
self.assertEqual(str(err), 'Nothing')
def test_raises2(self):
try:
raise stats_httpd.StatsHttpdDataError('Nothing')
except stats_httpd.StatsHttpdDataError as err:
self.assertEqual(str(err), 'Nothing')
class TestStatsHttpd(unittest.TestCase):
"""Tests for StatsHttpd class"""
......
Supports Markdown
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