Cache security group driver
Change I0932c652fb455fe10239215a93e183ea947234e3 from Mitaka was a performance improvement to cache the loaded security group driver since the API calls get_openstack_security_group_driver a lot. That performance fix was regressed with change Ia4a8d9954bf456253101b936f8b4ff513aaa73b2 in Newton. This caches the loaded security group driver once again. This is pretty similar to the original change except simpler since we don't have to account for the skip_policy_check flag. Change-Id: Icacc763f19db6dc90e72af32e17d480775ad5edf Closes-Bug: #1825018 (cherry picked from commit0461921d9e
) (cherry picked from commit3ea6a7f79b
) (cherry picked from commit99048af872
)
This commit is contained in:
parent
d575890399
commit
179b556a5b
|
@ -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():
|
||||
|
|
|
@ -331,7 +331,7 @@ class TestCase(testtools.TestCase):
|
|||
|
||||
self.useFixture(nova_fixtures.PoisonFunctions())
|
||||
|
||||
openstack_driver.DRIVER_CACHE = {}
|
||||
openstack_driver.DRIVER_CACHE = None
|
||||
|
||||
self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue