def test_load_driver_with_external_opts(self, m_driver_manager):
        m_driver_manager.return_value = DriverManager.make_test_instance(
            extension=Extension(
                name=FakeDriverWithExternalOpts.get_name(),
                entry_point="%s:%s" % (FakeDriverWithExternalOpts.__module__,
                                       FakeDriverWithExternalOpts.__name__),
                plugin=FakeDriverWithExternalOpts,
                obj=None,
            ),
            namespace=FakeDriverWithExternalOpts.namespace(),
        )

        loader_manager = DriverLoader(
            conf=cfg.CONF,
            namespace='TESTING',
            name='fake_with_ext_opts'
        )
        loaded_driver = loader_manager.load()

        self.assertEqual(
            hasattr(loaded_driver, "fake__test_external_opt"),
            True
        )
        self.assertEqual(
            loaded_driver.fake__test_external_opt,
            "fake_with_ext_opts"
        )
    def setUp(self):
        super(TestDriverLoader, self).setUp()
        # To load the drivers without using the config file
        self.useFixture(ConfFixture())

        def _fake_parse(self, *args, **kw):
            return cfg.ConfigOpts._parse_cli_opts(cfg.CONF, [])

        cfg.CONF._parse_cli_opts = _fake_parse

        # First dependency to be returned
        self.no_group_driver_manager = DriverManager.make_test_instance(
            extension=Extension(
                name=FakeDriverNoGroup.get_name(),
                entry_point="%s:%s" % (FakeDriverNoGroup.__module__,
                                       FakeDriverNoGroup.__name__),
                plugin=FakeDriverNoGroup,
                obj=None,
            ),
            namespace=FakeDriverNoGroup.namespace(),
        )

        # 2nd dependency to be returned
        self.with_ext_opts_driver_manager = DriverManager.make_test_instance(
            extension=Extension(
                name=FakeDriverWithExternalOpts.get_name(),
                entry_point="%s:%s" % (FakeDriverWithExternalOpts.__module__,
                                       FakeDriverWithExternalOpts.__name__),
                plugin=FakeDriverWithExternalOpts,
                obj=None,
            ),
            namespace=FakeDriverWithExternalOpts.namespace(),
        )

        self.patches.extend([
            # patch.object(cfg, "ConfigOpts", ),
        ])

        # Applies all of our patches before each test
        for _patch in self.patches:
            _patch.start()
Exemple #3
0
    def setUp(self):
        super(TestDriverLoader, self).setUp()
        # To load the drivers without using the config file
        self.useFixture(ConfFixture())

        def _fake_parse(self, *args, **kw):
            return cfg.ConfigOpts._parse_cli_opts(cfg.CONF, [])

        cfg.CONF._parse_cli_opts = _fake_parse

        # First dependency to be returned
        self.no_group_driver_manager = DriverManager.make_test_instance(
            extension=Extension(
                name=FakeDriverNoGroup.get_name(),
                entry_point="%s:%s" %
                (FakeDriverNoGroup.__module__, FakeDriverNoGroup.__name__),
                plugin=FakeDriverNoGroup,
                obj=None,
            ),
            namespace=FakeDriverNoGroup.namespace(),
        )

        # 2nd dependency to be returned
        self.with_ext_opts_driver_manager = DriverManager.make_test_instance(
            extension=Extension(
                name=FakeDriverWithExternalOpts.get_name(),
                entry_point="%s:%s" % (FakeDriverWithExternalOpts.__module__,
                                       FakeDriverWithExternalOpts.__name__),
                plugin=FakeDriverWithExternalOpts,
                obj=None,
            ),
            namespace=FakeDriverWithExternalOpts.namespace(),
        )

        self.patches.extend([
            # patch.object(cfg, "ConfigOpts", ),
        ])

        # Applies all of our patches before each test
        for _patch in self.patches:
            _patch.start()
Exemple #4
0
    def test_load_driver_with_external_opts(self, m_driver_manager):
        m_driver_manager.return_value = DriverManager.make_test_instance(
            extension=Extension(
                name=FakeDriverWithExternalOpts.get_name(),
                entry_point="%s:%s" % (FakeDriverWithExternalOpts.__module__,
                                       FakeDriverWithExternalOpts.__name__),
                plugin=FakeDriverWithExternalOpts,
                obj=None,
            ),
            namespace=FakeDriverWithExternalOpts.namespace(),
        )

        loader_manager = DriverLoader(conf=cfg.CONF,
                                      namespace='TESTING',
                                      name='fake_with_ext_opts')
        loaded_driver = loader_manager.load()

        self.assertEqual(hasattr(loaded_driver, "fake__test_external_opt"),
                         True)
        self.assertEqual(loaded_driver.fake__test_external_opt,
                         "fake_with_ext_opts")