Fix SQLite locking issue on unit tests
stestr runs tests in parallel and this can cause issues with locking
when SQLite is not mocked out properly and gets used in a test. This
patch just switches Storage to use :memory: so that locking does not
occur.
Closes-Bug: #1908282
Change-Id: Iaa1c7b78dee498e0cc6dc6fccf12e74f22225ecd
(cherry picked from commit 36ef217bc6
)
This commit is contained in:
parent
1c31b28fcc
commit
3e3bd32d74
@ -19,6 +19,8 @@ from unit_tests.test_utils import (
|
|||||||
get_default_config,
|
get_default_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import charmhelpers.core.unitdata
|
||||||
|
|
||||||
__default_config = get_default_config()
|
__default_config = get_default_config()
|
||||||
# NOTE(freyes): the default 'distro' makes the test suite behave different
|
# NOTE(freyes): the default 'distro' makes the test suite behave different
|
||||||
# depending on where it's being executed
|
# depending on where it's being executed
|
||||||
@ -34,6 +36,12 @@ TO_PATCH = [
|
|||||||
|
|
||||||
class PauseTestCase(CharmTestCase):
|
class PauseTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(PauseTestCase, self).setUp(
|
super(PauseTestCase, self).setUp(
|
||||||
actions,
|
actions,
|
||||||
@ -50,6 +58,12 @@ class PauseTestCase(CharmTestCase):
|
|||||||
|
|
||||||
class ResumeTestCase(CharmTestCase):
|
class ResumeTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ResumeTestCase, self).setUp(
|
super(ResumeTestCase, self).setUp(
|
||||||
actions, [
|
actions, [
|
||||||
@ -65,6 +79,12 @@ class ResumeTestCase(CharmTestCase):
|
|||||||
|
|
||||||
class ClearUnitKnownhostCacheTestCase(CharmTestCase):
|
class ClearUnitKnownhostCacheTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _relation_get(attribute=None, unit=None, rid=None):
|
def _relation_get(attribute=None, unit=None, rid=None):
|
||||||
return {
|
return {
|
||||||
@ -153,6 +173,12 @@ class ClearUnitKnownhostCacheTestCase(CharmTestCase):
|
|||||||
|
|
||||||
class SyncComputeAvailabilityZonesTestCase(CharmTestCase):
|
class SyncComputeAvailabilityZonesTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _relation_get(attribute=None, unit=None, rid=None):
|
def _relation_get(attribute=None, unit=None, rid=None):
|
||||||
return {
|
return {
|
||||||
@ -286,6 +312,12 @@ class SyncComputeAvailabilityZonesTestCase(CharmTestCase):
|
|||||||
|
|
||||||
class MainTestCase(CharmTestCase):
|
class MainTestCase(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(MainTestCase, self).setUp(
|
super(MainTestCase, self).setUp(
|
||||||
actions,
|
actions,
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
from mock import patch
|
from mock import patch
|
||||||
from unit_tests.test_utils import CharmTestCase
|
from unit_tests.test_utils import CharmTestCase
|
||||||
|
|
||||||
|
import charmhelpers.core.unitdata
|
||||||
|
|
||||||
import actions.openstack_upgrade as openstack_upgrade
|
import actions.openstack_upgrade as openstack_upgrade
|
||||||
|
|
||||||
|
|
||||||
@ -29,6 +31,12 @@ TO_PATCH = [
|
|||||||
|
|
||||||
class TestNovaCCUpgradeActions(CharmTestCase):
|
class TestNovaCCUpgradeActions(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestNovaCCUpgradeActions, self).setUp(openstack_upgrade,
|
super(TestNovaCCUpgradeActions, self).setUp(openstack_upgrade,
|
||||||
TO_PATCH)
|
TO_PATCH)
|
||||||
|
@ -19,6 +19,8 @@ import hooks.nova_cc_context as context
|
|||||||
|
|
||||||
from charmhelpers.contrib.openstack import neutron
|
from charmhelpers.contrib.openstack import neutron
|
||||||
from charmhelpers.contrib.openstack import utils
|
from charmhelpers.contrib.openstack import utils
|
||||||
|
import charmhelpers.core.unitdata
|
||||||
|
|
||||||
from unit_tests.test_utils import CharmTestCase
|
from unit_tests.test_utils import CharmTestCase
|
||||||
|
|
||||||
TO_PATCH = [
|
TO_PATCH = [
|
||||||
@ -41,6 +43,13 @@ def fake_log(msg, level=None):
|
|||||||
|
|
||||||
|
|
||||||
class NovaComputeContextTests(CharmTestCase):
|
class NovaComputeContextTests(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NovaComputeContextTests, self).setUp(context, TO_PATCH)
|
super(NovaComputeContextTests, self).setUp(context, TO_PATCH)
|
||||||
self.relation_get.side_effect = self.test_relation.get
|
self.relation_get.side_effect = self.test_relation.get
|
||||||
|
@ -19,6 +19,7 @@ import tempfile
|
|||||||
from unit_tests.test_utils import CharmTestCase
|
from unit_tests.test_utils import CharmTestCase
|
||||||
|
|
||||||
import charmhelpers.contrib.hardening.harden as harden
|
import charmhelpers.contrib.hardening.harden as harden
|
||||||
|
import charmhelpers.core.unitdata
|
||||||
|
|
||||||
import hooks.nova_cc_utils as utils
|
import hooks.nova_cc_utils as utils
|
||||||
import hooks.nova_cc_hooks as hooks
|
import hooks.nova_cc_hooks as hooks
|
||||||
@ -96,6 +97,12 @@ FAKE_KS_AUTH_CFG = {
|
|||||||
|
|
||||||
class NovaCCHooksTests(CharmTestCase):
|
class NovaCCHooksTests(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NovaCCHooksTests, self).setUp(hooks, TO_PATCH)
|
super(NovaCCHooksTests, self).setUp(hooks, TO_PATCH)
|
||||||
(tmpfd, hooks.NOVA_CONSOLEAUTH_OVERRIDE) = tempfile.mkstemp()
|
(tmpfd, hooks.NOVA_CONSOLEAUTH_OVERRIDE) = tempfile.mkstemp()
|
||||||
|
@ -16,6 +16,8 @@ from collections import OrderedDict
|
|||||||
from mock import patch, MagicMock, call
|
from mock import patch, MagicMock, call
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import charmhelpers.core.unitdata
|
||||||
|
|
||||||
from unit_tests.test_utils import (
|
from unit_tests.test_utils import (
|
||||||
CharmTestCase,
|
CharmTestCase,
|
||||||
patch_open,
|
patch_open,
|
||||||
@ -247,6 +249,12 @@ NM_CELLS_LIST = b"""
|
|||||||
|
|
||||||
class NovaCCUtilsTests(CharmTestCase):
|
class NovaCCUtilsTests(CharmTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
charmhelpers.core.unitdata._KV = (
|
||||||
|
charmhelpers.core.unitdata.Storage(':memory:'))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(NovaCCUtilsTests, self).setUp(utils, TO_PATCH)
|
super(NovaCCUtilsTests, self).setUp(utils, TO_PATCH)
|
||||||
self.config.side_effect = self.test_config.get
|
self.config.side_effect = self.test_config.get
|
||||||
|
Loading…
Reference in New Issue
Block a user