blob: dfe029163f86c0360389a8cc308a5c771809edb6 [file] [log] [blame]
Marc Kodererba6206d2013-10-11 08:04:10 +02001# Copyright 2013 Deutsche Telekom AG
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import shlex
17import subprocess
18
Doug Hellmann583ce2c2015-03-11 14:55:46 +000019from oslo_log import log as logging
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions
Matthew Treinishffad78a2016-04-16 14:39:52 -040021from tempest.tests import base
Marc Kodererba6206d2013-10-11 08:04:10 +020022
23LOG = logging.getLogger(__name__)
24
25
Matthew Treinishea42f112014-06-10 09:03:43 -040026class StressFrameworkTest(base.TestCase):
Ken'ichi Ohmichic864f592015-11-19 08:45:06 +000027 """Basic test for the stress test framework."""
Marc Kodererba6206d2013-10-11 08:04:10 +020028
29 def _cmd(self, cmd, param):
30 """Executes specified command."""
31 cmd = ' '.join([cmd, param])
32 LOG.info("running: '%s'" % cmd)
33 cmd_str = cmd
Matthew Treinish09487242015-05-10 12:43:58 -040034 cmd = shlex.split(cmd)
Marc Kodererba6206d2013-10-11 08:04:10 +020035 result = ''
36 result_err = ''
37 try:
38 stdout = subprocess.PIPE
39 stderr = subprocess.PIPE
40 proc = subprocess.Popen(
41 cmd, stdout=stdout, stderr=stderr)
42 result, result_err = proc.communicate()
43 if proc.returncode != 0:
44 LOG.debug('error of %s:\n%s' % (cmd_str, result_err))
Michael Hudson-Doyle884e2f32014-10-10 12:29:56 +130045 raise exceptions.CommandFailed(proc.returncode,
46 cmd,
47 result)
Marc Kodererba6206d2013-10-11 08:04:10 +020048 finally:
49 LOG.debug('output of %s:\n%s' % (cmd_str, result))
50 return proc.returncode
51
52 def test_help_function(self):
Matthew Treinish55e29b42014-05-07 01:04:17 -040053 result = self._cmd("python", "-m tempest.cmd.run_stress -h")
Marc Kodererba6206d2013-10-11 08:04:10 +020054 self.assertEqual(0, result)