Browse Source

Merge "Cache security group driver" into stable/stein

tags/19.1.0
Zuul Gerrit Code Review 2 months ago
parent
commit
b73b243f1c
3 changed files with 19 additions and 5 deletions
  1. +8
    -4
      nova/network/security_group/openstack_driver.py
  2. +1
    -1
      nova/test.py
  3. +10
    -0
      nova/tests/unit/network/test_config.py

+ 8
- 4
nova/network/security_group/openstack_driver.py View File

@@ -21,13 +21,17 @@ import nova.network
NOVA_DRIVER = ('nova.compute.api.SecurityGroupAPI')
NEUTRON_DRIVER = ('nova.network.security_group.neutron_driver.'
'SecurityGroupAPI')
DRIVER_CACHE = None # singleton of the driver once loaded


def get_openstack_security_group_driver():
if is_neutron_security_groups():
return importutils.import_object(NEUTRON_DRIVER)
else:
return importutils.import_object(NOVA_DRIVER)
global DRIVER_CACHE
if DRIVER_CACHE is None:
if is_neutron_security_groups():
DRIVER_CACHE = importutils.import_object(NEUTRON_DRIVER)
else:
DRIVER_CACHE = importutils.import_object(NOVA_DRIVER)
return DRIVER_CACHE


def is_neutron_security_groups():


+ 1
- 1
nova/test.py View File

@@ -296,7 +296,7 @@ class TestCase(testtools.TestCase):

self.useFixture(nova_fixtures.PoisonFunctions())

openstack_driver.DRIVER_CACHE = {}
openstack_driver.DRIVER_CACHE = None

self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())



+ 10
- 0
nova/tests/unit/network/test_config.py View File

@@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import mock

import nova.network
import nova.network.security_group.neutron_driver
import nova.network.security_group.openstack_driver as sgapi
@@ -55,3 +57,11 @@ class SecurityGroupAPIConfigTest(nova.test.NoDBTestCase):
self.assertIsInstance(
driver,
nova.compute.api.SecurityGroupAPI)

@mock.patch('oslo_utils.importutils.import_object')
def test_caches(self, mock_import):
self.flags(use_neutron=True)
sgapi.DRIVER_CACHE = None
for _ in range(2):
self.assertIsNotNone(sgapi.get_openstack_security_group_driver())
mock_import.assert_called_once_with(sgapi.NEUTRON_DRIVER)

Loading…
Cancel
Save