Пример #1
0
    def setUp(self):
        super(TestCase, self).setUp()

        # Manage required configuration
        conf_fixture = self.useFixture(config_fixture.Config(CONF))
        # The Database fixture will get confused if only one of the databases
        # is configured.
        for group in ('placement_database', 'api_database', 'database'):
            conf_fixture.config(group=group,
                                connection='sqlite://',
                                sqlite_synchronous=False)
        CONF([], default_config_files=[])

        self.useFixture(policy_fixture.PlacementPolicyFixture())

        self.useFixture(capture.Logging())
        self.useFixture(output.CaptureOutput())
        # Filter ignorable warnings during test runs.
        self.useFixture(capture.WarningsFixture())

        self.placement_db = self.useFixture(
            fixtures.Database(database='placement'))
        self._reset_database()
        self.context = context.RequestContext()
        # Do database syncs, such as traits sync.
        deploy.update_database()
        self.addCleanup(self._reset_database)
Пример #2
0
 def setUp(self):
     super(TestPlacementFixture, self).setUp()
     # We need ConfFixture since PlacementPolicyFixture reads from config.
     self.useFixture(conf_fixture.ConfFixture())
     # We need PlacementPolicyFixture because placement-api checks policy.
     self.useFixture(policy_fixture.PlacementPolicyFixture())
     # Database is needed to start placement API
     self.useFixture(fixtures.Database(database='placement'))
Пример #3
0
 def test_authorize_do_raise_false(self):
     """Tests that authorize does not raise an exception when the check
     fails.
     """
     fixture = self.useFixture(policy_fixture.PlacementPolicyFixture())
     fixture.set_rules({'placement': '!'})
     self.assertFalse(
         policy.authorize(
             self.ctxt, 'placement', self.target, do_raise=False))
Пример #4
0
 def start_fixture(self):
     super(OpenPolicyFixture, self).start_fixture()
     self.placement_policy_fixture = policy_fixture.PlacementPolicyFixture()
     self.placement_policy_fixture.setUp()
     # Get all of the registered rules and set them to '@' to allow any
     # user to have access. The nova policy "admin_or_owner" concept does
     # not really apply to most of placement resources since they do not
     # have a user_id/project_id attribute.
     rules = {}
     for rule in policies.list_rules():
         name = rule.name
         # Ignore "base" rules for role:admin.
         if name in ['placement', 'admin_api']:
             continue
         rules[name] = '@'
     self.placement_policy_fixture.set_rules(rules)
Пример #5
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self.useFixture(
            nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0),
                                  self.TIMEOUT_SCALING_FACTOR))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.output = nova_fixtures.OutputStreamCapture()
        self.useFixture(self.output)

        self.stdlog = nova_fixtures.StandardLogging()
        self.useFixture(self.stdlog)

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we ended up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path, group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        if self.STUB_RPC:
            self.useFixture(nova_fixtures.RPCFixture('nova.test'))

        # we cannot set this in the ConfFixture as oslo only registers the
        # notification opts at the first instantiation of a Notifier that
        # happens only in the RPCFixture
        CONF.set_default('driver', ['test'],
                         group='oslo_messaging_notifications')

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)
        objects.Service.clear_min_version_cache()

        # NOTE(danms): Reset the cached list of cells
        from nova.compute import api
        api.CELLS = []
        context.CELL_CACHE = {}
        context.CELLS = []

        self.cell_mappings = {}
        self.host_mappings = {}
        # NOTE(danms): If the test claims to want to set up the database
        # itself, then it is responsible for all the mapping stuff too.
        if self.USES_DB:
            # NOTE(danms): Full database setup involves a cell0, cell1,
            # and the relevant mappings.
            self.useFixture(nova_fixtures.Database(database='api'))
            self.useFixture(nova_fixtures.Database(database='placement'))
            self._setup_cells()
            self.useFixture(nova_fixtures.DefaultFlavorsFixture())
        elif not self.USES_DB_SELF:
            # NOTE(danms): If not using the database, we mock out the
            # mapping stuff and effectively collapse everything to a
            # single cell.
            self.useFixture(nova_fixtures.SingleCellSimple())
            self.useFixture(nova_fixtures.DatabasePoisonFixture())

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(nova_fixtures.WarningsFixture())

        self.useFixture(ovo_fixture.StableObjectJsonFixture())

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        # Reset the traits sync and rc cache flags
        def _reset_traits():
            resource_provider._TRAITS_SYNCED = False

        _reset_traits()
        self.addCleanup(_reset_traits)
        resource_provider._RC_CACHE = None
        # Reset the global QEMU version flag.
        images.QEMU_VERSION = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        self.placement_policy = self.useFixture(
            policy_fixture.PlacementPolicyFixture())

        self.useFixture(nova_fixtures.PoisonFunctions())

        openstack_driver.DRIVER_CACHE = {}

        self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())

        # NOTE(mikal): make sure we don't load a privsep helper accidentally
        self.useFixture(nova_fixtures.PrivsepNoHelperFixture())
        self.useFixture(mock_fixture.MockAutospecFixture())

        # FIXME(danms): Disable this for all tests by default to avoid breaking
        # any that depend on default/previous ordering
        self.flags(build_failure_weight_multiplier=0.0,
                   group='filter_scheduler')
Пример #6
0
 def setUp(self):
     super(TestPlacementFixture, self).setUp()
     # We need ConfFixture since PlacementPolicyFixture reads from config.
     self.useFixture(conf_fixture.ConfFixture())
     # We need PlacementPolicyFixture because placement-api checks policy.
     self.useFixture(policy_fixture.PlacementPolicyFixture())