Add OMSimulator nodule
This commit is contained in:
parent
6c3a43e8d0
commit
4ab6709723
|
@ -95,6 +95,9 @@ def _make_dir(name):
|
|||
|
||||
def generate_report(scenario, base_dir, mongo_url, db_name, doc_folder,
|
||||
tag=None):
|
||||
if 'report' not in scenario:
|
||||
return # nothing to do
|
||||
|
||||
LOG.info('Generate report')
|
||||
|
||||
doc_folder = doc_folder or tempfile.mkdtemp(prefix='performa')
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
ATOP_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.atop')
|
||||
UNIQUE_NAME = 'performa_omsimulator'
|
||||
DIR = '/tmp/performa/oslo.messaging/tools/'
|
||||
|
||||
PATTERNS = [
|
||||
r'(?P<msg_sent>\d+) messages were sent for (?P<duration>\d+) sec',
|
||||
r'(?P<bytes_sent>\d+) bytes were sent for',
|
||||
]
|
||||
TRANSFORM_FIELDS = {
|
||||
'msg_sent': int,
|
||||
'bytes_sent': int,
|
||||
'duration': int,
|
||||
}
|
||||
|
||||
|
||||
def parse_output(raw):
|
||||
result = {}
|
||||
|
||||
for pattern in PATTERNS:
|
||||
for parsed in re.finditer(pattern, raw):
|
||||
result.update(parsed.groupdict())
|
||||
|
||||
for k in result.keys():
|
||||
if k in TRANSFORM_FIELDS:
|
||||
result[k] = TRANSFORM_FIELDS[k](result[k])
|
||||
|
||||
result['msg_sent_bandwidth'] = (result.get('msg_sent', 0) /
|
||||
result.get('duration', 1))
|
||||
result['bytes_sent_bandwidth'] = (result.get('bytes_sent', 0) /
|
||||
result.get('duration', 1))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def chdir(module):
|
||||
try:
|
||||
os.chdir(DIR)
|
||||
except Exception as e:
|
||||
module.fail_json(msg='Failed to change dir to %s: %s' % (DIR, e))
|
||||
|
||||
|
||||
def start_daemon(module, cmd):
|
||||
cmd = ('daemon -n %(name)s -D %(dir)s -- %(cmd)s' %
|
||||
dict(name=UNIQUE_NAME, dir=DIR, cmd=cmd))
|
||||
|
||||
rc, stdout, stderr = module.run_command(cmd)
|
||||
result = dict(changed=True, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
|
||||
|
||||
if rc:
|
||||
module.fail_json(msg='Failed to start OMSimulator', **result)
|
||||
|
||||
|
||||
def run(module):
|
||||
params = module.params
|
||||
|
||||
if params['mode'] == 'notify':
|
||||
server_tool = 'notify-server'
|
||||
client_tool = 'notify-client'
|
||||
else:
|
||||
server_tool = 'rpc-server'
|
||||
client_tool = 'rpc-client'
|
||||
|
||||
params['server_tool'] = server_tool
|
||||
params['client_tool'] = client_tool
|
||||
|
||||
server = ('python simulator.py '
|
||||
'--url %(url)s '
|
||||
'%(server_tool)s '
|
||||
'--show-stats true') % params
|
||||
client = ('python simulator.py '
|
||||
'--url=%(url)s '
|
||||
'-l %(duration)s '
|
||||
'%(client_tool)s '
|
||||
'-p %(threads)s ') % params
|
||||
|
||||
if params['mode'] == 'cast':
|
||||
client += '--is-cast True '
|
||||
|
||||
if params['mode'] == 'fanout':
|
||||
client += '--is-fanout True '
|
||||
|
||||
start_daemon(module, server)
|
||||
|
||||
start = int(time.time())
|
||||
rc, stdout, stderr = module.run_command(client)
|
||||
end = int(time.time())
|
||||
|
||||
if rc:
|
||||
module.fail_json(msg='Failed to run omsimulator client', stderr=stderr)
|
||||
|
||||
try:
|
||||
parsed = parse_output(stdout)
|
||||
parsed['start'] = start
|
||||
parsed['end'] = end
|
||||
|
||||
result = dict(records=[parsed])
|
||||
module.exit_json(**result)
|
||||
except Exception as e:
|
||||
msg = 'Failed to start omsimulator client %s' % e
|
||||
module.fail_json(msg=msg, rc=rc, stderr=stderr, stdout=stdout)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
mode=dict(required=True,
|
||||
choices=['call', 'cast', 'fanout', 'notify']),
|
||||
url=dict(required=True),
|
||||
threads=dict(type='int', default=10),
|
||||
duration=dict(type='int', default=10),
|
||||
))
|
||||
|
||||
chdir(module)
|
||||
run(module)
|
||||
|
||||
|
||||
from ansible.module_utils.basic import * # noqa
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,32 @@
|
|||
Sysbench Report
|
||||
---------------
|
||||
|
||||
This is the report of execution test plan
|
||||
:ref:`mq_test_plan` with `Sysbench`_ tool.
|
||||
|
||||
Results
|
||||
^^^^^^^
|
||||
|
||||
Chart and table:
|
||||
|
||||
{{'''
|
||||
title: Messages per second
|
||||
axes:
|
||||
x: threads
|
||||
y: messages per sec
|
||||
chart: line
|
||||
pipeline:
|
||||
- { $match: { task: omsimulator, status: OK }}
|
||||
- { $group: { _id: { threads: "$threads" },
|
||||
msg_sent_per_sec: { $avg: { $divide: ["$msg_sent", "$duration"] }}
|
||||
}}
|
||||
- { $project: { x: "$_id.threads",
|
||||
y: "$msg_sent_per_sec"
|
||||
}}
|
||||
- { $sort: { x: 1 }}
|
||||
''' | chart
|
||||
}}
|
||||
|
||||
.. references:
|
||||
|
||||
.. _Sysbench: https://github.com/akopytov/sysbench
|
|
@ -0,0 +1,40 @@
|
|||
title: OMSimulator
|
||||
|
||||
description:
|
||||
This scenario uses oslo.messaging simulator tool to execute MQ test plan.
|
||||
|
||||
setup:
|
||||
-
|
||||
hosts: $target
|
||||
tasks:
|
||||
- name: installing omsimulator
|
||||
git: repo=git://git.openstack.org/openstack/oslo.messaging
|
||||
dest=/tmp/performa/oslo.messaging
|
||||
- apt: name=atop
|
||||
become: yes
|
||||
- apt: name=daemon
|
||||
become: yes
|
||||
-
|
||||
hosts: $target
|
||||
tasks:
|
||||
- atop: command=start
|
||||
|
||||
execution:
|
||||
-
|
||||
hosts: $target
|
||||
matrix:
|
||||
threads: [ 1, 2, 5, 10, 25, 50, 100 ]
|
||||
tasks:
|
||||
- omsimulator:
|
||||
mode: call
|
||||
duration: 10
|
||||
url: "rabbit://stackrabbit:swordfish@localhost:5672/"
|
||||
-
|
||||
hosts: $target
|
||||
tasks:
|
||||
- atop:
|
||||
command: stop
|
||||
labels: [ CPU, PRC, PRM ]
|
||||
|
||||
report:
|
||||
template: omsimulator.rst
|
|
@ -0,0 +1,5 @@
|
|||
2016-02-29 10:33:51,044 INFO root Preparing 1 messages
|
||||
2016-02-29 10:33:51,046 INFO root Messages has been prepared
|
||||
2016-02-29 10:34:01,062 INFO root 5313 messages were sent for 10 seconds. Bandwidth was 530 msg/sec
|
||||
2016-02-29 10:34:01,062 INFO root 14897652 bytes were sent for 10 seconds. Bandwidth is 1487420 b/s
|
||||
2016-02-29 10:34:01,062 INFO root calls finished, wait 0 seconds
|
|
@ -0,0 +1,31 @@
|
|||
# Copyright (c) 2016 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import testtools
|
||||
|
||||
from performa.modules import omsimulator
|
||||
|
||||
|
||||
def _read_sample():
|
||||
with open('performa/tests/omsimulator_sample.txt') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
class TestOMSimulator(testtools.TestCase):
|
||||
def test_parse_client_call(self):
|
||||
expected = dict(msg_sent=5313, bytes_sent=14897652, duration=10,
|
||||
msg_sent_bandwidth=531, bytes_sent_bandwidth=1489765)
|
||||
|
||||
self.assertEqual(expected, omsimulator.parse_output(_read_sample()))
|
Loading…
Reference in New Issue