From a37b9ed22842dd00df080c3477ab59ba02f1b2df Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Mon, 2 Mar 2015 18:27:36 +0300 Subject: [PATCH] Refactor executors build command lines Change-Id: I968148ce232607801e628ee0b4c2810b9eb3d9af --- shaker/engine/executors.py | 56 +++++++++++++++++++----------- shaker/engine/installer.yaml | 2 +- tests/test_iperf_graph_executor.py | 15 ++++++-- tests/test_netperf_executor.py | 38 ++++++++++++++++++++ 4 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 tests/test_netperf_executor.py diff --git a/shaker/engine/executors.py b/shaker/engine/executors.py index 1ab6b86..1c973ad 100644 --- a/shaker/engine/executors.py +++ b/shaker/engine/executors.py @@ -22,6 +22,19 @@ from shaker.openstack.common import log as logging 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): def __init__(self, test_definition, agent): super(BaseExecutor, self).__init__() @@ -47,11 +60,11 @@ class ShellExecutor(BaseExecutor): class NetperfExecutor(BaseExecutor): def get_command(self): - target = self.agent['slave']['ip'] - return ('netperf -H %(target)s -l %(time)s -t %(method)s' % - dict(target=self.test_definition.get('target') or target, - method=self.test_definition.get('method') or 'TCP_STREAM', - time=self.test_definition.get('time') or 60)) + cmd = CommandLine('netperf') + cmd.add('-H', self.agent['slave']['ip']) + cmd.add('-l', self.test_definition.get('time') or 60) + cmd.add('-t', self.test_definition.get('method') or 'TCP_STREAM') + return cmd.make() class NetperfWrapperExecutor(BaseExecutor): @@ -64,21 +77,22 @@ class NetperfWrapperExecutor(BaseExecutor): class IperfExecutor(BaseExecutor): def get_command(self): - target = self.agent['slave']['ip'] - mss = self.test_definition.get('mss') - interval = self.test_definition.get('interval') - return ('sudo nice -n -20 iperf --client %(target)s --format m' - '%(mss)s --len %(bs)s --nodelay' - '%(udp)s --time %(time)s --parallel %(threads)s' - '%(css)s %(interval)s' % - dict(target=self.test_definition.get('target') or target, - mss=mss and ' --mss %s' % mss or '', - bs=self.test_definition.get('buffer_size') or '8k', - udp=self.test_definition.get('udp') and ' --udp' or '', - threads=self.test_definition.get('threads') or 1, - time=self.test_definition.get('time') or 60, - css=self.test_definition.get('css') and ' -y C' or '', - interval=interval and '--interval %s' % interval or '')) + cmd = CommandLine('sudo nice -n -20 iperf') + cmd.add('--client', self.agent['slave']['ip']) + cmd.add('--format', 'm') + cmd.add('--nodelay') + if self.test_definition.get('mss'): + cmd.add('--mss', self.test_definition.get('mss')) + cmd.add('--len', self.test_definition.get('buffer_size') or '8k') + if self.test_definition.get('udp'): + cmd.add('--udp') + cmd.add('--time', self.test_definition.get('time') or 60) + cmd.add('--parallel', self.test_definition.get('threads') or 1) + if self.test_definition.get('csv'): + cmd.add('--reportstyle', 'C') + if self.test_definition.get('interval'): + cmd.add('--interval', self.test_definition.get('interval')) + return cmd.make() def _calc_stats(array): @@ -87,7 +101,7 @@ def _calc_stats(array): class IperfGraphExecutor(IperfExecutor): def get_command(self): - self.test_definition['css'] = True + self.test_definition['csv'] = True self.test_definition['interval'] = '1' return super(IperfGraphExecutor, self).get_command() diff --git a/shaker/engine/installer.yaml b/shaker/engine/installer.yaml index 0b4c056..a7e33bc 100644 --- a/shaker/engine/installer.yaml +++ b/shaker/engine/installer.yaml @@ -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 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 --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 params: "$UNUSED": foo diff --git a/tests/test_iperf_graph_executor.py b/tests/test_iperf_graph_executor.py index e7c80ba..0a632ca 100644 --- a/tests/test_iperf_graph_executor.py +++ b/tests/test_iperf_graph_executor.py @@ -27,9 +27,18 @@ class TestIperfGraphExecutor(testtools.TestCase): def test_get_command(self): executor = executors.IperfGraphExecutor({}, AGENT) - expected = ('sudo nice -n -20 iperf --client %s --format m ' - '--len 8k --nodelay --time 60 --parallel 1 ' - '-y C --interval 1') % IP + expected = ('sudo nice -n -20 iperf --client %s --format m --nodelay ' + '--len 8k --time 60 --parallel 1 ' + '--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()) def test_process_reply(self): diff --git a/tests/test_netperf_executor.py b/tests/test_netperf_executor.py new file mode 100644 index 0000000..6f2f104 --- /dev/null +++ b/tests/test_netperf_executor.py @@ -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())