Ejemplo n.º 1
0
    def test_db_version_alembic(self):
        engine = enginefacade.writer.get_engine()

        with mock.patch.object(migration, '_get_engine', return_value=engine):
            migration.db_sync(database='main')

            script = alembic_script.ScriptDirectory.from_config(self.config)
            head = script.get_current_head()
            self.assertEqual(head, migration.db_version(database='main'))
Ejemplo n.º 2
0
def setup():
    import mox  # Fail fast if you don't have mox. Workaround for bug 810424

    from nova import rpc  # Register rpc_backend before fake_flags sets it

    FLAGS.register_opts(rpc.rpc_opts)

    from nova import context
    from nova import db
    from nova.db import migration
    from nova.network import manager as network_manager
    from nova.tests import fake_flags

    fake_flags.set_defaults(FLAGS)
    rpc.register_opts(FLAGS)

    if FLAGS.sql_connection == "sqlite://":
        if migration.db_version() > migration.INIT_VERSION:
            return
    else:
        testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
        if os.path.exists(testdb):
            return
    migration.db_sync()
    ctxt = context.get_admin_context()
    network = network_manager.VlanManager()
    bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
    network.create_networks(
        ctxt,
        label="test",
        cidr=FLAGS.fixed_range,
        multi_host=FLAGS.multi_host,
        num_networks=FLAGS.num_networks,
        network_size=FLAGS.network_size,
        cidr_v6=FLAGS.fixed_range_v6,
        gateway=FLAGS.gateway,
        gateway_v6=FLAGS.gateway_v6,
        bridge=FLAGS.flat_network_bridge,
        bridge_interface=bridge_interface,
        vpn_start=FLAGS.vpn_start,
        vlan_start=FLAGS.vlan_start,
        dns1=FLAGS.flat_network_dns,
    )
    for net in db.network_get_all(ctxt):
        network.set_network_host(ctxt, net)

    if FLAGS.sql_connection == "sqlite://":
        global _DB
        engine = get_engine()
        conn = engine.connect()
        _DB = "".join(line for line in conn.connection.iterdump())
    else:
        cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
        shutil.copyfile(testdb, cleandb)
Ejemplo n.º 3
0
def setup():
    import mox  # Fail fast if you don't have mox. Workaround for bug 810424

    from nova import rpc  # Register rpc_backend before fake_flags sets it
    FLAGS.register_opts(rpc.rpc_opts)

    from nova import context
    from nova import db
    from nova.db import migration
    from nova.network import manager as network_manager
    from nova.tests import fake_flags
    rpc.register_opts(FLAGS)

    if FLAGS.sql_connection == "sqlite://":
        if migration.db_version() > migration.INIT_VERSION:
            return
    else:
        testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
        if os.path.exists(testdb):
            return
    migration.db_sync()
    ctxt = context.get_admin_context()
    network = network_manager.VlanManager()
    bridge_interface = FLAGS.flat_interface or FLAGS.vlan_interface
    network.create_networks(ctxt,
                            label='test',
                            cidr=FLAGS.fixed_range,
                            multi_host=FLAGS.multi_host,
                            num_networks=FLAGS.num_networks,
                            network_size=FLAGS.network_size,
                            cidr_v6=FLAGS.fixed_range_v6,
                            gateway=FLAGS.gateway,
                            gateway_v6=FLAGS.gateway_v6,
                            bridge=FLAGS.flat_network_bridge,
                            bridge_interface=bridge_interface,
                            vpn_start=FLAGS.vpn_start,
                            vlan_start=FLAGS.vlan_start,
                            dns1=FLAGS.flat_network_dns)
    for net in db.network_get_all(ctxt):
        network.set_network_host(ctxt, net)

    if FLAGS.sql_connection == "sqlite://":
        global _DB
        engine = get_engine()
        conn = engine.connect()
        _DB = "".join(line for line in conn.connection.iterdump())
    else:
        cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
        shutil.copyfile(testdb, cleandb)
Ejemplo n.º 4
0
    def test_db_version_not_controlled(
        self, mock_find_repo, mock_get_engine, mock_is_migrate,
        mock_is_alembic, mock_migrate_version, mock_m_context_configure,
    ):
        """Database is not controlled."""
        mock_is_migrate.return_value = False
        mock_is_alembic.return_value = False

        ret = migration.db_version()
        self.assertIsNone(ret)

        mock_find_repo.assert_called_once_with('main')
        mock_get_engine.assert_called_once_with('main', context=None)
        mock_is_migrate.assert_called_once()
        mock_is_alembic.assert_called_once()
        mock_migrate_version.assert_not_called()
        mock_m_context_configure.assert_not_called()
