Rest API Enhancements

Rest API Enhancements:
1. Add the public folder for holding static files (HTML+JS);
2. Add support for dumping logs with offset;
3. Add support for dumping the final report;

Others:
1. Fix the issue for not dumping complete console logs;
2. Remove .html from the gitignore list

Change-Id: I8a4c0b35c35a818b67d445bcb913d1abfc683301
This commit is contained in:
Yichen Wang 2015-09-03 13:47:24 -07:00
parent 0db7bc9d0e
commit 315f94bdc9
7 changed files with 59 additions and 18 deletions

1
.gitignore vendored
View File

@ -57,7 +57,6 @@ ChangeLog
# KloudBuster # KloudBuster
kb*.log kb*.log
*.json *.json
*.html
*.qcow2 *.qcow2
scale/dib/kloudbuster.d/ scale/dib/kloudbuster.d/
.vagrant/ .vagrant/

View File

@ -66,7 +66,7 @@ class KBController(object):
return response.text return response.text
@expose(generic=True) @expose(generic=True)
def log(self, *args): def log(self, *args, **kwargs):
if len(args): if len(args):
session_id = args[0] session_id = args[0]
else: else:
@ -74,9 +74,18 @@ class KBController(object):
response.text = u"Please specify the session_id." response.text = u"Please specify the session_id."
return response.text return response.text
offset = 0
if 'offset' in kwargs:
try:
offset = int(kwargs['offset'])
except ValueError:
response.status = 400
response.text = u"Parameter 'offset' is invalid."
return response.text
if KBSessionManager.has(session_id): if KBSessionManager.has(session_id):
kb_session = KBSessionManager.get(session_id) kb_session = KBSessionManager.get(session_id)
plog = kb_session.kloudbuster.dump_logs(offset=0)\ plog = kb_session.kloudbuster.dump_logs(offset=offset)\
if kb_session.kloudbuster else "" if kb_session.kloudbuster else ""
return json.dumps(plog) return json.dumps(plog)
else: else:
@ -85,7 +94,7 @@ class KBController(object):
return response.text return response.text
@expose(generic=True) @expose(generic=True)
def report(self, *args): def report(self, *args, **kwargs):
if len(args): if len(args):
session_id = args[0] session_id = args[0]
else: else:
@ -93,10 +102,17 @@ class KBController(object):
response.text = u"Please specify the session_id." response.text = u"Please specify the session_id."
return response.text return response.text
final = False
if 'final' in kwargs:
final = True if kwargs['final'].lower() == 'true' else False
preport = None
if KBSessionManager.has(session_id): if KBSessionManager.has(session_id):
kb_session = KBSessionManager.get(session_id) kb_session = KBSessionManager.get(session_id)
preport = kb_session.kloudbuster.kb_runner.report\ if kb_session.kloudbuster and kb_session.kloudbuster.kb_runner:
if kb_session.kloudbuster and kb_session.kloudbuster.kb_runner else "" preport = kb_session.kloudbuster.final_result\
if final else kb_session.kloudbuster.kb_runner.report
return json.dumps(preport) return json.dumps(preport)
else: else:
response.status = 404 response.status = 404

View File

@ -169,6 +169,11 @@ paths:
in: path in: path
description: The session to be queried description: The session to be queried
required: true required: true
- name: offset
type: int
in: query
description: The offset of the log file to read
required: false
tags: tags:
- kloudbuster - kloudbuster
responses: responses:
@ -177,14 +182,16 @@ paths:
schema: schema:
type: string type: string
description: The console log of the given session description: The console log of the given session
400:
description: Parameter is missing or invalid
404: 404:
description: The session_id is not found or invalid description: The session_id is not found or invalid
/kloudbuster/report/{session_id}: /kloudbuster/report/{session_id}:
get: get:
description: | description: |
Get KloudBuster periodical report for a given session. Only Get the latest KloudBuster periodical report for a given session.
last report will be returned. Set final to true to retrieve the final report.
parameters: parameters:
- name: session_id - name: session_id
type: string type: string
@ -192,6 +199,11 @@ paths:
in: path in: path
description: The session to be queried description: The session to be queried
required: true required: true
- name: final
type: boolean
in: query
description: Set to true to retrieve the final report
required: false
tags: tags:
- kloudbuster - kloudbuster
responses: responses:

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Test</p>
</body>
</html>

View File

@ -21,7 +21,7 @@ keystone_admin_role: "admin"
# Cleanup all kloudbuster resources upon exit # Cleanup all kloudbuster resources upon exit
# If set to False, resources created will not be deleted on exit and the user # If set to False, resources created will not be deleted on exit and the user
# will have to execute the cleanup script later to remove all these resources # will have to execute the cleanup script later to remove all these resources
cleanup_resources: True cleanup_resources: True
# VM creation concurrency # VM creation concurrency
@ -84,7 +84,7 @@ server:
# Availability zone to use for servers in the server cloud # Availability zone to use for servers in the server cloud
# Leave empty if you prefer to have the Nova scheduler place the server VMs # Leave empty if you prefer to have the Nova scheduler place the server VMs
# If you want to pick a particular AZ, put that AZ name (e.g. nova) # If you want to pick a particular AZ, put that AZ name (e.g. nova)
# If you want a paticular compute host, put the AZ and compute host names # If you want a paticular compute host, put the AZ and compute host names
# separated by ':' (e.g. nova:tme100) # separated by ':' (e.g. nova:tme100)
# Note that this is ignored/overriden if you specify a topology file (-t) # Note that this is ignored/overriden if you specify a topology file (-t)
availability_zone: availability_zone:
@ -119,7 +119,7 @@ client:
# HTTP tool specific configs (per VM) # HTTP tool specific configs (per VM)
# Every HTTP server VM is paired to 1 HTTP traffic generator VM # Every HTTP server VM is paired to 1 HTTP traffic generator VM
# KloudBuster will take care of setting up the proper static routes # KloudBuster will take care of setting up the proper static routes
# to allow connectivity between all pairs of VMs. # to allow connectivity between all pairs of VMs.
# For example, if 1000 HTTP servers are configured, KloudBuster will # For example, if 1000 HTTP servers are configured, KloudBuster will
# instantiate 1000 HTTP traffic generators and match them 1:1, for a total # instantiate 1000 HTTP traffic generators and match them 1:1, for a total

View File

@ -3,15 +3,17 @@
# #
# A typical use of this topology file is to shape traffic in order to maximize # A typical use of this topology file is to shape traffic in order to maximize
# inter-rack L3 traffic. # inter-rack L3 traffic.
#
# With 2 racks, simply place each rack node name in each group. # With 2 racks, simply place each rack node name in each group.
# With more than 2 racks, separate the racks in 2 groups. # With more than 2 racks, separate the racks in 2 groups.
# #
# When used, the topology file will override any availability zone settings in the # Note
# confguration file. # ====
# #
# 1. When used, the topology file will override any availability zone
# settings in the confguration file.
# The compute host name must be exactly the same as shown from NOVA: #
# 2. The compute host name must be exactly the same as shown from NOVA:
# i.e. "nova hypervisor-list" # i.e. "nova hypervisor-list"
# Grouping for placing all the server side VMs # Grouping for placing all the server side VMs

View File

@ -47,12 +47,15 @@ def setup(product_name, logfile=None):
handlers.ColorHandler.LEVEL_COLORS[logging.KBDEBUG] = dbg_color handlers.ColorHandler.LEVEL_COLORS[logging.KBDEBUG] = dbg_color
oslogging.setup(CONF, product_name) oslogging.setup(CONF, product_name)
# Adding the FileHandler to all known loggers inside KloudBuster
if logfile: if logfile:
if os.path.exists(logfile): if os.path.exists(logfile):
os.remove(logfile) os.remove(logfile)
CONF.log_file = logfile CONF.log_file = logfile
hdlr = logging.FileHandler(logfile) hdlr = logging.FileHandler(logfile)
oslogging.getLogger(product_name).logger.addHandler(hdlr) for name in oslogging._loggers:
if name:
oslogging.getLogger(name).logger.addHandler(hdlr)
if CONF.kb_debug: if CONF.kb_debug:
oslogging.getLogger( oslogging.getLogger(