Merge "Cache security group driver" into stable/rocky
This commit is contained in:
commit
c56d43002b
|
@ -21,13 +21,17 @@ import nova.network
|
||||||
NOVA_DRIVER = ('nova.compute.api.SecurityGroupAPI')
|
NOVA_DRIVER = ('nova.compute.api.SecurityGroupAPI')
|
||||||
NEUTRON_DRIVER = ('nova.network.security_group.neutron_driver.'
|
NEUTRON_DRIVER = ('nova.network.security_group.neutron_driver.'
|
||||||
'SecurityGroupAPI')
|
'SecurityGroupAPI')
|
||||||
|
DRIVER_CACHE = None # singleton of the driver once loaded
|
||||||
|
|
||||||
|
|
||||||
def get_openstack_security_group_driver():
|
def get_openstack_security_group_driver():
|
||||||
if is_neutron_security_groups():
|
global DRIVER_CACHE
|
||||||
return importutils.import_object(NEUTRON_DRIVER)
|
if DRIVER_CACHE is None:
|
||||||
else:
|
if is_neutron_security_groups():
|
||||||
return importutils.import_object(NOVA_DRIVER)
|
DRIVER_CACHE = importutils.import_object(NEUTRON_DRIVER)
|
||||||
|
else:
|
||||||
|
DRIVER_CACHE = importutils.import_object(NOVA_DRIVER)
|
||||||
|
return DRIVER_CACHE
|
||||||
|
|
||||||
|
|
||||||
def is_neutron_security_groups():
|
def is_neutron_security_groups():
|
||||||
|
|
|
@ -331,7 +331,7 @@ class TestCase(testtools.TestCase):
|
||||||
|
|
||||||
self.useFixture(nova_fixtures.PoisonFunctions())
|
self.useFixture(nova_fixtures.PoisonFunctions())
|
||||||
|
|
||||||
openstack_driver.DRIVER_CACHE = {}
|
openstack_driver.DRIVER_CACHE = None
|
||||||
|
|
||||||
self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
|
self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
import nova.network
|
import nova.network
|
||||||
import nova.network.security_group.neutron_driver
|
import nova.network.security_group.neutron_driver
|
||||||
import nova.network.security_group.openstack_driver as sgapi
|
import nova.network.security_group.openstack_driver as sgapi
|
||||||
|
@ -55,3 +57,11 @@ class SecurityGroupAPIConfigTest(nova.test.NoDBTestCase):
|
||||||
self.assertIsInstance(
|
self.assertIsInstance(
|
||||||
driver,
|
driver,
|
||||||
nova.compute.api.SecurityGroupAPI)
|
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…
Reference in New Issue