Ejemplo n.º 5
0
    def test_db_version_migrate(
        self, mock_find_repo, mock_get_engine, mock_is_migrate,
        mock_is_alembic, mock_migrate_version, mock_m_context_configure,
    ):
        """Database is controlled by sqlalchemy-migrate."""
        mock_is_migrate.return_value = True
        mock_is_alembic.return_value = False

        ret = migration.db_version('main')
        self.assertEqual(mock_migrate_version.return_value, ret)

        mock_find_repo.assert_called_once_with('main')
        mock_get_engine.assert_called_once_with('main', context=None)
        mock_is_migrate.assert_called_once()
        mock_is_alembic.assert_called_once()
        mock_migrate_version.assert_called_once_with(
            mock_get_engine.return_value, mock_find_repo.return_value)
        mock_m_context_configure.assert_not_called()
Ejemplo n.º 6
0
def setup():

    fake_flags.set_defaults(CONF)

    if CONF.sql_connection == "sqlite://":
        if migration.db_version() > migration.INIT_VERSION:
            return
    else:
        testdb = os.path.join(CONF.state_path, CONF.sqlite_db)
        if os.path.exists(testdb):
            return
    migration.db_sync()
    ctxt = context.get_admin_context()
    network = network_manager.VlanManager()
    bridge_interface = CONF.flat_interface or CONF.vlan_interface
    network.create_networks(
        ctxt,
        label="test",
        cidr=CONF.fixed_range,
        multi_host=CONF.multi_host,
        num_networks=CONF.num_networks,
        network_size=CONF.network_size,
        cidr_v6=CONF.fixed_range_v6,
        gateway=CONF.gateway,
        gateway_v6=CONF.gateway_v6,
        bridge=CONF.flat_network_bridge,
        bridge_interface=bridge_interface,
        vpn_start=CONF.vpn_start,
        vlan_start=CONF.vlan_start,
        dns1=CONF.flat_network_dns,
    )
    for net in db.network_get_all(ctxt):
        network.set_network_host(ctxt, net)

    if CONF.sql_connection == "sqlite://":
        global _DB
        engine = get_engine()
        conn = engine.connect()
        _DB = "".join(line for line in conn.connection.iterdump())
    else:
        cleandb = os.path.join(CONF.state_path, CONF.sqlite_clean_db)
        shutil.copyfile(testdb, cleandb)
Ejemplo n.º 7
0
def setup():

    fake_flags.set_defaults(CONF)

    if CONF.sql_connection == "sqlite://":
        if migration.db_version() > migration.INIT_VERSION:
            return
    else:
        testdb = os.path.join(CONF.state_path, CONF.sqlite_db)
        if os.path.exists(testdb):
            return
    migration.db_sync()
    ctxt = context.get_admin_context()
    network = network_manager.VlanManager()
    bridge_interface = CONF.flat_interface or CONF.vlan_interface
    network.create_networks(ctxt,
                            label='test',
                            cidr=CONF.fixed_range,
                            multi_host=CONF.multi_host,
                            num_networks=CONF.num_networks,
                            network_size=CONF.network_size,
                            cidr_v6=CONF.fixed_range_v6,
                            gateway=CONF.gateway,
                            gateway_v6=CONF.gateway_v6,
                            bridge=CONF.flat_network_bridge,
                            bridge_interface=bridge_interface,
                            vpn_start=CONF.vpn_start,
                            vlan_start=CONF.vlan_start,
                            dns1=CONF.flat_network_dns)
    for net in db.network_get_all(ctxt):
        network.set_network_host(ctxt, net)

    if CONF.sql_connection == "sqlite://":
        global _DB
        engine = get_engine()
        conn = engine.connect()
        _DB = "".join(line for line in conn.connection.iterdump())
    else:
        cleandb = os.path.join(CONF.state_path, CONF.sqlite_clean_db)
        shutil.copyfile(testdb, cleandb)
Ejemplo n.º 8
0
    def test_db_version_alembic(self):
        migration.db_sync(database='main')

        script = alembic_script.ScriptDirectory.from_config(self.config)
        head = script.get_current_head()
        self.assertEqual(head, migration.db_version(database='main'))
Ejemplo n.º 9
0
 def version(self):
     """Print the current database version."""
     print(migration.db_version())
Ejemplo n.º 10
0
 def version(self):
     """Print the current database version."""
     print migration.db_version()