From 4d1770004af9d54f1aaa62c3b0f6d2bb3c1fc0d1 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Fri, 3 Mar 2017 07:36:03 +0000 Subject: [PATCH] Every unit test creates and registers every OpenStack action That means around 1300 database inserts (or, attempted inserts, some seem to fail) before every test. This is very slow. Only one of the tests actually verifies the OpenStack actions are registered. Recently I5ab01395c507fc857dca7cf08ab344a07def0dcf gave us a way to set a different mapping file in the config. This change makes every test use the much smaller test mapping file, rather than the default file. Given that one test is checking specific actions being registered, these were added to the test file to make that test pass. Once the OpenStack actions are moved to mistral-extra this will improve again. The tempest tests verify the actions load and tests a number of the OpenStack actions directly, so our coverage of them isn't reduced. From a brief test on my laptop, this reduces the unit test run time by between 60 and 90 seconds. Related-Bug: #1669511 Change-Id: Icc4ec5ef7d93d5ebb64f21c62d0bf7fc91e2f084 --- mistral/tests/resources/openstack/test_mapping.json | 12 +++++++++++- .../tests/unit/actions/openstack/test_generator.py | 10 ++++++---- mistral/tests/unit/base.py | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mistral/tests/resources/openstack/test_mapping.json b/mistral/tests/resources/openstack/test_mapping.json index b09f0436..82d1347f 100644 --- a/mistral/tests/resources/openstack/test_mapping.json +++ b/mistral/tests/resources/openstack/test_mapping.json @@ -1,6 +1,16 @@ { "_comment": "Mapping OpenStack action namespaces to all its actions. Each action name is mapped to python-client method name in this namespace.", "nova": { - "servers_get": "servers.get" + "servers_get": "servers.get", + "servers_find": "servers.find", + "volumes_delete_server_volume": "volumes.delete_server_volume" + }, + "keystone": { + "users_list": "users.list", + "trusts_create": "trusts.create" + }, + "glance": { + "images_list": "images.list", + "images_delete": "images.delete" } } diff --git a/mistral/tests/unit/actions/openstack/test_generator.py b/mistral/tests/unit/actions/openstack/test_generator.py index 78a10080..57ec59f3 100644 --- a/mistral/tests/unit/actions/openstack/test_generator.py +++ b/mistral/tests/unit/actions/openstack/test_generator.py @@ -90,8 +90,9 @@ class GeneratorTest(base.BaseTest): cls = MODULE_MAPPING.get(generator_cls.action_namespace)[1] if cls == actions.NovaAction: - self.assertEqual(['nova.servers_get'], action_names) - else: + self.assertIn('nova.servers_get', action_names) + self.assertEqual(3, len(action_names)) + elif cls not in (actions.GlanceAction, actions.KeystoneAction): self.assertEqual([], action_names) def test_absolute_mapping_path(self): @@ -105,8 +106,9 @@ class GeneratorTest(base.BaseTest): cls = MODULE_MAPPING.get(generator_cls.action_namespace)[1] if cls == actions.NovaAction: - self.assertEqual(['nova.servers_get'], action_names) - else: + self.assertIn('nova.servers_get', action_names) + self.assertEqual(3, len(action_names)) + elif cls not in (actions.GlanceAction, actions.KeystoneAction): self.assertEqual([], action_names) diff --git a/mistral/tests/unit/base.py b/mistral/tests/unit/base.py index a94a666c..ac057f77 100644 --- a/mistral/tests/unit/base.py +++ b/mistral/tests/unit/base.py @@ -240,6 +240,8 @@ class DbTestCase(BaseTest): if cfg.CONF.database.connection.startswith('sqlite'): cfg.CONF.set_default('connection', 'sqlite://', group='database') + cfg.CONF.set_default("openstack_actions_mapping_path", + "tests/resources/openstack/test_mapping.json") cfg.CONF.set_default('max_overflow', -1, group='database') cfg.CONF.set_default('max_pool_size', 1000, group='database')