示例#1
0
    def autocreate_indices(self):
        """Create simple one-column indexes

        This creates indexes for all lookup_table entries and for all defined
        indexes columns in the OVSDB schema, as long as they are simple
        one-column indexes (e.g. 'name') fields.
        """

        tables = set(self.idl.tables.keys())
        # lookup table indices
        for table, (lt, col, uuid_col) in self.lookup_table.items():
            if table != lt or not col or uuid_col or table not in tables:
                # Just handle simple cases where we are looking up a single
                # column on a single table
                continue
            index_name = idlutils.index_name(col)
            try:
                idx = self.idl.tables[table].rows.index_create(index_name)
            except ValueError:
                LOG.debug("lookup_table index %s.%s already exists", table,
                          index_name)
            else:
                idx.add_column(col)
                LOG.debug("Created lookup_table index %s.%s", table,
                          index_name)
            tables.remove(table)

        # Simple ovsdb-schema indices
        for table in self.idl.tables.values():
            if table.name not in tables:
                continue
            col = idlutils.get_index_column(table)
            if not col:
                continue
            index_name = idlutils.index_name(col)
            try:
                idx = table.rows.index_create(index_name)
            except ValueError:
                LOG.debug("schema index %s.%s already exists", table,
                          index_name)
            else:
                idx.add_column(col)
                LOG.debug("Created schema index %s.%s", table.name, index_name)
            tables.remove(table.name)
示例#2
0
    def test_index_name(self):
        expected = {
            ('one',): 'one',
            ('abc', 'def'): 'abc_def',
            ('def', 'abc'): 'abc_def',
            ('one', 'two', 'three'): 'one_three_two',
        }
        for args, result in expected.items():
            self.assertEqual(result, idlutils.index_name(*args))

        self.assertRaises(AssertionError, idlutils.index_name)
示例#3
0
    def create_index(self, table, *columns):
        """Create a multi-column index on a table

        :param table:   The table on which to create an index
        :type table:    string
        :param columns: The columns in the index
        :type columns:  string
        """

        index_name = idlutils.index_name(*columns)
        idx = self.tables[table].rows.index_create(index_name)
        idx.add_columns(*columns)