diff options
author | Zuul <zuul@review.opendev.org> | 2023-04-18 17:55:52 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-04-18 17:55:52 +0000 |
commit | e329035528e137066ae2f0afed232c0a1c91ee6f (patch) | |
tree | df7f739c01da1bb947f800568d2445950439c524 /nova/tests/unit/scheduler/client/test_report.py | |
parent | f5b4125cbfbbcf7abaa9b1b5d6f5c4c562b9f261 (diff) | |
parent | 77273f067d96a4ec401c3b36f2922d63c4ad7103 (diff) | |
download | nova-e329035528e137066ae2f0afed232c0a1c91ee6f.tar.gz |
Merge "Unify placement client singleton implementations" into stable/yoga
Diffstat (limited to 'nova/tests/unit/scheduler/client/test_report.py')
-rw-r--r-- | nova/tests/unit/scheduler/client/test_report.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index 0650c62096..485f187d9e 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. import copy +import ddt import time from urllib import parse @@ -150,6 +151,41 @@ class SafeConnectedTestCase(test.NoDBTestCase): self.assertTrue(req.called) +@ddt.ddt +class TestSingleton(test.NoDBTestCase): + def test_singleton(self): + # Make sure we start with a clean slate + self.assertIsNone(report.PLACEMENTCLIENT) + + # Make sure the first call creates the singleton, sets it + # globally, and returns it + client = report.report_client_singleton() + self.assertEqual(client, report.PLACEMENTCLIENT) + + # Make sure that a subsequent call returns the same thing + # again and that the global is unchanged + self.assertEqual(client, report.report_client_singleton()) + self.assertEqual(client, report.PLACEMENTCLIENT) + + @ddt.data(ks_exc.EndpointNotFound, + ks_exc.MissingAuthPlugin, + ks_exc.Unauthorized, + ks_exc.DiscoveryFailure, + ks_exc.ConnectFailure, + ks_exc.RequestTimeout, + ks_exc.GatewayTimeout, + test.TestingException) + def test_errors(self, exc): + self._test_error(exc) + + @mock.patch.object(report, 'LOG') + def _test_error(self, exc, mock_log): + with mock.patch.object(report.SchedulerReportClient, '_create_client', + side_effect=exc): + self.assertRaises(exc, report.report_client_singleton) + mock_log.error.assert_called_once() + + class TestConstructor(test.NoDBTestCase): def setUp(self): super(TestConstructor, self).setUp() |