Matthew Treinish | f610aca | 2015-06-30 15:32:34 -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 os |
| 16 | |
| 17 | import fixtures |
| 18 | |
| 19 | from tempest.cmd import init |
| 20 | from tempest.tests import base |
| 21 | |
| 22 | |
| 23 | class TestTempestInit(base.TestCase): |
| 24 | |
| 25 | def test_generate_testr_conf(self): |
| 26 | # Create fake conf dir |
| 27 | conf_dir = self.useFixture(fixtures.TempDir()) |
| 28 | |
| 29 | init_cmd = init.TempestInit(None, None) |
| 30 | init_cmd.generate_testr_conf(conf_dir.path) |
| 31 | |
| 32 | # Generate expected file contents |
| 33 | top_level_path = os.path.dirname(os.path.dirname(init.__file__)) |
| 34 | discover_path = os.path.join(top_level_path, 'test_discover') |
| 35 | testr_conf_file = init.TESTR_CONF % (top_level_path, discover_path) |
| 36 | |
| 37 | conf_path = conf_dir.join('.testr.conf') |
| 38 | conf_file = open(conf_path, 'r') |
| 39 | self.addCleanup(conf_file.close) |
| 40 | self.assertEqual(conf_file.read(), testr_conf_file) |
| 41 | |
| 42 | def test_create_working_dir(self): |
| 43 | fake_local_dir = self.useFixture(fixtures.TempDir()) |
| 44 | fake_local_conf_dir = self.useFixture(fixtures.TempDir()) |
| 45 | # Create a fake conf file |
| 46 | fake_file = fake_local_conf_dir.join('conf_file.conf') |
| 47 | open(fake_file, 'w').close() |
| 48 | init_cmd = init.TempestInit(None, None) |
| 49 | init_cmd.create_working_dir(fake_local_dir.path, |
| 50 | fake_local_conf_dir.path) |
| 51 | # Assert directories are created |
| 52 | lock_path = os.path.join(fake_local_dir.path, 'tempest_lock') |
| 53 | etc_dir = os.path.join(fake_local_dir.path, 'etc') |
| 54 | log_dir = os.path.join(fake_local_dir.path, 'logs') |
| 55 | testr_dir = os.path.join(fake_local_dir.path, '.testrepository') |
| 56 | self.assertTrue(os.path.isdir(lock_path)) |
| 57 | self.assertTrue(os.path.isdir(etc_dir)) |
| 58 | self.assertTrue(os.path.isdir(log_dir)) |
| 59 | self.assertTrue(os.path.isdir(testr_dir)) |
| 60 | # Assert file creation |
| 61 | fake_file_moved = os.path.join(etc_dir, 'conf_file.conf') |
| 62 | local_conf_file = os.path.join(etc_dir, 'tempest.conf') |
| 63 | local_testr_conf = os.path.join(fake_local_dir.path, '.testr.conf') |
| 64 | self.assertTrue(os.path.isfile(fake_file_moved)) |
| 65 | self.assertTrue(os.path.isfile(local_conf_file)) |
| 66 | self.assertTrue(os.path.isfile(local_testr_conf)) |