Allow to store and read execution results in JSON format
Change-Id: I92a197dbe18bde44d2304e94aa034fb9a1c333ea
This commit is contained in:
parent
f73982d12f
commit
1e5c9da51b
@ -137,6 +137,13 @@
|
||||
# report is printed to stdout. (string value)
|
||||
#report = <None>
|
||||
|
||||
# File for output in JSON format, defaults to env[SHAKER_OUTPUT]. (string
|
||||
# value)
|
||||
#output = <None>
|
||||
|
||||
# File to read test results from, defaults to env[SHAKER_INPUT]. (string value)
|
||||
#input = <None>
|
||||
|
||||
#
|
||||
# From shaker.engine.config
|
||||
#
|
||||
|
15
scenarios/misc/static_agent.yaml
Normal file
15
scenarios/misc/static_agent.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
description:
|
||||
This scenario runs tests on pre-deployed static agents
|
||||
|
||||
deployment:
|
||||
agents:
|
||||
-
|
||||
id: the-agent
|
||||
mode: alone
|
||||
|
||||
execution:
|
||||
tests:
|
||||
-
|
||||
title: List all files
|
||||
class: shell
|
||||
method: ls -al
|
@ -74,7 +74,6 @@ OPENSTACK_OPTS = [
|
||||
SERVER_OPTS = [
|
||||
cfg.StrOpt('scenario',
|
||||
default=utils.env('SHAKER_SCENARIO'),
|
||||
required=True,
|
||||
help='Scenario file name, defaults to env[SHAKER_SCENARIO].'),
|
||||
|
||||
cfg.StrOpt('report-template',
|
||||
@ -85,6 +84,15 @@ SERVER_OPTS = [
|
||||
default=utils.env('SHAKER_REPORT'),
|
||||
help='Report file name, defaults to env[SHAKER_REPORT]. '
|
||||
'If no value provided the report is printed to stdout.'),
|
||||
|
||||
cfg.StrOpt('output',
|
||||
default=utils.env('SHAKER_OUTPUT'),
|
||||
help='File for output in JSON format, '
|
||||
'defaults to env[SHAKER_OUTPUT].'),
|
||||
cfg.StrOpt('input',
|
||||
default=utils.env('SHAKER_INPUT'),
|
||||
help='File to read test results from, '
|
||||
'defaults to env[SHAKER_INPUT].'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import logging as std_logging
|
||||
import os
|
||||
import time
|
||||
@ -207,6 +208,9 @@ def main():
|
||||
try:
|
||||
conf(project='shaker')
|
||||
utils.validate_required_opts(conf, opts)
|
||||
if not cfg.CONF.scenario and not cfg.CONF.input:
|
||||
raise cfg.RequiredOptError('One of "scenario" or "input" options '
|
||||
'must be set')
|
||||
except cfg.RequiredOptError as e:
|
||||
print('Error: %s' % e)
|
||||
conf.print_usage()
|
||||
@ -216,38 +220,55 @@ def main():
|
||||
LOG.info('Logging enabled')
|
||||
conf.log_opt_values(LOG, std_logging.DEBUG)
|
||||
|
||||
deployment = None
|
||||
try:
|
||||
report_data = None
|
||||
|
||||
if cfg.CONF.scenario:
|
||||
# run scenario
|
||||
scenario = read_scenario()
|
||||
deployment = deploy.Deployment(cfg.CONF.os_username,
|
||||
cfg.CONF.os_password,
|
||||
cfg.CONF.os_tenant_name,
|
||||
cfg.CONF.os_auth_url,
|
||||
cfg.CONF.os_region_name,
|
||||
cfg.CONF.server_endpoint,
|
||||
cfg.CONF.external_net,
|
||||
cfg.CONF.flavor_name,
|
||||
cfg.CONF.image_name)
|
||||
agents = deployment.deploy(scenario['deployment'],
|
||||
base_dir=os.path.dirname(cfg.CONF.scenario))
|
||||
|
||||
if not agents:
|
||||
LOG.info('No agents deployed. Terminating.')
|
||||
return
|
||||
deployment = None
|
||||
agents = {}
|
||||
result = []
|
||||
|
||||
LOG.debug('Agents: %s', agents)
|
||||
try:
|
||||
deployment = deploy.Deployment(cfg.CONF.os_username,
|
||||
cfg.CONF.os_password,
|
||||
cfg.CONF.os_tenant_name,
|
||||
cfg.CONF.os_auth_url,
|
||||
cfg.CONF.os_region_name,
|
||||
cfg.CONF.server_endpoint,
|
||||
cfg.CONF.external_net,
|
||||
cfg.CONF.flavor_name,
|
||||
cfg.CONF.image_name)
|
||||
|
||||
result = execute(scenario['execution'], agents)
|
||||
LOG.debug('Result: %s', result)
|
||||
agents = deployment.deploy(
|
||||
scenario['deployment'],
|
||||
base_dir=os.path.dirname(cfg.CONF.scenario))
|
||||
LOG.debug('Deployed agents: %s', agents)
|
||||
|
||||
report.generate_report(cfg.CONF.report_template,
|
||||
cfg.CONF.report,
|
||||
dict(scenario=yaml.dump(scenario),
|
||||
agents=agents.values(),
|
||||
result=result))
|
||||
finally:
|
||||
if deployment:
|
||||
deployment.cleanup()
|
||||
if not agents:
|
||||
LOG.warning('No agents deployed.')
|
||||
else:
|
||||
result = execute(scenario['execution'], agents)
|
||||
LOG.debug('Result: %s', result)
|
||||
except Exception as e:
|
||||
LOG.error('Error while executing scenario: %s', cfg.CONF.scenario)
|
||||
finally:
|
||||
if deployment:
|
||||
deployment.cleanup()
|
||||
|
||||
report_data = dict(scenario=yaml.dump(scenario),
|
||||
agents=agents.values(),
|
||||
result=result)
|
||||
if cfg.CONF.output:
|
||||
utils.write_file(json.dumps(report_data), cfg.CONF.output)
|
||||
|
||||
elif cfg.CONF.input:
|
||||
# read json results
|
||||
report_data = json.loads(utils.read_file(cfg.CONF.input))
|
||||
|
||||
report.generate_report(cfg.CONF.report_template, cfg.CONF.report,
|
||||
report_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -58,6 +58,20 @@ def read_file(file_name, base_dir=''):
|
||||
fd.close()
|
||||
|
||||
|
||||
def write_file(data, file_name, base_dir=''):
|
||||
full_path = os.path.normpath(os.path.join(base_dir, file_name))
|
||||
fd = None
|
||||
try:
|
||||
fd = open(full_path, 'w')
|
||||
return fd.write(data)
|
||||
except IOError as e:
|
||||
LOG.error('Error writing file: %s', e)
|
||||
raise
|
||||
finally:
|
||||
if fd:
|
||||
fd.close()
|
||||
|
||||
|
||||
def split_address(address):
|
||||
try:
|
||||
host, port = address.split(':')
|
||||
|
Loading…
x
Reference in New Issue
Block a user