Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 1 | # Copyright 2015 Red Hat, Inc. |
| 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 | |
Ngo Quoc Cuong | 33710b3 | 2017-05-11 14:17:17 +0700 | [diff] [blame] | 15 | import fixtures |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 16 | from oslo_config import cfg |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 17 | |
Andrea Frittoli (andreaf) | 290b3e1 | 2015-10-08 10:25:02 +0100 | [diff] [blame] | 18 | from tempest.common import credentials_factory as credentials |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 19 | from tempest import config |
Matthew Treinish | ffad78a | 2016-04-16 14:39:52 -0400 | [diff] [blame] | 20 | from tempest.tests import base |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 21 | from tempest.tests import fake_config |
| 22 | |
| 23 | |
| 24 | class TestAltAvailable(base.TestCase): |
| 25 | |
| 26 | identity_version = 'v2' |
| 27 | |
| 28 | def setUp(self): |
| 29 | super(TestAltAvailable, self).setUp() |
| 30 | self.useFixture(fake_config.ConfigFixture()) |
Jordan Pittier | 0021c29 | 2016-03-29 21:33:34 +0200 | [diff] [blame] | 31 | self.patchobject(config, 'TempestConfigPrivate', |
| 32 | fake_config.FakePrivate) |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 33 | |
| 34 | def run_test(self, dynamic_creds, use_accounts_file, creds): |
| 35 | |
| 36 | cfg.CONF.set_default('use_dynamic_credentials', |
| 37 | dynamic_creds, group='auth') |
| 38 | if use_accounts_file: |
| 39 | accounts = [dict(username="u%s" % ii, |
Sean Dague | ed6e586 | 2016-04-04 10:49:13 -0400 | [diff] [blame] | 40 | project_name="t%s" % ii, |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 41 | password="p") for ii in creds] |
Ngo Quoc Cuong | 33710b3 | 2017-05-11 14:17:17 +0700 | [diff] [blame] | 42 | self.useFixture(fixtures.MockPatch( |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 43 | 'tempest.common.preprov_creds.read_accounts_yaml', |
| 44 | return_value=accounts)) |
| 45 | cfg.CONF.set_default('test_accounts_file', |
| 46 | use_accounts_file, group='auth') |
Ngo Quoc Cuong | 33710b3 | 2017-05-11 14:17:17 +0700 | [diff] [blame] | 47 | self.useFixture(fixtures.MockPatch('os.path.isfile', |
| 48 | return_value=True)) |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 49 | else: |
Ngo Quoc Cuong | 33710b3 | 2017-05-11 14:17:17 +0700 | [diff] [blame] | 50 | self.useFixture(fixtures.MockPatch('os.path.isfile', |
| 51 | return_value=False)) |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 52 | expected = len(set(creds)) > 1 or dynamic_creds |
| 53 | observed = credentials.is_alt_available( |
| 54 | identity_version=self.identity_version) |
| 55 | self.assertEqual(expected, observed) |
| 56 | |
| 57 | # Dynamic credentials implies alt so only one test case for True |
| 58 | def test__dynamic_creds__accounts_file__one_user(self): |
| 59 | self.run_test(dynamic_creds=True, |
| 60 | use_accounts_file=False, |
| 61 | creds=['1', '2']) |
| 62 | |
| 63 | def test__no_dynamic_creds__accounts_file__one_user(self): |
| 64 | self.run_test(dynamic_creds=False, |
| 65 | use_accounts_file=True, |
| 66 | creds=['1']) |
| 67 | |
| 68 | def test__no_dynamic_creds__accounts_file__two_users(self): |
| 69 | self.run_test(dynamic_creds=False, |
| 70 | use_accounts_file=True, |
| 71 | creds=['1', '2']) |
| 72 | |
| 73 | def test__no_dynamic_creds__accounts_file__two_users_identical(self): |
| 74 | self.run_test(dynamic_creds=False, |
| 75 | use_accounts_file=True, |
| 76 | creds=['1', '1']) |
| 77 | |
Andrea Frittoli (andreaf) | 9c79845 | 2015-10-09 13:38:20 +0100 | [diff] [blame] | 78 | |
| 79 | class TestAltAvailableV3(TestAltAvailable): |
| 80 | |
| 81 | identity_version = 'v3' |