Skip to content

[Backport 2026.1] refactor(nemesis): extract 6 network disruption monkeys into network.py #15175

Open
scylladbbot wants to merge 5 commits into
scylladb:branch-2026.1from
scylladbbot:backport/14372/to-2026.1
Open

[Backport 2026.1] refactor(nemesis): extract 6 network disruption monkeys into network.py #15175
scylladbbot wants to merge 5 commits into
scylladb:branch-2026.1from
scylladbbot:backport/14372/to-2026.1

Conversation

@scylladbbot

Copy link
Copy Markdown

Phase 1 of nemesis rework plan
Fixes https://scylladb.atlassian.net/browse/SCT-207

Testing

PR pre-checks (self review)

  • I added the relevant backport labels
  • I didn't leave commented-out/debugging code

Reminders

  • Add New configuration option and document them (in sdcm/sct_config.py)

  • Add unit tests to cover my changes (under unit-test/ folder)

  • Update the Readme/doc folder relevant to this change (if needed)

  • (cherry picked from commit 3213eca)

  • (cherry picked from commit 9a9e4c7)

  • (cherry picked from commit 6fd8678)

Parent PR: #14372

@scylladbbot

Copy link
Copy Markdown
Author

@pehala - This PR has conflicts, therefore it was moved to draft
Please resolve them and mark this PR as ready for review

@github-actions github-actions Bot added the P1 Urgent label Jun 23, 2026
@scylladbbot scylladbbot force-pushed the backport/14372/to-2026.1 branch 2 times, most recently from 5a05615 to fce34ca Compare June 23, 2026 09:19
@pehala pehala removed the conflicts label Jun 23, 2026
@pehala pehala marked this pull request as ready for review June 23, 2026 11:42
pehala added 5 commits June 23, 2026 14:19
Phase 1 of the nemesis extraction plan: move all network disruption
logic from the monolithic __init__.py into sdcm/nemesis/monkey/network.py
as self-contained monkey classes with inline disrupt() methods.

Extracted monkeys:
- RandomInterruptionNetworkMonkey (disrupt_network_random_interruptions)
- BlockNetworkMonkey (disrupt_network_block)
- RejectInterNodeNetworkMonkey (disrupt_network_reject_inter_node_communication)
- RejectNodeExporterNetworkMonkey (disrupt_network_reject_node_exporter)
- RejectThriftNetworkMonkey (disrupt_network_reject_thrift)
- StopStartInterfacesNetworkMonkey (disrupt_network_start_stop_interface)

Also extracted 5 helper functions: install_iptables,
iptables_randomly_get_random_matching_rule,
iptables_randomly_get_disrupting_target,
run_commands_wait_and_cleanup, get_rate_limit_for_network_disruption.

Removed 13 methods from NemesisRunner and 6 classes from monkey/__init__.py.
Cleaned up 6 now-unused imports from __init__.py.

Strict behavior-preserving: no logic changes, known bugs preserved as-is.
Net reduction: __init__.py 5953->5530 (-423 lines), monkey/__init__.py
995->920 (-75 lines).

53 new unit tests in test_network.py covering helpers, monkey flags,
instantiation, UnsupportedNemesis guards, and registry auto-discovery.

(cherry picked from commit 3213eca)
…sage

Fix bug in iptables_randomly_get_random_matching_rule where the
'statistic' branch compared match_type instead of mode, causing
the 'random' (probability) and 'nth' (every-N-packet) sub-branches
to always fall through to the default 'every packet' return.

Also remove the unreachable 'connbytes' branch that was never present
in the choice list.

Also standardize all random usage in network.py: helper functions
now accept a mandatory rnd parameter, and all monkey classes pass
self.runner.random through it. This ensures nemesis randomness is
seeded and reproducible.

Changes:
- iptables_randomly_get_random_matching_rule: match_type -> mode in
  the statistic sub-branch comparisons; add rnd parameter; remove
  dead connbytes branch
- iptables_randomly_get_disrupting_target: add rnd parameter
- get_rate_limit_for_network_disruption: add rnd parameter
- All 6 monkey classes: replace bare random.* calls with
  self.runner.random.* and pass rnd=self.runner.random to helpers

5 new tests covering statistic/random mode, statistic/nth mode,
rnd parameter plumbing, and module-level fallback behavior.

(cherry picked from commit 9a9e4c7)
…ble-unit bug

- Remove connbytes test case (branch was removed from production code)
- Fix RejectThriftNetworkMonkey docstring: port 9100 -> 9160
- Fix BlockNetworkMonkey._disrupt_k8s: additional_info used 'for {duration}sec'
  where duration is already '60s', producing 'for 60ssec'; drop the redundant 'sec'

(cherry picked from commit 6fd8678)
@pehala pehala force-pushed the backport/14372/to-2026.1 branch from 631a54f to 7ea2b50 Compare June 23, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants