# Buggy code
def _gluster_output_cleanup(result):
    """
    Gluster versions prior to 6 have a bug that requires tricking
    isatty. This adds "gluster> " to the output. Strip it off and
    produce clean xml for ElementTree.
    """
    ret = ""
    for line in result.splitlines():
        if line.startswith("gluster>"):
            ret += line[9:].strip()
        else:
            ret += line.strip()

    return ret


# Traceback (ParseError)
[INFO    ] Running state [backups] at time 12:26:20.235866
[INFO    ] Executing state glusterfs.volume_present for [backups]
[DEBUG   ] LazyLoaded cmd.run
[INFO    ] Executing command 'gluster --version' in directory '/root'
[DEBUG   ] stdout: glusterfs 6.0
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
[DEBUG   ] output: glusterfs 6.0
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
[INFO    ] Executing command 'gluster --xml --mode=script' in directory '/root'
[DEBUG   ] stdout: Welcome to gluster prompt, type 'help' to see the available commands.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>0</opErrno>
<opErrstr/>
<volList>
<count>1</count>
<volume>backups</volume>
</volList>
</cliOutput>
[DEBUG   ] output: Welcome to gluster prompt, type 'help' to see the available commands.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>0</opErrno>
<opErrstr/>
<volList>
<count>1</count>
<volume>backups</volume>
</volList>
</cliOutput>
[DEBUG   ] An exception occurred in this state: syntax error: line 1, column 0
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1933, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1939, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/glusterfs.py", line 171, in volume_present
volumes = __salt__['glusterfs.list_volumes']()
File "/usr/lib/python2.7/dist-packages/salt/modules/glusterfs.py", line 333, in list_volumes
root = _gluster_xml('volume list')
File "/usr/lib/python2.7/dist-packages/salt/modules/glusterfs.py", line 86, in _gluster_xml
raise e
ParseError: syntax error: line 1, column 0
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1933, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1939, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/glusterfs.py", line 171, in volume_present
volumes = __salt__['glusterfs.list_volumes']()
File "/usr/lib/python2.7/dist-packages/salt/modules/glusterfs.py", line 333, in list_volumes
root = _gluster_xml('volume list')
File "/usr/lib/python2.7/dist-packages/salt/modules/glusterfs.py", line 86, in _gluster_xml
raise e
ParseError: syntax error: line 1, column 0

[INFO    ] Completed state [backups] at time 12:26:20.337134 (duration_in_ms=101.268)

# Fixed code
def _gluster_output_cleanup(result):
    """
    Gluster versions prior to 6 have a bug that requires tricking
    isatty. This adds "gluster> " to the output. Strip it off and
    produce clean xml for ElementTree.
    """
    ret = ""
    for line in result.splitlines():
        if line.startswith("gluster>"):
            ret += line[9:].strip()
        elif line.startswith("Welcome to gluster prompt"):
            pass
        else:
            ret += line.strip()

    return ret