Ejemplo n.º 1
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()
        self.sudo_enabled = base.bool_from_env('OS_SUDO_TESTING')
        self.fail_on_missing_deps = (
            base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'))

        self.root_helper = os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD)
        config.register_root_helper(cfg.CONF)
        cfg.CONF.set_override('root_helper', self.root_helper, group='AGENT')
Ejemplo n.º 2
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()
        self.sudo_enabled = base.bool_from_env('OS_SUDO_TESTING')
        self.fail_on_missing_deps = (
            base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'))

        self.root_helper = os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD)
        config.register_root_helper(cfg.CONF)
        cfg.CONF.set_override('root_helper', self.root_helper, group='AGENT')
Ejemplo n.º 3
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()

        if not base.bool_from_env('OS_SUDO_TESTING'):
            self.skipTest('Testing with sudo is not enabled')

        self.fail_on_missing_deps = (
            base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'))

        config.register_root_helper(cfg.CONF)
        self.config(group='AGENT',
                    root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
Ejemplo n.º 4
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()

        if not base.bool_from_env('OS_SUDO_TESTING'):
            self.skipTest('Testing with sudo is not enabled')

        self.fail_on_missing_deps = (
            base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'))

        config.register_root_helper(cfg.CONF)
        self.config(group='AGENT',
                    root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
Ejemplo n.º 5
0
    def cleanup_core_plugin(self):
        """Ensure that the core plugin is deallocated."""
        nm = manager.NeutronManager
        if not nm.has_instance():
            return

        # TODO(marun) Fix plugins that do not properly initialize notifiers
        agentschedulers_db.AgentSchedulerDbMixin.agent_notifiers = {}

        # Perform a check for deallocation only if explicitly
        # configured to do so since calling gc.collect() after every
        # test increases test suite execution time by ~50%.
        check_plugin_deallocation = (
            base.bool_from_env('OS_CHECK_PLUGIN_DEALLOCATION'))
        if check_plugin_deallocation:
            plugin = weakref.ref(nm._instance.plugin)

        nm.clear_instance()

        if check_plugin_deallocation:
            gc.collect()

            # TODO(marun) Ensure that mocks are deallocated?
            if plugin() and not isinstance(plugin(), mock.Base):
                self.fail('The plugin for this test was not deallocated.')
Ejemplo n.º 6
0
class PostgreSQLTestCase(test_base.PostgreSQLOpportunisticTestCase):
    """Base test class for PostgreSQL tests.

    If the PostgreSQL db is unavailable then this test is skipped, unless
    OS_FAIL_ON_MISSING_DEPS is enabled.
    """
    SKIP_ON_UNAVAILABLE_DB = not base.bool_from_env('OS_FAIL_ON_MISSING_DEPS')
Ejemplo n.º 7
0
    def cleanup_core_plugin(self):
        """Ensure that the core plugin is deallocated."""
        nm = manager.NeutronManager
        if not nm.has_instance():
            return

        # TODO(marun) Fix plugins that do not properly initialize notifiers
        agentschedulers_db.AgentSchedulerDbMixin.agent_notifiers = {}

        # Perform a check for deallocation only if explicitly
        # configured to do so since calling gc.collect() after every
        # test increases test suite execution time by ~50%.
        check_plugin_deallocation = (
            base.bool_from_env('OS_CHECK_PLUGIN_DEALLOCATION'))
        if check_plugin_deallocation:
            plugin = weakref.ref(nm._instance.plugin)

        nm.clear_instance()

        if check_plugin_deallocation:
            gc.collect()

            # TODO(marun) Ensure that mocks are deallocated?
            if plugin() and not isinstance(plugin(), mock.Base):
                self.fail('The plugin for this test was not deallocated.')
Ejemplo n.º 8
0
 def setUp(self):
     super(BaseSudoTestCase, self).setUp()
     if not base.bool_from_env('OS_SUDO_TESTING'):
         self.skipTest('Testing with sudo is not enabled')
     self.setup_rootwrap()
     config.setup_privsep()
     self._override_default_config()
Ejemplo n.º 9
0
 def wrapper(*args, **kwargs):
     try:
         return wrapped(*args, **kwargs)
     except (testtools.TestCase.skipException, unittest.case.SkipTest) as e:
         if base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'):
             tools.fail(
                 '%s cannot be skipped because OS_FAIL_ON_MISSING_DEPS '
                 'is enabled, skip reason: %s' % (wrapped.__name__, e))
         raise
Ejemplo n.º 10
0
 def wrapper(*args, **kwargs):
     try:
         return wrapped(*args, **kwargs)
     except (testtools.TestCase.skipException, unittest.case.SkipTest) as e:
         if base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'):
             tools.fail(
                 '%s cannot be skipped because OS_FAIL_ON_MISSING_DEPS '
                 'is enabled, skip reason: %s' % (wrapped.__name__, e))
         raise
Ejemplo n.º 11
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()
        if not base.bool_from_env('OS_SUDO_TESTING'):
            self.skipTest('Testing with sudo is not enabled')

        config.register_root_helper(cfg.CONF)
        self.config(group='AGENT',
                    root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
        self.config(
            group='AGENT',
            root_helper_daemon=os.environ.get('OS_ROOTWRAP_DAEMON_CMD'))
Ejemplo n.º 12
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()
        if not base.bool_from_env('OS_SUDO_TESTING'):
            self.skipTest('Testing with sudo is not enabled')

        config.register_root_helper(cfg.CONF)
        self.config(group='AGENT',
                    root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
        self.config(group='AGENT',
                    root_helper_daemon=os.environ.get(
                        'OS_ROOTWRAP_DAEMON_CMD'))
Ejemplo n.º 13
0
class OpportunisticDBTestMixin(object):
    """Mixin that converts a BaseSqlTestCase to use the
    OpportunisticSqlFixture.
    """

    SKIP_ON_UNAVAILABLE_DB = not base.bool_from_env('OS_FAIL_ON_MISSING_DEPS')

    FIXTURE = OpportunisticSqlFixture

    BUILD_WITH_MIGRATIONS = False

    def _setup_database_fixtures(self):
        self.useFixture(self.FIXTURE(self))

        if not hasattr(self, 'db'):
            msg = "backend '%s' unavailable" % self.DRIVER
            if self.SKIP_ON_UNAVAILABLE_DB:
                self.skipTest(msg)
            else:
                self.fail(msg)

    _schema_resources = {}
    _database_resources = {}

    @property
    def resources(self):
        """this attribute is used by testresources for optimized
        sorting of tests.

        This is the big requirement that allows testresources to sort
        tests such that database "resources" can be kept open for
        many tests at once.

        IMO(zzzeek) "sorting" should not be needed; only that necessary
        resources stay open as long as they are needed (or long enough to
        reduce overhead).  testresources would be improved to not depend on
        custom, incompatible-with-pytest "suite classes", fixture information
        leaking out of the Fixture classes themselves, and exotic sorting
        schemes for something that can nearly always be handled "good enough"
        with unittest-standard setupclass/setupmodule schemes.

        """

        return self.FIXTURE.resources_collection(self)
Ejemplo n.º 14
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()
        if not base.bool_from_env('OS_SUDO_TESTING'):
            self.skipTest('Testing with sudo is not enabled')

        # Have each test log into its own log file
        cfg.CONF.set_override('debug', True)
        common_utils.ensure_dir(DEFAULT_LOG_DIR)
        log_file = base.sanitize_log_path(
            os.path.join(DEFAULT_LOG_DIR, "%s.log" % self.id()))
        cfg.CONF.set_override('log_file', log_file)
        config.setup_logging()

        config.register_root_helper(cfg.CONF)
        self.config(group='AGENT',
                    root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
        self.config(group='AGENT',
                    root_helper_daemon=os.environ.get(
                        'OS_ROOTWRAP_DAEMON_CMD'))
Ejemplo n.º 15
0
    def setUp(self):
        super(BaseSudoTestCase, self).setUp()
        if not base.bool_from_env('OS_SUDO_TESTING'):
            self.skipTest('Testing with sudo is not enabled')

        # Have each test log into its own log file
        cfg.CONF.set_override('debug', True)
        common_utils.ensure_dir(DEFAULT_LOG_DIR)
        log_file = base.sanitize_log_path(
            os.path.join(DEFAULT_LOG_DIR, "%s.log" % self.id()))
        cfg.CONF.set_override('log_file', log_file)
        config.setup_logging()

        config.register_root_helper(cfg.CONF)
        self.config(group='AGENT',
                    root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
        self.config(
            group='AGENT',
            root_helper_daemon=os.environ.get('OS_ROOTWRAP_DAEMON_CMD'))
Ejemplo n.º 16
0
def rest_enabled():
    return tests_base.bool_from_env('OS_TEST_API_WITH_REST')
Ejemplo n.º 17
0
 def setUp(self):
     super(BaseSudoTestCase, self).setUp()
     self.sudo_enabled = base.bool_from_env('OS_SUDO_TESTING')
     self.root_helper = os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD)
     self.fail_on_missing_deps = (
         base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'))