Пример #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.PolicyFixture())

        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 generate_schema_create_all(self, engine):
        # note: at this point in oslo_db's fixtures, the incoming
        # Engine has **not** been associated with the global
        # context manager yet.
        migration.create_schema(engine)

        # Clear the graph DB
        graph_db.delete_all()
        # Create the constraints. Eventually this should be moved to somewhere
        # higher-level, but for now this is good enough for tests.
        constraints = [
            "CREATE CONSTRAINT ON (rp:RESOURCE_PROVIDER) ASSERT rp.uuid "
            "IS UNIQUE",
            "CREATE CONSTRAINT ON (rp:RESOURCE_PROVIDER) ASSERT rp.name "
            "IS UNIQUE",
            "CREATE CONSTRAINT ON (rc:RESOURCE_CLASS) ASSERT rc.name "
            "IS UNIQUE",
            "CREATE CONSTRAINT ON (t:TRAIT) ASSERT t.name IS UNIQUE",
            "CREATE CONSTRAINT ON (pj:PROJECT) ASSERT pj.uuid IS UNIQUE",
            "CREATE CONSTRAINT ON (u:USER) ASSERT u.uuid IS UNIQUE",
            "CREATE CONSTRAINT ON (cs:CONSUMER) ASSERT cs.uuid IS UNIQUE",
        ]
        for constraint in constraints:
            graph_db.execute(constraint)

        # Make sure db flags are correct at both the start and finish
        # of the test.
        self.addCleanup(self.cleanup)
        self.cleanup()

        # Sync traits and resource classes.
        deploy.update_database(self.conf_fixture.conf)
Пример #3
0
    def start_fixture(self):
        # Set up stderr and stdout captures by directly driving the
        # existing nova fixtures that do that. This captures the
        # output that happens outside individual tests (for
        # example database migrations).
        self.standard_logging_fixture = fixtures.StandardLogging()
        self.standard_logging_fixture.setUp()
        self.output_stream_fixture = fixtures.OutputStreamCapture()
        self.output_stream_fixture.setUp()

        self.conf = CONF
        self.conf.set_override('auth_strategy', 'noauth2', group='api')
        # Be explicit about all three database connections to avoid
        # potential conflicts with config on disk.
        self.conf.set_override('connection', "sqlite://", group='database')
        self.conf.set_override('connection', "sqlite://",
                               group='api_database')
        self.conf.set_override('connection', "sqlite://",
                               group='placement_database')

        # Register CORS opts, but do not set config. This has the
        # effect of exercising the "don't use cors" path in
        # deploy.py. Without setting some config the group will not
        # be present.
        self.conf.register_opts(cors.CORS_OPTS, 'cors')

        # Make sure default_config_files is an empty list, not None.
        # If None /etc/nova/nova.conf is read and confuses results.
        config.parse_args([], default_config_files=[], configure_db=False,
                          init_rpc=False)

        # NOTE(cdent): All three database fixtures need to be
        # managed for database handling to work and not cause
        # conflicts with other tests in the same process.
        self._reset_db_flags()
        self.placement_db_fixture = fixtures.Database('placement')
        self.api_db_fixture = fixtures.Database('api')
        self.main_db_fixture = fixtures.Database('main')
        self.placement_db_fixture.reset()
        self.api_db_fixture.reset()
        self.main_db_fixture.reset()
        # Do this now instead of waiting for the WSGI app to start so that
        # fixtures can have traits.
        deploy.update_database()

        os.environ['RP_UUID'] = uuidutils.generate_uuid()
        os.environ['RP_NAME'] = uuidutils.generate_uuid()
        os.environ['CUSTOM_RES_CLASS'] = 'CUSTOM_IRON_NFV'
        os.environ['PROJECT_ID'] = uuidutils.generate_uuid()
        os.environ['USER_ID'] = uuidutils.generate_uuid()
        os.environ['PROJECT_ID_ALT'] = uuidutils.generate_uuid()
        os.environ['USER_ID_ALT'] = uuidutils.generate_uuid()
        os.environ['INSTANCE_UUID'] = uuidutils.generate_uuid()
        os.environ['MIGRATION_UUID'] = uuidutils.generate_uuid()
        os.environ['CONSUMER_UUID'] = uuidutils.generate_uuid()
        os.environ['PARENT_PROVIDER_UUID'] = uuidutils.generate_uuid()
        os.environ['ALT_PARENT_PROVIDER_UUID'] = uuidutils.generate_uuid()
