Skip to content

Commit f3ec881

Browse files
mykauldkropachev
authored andcommitted
tests: save/restore SCYLLA_EXT_OPTS to prevent env variable leak
Several test modules set SCYLLA_EXT_OPTS in setup_module() but never restore it in teardown_module(). When tests are reordered to share clusters, stale values can leak into subsequent modules and cause misconfigured clusters. Save the original value before overwriting and restore it on teardown in: - test_cluster.py - test_shard_aware.py - test_use_keyspace.py - test_ip_change.py - test_client_routes.py (module-level and TestFullNodeReplacementThroughNlb) - test_authentication.py
1 parent 4eb1bfa commit f3ec881

6 files changed

Lines changed: 71 additions & 0 deletions

File tree

tests/integration/standard/test_authentication.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434
#This can be tested for remote hosts, but the cluster has to be configured accordingly
3535
#@local
3636

37+
_saved_scylla_ext_opts = None
38+
3739

3840
def setup_module():
41+
global _saved_scylla_ext_opts
42+
_saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
3943
if CASSANDRA_IP.startswith("127.0.0.") and not USE_CASS_EXTERNAL:
4044
use_singledc(start=False)
4145
ccm_cluster = get_cluster()
@@ -71,6 +75,10 @@ def _check_auth_ready():
7175

7276
def teardown_module():
7377
remove_cluster() # this test messes with config
78+
if _saved_scylla_ext_opts is None:
79+
os.environ.pop('SCYLLA_EXT_OPTS', None)
80+
else:
81+
os.environ['SCYLLA_EXT_OPTS'] = _saved_scylla_ext_opts
7482

7583

7684
class AuthenticationTests(unittest.TestCase):

tests/integration/standard/test_client_routes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,22 @@ def assert_routes_direct(test, cluster, expected_node_ids, direct_port=9042):
519519
)
520520

521521

522+
_saved_scylla_ext_opts = None
523+
524+
522525
def setup_module():
526+
global _saved_scylla_ext_opts
527+
_saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
523528
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2 --memory 2048M"
524529
use_cluster('shared_aware', [3], start=True)
525530

531+
532+
def teardown_module():
533+
if _saved_scylla_ext_opts is None:
534+
os.environ.pop('SCYLLA_EXT_OPTS', None)
535+
else:
536+
os.environ['SCYLLA_EXT_OPTS'] = _saved_scylla_ext_opts
537+
526538
@skip_scylla_version_lt(reason='scylladb/scylladb#26992 - system.client_routes is not yet supported',
527539
scylla_version="2026.1.0")
528540
class TestGetHostPortMapping(unittest.TestCase):
@@ -1116,6 +1128,7 @@ class TestFullNodeReplacementThroughNlb(unittest.TestCase):
11161128

11171129
@classmethod
11181130
def setUpClass(cls):
1131+
cls._saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
11191132
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2 --memory 2048M"
11201133
use_cluster('test_client_routes_replacement', [3], start=True)
11211134

@@ -1133,6 +1146,10 @@ def setUpClass(cls):
11331146
@classmethod
11341147
def tearDownClass(cls):
11351148
cls.direct_cluster.shutdown()
1149+
if cls._saved_scylla_ext_opts is None:
1150+
os.environ.pop('SCYLLA_EXT_OPTS', None)
1151+
else:
1152+
os.environ['SCYLLA_EXT_OPTS'] = cls._saved_scylla_ext_opts
11361153

11371154
def test_should_survive_full_node_replacement_through_nlb(self):
11381155
"""

tests/integration/standard/test_cluster.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,24 @@
5151
log = logging.getLogger(__name__)
5252

5353

54+
_saved_scylla_ext_opts = None
55+
56+
5457
def setup_module():
58+
global _saved_scylla_ext_opts
59+
_saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
5560
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2"
5661
use_cluster("cluster_tests", [3], start=True, workloads=None)
5762
warnings.simplefilter("always")
5863

5964

65+
def teardown_module():
66+
if _saved_scylla_ext_opts is None:
67+
os.environ.pop('SCYLLA_EXT_OPTS', None)
68+
else:
69+
os.environ['SCYLLA_EXT_OPTS'] = _saved_scylla_ext_opts
70+
71+
6072
class IgnoredHostPolicy(RoundRobinPolicy):
6173

6274
def __init__(self, ignored_hosts):

tests/integration/standard/test_ip_change.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@
1010

1111
LOGGER = logging.getLogger(__name__)
1212

13+
_saved_scylla_ext_opts = None
14+
1315

1416
def setup_module():
17+
global _saved_scylla_ext_opts
18+
_saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
1519
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2 --memory 2048M"
1620
use_cluster('test_ip_change', [3], start=True)
1721

22+
23+
def teardown_module():
24+
if _saved_scylla_ext_opts is None:
25+
os.environ.pop('SCYLLA_EXT_OPTS', None)
26+
else:
27+
os.environ['SCYLLA_EXT_OPTS'] = _saved_scylla_ext_opts
28+
1829
@local
1930
class TestIpAddressChange(unittest.TestCase):
2031
@classmethod

tests/integration/standard/test_shard_aware.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,23 @@
3131
LOGGER = logging.getLogger(__name__)
3232

3333

34+
_saved_scylla_ext_opts = None
35+
36+
3437
def setup_module():
38+
global _saved_scylla_ext_opts
39+
_saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
3540
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2"
3641
use_cluster('cluster_tests', [3], start=True)
3742

3843

44+
def teardown_module():
45+
if _saved_scylla_ext_opts is None:
46+
os.environ.pop('SCYLLA_EXT_OPTS', None)
47+
else:
48+
os.environ['SCYLLA_EXT_OPTS'] = _saved_scylla_ext_opts
49+
50+
3951
class TestShardAwareIntegration(unittest.TestCase):
4052
@classmethod
4153
def setup_class(cls):

tests/integration/standard/test_use_keyspace.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,23 @@
1414

1515
LOGGER = logging.getLogger(__name__)
1616

17+
_saved_scylla_ext_opts = None
18+
1719

1820
def setup_module():
21+
global _saved_scylla_ext_opts
22+
_saved_scylla_ext_opts = os.environ.get('SCYLLA_EXT_OPTS')
1923
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2 --memory 2048M"
2024
use_cluster('shared_aware', [3], start=True)
2125

2226

27+
def teardown_module():
28+
if _saved_scylla_ext_opts is None:
29+
os.environ.pop('SCYLLA_EXT_OPTS', None)
30+
else:
31+
os.environ['SCYLLA_EXT_OPTS'] = _saved_scylla_ext_opts
32+
33+
2334
@local
2435
class TestUseKeyspace(unittest.TestCase):
2536
@classmethod

0 commit comments

Comments
 (0)