Refactor executors build command lines
Change-Id: I968148ce232607801e628ee0b4c2810b9eb3d9af
This commit is contained in:
parent
7b873badcd
commit
a37b9ed228
@ -22,6 +22,19 @@ from shaker.openstack.common import log as logging
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandLine(object):
|
||||||
|
def __init__(self, command):
|
||||||
|
self.commands = [command]
|
||||||
|
|
||||||
|
def add(self, param_name, param_value=None):
|
||||||
|
self.commands.append('%s' % param_name)
|
||||||
|
if param_value:
|
||||||
|
self.commands.append(str(param_value))
|
||||||
|
|
||||||
|
def make(self):
|
||||||
|
return ' '.join(self.commands)
|
||||||
|
|
||||||
|
|
||||||
class BaseExecutor(object):
|
class BaseExecutor(object):
|
||||||
def __init__(self, test_definition, agent):
|
def __init__(self, test_definition, agent):
|
||||||
super(BaseExecutor, self).__init__()
|
super(BaseExecutor, self).__init__()
|
||||||
@ -47,11 +60,11 @@ class ShellExecutor(BaseExecutor):
|
|||||||
|
|
||||||
class NetperfExecutor(BaseExecutor):
|
class NetperfExecutor(BaseExecutor):
|
||||||
def get_command(self):
|
def get_command(self):
|
||||||
target = self.agent['slave']['ip']
|
cmd = CommandLine('netperf')
|
||||||
return ('netperf -H %(target)s -l %(time)s -t %(method)s' %
|
cmd.add('-H', self.agent['slave']['ip'])
|
||||||
dict(target=self.test_definition.get('target') or target,
|
cmd.add('-l', self.test_definition.get('time') or 60)
|
||||||
method=self.test_definition.get('method') or 'TCP_STREAM',
|
cmd.add('-t', self.test_definition.get('method') or 'TCP_STREAM')
|
||||||
time=self.test_definition.get('time') or 60))
|
return cmd.make()
|
||||||
|
|
||||||
|
|
||||||
class NetperfWrapperExecutor(BaseExecutor):
|
class NetperfWrapperExecutor(BaseExecutor):
|
||||||
@ -64,21 +77,22 @@ class NetperfWrapperExecutor(BaseExecutor):
|
|||||||
|
|
||||||
class IperfExecutor(BaseExecutor):
|
class IperfExecutor(BaseExecutor):
|
||||||
def get_command(self):
|
def get_command(self):
|
||||||
target = self.agent['slave']['ip']
|
cmd = CommandLine('sudo nice -n -20 iperf')
|
||||||
mss = self.test_definition.get('mss')
|
cmd.add('--client', self.agent['slave']['ip'])
|
||||||
interval = self.test_definition.get('interval')
|
cmd.add('--format', 'm')
|
||||||
return ('sudo nice -n -20 iperf --client %(target)s --format m'
|
cmd.add('--nodelay')
|
||||||
'%(mss)s --len %(bs)s --nodelay'
|
if self.test_definition.get('mss'):
|
||||||
'%(udp)s --time %(time)s --parallel %(threads)s'
|
cmd.add('--mss', self.test_definition.get('mss'))
|
||||||
'%(css)s %(interval)s' %
|
cmd.add('--len', self.test_definition.get('buffer_size') or '8k')
|
||||||
dict(target=self.test_definition.get('target') or target,
|
if self.test_definition.get('udp'):
|
||||||
mss=mss and ' --mss %s' % mss or '',
|
cmd.add('--udp')
|
||||||
bs=self.test_definition.get('buffer_size') or '8k',
|
cmd.add('--time', self.test_definition.get('time') or 60)
|
||||||
udp=self.test_definition.get('udp') and ' --udp' or '',
|
cmd.add('--parallel', self.test_definition.get('threads') or 1)
|
||||||
threads=self.test_definition.get('threads') or 1,
|
if self.test_definition.get('csv'):
|
||||||
time=self.test_definition.get('time') or 60,
|
cmd.add('--reportstyle', 'C')
|
||||||
css=self.test_definition.get('css') and ' -y C' or '',
|
if self.test_definition.get('interval'):
|
||||||
interval=interval and '--interval %s' % interval or ''))
|
cmd.add('--interval', self.test_definition.get('interval'))
|
||||||
|
return cmd.make()
|
||||||
|
|
||||||
|
|
||||||
def _calc_stats(array):
|
def _calc_stats(array):
|
||||||
@ -87,7 +101,7 @@ def _calc_stats(array):
|
|||||||
|
|
||||||
class IperfGraphExecutor(IperfExecutor):
|
class IperfGraphExecutor(IperfExecutor):
|
||||||
def get_command(self):
|
def get_command(self):
|
||||||
self.test_definition['css'] = True
|
self.test_definition['csv'] = True
|
||||||
self.test_definition['interval'] = '1'
|
self.test_definition['interval'] = '1'
|
||||||
return super(IperfGraphExecutor, self).get_command()
|
return super(IperfGraphExecutor, self).get_command()
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ resources:
|
|||||||
git clone git://git.openstack.org/stackforge/shaker && cd shaker && sudo pip install -r requirements.txt && sudo python setup.py develop
|
git clone git://git.openstack.org/stackforge/shaker && cd shaker && sudo pip install -r requirements.txt && sudo python setup.py develop
|
||||||
sudo sed -i '1i supersede interface-mtu 1458;' /etc/dhcp/dhclient.conf
|
sudo sed -i '1i supersede interface-mtu 1458;' /etc/dhcp/dhclient.conf
|
||||||
echo -e 'start on startup\ntask\nexec /usr/bin/screen -dmS sudo nice -n -20 /usr/bin/iperf -s' | sudo tee /etc/init/iperf-tcp.conf
|
echo -e 'start on startup\ntask\nexec /usr/bin/screen -dmS sudo nice -n -20 /usr/bin/iperf -s' | sudo tee /etc/init/iperf-tcp.conf
|
||||||
echo -e 'start on startup\ntask\nexec /usr/bin/screen -dmS sudo nice -n -20 /usr/bin/iperf -s --port 5002 --udp' | sudo tee /etc/init/iperf-udp.conf
|
echo -e 'start on startup\ntask\nexec /usr/bin/screen -dmS sudo nice -n -20 /usr/bin/iperf -s --udp' | sudo tee /etc/init/iperf-udp.conf
|
||||||
sudo shutdown -P -f now
|
sudo shutdown -P -f now
|
||||||
params:
|
params:
|
||||||
"$UNUSED": foo
|
"$UNUSED": foo
|
||||||
|
@ -27,9 +27,18 @@ class TestIperfGraphExecutor(testtools.TestCase):
|
|||||||
def test_get_command(self):
|
def test_get_command(self):
|
||||||
executor = executors.IperfGraphExecutor({}, AGENT)
|
executor = executors.IperfGraphExecutor({}, AGENT)
|
||||||
|
|
||||||
expected = ('sudo nice -n -20 iperf --client %s --format m '
|
expected = ('sudo nice -n -20 iperf --client %s --format m --nodelay '
|
||||||
'--len 8k --nodelay --time 60 --parallel 1 '
|
'--len 8k --time 60 --parallel 1 '
|
||||||
'-y C --interval 1') % IP
|
'--reportstyle C --interval 1') % IP
|
||||||
|
self.assertEqual(expected, executor.get_command())
|
||||||
|
|
||||||
|
def test_get_command_udp(self):
|
||||||
|
executor = executors.IperfGraphExecutor(
|
||||||
|
{'udp': True, 'time': 30}, AGENT)
|
||||||
|
|
||||||
|
expected = ('sudo nice -n -20 iperf --client %s --format m --nodelay '
|
||||||
|
'--len 8k --udp --time 30 --parallel 1 '
|
||||||
|
'--reportstyle C --interval 1') % IP
|
||||||
self.assertEqual(expected, executor.get_command())
|
self.assertEqual(expected, executor.get_command())
|
||||||
|
|
||||||
def test_process_reply(self):
|
def test_process_reply(self):
|
||||||
|
38
tests/test_netperf_executor.py
Normal file
38
tests/test_netperf_executor.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (c) 2015 Mirantis Inc.
|
||||||
|
#
|
||||||
|
# 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 shaker.engine import executors
|
||||||
|
|
||||||
|
|
||||||
|
IP = '10.0.0.10'
|
||||||
|
AGENT = {'slave': {'ip': IP}}
|
||||||
|
|
||||||
|
|
||||||
|
class TestNetperfExecutor(testtools.TestCase):
|
||||||
|
|
||||||
|
def test_get_command(self):
|
||||||
|
executor = executors.NetperfExecutor({}, AGENT)
|
||||||
|
|
||||||
|
expected = 'netperf -H %s -l 60 -t TCP_STREAM' % IP
|
||||||
|
self.assertEqual(expected, executor.get_command())
|
||||||
|
|
||||||
|
def test_get_command_options(self):
|
||||||
|
executor = executors.NetperfExecutor(
|
||||||
|
{'method': 'UDP_STREAM', 'time': 30}, AGENT)
|
||||||
|
|
||||||
|
expected = 'netperf -H %s -l 30 -t UDP_STREAM' % IP
|
||||||
|
self.assertEqual(expected, executor.get_command())
|
Loading…
x
Reference in New Issue
Block a user