import contextlib
import gc
-import logging as std_logging
import os
import os.path
import random
from oslo_config import cfg
from oslo_messaging import conffixture as messaging_conffixture
from oslo_utils import strutils
+from oslotest import base
import six
-import testtools
from neutron._i18n import _
from neutron.agent.linux import external_process
CONF = cfg.CONF
CONF.import_opt('state_path', 'neutron.common.config')
-LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s"
ROOTDIR = os.path.dirname(__file__)
ETCDIR = os.path.join(ROOTDIR, 'etc')
return strutils.bool_from_string(value, strict=strict, default=default)
-def get_test_timeout(default=0):
- return int(os.environ.get('OS_TEST_TIMEOUT', 0))
-
-
def sanitize_log_path(path):
# Sanitize the string so that its log path is shell friendly
return path.replace(' ', '-').replace('(', '_').replace(')', '_')
raise AttributeError(_("Unknown attribute '%s'.") % name)
-class DietTestCase(testtools.TestCase):
+class DietTestCase(base.BaseTestCase):
"""Same great taste, less filling.
BaseTestCase is responsible for doing lots of plugin-centric setup
# Make sure we see all relevant deprecation warnings when running tests
self.useFixture(tools.WarningsFixture())
- if bool_from_env('OS_DEBUG'):
- _level = std_logging.DEBUG
- else:
- _level = std_logging.INFO
- capture_logs = bool_from_env('OS_LOG_CAPTURE')
- if not capture_logs:
- std_logging.basicConfig(format=LOG_FORMAT, level=_level)
- self.log_fixture = self.useFixture(
- fixtures.FakeLogger(
- format=LOG_FORMAT,
- level=_level,
- nuke_handlers=capture_logs,
- ))
-
- test_timeout = get_test_timeout()
- if test_timeout == -1:
- test_timeout = 0
- if test_timeout > 0:
- self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
-
- # If someone does use tempfile directly, ensure that it's cleaned up
- self.useFixture(fixtures.NestedTempfile())
- self.useFixture(fixtures.TempHomeDir())
-
+ # NOTE(ihrachys): oslotest already sets stopall for cleanup, but it
+ # does it using six.moves.mock (the library was moved into
+ # unittest.mock in Python 3.4). So until we switch to six.moves.mock
+ # everywhere in unit tests, we can't remove this setup. The base class
+ # is used in 3party projects, so we would need to switch all of them to
+ # six before removing the cleanup callback from here.
self.addCleanup(mock.patch.stopall)
- if bool_from_env('OS_STDOUT_CAPTURE'):
- stdout = self.useFixture(fixtures.StringStream('stdout')).stream
- self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
- if bool_from_env('OS_STDERR_CAPTURE'):
- stderr = self.useFixture(fixtures.StringStream('stderr')).stream
- self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
-
self.addOnException(self.check_for_systemexit)
self.orig_pid = os.getpid()
def setUp(self):
super(BaseTestCase, self).setUp()
- # suppress all but errors here
- capture_logs = bool_from_env('OS_LOG_CAPTURE')
- self.useFixture(
- fixtures.FakeLogger(
- name='neutron.api.extensions',
- format=LOG_FORMAT,
- level=std_logging.ERROR,
- nuke_handlers=capture_logs,
- ))
-
self.useFixture(lockutils.ExternalLockFixture())
cfg.CONF.set_override('state_path', self.get_default_temp_dir().path)
from neutron.agent.linux import ovsdb_monitor
from neutron.agent.linux import utils
-from neutron.tests import base as tests_base
from neutron.tests.common import net_helpers
from neutron.tests.functional.agent.linux import base as linux_base
from neutron.tests.functional import base as functional_base
self.monitor = ovsdb_monitor.SimpleInterfaceMonitor()
self.addCleanup(self.monitor.stop)
- # In case a global test timeout isn't set or disabled, use a
- # value that will ensure the monitor has time to start.
- timeout = max(tests_base.get_test_timeout(), 60)
- self.monitor.start(block=True, timeout=timeout)
+ self.monitor.start(block=True, timeout=60)
def test_has_updates(self):
utils.wait_until_true(lambda: self.monitor.has_updates)
# License for the specific language governing permissions and limitations
# under the License.
-import fixtures
import mock
from oslo_db import exception as exc
-from oslo_log import log as logging
from sqlalchemy.orm import query
import neutron.db.api as db
-from neutron.plugins.ml2.drivers import helpers
from neutron.plugins.ml2.drivers import type_vlan
-from neutron.tests import base
from neutron.tests.unit import testlib_api
self.driver.network_vlan_ranges = NETWORK_VLAN_RANGES
self.driver._sync_vlan_allocations()
self.session = db.get_session()
- self.useFixture(
- fixtures.FakeLogger(
- name=helpers.__name__,
- format=base.LOG_FORMAT,
- level=logging.DEBUG
- ))
def check_raw_segment(self, expected, observed):
for key, value in expected.items():