Skip to content

Commit

Permalink
Fix python sys.platform check for Linux (elastic#15727)
Browse files Browse the repository at this point in the history
On Linux, sys.platform doesn’t contain the major version anymore. It is now always ‘linux’, instead of ‘linux2’ or ‘linux3’ depending on the Linux version used to build Python. Replace sys.platform == ‘linux2’ with sys.platform.startswith(‘linux’), or directly sys.platform == ‘linux’ if you don’t need to support older Python versions.

Ref: https://docs.python.org/3.3/whatsnew/3.3.html#porting-python-code
  • Loading branch information
andrewkroh authored Jan 22, 2020
1 parent 099888a commit d197699
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions x-pack/auditbeat/tests/system/test_metricsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_metricset_host(self):

self.check_metricset("system", "host", COMMON_FIELDS + fields)

@unittest.skipUnless(sys.platform == "linux2", "Only implemented for Linux")
@unittest.skipUnless(sys.platform.startswith('linux'), "Only implemented for Linux")
@unittest.skipIf(sys.byteorder != "little", "Test only implemented for little-endian systems")
def test_metricset_login(self):
"""
Expand All @@ -43,7 +43,7 @@ def test_metricset_login(self):
self.check_metricset("system", "login", COMMON_FIELDS + fields, config, warnings_allowed=True)

@unittest.skipIf(sys.platform == "win32", "Not implemented for Windows")
@unittest.skipIf(sys.platform == "linux2" and not (os.path.isdir("/var/lib/dpkg") or os.path.isdir("/var/lib/rpm")),
@unittest.skipIf(sys.platform.startswith('linux') and not (os.path.isdir("/var/lib/dpkg") or os.path.isdir("/var/lib/rpm")),
"Only implemented for dpkg and rpm")
def test_metricset_package(self):
"""
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_metricset_process(self):
self.check_metricset("system", "process", COMMON_FIELDS + fields, {"process.hash.max_file_size": 1},
errors_allowed=True, warnings_allowed=True)

@unittest.skipUnless(sys.platform == "linux2", "Only implemented for Linux")
@unittest.skipUnless(sys.platform.startswith('linux'), "Only implemented for Linux")
def test_metricset_user(self):
"""
user metricset collects information about users on a server.
Expand Down

0 comments on commit d197699

Please sign in to comment.