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