Skip to content

Commit a549ca6

Browse files
authored
Merge pull request apache#833 from datastax/python-810
PYTHON-810: Revert Deprecation of WhiteListRoundRobinPolicy
2 parents 2ee077e + 4ef23f3 commit a549ca6

4 files changed

Lines changed: 27 additions & 40 deletions

File tree

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Bug Fixes
1616
* cqlengine: allow min_length=0 for Ascii and Text column types (PYTHON-735)
1717
* Rare exception when "sys.exit(0)" after query timeouts (PYTHON-752)
1818

19+
Others
20+
------
21+
* Remove DeprecationWarning when using WhiteListRoundRobinPolicy (PYTHON-810)
22+
1923
3.11.0
2024
======
2125
July 24, 2017

cassandra/policies.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from random import randint, shuffle
1818
from threading import Lock
1919
import socket
20-
from warnings import warn
2120

2221
from cassandra import ConsistencyLevel, OperationTimedOut
2322

@@ -397,10 +396,6 @@ def on_remove(self, *args, **kwargs):
397396

398397
class WhiteListRoundRobinPolicy(RoundRobinPolicy):
399398
"""
400-
|wlrrp| **is deprecated. It will be removed in 4.0.** It can effectively be
401-
reimplemented using :class:`.HostFilterPolicy`. For more information, see
402-
PYTHON-758_.
403-
404399
A subclass of :class:`.RoundRobinPolicy` which evenly
405400
distributes queries across all nodes in the cluster,
406401
regardless of what datacenter the nodes may be in, but
@@ -410,26 +405,13 @@ class WhiteListRoundRobinPolicy(RoundRobinPolicy):
410405
https://datastax-oss.atlassian.net/browse/JAVA-145
411406
Where connection errors occur when connection
412407
attempts are made to private IP addresses remotely
413-
414-
.. |wlrrp| raw:: html
415-
416-
<b><code>WhiteListRoundRobinPolicy</code></b>
417-
418-
.. _PYTHON-758: https://datastax-oss.atlassian.net/browse/PYTHON-758
419-
420408
"""
409+
421410
def __init__(self, hosts):
422411
"""
423412
The `hosts` parameter should be a sequence of hosts to permit
424413
connections to.
425414
"""
426-
msg = ('WhiteListRoundRobinPolicy is deprecated. '
427-
'It will be removed in 4.0. '
428-
'It can effectively be reimplemented using HostFilterPolicy.')
429-
warn(msg, DeprecationWarning)
430-
# DeprecationWarnings are silent by default so we also log the message
431-
log.warning(msg)
432-
433415
self._allowed_hosts = hosts
434416
self._allowed_hosts_resolved = [endpoint[4][0] for a in self._allowed_hosts
435417
for endpoint in socket.getaddrinfo(a, None, socket.AF_UNSPEC, socket.SOCK_STREAM)]

tests/integration/standard/test_policies.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
except ImportError:
2020
import unittest # noqa
2121

22-
from cassandra.cluster import Cluster
23-
from cassandra.policies import HostFilterPolicy, RoundRobinPolicy, \
24-
SimpleConvictionPolicy
22+
from cassandra.cluster import Cluster, ExecutionProfile
23+
from cassandra.policies import HostFilterPolicy, RoundRobinPolicy, SimpleConvictionPolicy, WhiteListRoundRobinPolicy
2524
from cassandra.pool import Host
2625

27-
from tests.integration import PROTOCOL_VERSION
28-
26+
from tests.integration import PROTOCOL_VERSION, local
2927

3028
from concurrent.futures import wait as wait_futures
3129

30+
3231
def setup_module():
3332
use_singledc()
3433

34+
3535
class HostFilterPolicyTests(unittest.TestCase):
3636

3737
def test_predicate_changes(self):
@@ -74,3 +74,20 @@ def test_predicate_changes(self):
7474
response = session.execute("SELECT * from system.local")
7575
queried_hosts.update(response.response_future.attempted_hosts)
7676
self.assertEqual(queried_hosts, all_hosts)
77+
78+
79+
class WhiteListRoundRobinPolicyTests(unittest.TestCase):
80+
81+
@local
82+
def test_only_connects_to_subset(self):
83+
only_connect_hosts = {"127.0.0.1", "127.0.0.2"}
84+
white_list = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy(only_connect_hosts))
85+
cluster = Cluster(execution_profiles={"white_list": white_list})
86+
#cluster = Cluster(load_balancing_policy=WhiteListRoundRobinPolicy(only_connect_hosts))
87+
session = cluster.connect(wait_for_all_pools=True)
88+
queried_hosts = set()
89+
for _ in range(10):
90+
response = session.execute('SELECT * from system.local', execution_profile="white_list")
91+
queried_hosts.update(response.response_future.attempted_hosts)
92+
queried_hosts = set(host.address for host in queried_hosts)
93+
self.assertEqual(queried_hosts, only_connect_hosts)

tests/unit/test_policies.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,22 +1232,6 @@ def test_hosts_with_hostname(self):
12321232

12331233
self.assertEqual(policy.distance(host), HostDistance.LOCAL)
12341234

1235-
def test_deprecated(self):
1236-
import warnings
1237-
1238-
warnings.resetwarnings() # in case we've instantiated one before
1239-
1240-
# set up warning filters to allow all, set up restore when this test is done
1241-
filters_backup, warnings.filters = warnings.filters, []
1242-
self.addCleanup(setattr, warnings, 'filters', filters_backup)
1243-
1244-
with warnings.catch_warnings(record=True) as caught_warnings:
1245-
WhiteListRoundRobinPolicy([])
1246-
self.assertEqual(len(caught_warnings), 1)
1247-
warning_message = caught_warnings[-1]
1248-
self.assertEqual(warning_message.category, DeprecationWarning)
1249-
self.assertIn('4.0', warning_message.message.args[0])
1250-
12511235

12521236
class AddressTranslatorTest(unittest.TestCase):
12531237

0 commit comments

Comments
 (0)