Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
handle unicode error and clean up offending facts. Closes #495 (#497)
Browse files Browse the repository at this point in the history
* handle unicode error and clean up offending facts. Closes #495
  • Loading branch information
chambridge committed Nov 30, 2017
1 parent 47fd969 commit 1dc5f7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion rho/postprocessing.py
Expand Up @@ -11,6 +11,7 @@

# pylint: disable=too-many-lines

from __future__ import print_function
import os.path
import sys
import xml
Expand Down Expand Up @@ -919,7 +920,11 @@ def escape_characters(data):
"""
for key in data:
if utilities.is_stringlike(data[key]):
data[key] = data[key].replace('\r\n', ' ').replace(',', ' ')
value = data[key].replace('\r\n', ' ').replace(',', ' ')
try:
data[key] = value.encode('unicode_escape')
except UnicodeEncodeError:
data[key] = ''
return data


Expand Down
4 changes: 2 additions & 2 deletions roles/date/tasks/main.yml
Expand Up @@ -55,7 +55,7 @@
when: '"date.machine_id" in facts_to_collect'

- name: gather date.filesystem_create fact
raw: fs_date=$(tune2fs -l $(mount | egrep '/ type' | grep -o '/dev.* on' | sed -e 's/\on//g') 2> /dev/null | grep 'Filesystem created' | sed 's/Filesystem created:\s*//g'); if [[ $fs_date ]]; then date +'%F' -d \"$fs_date\"; else echo "" ; fi
raw: fs_date=$(tune2fs -l $(mount | egrep '/ type' | grep -o '/dev.* on' | sed -e 's/\on//g') 2> /dev/null | grep 'Filesystem created' | sed 's/Filesystem created:\s*//g'); if [[ $fs_date ]]; then date +'%F' -d \"$fs_date\" 2> /dev/null; else echo "" ; fi
register: date_filesystem_create
ignore_errors: yes
when: 'have_tune2fs and "date.filesystem_create" in facts_to_collect'
Expand All @@ -68,7 +68,7 @@
when: '"date.filesystem_create" in facts_to_collect'

- name: gather date.yum_history fact
raw: yum history | tail -n 4 | grep -o '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}'
raw: yum history 2> /dev/null| tail -n 4 | grep -o '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}'
register: date_yum_history_cmd
become: yes
ignore_errors: yes
Expand Down
2 changes: 1 addition & 1 deletion roles/redhat_packages/tasks/main.yml
Expand Up @@ -145,7 +145,7 @@
when: gather_certs

- name: gather redhat-packages.certs fact
raw: ls /etc/pki/product/ | grep '.pem'
raw: ls /etc/pki/product/ 2> /dev/null| grep '.pem'
register: redhat_packages_certs_cmd
ignore_errors: yes
when: gather_certs
Expand Down
4 changes: 2 additions & 2 deletions test/test_postprocessing.py
Expand Up @@ -337,12 +337,12 @@ class TestEscapeCharacters(unittest.TestCase):
def test_string(self):
data = {'key': 'abc\r\nde,f'}
postprocessing.escape_characters(data)
self.assertEqual(data['key'], 'abc de f')
self.assertEqual(data['key'], b'abc de f')

def test_unicode(self):
data = {'key': u'abc\r\nde,f'}
postprocessing.escape_characters(data)
self.assertEqual(data['key'], u'abc de f')
self.assertEqual(data['key'], b'abc de f')


class TestProcessJbossEapInitFiles(unittest.TestCase):
Expand Down

0 comments on commit 1dc5f7f

Please sign in to comment.