Repository: RedHatInsights/insights-core

Issue:
subscription manager identity datasource raises exception
```
Traceback (most recent call last):
  File "/var/lib/insights/newest.egg/insights/core/dr.py", line 952, in run
    result = DELEGATES[component].process(broker)
  File "/var/lib/insights/newest.egg/insights/core/dr.py", line 673, in process
    return self.invoke(broker)
  File "/var/lib/insights/newest.egg/insights/core/plugins.py", line 90, in invoke
    return self.component(dep_value)
  File "/var/lib/insights/newest.egg/insights/core/__init__.py", line 82, in __init__
    self._handle_content(context)
  File "/var/lib/insights/newest.egg/insights/core/__init__.py", line 85, in _handle_content
    self.parse_content(context.content)
  File "/var/lib/insights/newest.egg/insights/core/spec_factory.py", line 110, in content
    self._content = self.load()
  File "/var/lib/insights/newest.egg/insights/core/spec_factory.py", line 315, in load
    timeout=self.timeout, env=self.create_env())
  File "/var/lib/insights/newest.egg/insights/core/context.py", line 142, in shell_out
    raw = self.check_output(cmd, timeout=timeout, keep_rc=keep_rc, env=env)
  File "/var/lib/insights/newest.egg/insights/core/context.py", line 137, in check_output
    keep_rc=keep_rc, env=env)
  File "/var/lib/insights/newest.egg/insights/util/subproc.py", line 208, in call
    res = p(keep_rc=keep_rc)
  File "/var/lib/insights/newest.egg/insights/util/subproc.py", line 121, in __call__
    raise CalledProcessError(rc, self.cmds[0], output)
insights.util.subproc.CalledProcessError: (1, ['timeout', '-s', '9', '30', '/usr/bin/subscription-manager', 'identity'], b'Traceback (most recent call last):\n  File "/usr/sbin/subscription-manager", line 11, in <module>\n    load_entry_point(\'subscription-manager==1.23.8\', \'console_scripts\', \'subscription-manager\')()\n  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 476, in load_entry_point\n    return get_distribution(dist).load_entry_point(group, name)\n  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2700, in load_entry_point\n    return ep.load()\n  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2318, in load\n    return self.resolve()\n  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in resolve\n    module = __import__(self.module_name, fromlist=[\'__name__\'], level=0)\n  File "/usr/lib64/python3.6/site-packages/subscription_manager/scripts/subscription_manager.py", line 57, in <module>\n    configure_i18n()\n  File "/usr/lib64/python3.6/site-packages/subscription_manager/i18n.py", line 51, in configure_i18n\n    Locale.set(os.environ.get("LANG"))\n  File "/usr/lib64/python3.6/site-packages/subscription_manager/i18n.py", line 147, in set\n    lang = gettext.translation(APP, DIR, languages=[language])\n  File "/usr/lib64/python3.6/gettext.py", line 510, in translation\n    mofiles = find(domain, localedir, languages, all=True)\n  File "/usr/lib64/python3.6/gettext.py", line 482, in find\n    for nelang in _expand_lang(lang):\n  File "/usr/lib64/python3.6/gettext.py", line 206, in _expand_lang\n    loc = locale.normalize(loc)\n  File "/usr/lib64/python3.6/locale.py", line 396, in normalize\n    code = localename.lower()\nAttributeError: \'NoneType\' object has no attribute \'lower\'\n')
```


Discussion:

Resolving patch:
diff --git a/insights/collect.py b/insights/collect.py
--- a/insights/collect.py
+++ b/insights/collect.py
@@ -24,9 +24,19 @@
 from insights.util.subproc import call
 
 SAFE_ENV = {
-    "PATH": os.path.pathsep.join(["/bin", "/usr/bin", "/sbin", "/usr/sbin"])
+    "PATH": os.path.pathsep.join([
+        "/bin",
+        "/usr/bin",
+        "/sbin",
+        "/usr/sbin",
+        "/usr/share/Modules/bin",
+    ]),
+    "LC_ALL": "C",
 }
 
+if "LANG" in os.environ:
+    SAFE_ENV["LANG"] = os.environ["LANG"]
+
 log = logging.getLogger(__name__)
 
 default_manifest = """
diff --git a/insights/core/spec_factory.py b/insights/core/spec_factory.py
--- a/insights/core/spec_factory.py
+++ b/insights/core/spec_factory.py
@@ -22,11 +22,20 @@
 
 
 SAFE_ENV = {
-    "PATH": os.path.pathsep.join(["/bin", "/usr/bin", "/sbin", "/usr/sbin"]),
+    "PATH": os.path.pathsep.join([
+        "/bin",
+        "/usr/bin",
+        "/sbin",
+        "/usr/sbin",
+        "/usr/share/Modules/bin",
+    ]),
+    "LC_ALL": "C",
 }
 """
 A minimal set of environment variables for use in subprocess calls
 """
+if "LANG" in os.environ:
+    SAFE_ENV["LANG"] = os.environ["LANG"]
 
 
 def enc(s):


Test patch: