Commit 93716b02 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[master] Merge branch 'trac1897'

parents d94641e5 cd2c2c8e
......@@ -43,8 +43,8 @@ isc.log.init("b10-stats-httpd", buffer=True)
logger = isc.log.Logger("stats-httpd")
# Some constants for debug levels.
DBG_STATHTTPD_INIT = logger.DBGLVL_START_SHUT
DBG_STATHTTPD_MESSAGING = logger.DBGLVL_COMMAND
DBG_STATSHTTPD_INIT = logger.DBGLVL_START_SHUT
DBG_STATSHTTPD_MESSAGING = logger.DBGLVL_COMMAND
# If B10_FROM_SOURCE is set in the environment, we use data files
# from a directory relative to that, otherwise we use the ones
......@@ -187,11 +187,11 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
# Couldn't find neither specified module name nor
# specified item name
self.send_error(404)
logger.error(STATHTTPD_SERVER_DATAERROR, err)
logger.error(STATSHTTPD_SERVER_DATAERROR, err)
return None
except Exception as err:
self.send_error(500)
logger.error(STATHTTPD_SERVER_ERROR, err)
logger.error(STATSHTTPD_SERVER_ERROR, err)
return None
else:
self.send_response(200)
......@@ -201,6 +201,14 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
self.end_headers()
return body
def log_message(self, format, *args):
"""overrides the parent method log_message()
to use the bind10 logging framework.
"""
logger.debug(DBG_STATSHTTPD_MESSAGING, STATSHTTPD_HTTPLOG,
self.address_string(),
format%args)
class HttpServerError(Exception):
"""Exception class for HttpServer class. It is intended to be
passed from the HttpServer object to the StatsHttpd object."""
......@@ -263,7 +271,7 @@ class StatsHttpd:
def open_mccs(self):
"""Opens a ModuleCCSession object"""
# create ModuleCCSession
logger.debug(DBG_STATHTTPD_INIT, STATHTTPD_STARTING_CC_SESSION)
logger.debug(DBG_STATSHTTPD_INIT, STATSHTTPD_STARTING_CC_SESSION)
self.mccs = isc.config.ModuleCCSession(
SPECFILE_LOCATION, self.config_handler, self.command_handler)
self.cc_session = self.mccs._session
......@@ -274,7 +282,7 @@ class StatsHttpd:
return
self.mccs.send_stopping()
logger.debug(DBG_STATHTTPD_INIT, STATHTTPD_CLOSING_CC_SESSION)
logger.debug(DBG_STATSHTTPD_INIT, STATSHTTPD_CLOSING_CC_SESSION)
self.mccs.close()
self.mccs = None
......@@ -317,7 +325,7 @@ class StatsHttpd:
server_address, HttpHandler,
self.xml_handler, self.xsd_handler, self.xsl_handler,
self.write_log)
logger.info(STATHTTPD_STARTED, server_address[0],
logger.info(STATSHTTPD_STARTED, server_address[0],
server_address[1])
return httpd
except (socket.gaierror, socket.error,
......@@ -333,7 +341,7 @@ class StatsHttpd:
"""Closes sockets for HTTP"""
while len(self.httpd)>0:
ht = self.httpd.pop()
logger.info(STATHTTPD_CLOSING, ht.server_address[0],
logger.info(STATSHTTPD_CLOSING, ht.server_address[0],
ht.server_address[1])
ht.server_close()
......@@ -369,7 +377,7 @@ class StatsHttpd:
def stop(self):
"""Stops the running StatsHttpd objects. Closes CC session and
HTTP handling sockets"""
logger.info(STATHTTPD_SHUTDOWN)
logger.info(STATSHTTPD_SHUTDOWN)
self.close_httpd()
self.close_mccs()
self.running = False
......@@ -387,7 +395,7 @@ class StatsHttpd:
def config_handler(self, new_config):
"""Config handler for the ModuleCCSession object. It resets
addresses and ports to listen HTTP requests on."""
logger.debug(DBG_STATHTTPD_MESSAGING, STATHTTPD_HANDLE_CONFIG,
logger.debug(DBG_STATSHTTPD_MESSAGING, STATSHTTPD_HANDLE_CONFIG,
new_config)
errors = []
if not self.mccs.get_module_spec().\
......@@ -405,7 +413,7 @@ class StatsHttpd:
try:
self.open_httpd()
except HttpServerError as err:
logger.error(STATHTTPD_SERVER_ERROR, err)
logger.error(STATSHTTPD_SERVER_ERROR, err)
# restore old config
self.load_config(old_config)
self.open_httpd()
......@@ -417,18 +425,18 @@ class StatsHttpd:
"""Command handler for the ModuleCCSesson object. It handles
"status" and "shutdown" commands."""
if command == "status":
logger.debug(DBG_STATHTTPD_MESSAGING,
STATHTTPD_RECEIVED_STATUS_COMMAND)
logger.debug(DBG_STATSHTTPD_MESSAGING,
STATSHTTPD_RECEIVED_STATUS_COMMAND)
return isc.config.ccsession.create_answer(
0, "Stats Httpd is up. (PID " + str(os.getpid()) + ")")
elif command == "shutdown":
logger.debug(DBG_STATHTTPD_MESSAGING,
STATHTTPD_RECEIVED_SHUTDOWN_COMMAND)
logger.debug(DBG_STATSHTTPD_MESSAGING,
STATSHTTPD_RECEIVED_SHUTDOWN_COMMAND)
self.running = False
return isc.config.ccsession.create_answer(0)
else:
logger.debug(DBG_STATHTTPD_MESSAGING,
STATHTTPD_RECEIVED_UNKNOWN_COMMAND, command)
logger.debug(DBG_STATSHTTPD_MESSAGING,
STATSHTTPD_RECEIVED_UNKNOWN_COMMAND, command)
return isc.config.ccsession.create_answer(
1, "Unknown command: " + str(command))
......@@ -613,13 +621,13 @@ if __name__ == "__main__":
stats_httpd = StatsHttpd()
stats_httpd.start()
except OptionValueError as ove:
logger.fatal(STATHTTPD_BAD_OPTION_VALUE, ove)
logger.fatal(STATSHTTPD_BAD_OPTION_VALUE, ove)
sys.exit(1)
except isc.cc.session.SessionError as se:
logger.fatal(STATHTTPD_CC_SESSION_ERROR, se)
logger.fatal(STATSHTTPD_CC_SESSION_ERROR, se)
sys.exit(1)
except HttpServerError as hse:
logger.fatal(STATHTTPD_START_SERVER_INIT_ERROR, hse)
logger.fatal(STATSHTTPD_START_SERVER_INIT_ERROR, hse)
sys.exit(1)
except KeyboardInterrupt as kie:
logger.info(STATHTTPD_STOPPED_BY_KEYBOARD)
logger.info(STATSHTTPD_STOPPED_BY_KEYBOARD)
......@@ -15,84 +15,90 @@
# No namespace declaration - these constants go in the global namespace
# of the stats_httpd_messages python module.
% STATHTTPD_BAD_OPTION_VALUE bad command line argument: %1
% STATSHTTPD_BAD_OPTION_VALUE bad command line argument: %1
The stats-httpd module was called with a bad command-line argument
and will not start.
% STATHTTPD_CC_SESSION_ERROR error connecting to message bus: %1
% STATSHTTPD_CC_SESSION_ERROR error connecting to message bus: %1
The stats-httpd module was unable to connect to the BIND 10 command
and control bus. A likely problem is that the message bus daemon
(b10-msgq) is not running. The stats-httpd module will now shut down.
% STATHTTPD_CLOSING closing %1#%2
% STATSHTTPD_CLOSING closing %1#%2
The stats-httpd daemon will stop listening for requests on the given
address and port number.
% STATHTTPD_CLOSING_CC_SESSION stopping cc session
% STATSHTTPD_CLOSING_CC_SESSION stopping cc session
Debug message indicating that the stats-httpd module is disconnecting
from the command and control bus.
% STATHTTPD_HANDLE_CONFIG reading configuration: %1
% STATSHTTPD_HANDLE_CONFIG reading configuration: %1
The stats-httpd daemon has received new configuration data and will now
process it. The (changed) data is printed.
% STATHTTPD_RECEIVED_SHUTDOWN_COMMAND shutdown command received
% STATSHTTPD_RECEIVED_SHUTDOWN_COMMAND shutdown command received
A shutdown command was sent to the stats-httpd module, and it will
now shut down.
% STATHTTPD_RECEIVED_STATUS_COMMAND received command to return status
% STATSHTTPD_RECEIVED_STATUS_COMMAND received command to return status
A status command was sent to the stats-httpd module, and it will
respond with 'Stats Httpd is up.' and its PID.
% STATHTTPD_RECEIVED_UNKNOWN_COMMAND received unknown command: %1
% STATSHTTPD_RECEIVED_UNKNOWN_COMMAND received unknown command: %1
An unknown command has been sent to the stats-httpd module. The
stats-httpd module will respond with an error, and the command will
be ignored.
% STATHTTPD_SERVER_DATAERROR HTTP server data error: %1
% STATSHTTPD_SERVER_DATAERROR HTTP server data error: %1
An internal error occurred while handling an HTTP request. An HTTP 404
response will be sent back, and the specific error is printed. This
is an error condition that likely points the specified data
corresponding to the requested URI is incorrect.
% STATHTTPD_SERVER_ERROR HTTP server error: %1
% STATSHTTPD_SERVER_ERROR HTTP server error: %1
An internal error occurred while handling an HTTP request. An HTTP 500
response will be sent back, and the specific error is printed. This
is an error condition that likely points to a module that is not
responding correctly to statistic requests.
% STATHTTPD_SERVER_INIT_ERROR HTTP server initialization error: %1
% STATSHTTPD_SERVER_INIT_ERROR HTTP server initialization error: %1
There was a problem initializing the HTTP server in the stats-httpd
module upon receiving its configuration data. The most likely cause
is a port binding problem or a bad configuration value. The specific
error is printed in the message. The new configuration is ignored,
and an error is sent back.
% STATHTTPD_SHUTDOWN shutting down
% STATSHTTPD_SHUTDOWN shutting down
The stats-httpd daemon is shutting down.
% STATHTTPD_STARTED listening on %1#%2
% STATSHTTPD_STARTED listening on %1#%2
The stats-httpd daemon will now start listening for requests on the
given address and port number.
% STATHTTPD_STARTING_CC_SESSION starting cc session
% STATSHTTPD_STARTING_CC_SESSION starting cc session
Debug message indicating that the stats-httpd module is connecting to
the command and control bus.
% STATHTTPD_START_SERVER_INIT_ERROR HTTP server initialization error: %1
% STATSHTTPD_START_SERVER_INIT_ERROR HTTP server initialization error: %1
There was a problem initializing the HTTP server in the stats-httpd
module upon startup. The most likely cause is that it was not able
to bind to the listening port. The specific error is printed, and the
module will shut down.
% STATHTTPD_STOPPED_BY_KEYBOARD keyboard interrupt, shutting down
% STATSHTTPD_STOPPED_BY_KEYBOARD keyboard interrupt, shutting down
There was a keyboard interrupt signal to stop the stats-httpd
daemon. The daemon will now shut down.
% STATHTTPD_UNKNOWN_CONFIG_ITEM unknown configuration item: %1
% STATSHTTPD_UNKNOWN_CONFIG_ITEM unknown configuration item: %1
The stats-httpd daemon received a configuration update from the
configuration manager. However, one of the items in the
configuration is unknown. The new configuration is ignored, and an
error is sent back. As possible cause is that there was an upgrade
problem, and the stats-httpd version is out of sync with the rest of
the system.
% STATSHTTPD_HTTPLOG %1 %2
Debug HTTP log message. These are the messages logged by the http server
instance. For most logs, the message shows HTTP client and query
information like HTTP method, URI, and status code, but the http server
can also log other information, such as extended status reports.
......@@ -17,7 +17,7 @@ Feature: control with bindctl
And wait for bind10 stderr message XFRIN_STARTED
And wait for bind10 stderr message XFROUT_STARTED
And wait for bind10 stderr message STATS_STARTING
And wait for bind10 stderr message STATHTTPD_STARTED
And wait for bind10 stderr message STATSHTTPD_STARTED
Then remove bind10 configuration Boss/components/NOSUCHMODULE
last bindctl output should contain Error
......
Feature: b10-stats-httpd module
Tests the stats httpd module
Scenario: Check that the module logs and responds to requests
Given I have bind10 running with configuration bindctl_commands.config
And wait for bind10 stderr message STATSHTTPD_STARTED
When I request the URL http://127.0.0.1:47811/
# Should result in redirect, so two query logs
And wait for new bind10 stderr message "GET / HTTP/1.0" 302 -
And wait for new bind10 stderr message "GET /bind10/statistics/xml/ HTTP/1.0" 200 -
The last http response status code should be 200
When I request the URL http://127.0.0.1:47811/no_such_url
And wait for new bind10 stderr message "GET /no_such_url HTTP/1.0" 404 -
The last http response status code should be 404
# Copyright (C) 2013 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from lettuce import *
import urllib
# Basic request
@step('request the URL (.*)')
def request_url(step, url):
"""
Performs one basic HTTP GET request. The resulting HTTPResponse object
will we placed in world.last_http_response
Parameters:
url: the full URL to query
"""
world.last_http_response = urllib.urlopen(url)
@step('last http response status code should be ([0-9]+)')
def check_last_response_code(step, code):
"""
Checks whether the last call to request_url resulted in a response
with the given (numeric) status code
Fails if it does not, or if there never was a complete request_url
operation
"""
assert world.last_http_response != None, "No HTTP request made yet"
assert int(code) == world.last_http_response.getcode(),\
code + " != " +\
str(world.last_http_response.getcode())
......@@ -30,7 +30,7 @@ def stop_a_named_process(step, process_name):
"""
world.processes.stop_process(process_name)
@step('wait (?:(\d+) times )?for (new )?(\w+) stderr message (\w+)(?: not (\w+))?')
@step('wait (?:(\d+) times )?for (new )?(\w+) stderr message (.+)(?: not (.+))?')
def wait_for_stderr_message(step, times, new, process_name, message, not_message):
"""
Block until the given message is printed to the given process's stderr
......
# Copyright (C) 2011 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
......@@ -380,6 +381,9 @@ def initialize(scenario):
# Convenience variable to access the last query result from querying.py
world.last_query_result = None
# Convenience variable to access the last HTTP response from http.py
world.last_http_response = None
# For slightly better errors, initialize a process_pids for the relevant
# steps
world.process_pids = None
......
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