Remove deprecated cqlengine keyspace management functions

This commit is contained in:
Adam Holmberg
2015-10-06 14:05:41 -05:00
parent a2d3a9862f
commit 4bd590960a
2 changed files with 8 additions and 80 deletions

View File

@@ -37,58 +37,6 @@ log = logging.getLogger(__name__)
schema_columnfamilies = NamedTable('system', 'schema_columnfamilies')
def create_keyspace(name, strategy_class, replication_factor, durable_writes=True, **replication_values):
"""
*Deprecated - use :func:`create_keyspace_simple` or :func:`create_keyspace_network_topology` instead*
Creates a keyspace
If the keyspace already exists, it will not be modified.
**This function should be used with caution, especially in production environments.
Take care to execute schema modifications in a single context (i.e. not concurrently with other clients).**
*There are plans to guard schema-modifying functions with an environment-driven conditional.*
:param str name: name of keyspace to create
:param str strategy_class: keyspace replication strategy class (:attr:`~.SimpleStrategy` or :attr:`~.NetworkTopologyStrategy`
:param int replication_factor: keyspace replication factor, used with :attr:`~.SimpleStrategy`
:param bool durable_writes: Write log is bypassed if set to False
:param \*\*replication_values: Additional values to ad to the replication options map
"""
if not _allow_schema_modification():
return
msg = "Deprecated. Use create_keyspace_simple or create_keyspace_network_topology instead"
warnings.warn(msg, DeprecationWarning)
log.warning(msg)
cluster = get_cluster()
if name not in cluster.metadata.keyspaces:
# try the 1.2 method
replication_map = {
'class': strategy_class,
'replication_factor': replication_factor
}
replication_map.update(replication_values)
if strategy_class.lower() != 'simplestrategy':
# Although the Cassandra documentation states for `replication_factor`
# that it is "Required if class is SimpleStrategy; otherwise,
# not used." we get an error if it is present.
replication_map.pop('replication_factor', None)
query = """
CREATE KEYSPACE {0}
WITH REPLICATION = {1}
""".format(metadata.protect_name(name), json.dumps(replication_map).replace('"', "'"))
if strategy_class != 'SimpleStrategy':
query += " AND DURABLE_WRITES = {0}".format('true' if durable_writes else 'false')
execute(query)
def create_keyspace_simple(name, replication_factor, durable_writes=True):
"""
Creates a keyspace with SimpleStrategy for replica placement
@@ -140,13 +88,6 @@ def _create_keyspace(name, durable_writes, strategy_class, strategy_options):
log.info("Not creating keyspace %s because it already exists", name)
def delete_keyspace(name):
msg = "Deprecated. Use drop_keyspace instead"
warnings.warn(msg, DeprecationWarning)
log.warning(msg)
drop_keyspace(name)
def drop_keyspace(name):
"""
Drops a keyspace, if it exists.

View File

@@ -37,33 +37,20 @@ class KeyspaceManagementTest(BaseCassEngTestCase):
cluster = get_cluster()
keyspace_ss = 'test_ks_ss'
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
management.create_keyspace_simple(keyspace_ss, 2)
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
self.assertIn(keyspace_ss, cluster.metadata.keyspaces)
management.drop_keyspace(keyspace_ss)
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
with warnings.catch_warnings(record=True) as w:
management.create_keyspace(keyspace_ss, strategy_class="SimpleStrategy", replication_factor=1)
self.assertEqual(len(w), 1)
self.assertEqual(w[-1].category, DeprecationWarning)
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
management.drop_keyspace(keyspace_ss)
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
keyspace_nts = 'test_ks_nts'
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
management.create_keyspace_simple(keyspace_nts, 2)
self.assertTrue(keyspace_nts in cluster.metadata.keyspaces)
self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
management.create_keyspace_network_topology(keyspace_nts, {'dc1': 1})
self.assertIn(keyspace_nts, cluster.metadata.keyspaces)
with warnings.catch_warnings(record=True) as w:
management.delete_keyspace(keyspace_nts)
self.assertEqual(len(w), 1)
self.assertEqual(w[-1].category, DeprecationWarning)
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
management.drop_keyspace(keyspace_nts)
self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
class DropTableTest(BaseCassEngTestCase):