Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 1 | # 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 | |
| 16 | import shlex |
| 17 | import subprocess |
| 18 | |
Matthew Treinish | 411130a | 2014-08-28 19:21:40 -0400 | [diff] [blame] | 19 | from tempest_lib import exceptions |
| 20 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 21 | from oslo_log import log as logging |
Matthew Treinish | ea42f11 | 2014-06-10 09:03:43 -0400 | [diff] [blame] | 22 | from tempest.tests import base |
Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 23 | |
| 24 | LOG = logging.getLogger(__name__) |
| 25 | |
| 26 | |
Matthew Treinish | ea42f11 | 2014-06-10 09:03:43 -0400 | [diff] [blame] | 27 | class StressFrameworkTest(base.TestCase): |
Ken'ichi Ohmichi | c864f59 | 2015-11-19 08:45:06 +0000 | [diff] [blame] | 28 | """Basic test for the stress test framework.""" |
Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 29 | |
| 30 | def _cmd(self, cmd, param): |
| 31 | """Executes specified command.""" |
| 32 | cmd = ' '.join([cmd, param]) |
| 33 | LOG.info("running: '%s'" % cmd) |
| 34 | cmd_str = cmd |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 35 | cmd = shlex.split(cmd) |
Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 36 | result = '' |
| 37 | result_err = '' |
| 38 | try: |
| 39 | stdout = subprocess.PIPE |
| 40 | stderr = subprocess.PIPE |
| 41 | proc = subprocess.Popen( |
| 42 | cmd, stdout=stdout, stderr=stderr) |
| 43 | result, result_err = proc.communicate() |
| 44 | if proc.returncode != 0: |
| 45 | LOG.debug('error of %s:\n%s' % (cmd_str, result_err)) |
Michael Hudson-Doyle | 884e2f3 | 2014-10-10 12:29:56 +1300 | [diff] [blame] | 46 | raise exceptions.CommandFailed(proc.returncode, |
| 47 | cmd, |
| 48 | result) |
Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 49 | finally: |
| 50 | LOG.debug('output of %s:\n%s' % (cmd_str, result)) |
| 51 | return proc.returncode |
| 52 | |
| 53 | def test_help_function(self): |
Matthew Treinish | 55e29b4 | 2014-05-07 01:04:17 -0400 | [diff] [blame] | 54 | result = self._cmd("python", "-m tempest.cmd.run_stress -h") |
Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 55 | self.assertEqual(0, result) |