Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simplyblock_core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def ping_host(ip):
logger.debug(f"Pinging ip ... {ip}")
try:
result = subprocess.run(
["sudo", "ping", "-c", "2", "-W", "2", ip],
["ping", "-c", "2", "-W", "2", ip],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
up = result.returncode == 0
except Exception as e:
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_node_reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,15 @@ def test_exactly_the_cap_is_allowed():
addresses = [f"192.0.2.{i + 1}" for i in range(health_controller.MAX_REACHABILITY_ADDRESSES)]
with patch.object(health_controller, "_check_node_ping", return_value=True):
assert len(health_controller.address_reachability(addresses)) == len(addresses)


def test_ping_host_runs_ping_without_sudo():
"""The control plane pods may run as a random UID without privilege
escalation (OpenShift restricted-v2), where sudo fails. They allow
unprivileged ICMP sockets through net.ipv4.ping_group_range instead, so
ping_host must call ping directly."""
from simplyblock_core import utils
with patch.object(utils.subprocess, "run") as run:
run.return_value.returncode = 0
assert utils.ping_host("10.0.0.1") is True
assert run.call_args.args[0][0] == "ping"
Loading