diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2020-05-22 12:38:29 +0100 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-05-26 09:49:00 -0400 |
commit | 412ed53287fba6fd5d8b235569a35e7917f84a6f (patch) | |
tree | 80546bc578c6a5cb75b804d823b039062e1e7b35 | |
parent | 2d17a97a5c2fdb34898cf83911cdad808fa313df (diff) | |
download | sos-412ed53287fba6fd5d8b235569a35e7917f84a6f.tar.gz |
[policies/cos] check for blank and comment lines in os-release
The os-release file may contain blank and comment lines. Skip
them when parsing values.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/policies/cos.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sos/policies/cos.py b/sos/policies/cos.py index d9da0a3d..a96d67ef 100644 --- a/sos/policies/cos.py +++ b/sos/policies/cos.py @@ -12,6 +12,20 @@ from sos.report.plugins import CosPlugin from sos.policies import LinuxPolicy +def _blank_or_comment(line): + """Test whether line is empty of contains a comment. + + Test whether the ``line`` argument is either blank, or a + whole-line comment. + + :param line: the line of text to be checked. + :returns: ``True`` if the line is blank or a comment, + and ``False`` otherwise. + :rtype: bool + """ + return not line.strip() or line.lstrip().startswith('#') + + class CosPolicy(LinuxPolicy): distro = "Container-Optimized OS" vendor = "Google Cloud Platform" @@ -21,14 +35,13 @@ class CosPolicy(LinuxPolicy): @classmethod def check(cls, remote=''): - if remote: return cls.distro in remote try: with open('/etc/os-release', 'r') as fp: os_release = dict(line.strip().split('=') for line in fp - if line.strip()) + if not _blank_or_comment(line)) id = os_release.get('ID') return id == 'cos' except IOError: |