host.socket.get_listening_sockets() does not work on Ubuntu 18.04.1 LTS
See original GitHub issueI’m using this snippet of code to test listening ports:
def test_listening_socket(host):
listening = host.socket.get_listening_sockets()
for spec in (
"tcp://:::22",
"tcp://:::5432",
):
socket = host.socket(spec)
assert socket.is_listening
but it fails on Ubuntu 18.04.1 LTS:
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
==================================================================================================================================== FAILURES =====================================================================================================================================
_______________________________________________________________________________________________________________ test_listening_socket[paramiko://alpha] _______________________________________________________________________________________________________________
host = <testinfra.host.Host object at 0x7fc1b010e190>
def test_listening_socket(host):
> listening = host.socket.get_listening_sockets()
test_alpha.py:80:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python2.7/dist-packages/testinfra/modules/socket.py:171: in get_listening_sockets
for sock in cls(None)._iter_sockets(True):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <socket None://None>, listening = True
def _iter_sockets(self, listening):
cmd = 'ss --numeric'
if listening:
cmd += ' --listening'
else:
cmd += ' --all'
if self.protocol == 'tcp':
cmd += ' --tcp'
elif self.protocol == 'udp':
cmd += ' --udp'
elif self.protocol == 'unix':
cmd += ' --unix'
for line in self.run(cmd).stdout_bytes.splitlines()[1:]:
# Ignore unix datagram sockets.
if line.split(None, 1)[0] == b'u_dgr':
continue
splitted = line.decode().split()
# If listing only TCP or UDP sockets, output has 5 columns:
# (State, Recv-Q, Send-Q, Local Address:Port, Peer Address:Port)
if self.protocol in ('tcp', 'udp'):
protocol = self.protocol
status, local, remote = (
splitted[0], splitted[3], splitted[4])
# If listing all or just unix sockets, output has 6 columns:
# Netid, State, Recv-Q, Send-Q, LocalAddress:Port, PeerAddress:Port
else:
protocol, status, local, remote = (
> splitted[0], splitted[1], splitted[4], splitted[5])
E IndexError: list index out of range
/usr/local/lib/python2.7/dist-packages/testinfra/modules/socket.py:238: IndexError
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
BionicBeaver/ReleaseNotes/18.04.1 - Ubuntu Wiki
Press Alt+F2 and type update-manager -c into the command box. Update Manager should open up and tell you that Ubuntu 18.04 LTS is...
Read more >SoundTroubleshootingProcedure - Community Help Wiki
You may want to follow this guide to gather essential troubleshooting information about your sound card. This information will be useful in ...
Read more >Ubuntu Server Documentation
This chapter provides an overview of installing Ubuntu Server Edition. There is more detailed documentation on other installer topics. Preparing to Install.
Read more >How to upgrade from Ubuntu 18.04 LTS to 20.04 LTS today
The upgrade process can be done using the Ubuntu update manager or on the command line. The Ubuntu update manager will start showing...
Read more >Webcam - Community Help Wiki
It has been in the Universe repository since Ubuntu 8.04 LTS (Hardy Heron). If it doesn't work, you may need to update the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, it’s definetly the commit mentioned above. Quickly builded 4.18 (from bionic-backports) and problem gone:
But it’s still a bit of “too hackish” way to solve “failed test” issue. Don’t you think? 8)
Looks like this story hasn’t ended yet. We faced similar problem, but with LXD instead of Nginx. Here is how our tests crashed:
And here is an interesting part. How TCP socket will be checked in case of Ubuntu 16.04/xenial:
And the same for Ubuntu 18.04/bionic (which crashed):
As you can see there is something strange with first two columns. They just merged to one by some reason. Digging deeper and trying to run same comand within bionic:
Looks ok, but here is subshell version (same as lxc exec … works?):
And columns again merged. Here is how to reproduced it without subshell (just make your terminal smaller):
Probably the main problem are the long addresses in column “Local Addres”? After some digging I found this commit:
This looks suspiciously similar to our case here. I don’t sure in which versions exactly problem came. But I guess, that bionic wouldn’t be getting iproute >=5.1 in any time soon (or ever?).
@philpep, after all that, what are our options here? Only fallback to netstat if it’s available (or use it first)? 0_o