Пример #4
0
    def start_fixture(self):
        # Set up stderr and stdout captures by directly driving the
        # existing nova fixtures that do that. This captures the
        # output that happens outside individual tests (for
        # example database migrations).
        self.standard_logging_fixture = capture.Logging()
        self.standard_logging_fixture.setUp()
        self.output_stream_fixture = output.CaptureOutput()
        self.output_stream_fixture.setUp()
        # Filter ignorable warnings during test runs.
        self.warnings_fixture = capture.WarningsFixture()
        self.warnings_fixture.setUp()

        self.conf_fixture = config_fixture.Config(CONF)
        self.conf_fixture.setUp()
        # The Database fixture will get confused if only one of the databases
        # is configured.
        for group in ('placement_database', 'api_database', 'database'):
            self.conf_fixture.config(group=group,
                                     connection='sqlite://',
                                     sqlite_synchronous=False)
        self.conf_fixture.config(group='api', auth_strategy='noauth2')

        self.context = context.RequestContext()

        # Register CORS opts, but do not set config. This has the
        # effect of exercising the "don't use cors" path in
        # deploy.py. Without setting some config the group will not
        # be present.
        CONF.register_opts(cors.CORS_OPTS, 'cors')
        # Set default policy opts, otherwise the deploy module can
        # NoSuchOptError.
        policy_opts.set_defaults(CONF)

        # Make sure default_config_files is an empty list, not None.
        # If None /etc/nova/nova.conf is read and confuses results.
        CONF([], default_config_files=[])

        self._reset_db_flags()
        self.placement_db_fixture = fixtures.Database('placement')
        self.placement_db_fixture.setUp()
        # Do this now instead of waiting for the WSGI app to start so that
        # fixtures can have traits.
        deploy.update_database()

        os.environ['RP_UUID'] = uuidutils.generate_uuid()
        os.environ['RP_NAME'] = uuidutils.generate_uuid()
        os.environ['CUSTOM_RES_CLASS'] = 'CUSTOM_IRON_NFV'
        os.environ['PROJECT_ID'] = uuidutils.generate_uuid()
        os.environ['USER_ID'] = uuidutils.generate_uuid()
        os.environ['PROJECT_ID_ALT'] = uuidutils.generate_uuid()
        os.environ['USER_ID_ALT'] = uuidutils.generate_uuid()
        os.environ['INSTANCE_UUID'] = uuidutils.generate_uuid()
        os.environ['MIGRATION_UUID'] = uuidutils.generate_uuid()
        os.environ['CONSUMER_UUID'] = uuidutils.generate_uuid()
        os.environ['PARENT_PROVIDER_UUID'] = uuidutils.generate_uuid()
        os.environ['ALT_PARENT_PROVIDER_UUID'] = uuidutils.generate_uuid()
Пример #5
0
    def generate_schema_create_all(self, engine):
        # note: at this point in oslo_db's fixtures, the incoming
        # Engine has **not** been associated with the global
        # context manager yet.
        migration.create_schema(engine)

        # so, to work around that placement's setup code really wants to
        # use the enginefacade, we will patch the engine into it early.
        # oslo_db is going to patch it anyway later.  So the bug in oslo.db
        # is that code these days really wants the facade to be set up fully
        # when it's time to create the database.  When oslo_db's fixtures
        # were written, enginefacade was not in use yet so it was not
        # anticipated that everyone would be doing things this way
        _reset_facade = placement_db.placement_context_manager.patch_engine(
            engine)
        self.addCleanup(_reset_facade)

        # Make sure db flags are correct at both the start and finish
        # of the test.
        self.addCleanup(self.cleanup)
        self.cleanup()

        # Sync traits and resource classes.
        deploy.update_database(self.conf_fixture.conf)