Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 1 | # Copyright 2015 Hewlett-Packard Development Company, L.P. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import argparse |
Divyansh Acharya | 1bc06aa | 2017-08-18 15:09:46 +0000 | [diff] [blame] | 16 | import atexit |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 17 | import os |
| 18 | import shutil |
| 19 | import subprocess |
| 20 | import tempfile |
| 21 | |
Brant Knudson | 6a090f4 | 2016-10-13 12:51:49 -0500 | [diff] [blame] | 22 | import fixtures |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 23 | import mock |
Matthew Treinish | f9902ec | 2018-02-22 12:11:46 -0500 | [diff] [blame] | 24 | import six |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 25 | |
| 26 | from tempest.cmd import run |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 27 | from tempest.cmd import workspace |
Manik Bindlish | 321c85c | 2018-07-30 06:48:24 +0000 | [diff] [blame] | 28 | from tempest import config |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 29 | from tempest.lib.common.utils import data_utils |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 30 | from tempest.tests import base |
| 31 | |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 32 | if six.PY2: |
| 33 | # Python 2 has not FileNotFoundError exception |
| 34 | FileNotFoundError = IOError |
| 35 | |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 36 | DEVNULL = open(os.devnull, 'wb') |
Divyansh Acharya | 1bc06aa | 2017-08-18 15:09:46 +0000 | [diff] [blame] | 37 | atexit.register(DEVNULL.close) |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 38 | |
Manik Bindlish | 321c85c | 2018-07-30 06:48:24 +0000 | [diff] [blame] | 39 | CONF = config.CONF |
| 40 | |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 41 | |
| 42 | class TestTempestRun(base.TestCase): |
| 43 | |
| 44 | def setUp(self): |
| 45 | super(TestTempestRun, self).setUp() |
| 46 | self.run_cmd = run.TempestRun(None, None) |
| 47 | |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 48 | def test__build_regex_default(self): |
| 49 | args = mock.Mock(spec=argparse.Namespace) |
| 50 | setattr(args, 'smoke', False) |
| 51 | setattr(args, 'regex', '') |
Chandan Kumar | 8a4396e | 2017-09-15 12:18:10 +0530 | [diff] [blame] | 52 | self.assertIsNone(None, self.run_cmd._build_regex(args)) |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 53 | |
| 54 | def test__build_regex_smoke(self): |
| 55 | args = mock.Mock(spec=argparse.Namespace) |
| 56 | setattr(args, "smoke", True) |
| 57 | setattr(args, 'regex', '') |
Chandan Kumar | 8a4396e | 2017-09-15 12:18:10 +0530 | [diff] [blame] | 58 | self.assertEqual(['smoke'], self.run_cmd._build_regex(args)) |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 59 | |
| 60 | def test__build_regex_regex(self): |
| 61 | args = mock.Mock(spec=argparse.Namespace) |
| 62 | setattr(args, 'smoke', False) |
| 63 | setattr(args, "regex", 'i_am_a_fun_little_regex') |
Chandan Kumar | 8a4396e | 2017-09-15 12:18:10 +0530 | [diff] [blame] | 64 | self.assertEqual(['i_am_a_fun_little_regex'], |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 65 | self.run_cmd._build_regex(args)) |
| 66 | |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 67 | def test__build_regex_smoke_regex(self): |
| 68 | args = mock.Mock(spec=argparse.Namespace) |
| 69 | setattr(args, "smoke", True) |
| 70 | setattr(args, 'regex', 'i_am_a_fun_little_regex') |
| 71 | self.assertEqual(['smoke'], self.run_cmd._build_regex(args)) |
| 72 | |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 73 | |
| 74 | class TestRunReturnCode(base.TestCase): |
| 75 | def setUp(self): |
| 76 | super(TestRunReturnCode, self).setUp() |
| 77 | # Setup test dirs |
| 78 | self.directory = tempfile.mkdtemp(prefix='tempest-unit') |
| 79 | self.addCleanup(shutil.rmtree, self.directory) |
| 80 | self.test_dir = os.path.join(self.directory, 'tests') |
| 81 | os.mkdir(self.test_dir) |
| 82 | # Setup Test files |
Chandan Kumar | 8a4396e | 2017-09-15 12:18:10 +0530 | [diff] [blame] | 83 | self.stestr_conf_file = os.path.join(self.directory, '.stestr.conf') |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 84 | self.setup_cfg_file = os.path.join(self.directory, 'setup.cfg') |
| 85 | self.passing_file = os.path.join(self.test_dir, 'test_passing.py') |
| 86 | self.failing_file = os.path.join(self.test_dir, 'test_failing.py') |
| 87 | self.init_file = os.path.join(self.test_dir, '__init__.py') |
| 88 | self.setup_py = os.path.join(self.directory, 'setup.py') |
Chandan Kumar | 8a4396e | 2017-09-15 12:18:10 +0530 | [diff] [blame] | 89 | shutil.copy('tempest/tests/files/testr-conf', self.stestr_conf_file) |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 90 | shutil.copy('tempest/tests/files/passing-tests', self.passing_file) |
| 91 | shutil.copy('tempest/tests/files/failing-tests', self.failing_file) |
| 92 | shutil.copy('setup.py', self.setup_py) |
| 93 | shutil.copy('tempest/tests/files/setup.cfg', self.setup_cfg_file) |
| 94 | shutil.copy('tempest/tests/files/__init__.py', self.init_file) |
| 95 | # Change directory, run wrapper and check result |
| 96 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 97 | os.chdir(self.directory) |
| 98 | |
| 99 | def assertRunExit(self, cmd, expected): |
| 100 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 101 | stderr=subprocess.PIPE) |
| 102 | out, err = p.communicate() |
| 103 | msg = ("Running %s got an unexpected returncode\n" |
| 104 | "Stdout: %s\nStderr: %s" % (' '.join(cmd), out, err)) |
| 105 | self.assertEqual(p.returncode, expected, msg) |
Matthew Treinish | f9902ec | 2018-02-22 12:11:46 -0500 | [diff] [blame] | 106 | return out, err |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 107 | |
| 108 | def test_tempest_run_passes(self): |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 109 | self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0) |
| 110 | |
Chandan Kumar | 8a4396e | 2017-09-15 12:18:10 +0530 | [diff] [blame] | 111 | def test_tempest_run_passes_with_stestr_repository(self): |
| 112 | subprocess.call(['stestr', 'init']) |
Masayuki Igawa | fe2fa00 | 2016-06-22 12:58:34 +0900 | [diff] [blame] | 113 | self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0) |
| 114 | |
Manik Bindlish | 71c8237 | 2019-01-29 10:52:27 +0000 | [diff] [blame] | 115 | def test_tempest_run_failing(self): |
| 116 | self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1) |
| 117 | |
| 118 | def test_tempest_run_failing_with_stestr_repository(self): |
| 119 | subprocess.call(['stestr', 'init']) |
| 120 | self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1) |
| 121 | |
| 122 | def test_tempest_run_blackregex_failing(self): |
| 123 | self.assertRunExit(['tempest', 'run', '--black-regex', 'failing'], 0) |
| 124 | |
| 125 | def test_tempest_run_blackregex_failing_with_stestr_repository(self): |
| 126 | subprocess.call(['stestr', 'init']) |
| 127 | self.assertRunExit(['tempest', 'run', '--black-regex', 'failing'], 0) |
| 128 | |
| 129 | def test_tempest_run_blackregex_passing(self): |
| 130 | self.assertRunExit(['tempest', 'run', '--black-regex', 'passing'], 1) |
| 131 | |
| 132 | def test_tempest_run_blackregex_passing_with_stestr_repository(self): |
| 133 | subprocess.call(['stestr', 'init']) |
| 134 | self.assertRunExit(['tempest', 'run', '--black-regex', 'passing'], 1) |
| 135 | |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 136 | def test_tempest_run_fails(self): |
Matthew Treinish | a051c22 | 2016-05-23 15:48:22 -0400 | [diff] [blame] | 137 | self.assertRunExit(['tempest', 'run'], 1) |
Brant Knudson | 6a090f4 | 2016-10-13 12:51:49 -0500 | [diff] [blame] | 138 | |
Matthew Treinish | f9902ec | 2018-02-22 12:11:46 -0500 | [diff] [blame] | 139 | def test_run_list(self): |
| 140 | subprocess.call(['stestr', 'init']) |
| 141 | out, err = self.assertRunExit(['tempest', 'run', '-l'], 0) |
| 142 | tests = out.split() |
| 143 | tests = sorted([six.text_type(x.rstrip()) for x in tests if x]) |
| 144 | result = [ |
| 145 | six.text_type('tests.test_failing.FakeTestClass.test_pass'), |
| 146 | six.text_type('tests.test_failing.FakeTestClass.test_pass_list'), |
| 147 | six.text_type('tests.test_passing.FakeTestClass.test_pass'), |
| 148 | six.text_type('tests.test_passing.FakeTestClass.test_pass_list'), |
| 149 | ] |
| 150 | # NOTE(mtreinish): on python 3 the subprocess prints b'' around |
| 151 | # stdout. |
| 152 | if six.PY3: |
| 153 | result = ["b\'" + x + "\'" for x in result] |
| 154 | self.assertEqual(result, tests) |
| 155 | |
Matthew Treinish | 3c6b15d | 2018-02-22 11:37:52 -0500 | [diff] [blame] | 156 | def test_tempest_run_with_whitelist(self): |
| 157 | fd, path = tempfile.mkstemp() |
| 158 | self.addCleanup(os.remove, path) |
| 159 | whitelist_file = os.fdopen(fd, 'wb', 0) |
| 160 | self.addCleanup(whitelist_file.close) |
| 161 | whitelist_file.write('passing'.encode('utf-8')) |
| 162 | self.assertRunExit(['tempest', 'run', '--whitelist-file=%s' % path], 0) |
| 163 | |
Manik Bindlish | 5a276ea | 2019-01-29 07:43:52 +0000 | [diff] [blame] | 164 | def test_tempest_run_with_whitelist_regex_include_pass_check_fail(self): |
Matthew Treinish | 3c6b15d | 2018-02-22 11:37:52 -0500 | [diff] [blame] | 165 | fd, path = tempfile.mkstemp() |
| 166 | self.addCleanup(os.remove, path) |
| 167 | whitelist_file = os.fdopen(fd, 'wb', 0) |
| 168 | self.addCleanup(whitelist_file.close) |
| 169 | whitelist_file.write('passing'.encode('utf-8')) |
| 170 | self.assertRunExit(['tempest', 'run', '--whitelist-file=%s' % path, |
| 171 | '--regex', 'fail'], 1) |
| 172 | |
Manik Bindlish | 5a276ea | 2019-01-29 07:43:52 +0000 | [diff] [blame] | 173 | def test_tempest_run_with_whitelist_regex_include_pass_check_pass(self): |
| 174 | fd, path = tempfile.mkstemp() |
| 175 | self.addCleanup(os.remove, path) |
| 176 | whitelist_file = os.fdopen(fd, 'wb', 0) |
| 177 | self.addCleanup(whitelist_file.close) |
| 178 | whitelist_file.write('passing'.encode('utf-8')) |
| 179 | self.assertRunExit(['tempest', 'run', '--whitelist-file=%s' % path, |
| 180 | '--regex', 'passing'], 0) |
| 181 | |
| 182 | def test_tempest_run_with_whitelist_regex_include_fail_check_pass(self): |
| 183 | fd, path = tempfile.mkstemp() |
| 184 | self.addCleanup(os.remove, path) |
| 185 | whitelist_file = os.fdopen(fd, 'wb', 0) |
| 186 | self.addCleanup(whitelist_file.close) |
| 187 | whitelist_file.write('failing'.encode('utf-8')) |
| 188 | self.assertRunExit(['tempest', 'run', '--whitelist-file=%s' % path, |
| 189 | '--regex', 'pass'], 1) |
| 190 | |
Masayuki Igawa | ff07eac | 2018-02-22 16:53:09 +0900 | [diff] [blame] | 191 | def test_tempest_run_passes_with_config_file(self): |
| 192 | self.assertRunExit(['tempest', 'run', |
| 193 | '--config-file', self.stestr_conf_file, |
| 194 | '--regex', 'passing'], 0) |
| 195 | |
Manik Bindlish | 9334ddb | 2019-01-29 10:26:43 +0000 | [diff] [blame] | 196 | def test_tempest_run_with_blacklist_failing(self): |
| 197 | fd, path = tempfile.mkstemp() |
| 198 | self.addCleanup(os.remove, path) |
| 199 | blacklist_file = os.fdopen(fd, 'wb', 0) |
| 200 | self.addCleanup(blacklist_file.close) |
| 201 | blacklist_file.write('failing'.encode('utf-8')) |
| 202 | self.assertRunExit(['tempest', 'run', '--blacklist-file=%s' % path], 0) |
| 203 | |
| 204 | def test_tempest_run_with_blacklist_passing(self): |
| 205 | fd, path = tempfile.mkstemp() |
| 206 | self.addCleanup(os.remove, path) |
| 207 | blacklist_file = os.fdopen(fd, 'wb', 0) |
| 208 | self.addCleanup(blacklist_file.close) |
| 209 | blacklist_file.write('passing'.encode('utf-8')) |
| 210 | self.assertRunExit(['tempest', 'run', '--blacklist-file=%s' % path], 1) |
| 211 | |
| 212 | def test_tempest_run_with_blacklist_regex_exclude_fail_check_pass(self): |
| 213 | fd, path = tempfile.mkstemp() |
| 214 | self.addCleanup(os.remove, path) |
| 215 | blacklist_file = os.fdopen(fd, 'wb', 0) |
| 216 | self.addCleanup(blacklist_file.close) |
| 217 | blacklist_file.write('failing'.encode('utf-8')) |
| 218 | self.assertRunExit(['tempest', 'run', '--blacklist-file=%s' % path, |
| 219 | '--regex', 'pass'], 0) |
| 220 | |
| 221 | def test_tempest_run_with_blacklist_regex_exclude_pass_check_pass(self): |
| 222 | fd, path = tempfile.mkstemp() |
| 223 | self.addCleanup(os.remove, path) |
| 224 | blacklist_file = os.fdopen(fd, 'wb', 0) |
| 225 | self.addCleanup(blacklist_file.close) |
| 226 | blacklist_file.write('passing'.encode('utf-8')) |
| 227 | self.assertRunExit(['tempest', 'run', '--blacklist-file=%s' % path, |
| 228 | '--regex', 'pass'], 1) |
| 229 | |
| 230 | def test_tempest_run_with_blacklist_regex_exclude_pass_check_fail(self): |
| 231 | fd, path = tempfile.mkstemp() |
| 232 | self.addCleanup(os.remove, path) |
| 233 | blacklist_file = os.fdopen(fd, 'wb', 0) |
| 234 | self.addCleanup(blacklist_file.close) |
| 235 | blacklist_file.write('passing'.encode('utf-8')) |
| 236 | self.assertRunExit(['tempest', 'run', '--blacklist-file=%s' % path, |
| 237 | '--regex', 'fail'], 1) |
| 238 | |
Brant Knudson | 6a090f4 | 2016-10-13 12:51:49 -0500 | [diff] [blame] | 239 | |
Manik Bindlish | 321c85c | 2018-07-30 06:48:24 +0000 | [diff] [blame] | 240 | class TestConfigPathCheck(base.TestCase): |
| 241 | def setUp(self): |
| 242 | super(TestConfigPathCheck, self).setUp() |
| 243 | self.run_cmd = run.TempestRun(None, None) |
| 244 | |
| 245 | def test_tempest_run_set_config_path(self): |
| 246 | # Note: (mbindlish) This test is created for the bug id: 1783751 |
| 247 | # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG is actually |
| 248 | # getting set in os environment when some data has passed to |
| 249 | # set the environment. |
| 250 | |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 251 | _, path = tempfile.mkstemp() |
| 252 | self.addCleanup(os.remove, path) |
Manik Bindlish | 321c85c | 2018-07-30 06:48:24 +0000 | [diff] [blame] | 253 | |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 254 | self.run_cmd._set_env(path) |
| 255 | self.assertEqual(path, CONF._path) |
| 256 | self.assertIn('TEMPEST_CONFIG_DIR', os.environ) |
| 257 | self.assertEqual(path, os.path.join(os.environ['TEMPEST_CONFIG_DIR'], |
| 258 | os.environ['TEMPEST_CONFIG'])) |
| 259 | |
| 260 | def test_tempest_run_set_config_no_exist_path(self): |
| 261 | path = "fake/path" |
| 262 | self.assertRaisesRegex(FileNotFoundError, |
| 263 | 'Config file: .* doesn\'t exist', |
| 264 | self.run_cmd._set_env, path) |
| 265 | |
| 266 | def test_tempest_run_no_config_path(self): |
Manik Bindlish | 321c85c | 2018-07-30 06:48:24 +0000 | [diff] [blame] | 267 | # Note: (mbindlish) This test is created for the bug id: 1783751 |
| 268 | # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG should have no value |
| 269 | # in os environment when no data has passed to set the environment. |
| 270 | |
| 271 | self.run_cmd._set_env("") |
| 272 | self.assertFalse(CONF._path) |
| 273 | self.assertNotIn('TEMPEST_CONFIG_DIR', os.environ) |
| 274 | self.assertNotIn('TEMPEST_CONFIG', os.environ) |
| 275 | |
| 276 | |
Brant Knudson | 6a090f4 | 2016-10-13 12:51:49 -0500 | [diff] [blame] | 277 | class TestTakeAction(base.TestCase): |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 278 | def setUp(self): |
| 279 | super(TestTakeAction, self).setUp() |
| 280 | self.name = data_utils.rand_name('workspace') |
| 281 | self.path = tempfile.mkdtemp() |
| 282 | self.addCleanup(shutil.rmtree, self.path, ignore_errors=True) |
| 283 | store_dir = tempfile.mkdtemp() |
| 284 | self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True) |
| 285 | self.store_file = os.path.join(store_dir, 'workspace.yaml') |
| 286 | self.workspace_manager = workspace.WorkspaceManager( |
| 287 | path=self.store_file) |
| 288 | self.workspace_manager.register_new_workspace(self.name, self.path) |
| 289 | |
| 290 | def _setup_test_dirs(self): |
| 291 | self.directory = tempfile.mkdtemp(prefix='tempest-unit') |
| 292 | self.addCleanup(shutil.rmtree, self.directory, ignore_errors=True) |
| 293 | self.test_dir = os.path.join(self.directory, 'tests') |
| 294 | os.mkdir(self.test_dir) |
| 295 | # Change directory, run wrapper and check result |
| 296 | self.addCleanup(os.chdir, os.path.abspath(os.curdir)) |
| 297 | os.chdir(self.directory) |
| 298 | |
Brant Knudson | 6a090f4 | 2016-10-13 12:51:49 -0500 | [diff] [blame] | 299 | def test_workspace_not_registered(self): |
| 300 | class Exception_(Exception): |
| 301 | pass |
| 302 | |
| 303 | m_exit = self.useFixture(fixtures.MockPatch('sys.exit')).mock |
| 304 | # sys.exit must not continue (or exit) |
| 305 | m_exit.side_effect = Exception_ |
| 306 | |
| 307 | workspace = self.getUniqueString() |
| 308 | |
| 309 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 310 | parsed_args = mock.Mock() |
| 311 | parsed_args.config_file = [] |
| 312 | |
| 313 | # Override $HOME so that empty workspace gets created in temp dir. |
| 314 | self.useFixture(fixtures.TempHomeDir()) |
| 315 | |
| 316 | # Force use of the temporary home directory. |
| 317 | parsed_args.workspace_path = None |
| 318 | |
| 319 | # Simulate --workspace argument. |
| 320 | parsed_args.workspace = workspace |
| 321 | |
| 322 | self.assertRaises(Exception_, tempest_run.take_action, parsed_args) |
| 323 | exit_msg = m_exit.call_args[0][0] |
| 324 | self.assertIn(workspace, exit_msg) |
Masayuki Igawa | ff07eac | 2018-02-22 16:53:09 +0900 | [diff] [blame] | 325 | |
| 326 | def test_config_file_specified(self): |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 327 | self._setup_test_dirs() |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 328 | _, path = tempfile.mkstemp() |
| 329 | self.addCleanup(os.remove, path) |
Masayuki Igawa | ff07eac | 2018-02-22 16:53:09 +0900 | [diff] [blame] | 330 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 331 | parsed_args = mock.Mock() |
Masayuki Igawa | ff07eac | 2018-02-22 16:53:09 +0900 | [diff] [blame] | 332 | |
| 333 | parsed_args.workspace = None |
| 334 | parsed_args.state = None |
| 335 | parsed_args.list_tests = False |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 336 | parsed_args.config_file = path |
Masayuki Igawa | ff07eac | 2018-02-22 16:53:09 +0900 | [diff] [blame] | 337 | |
| 338 | with mock.patch('stestr.commands.run_command') as m: |
| 339 | m.return_value = 0 |
| 340 | self.assertEqual(0, tempest_run.take_action(parsed_args)) |
| 341 | m.assert_called() |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 342 | |
| 343 | def test_no_config_file_no_workspace_no_state(self): |
| 344 | self._setup_test_dirs() |
| 345 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 346 | parsed_args = mock.Mock() |
| 347 | |
| 348 | parsed_args.workspace = None |
| 349 | parsed_args.state = None |
| 350 | parsed_args.list_tests = False |
| 351 | parsed_args.config_file = '' |
| 352 | |
| 353 | with mock.patch('stestr.commands.run_command'): |
| 354 | self.assertRaises(SystemExit, tempest_run.take_action, parsed_args) |
| 355 | |
| 356 | def test_config_file_workspace_registered(self): |
| 357 | self._setup_test_dirs() |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 358 | _, path = tempfile.mkstemp() |
| 359 | self.addCleanup(os.remove, path) |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 360 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 361 | parsed_args = mock.Mock() |
| 362 | parsed_args.workspace = self.name |
| 363 | parsed_args.workspace_path = self.store_file |
| 364 | parsed_args.state = None |
| 365 | parsed_args.list_tests = False |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 366 | parsed_args.config_file = path |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 367 | |
| 368 | with mock.patch('stestr.commands.run_command') as m: |
| 369 | m.return_value = 0 |
| 370 | self.assertEqual(0, tempest_run.take_action(parsed_args)) |
| 371 | m.assert_called() |
| 372 | |
| 373 | @mock.patch('tempest.cmd.run.TempestRun._init_state') |
| 374 | def test_workspace_registered_no_config_no_state(self, mock_init_state): |
| 375 | self._setup_test_dirs() |
| 376 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 377 | parsed_args = mock.Mock() |
| 378 | parsed_args.workspace = self.name |
| 379 | parsed_args.workspace_path = self.store_file |
| 380 | parsed_args.state = None |
| 381 | parsed_args.list_tests = False |
| 382 | parsed_args.config_file = '' |
| 383 | |
| 384 | with mock.patch('stestr.commands.run_command') as m: |
| 385 | m.return_value = 0 |
| 386 | self.assertEqual(0, tempest_run.take_action(parsed_args)) |
| 387 | m.assert_called() |
| 388 | mock_init_state.assert_not_called() |
| 389 | |
| 390 | @mock.patch('tempest.cmd.run.TempestRun._init_state') |
| 391 | def test_no_config_file_no_workspace_state_true(self, mock_init_state): |
| 392 | self._setup_test_dirs() |
| 393 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 394 | parsed_args = mock.Mock() |
| 395 | |
| 396 | parsed_args.workspace = None |
| 397 | parsed_args.state = True |
| 398 | parsed_args.list_tests = False |
| 399 | parsed_args.config_file = '' |
| 400 | |
| 401 | with mock.patch('stestr.commands.run_command'): |
| 402 | self.assertRaises(SystemExit, tempest_run.take_action, parsed_args) |
| 403 | mock_init_state.assert_not_called() |
| 404 | |
| 405 | @mock.patch('tempest.cmd.run.TempestRun._init_state') |
| 406 | def test_workspace_registered_no_config_state_true(self, mock_init_state): |
| 407 | self._setup_test_dirs() |
| 408 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 409 | parsed_args = mock.Mock() |
| 410 | parsed_args.workspace = self.name |
| 411 | parsed_args.workspace_path = self.store_file |
| 412 | parsed_args.state = True |
| 413 | parsed_args.list_tests = False |
| 414 | parsed_args.config_file = '' |
| 415 | |
| 416 | with mock.patch('stestr.commands.run_command') as m: |
| 417 | m.return_value = 0 |
| 418 | self.assertEqual(0, tempest_run.take_action(parsed_args)) |
| 419 | m.assert_called() |
| 420 | mock_init_state.assert_called() |
| 421 | |
| 422 | @mock.patch('tempest.cmd.run.TempestRun._init_state') |
| 423 | def test_no_workspace_config_file_state_true(self, mock_init_state): |
| 424 | self._setup_test_dirs() |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 425 | _, path = tempfile.mkstemp() |
| 426 | self.addCleanup(os.remove, path) |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 427 | tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock()) |
| 428 | parsed_args = mock.Mock() |
| 429 | parsed_args.workspace = None |
| 430 | parsed_args.workspace_path = self.store_file |
| 431 | parsed_args.state = True |
| 432 | parsed_args.list_tests = False |
Manik Bindlish | 21491df | 2018-12-14 06:58:42 +0000 | [diff] [blame^] | 433 | parsed_args.config_file = path |
Manik Bindlish | 087d4d0 | 2018-08-01 10:10:22 +0000 | [diff] [blame] | 434 | |
| 435 | with mock.patch('stestr.commands.run_command') as m: |
| 436 | m.return_value = 0 |
| 437 | self.assertEqual(0, tempest_run.take_action(parsed_args)) |
| 438 | m.assert_called() |
| 439 | mock_init_state.assert_called() |