mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Fix listing minions on OpenBSD
This commit is contained in:
parent
fed79378c0
commit
676be79ba7
3 changed files with 24 additions and 3 deletions
1
changelog/61966.fixed
Normal file
1
changelog/61966.fixed
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fixed listing minions on OpenBSD
|
|
@ -1928,11 +1928,11 @@ def _openbsd_remotes_on(port, which_end):
|
||||||
data = subprocess.check_output(
|
data = subprocess.check_output(
|
||||||
["netstat", "-nf", "inet"]
|
["netstat", "-nf", "inet"]
|
||||||
) # pylint: disable=minimum-python-version
|
) # pylint: disable=minimum-python-version
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as exc:
|
||||||
log.error("Failed netstat")
|
log.error('Failed "netstat" with returncode = %s', exc.returncode)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
lines = data.split("\n")
|
lines = salt.utils.stringutils.to_str(data).split("\n")
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if "ESTABLISHED" not in line:
|
if "ESTABLISHED" not in line:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -111,6 +111,12 @@ USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
|
||||||
salt-master python2.781106 35 tcp4 127.0.0.1:61115 127.0.0.1:4506
|
salt-master python2.781106 35 tcp4 127.0.0.1:61115 127.0.0.1:4506
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
OPENBSD_NETSTAT = """\
|
||||||
|
Active Internet connections
|
||||||
|
Proto Recv-Q Send-Q Local Address Foreign Address (state)
|
||||||
|
tcp 0 0 127.0.0.1.61115 127.0.0.1.4506 ESTABLISHED
|
||||||
|
"""
|
||||||
|
|
||||||
LINUX_NETLINK_SS_OUTPUT = """\
|
LINUX_NETLINK_SS_OUTPUT = """\
|
||||||
State Recv-Q Send-Q Local Address:Port Peer Address:Port
|
State Recv-Q Send-Q Local Address:Port Peer Address:Port
|
||||||
TIME-WAIT 0 0 [::1]:8009 [::1]:40368
|
TIME-WAIT 0 0 [::1]:8009 [::1]:40368
|
||||||
|
@ -647,6 +653,20 @@ class NetworkTestCase(TestCase):
|
||||||
remotes = network._netlink_tool_remote_on("4505", "remote_port")
|
remotes = network._netlink_tool_remote_on("4505", "remote_port")
|
||||||
self.assertEqual(remotes, {"127.0.0.1", "::ffff:1.2.3.4"})
|
self.assertEqual(remotes, {"127.0.0.1", "::ffff:1.2.3.4"})
|
||||||
|
|
||||||
|
def test_openbsd_remotes_on(self):
|
||||||
|
with patch("subprocess.check_output", return_value=OPENBSD_NETSTAT):
|
||||||
|
remotes = network._openbsd_remotes_on("4506", "remote")
|
||||||
|
self.assertEqual(remotes, {"127.0.0.1"})
|
||||||
|
|
||||||
|
def test_openbsd_remotes_on_issue_61966(self):
|
||||||
|
"""
|
||||||
|
Test that the command output is correctly converted to string before
|
||||||
|
treating it as such
|
||||||
|
"""
|
||||||
|
with patch("subprocess.check_output", return_value=OPENBSD_NETSTAT.encode()):
|
||||||
|
remotes = network._openbsd_remotes_on("4506", "remote")
|
||||||
|
self.assertEqual(remotes, {"127.0.0.1"})
|
||||||
|
|
||||||
def test_generate_minion_id_distinct(self):
|
def test_generate_minion_id_distinct(self):
|
||||||
"""
|
"""
|
||||||
Test if minion IDs are distinct in the pool.
|
Test if minion IDs are distinct in the pool.
|
||||||
|
|
Loading…
Add table
Reference in a new issue