+8
-80
lines changedFilter options
+8
-80
lines changed Original file line number Diff line number Diff line change
@@ -37,58 +37,6 @@
37
37
schema_columnfamilies = NamedTable('system', 'schema_columnfamilies')
38
38
39
39
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
-
92
40
def create_keyspace_simple(name, replication_factor, durable_writes=True):
93
41
"""
94
42
Creates a keyspace with SimpleStrategy for replica placement
@@ -140,13 +88,6 @@ def _create_keyspace(name, durable_writes, strategy_class, strategy_options):
140
88
log.info("Not creating keyspace %s because it already exists", name)
141
89
142
90
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
-
150
91
def drop_keyspace(name):
151
92
"""
152
93
Drops a keyspace, if it exists.
Original file line number Diff line number Diff line change
@@ -37,33 +37,20 @@ def test_create_drop_succeeeds(self):
37
37
cluster = get_cluster()
38
38
39
39
keyspace_ss = 'test_ks_ss'
40
-
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
40
+
self.assertNotIn(keyspace_ss, cluster.metadata.keyspaces)
41
41
management.create_keyspace_simple(keyspace_ss, 2)
42
-
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
42
+
self.assertIn(keyspace_ss, cluster.metadata.keyspaces)
43
43
44
44
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)
55
46
56
47
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)
65
51
66
-
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
52
+
management.drop_keyspace(keyspace_nts)
53
+
self.assertNotIn(keyspace_nts, cluster.metadata.keyspaces)
67
54
68
55
69
56
class DropTableTest(BaseCassEngTestCase):
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4