Skip to content

Commit 4bd5909

Browse files
committed
Remove deprecated cqlengine keyspace management functions
1 parent a2d3a98 commit 4bd5909

File tree

2 files changed

+8
-80
lines changed

2 files changed

+8
-80
lines changed

cassandra/cqlengine/management.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,6 @@
3737
schema_columnfamilies = NamedTable('system', 'schema_columnfamilies')
3838

3939

40-
def create_keyspace(name, strategy_class, replication_factor, durable_writes=True, **replication_values):
41-
"""
42-
*Deprecated - use :func:`create_keyspace_simple` or :func:`create_keyspace_network_topology` instead*
43-
44-
Creates a keyspace
45-
46-
If the keyspace already exists, it will not be modified.
47-
48-
**This function should be used with caution, especially in production environments.
49-
Take care to execute schema modifications in a single context (i.e. not concurrently with other clients).**
50-
51-
*There are plans to guard schema-modifying functions with an environment-driven conditional.*
52-
53-
:param str name: name of keyspace to create
54-
:param str strategy_class: keyspace replication strategy class (:attr:`~.SimpleStrategy` or :attr:`~.NetworkTopologyStrategy`
55-
:param int replication_factor: keyspace replication factor, used with :attr:`~.SimpleStrategy`
56-
:param bool durable_writes: Write log is bypassed if set to False
57-
:param \*\*replication_values: Additional values to ad to the replication options map
58-
"""
59-
if not _allow_schema_modification():
60-
return
61-
62-
msg = "Deprecated. Use create_keyspace_simple or create_keyspace_network_topology instead"
63-
warnings.warn(msg, DeprecationWarning)
64-
log.warning(msg)
65-
66-
cluster = get_cluster()
67-
68-
if name not in cluster.metadata.keyspaces:
69-
# try the 1.2 method
70-
replication_map = {
71-
'class': strategy_class,
72-
'replication_factor': replication_factor
73-
}
74-
replication_map.update(replication_values)
75-
if strategy_class.lower() != 'simplestrategy':
76-
# Although the Cassandra documentation states for `replication_factor`
77-
# that it is "Required if class is SimpleStrategy; otherwise,
78-
# not used." we get an error if it is present.
79-
replication_map.pop('replication_factor', None)
80-
81-
query = """
82-
CREATE KEYSPACE {0}
83-
WITH REPLICATION = {1}
84-
""".format(metadata.protect_name(name), json.dumps(replication_map).replace('"', "'"))
85-
86-
if strategy_class != 'SimpleStrategy':
87-
query += " AND DURABLE_WRITES = {0}".format('true' if durable_writes else 'false')
88-
89-
execute(query)
90-
91-
9240
def create_keyspace_simple(name, replication_factor, durable_writes=True):
9341
"""
9442
Creates a keyspace with SimpleStrategy for replica placement
@@ -140,13 +88,6 @@ def _create_keyspace(name, durable_writes, strategy_class, strategy_options):
14088
log.info("Not creating keyspace %s because it already exists", name)
14189

14290

143-
def delete_keyspace(name):
144-
msg = "Deprecated. Use drop_keyspace instead"
145-
warnings.warn(msg, DeprecationWarning)
146-
log.warning(msg)
147-
drop_keyspace(name)
148-
149-
15091
def drop_keyspace(name):
15192
"""
15293
Drops a keyspace, if it exists.

tests/integration/cqlengine/management/test_management.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,20 @@ def test_create_drop_succeeeds(self):
3737
cluster = get_cluster()
3838

3939
keyspace_ss = 'test_ks_ss'
40-
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
40+
self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
4141
management.create_keyspace_simple(keyspace_ss, 2)
42-
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
42+
self.assertIn(keyspace_ss, cluster.metadata.keyspaces)
4343

4444
management.drop_keyspace(keyspace_ss)
45-
46-
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
47-
with warnings.catch_warnings(record=True) as w:
48-
management.create_keyspace(keyspace_ss, strategy_class="SimpleStrategy", replication_factor=1)
49-
self.assertEqual(len(w), 1)
50-
self.assertEqual(w[-1].category, DeprecationWarning)
51-
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
52-
53-
management.drop_keyspace(keyspace_ss)
54-
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
45+
self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
5546

5647
keyspace_nts = 'test_ks_nts'
57-
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
58-
management.create_keyspace_simple(keyspace_nts, 2)
59-
self.assertTrue(keyspace_nts in cluster.metadata.keyspaces)
60-
61-
with warnings.catch_warnings(record=True) as w:
62-
management.delete_keyspace(keyspace_nts)
63-
self.assertEqual(len(w), 1)
64-
self.assertEqual(w[-1].category, DeprecationWarning)
48+
self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
49+
management.create_keyspace_network_topology(keyspace_nts, {'dc1': 1})
50+
self.assertIn(keyspace_nts, cluster.metadata.keyspaces)
6551

66-
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
52+
management.drop_keyspace(keyspace_nts)
53+
self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
6754

6855

6956
class DropTableTest(BaseCassEngTestCase):

0 commit comments

Comments
 (0)