Repository: cekit/cekit

Issue:
ValueError: dictionary update sequence element #12 has length 1; 2 is required
With [this image source](https://github.com/jmtd/openjdk/tree/rhel8-2k19) (branch rhel8-2k19, commit 503685f9621f91183a1d9fcfcf65cbe8f5745b84) and [this module cloned locally](https://github.com/jmtd/cct_module/tree/rhel82k19) (branch rhel82k1 commit d5e432eeedc503ca2c68744d0167741b0bbd54a9), I get the following when I try `cekit build --overrides-file rhel8-jdk11-overrides.yaml docker`, using cekit develop HEAD=`16489fa42ec264613b91217d1f719c8c702ea1ef`:

```
2019-03-20 15:40:29,115 cekit        WARNING  You are running unreleased development version of CEKit, use it only at your own risk!
Traceback (most recent call last):
  File "/home/ce/cekit/develop/bin/cekit", line 11, in <module>
    load_entry_point('cekit==3.0.dev0', 'console_scripts', 'cekit')()
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/cli.py", line 106, in build_docker
    run_build(ctx, 'docker')
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/cli.py", line 280, in run_build
    run_command(ctx, builder_impl)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/cli.py", line 249, in run_command
    Cekit(common_params).run(clazz, params)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/cli.py", line 333, in run
    command = clazz(self.params, params)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/builders/docker_builder.py", line 49, in __init__
    super(DockerBuilder, self).__init__('docker', common_params, params)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/builder.py", line 50, in __init__
    super(Builder, self).__init__(self.build_engine, Command.TYPE_BUILDER)
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/builder.py", line 20, in __init__
    self.dependency_handler = DependencyHandler()
  File "/home/ce/cekit/develop/lib/python2.7/site-packages/cekit/tools.py", line 161, in __init__
    self.os_release = dict(l.strip().split('=') for l in content)
ValueError: dictionary update sequence element #12 has length 1; 2 is required

```

Comments:

Patch:
diff --git a/cekit/tools.py b/cekit/tools.py
index 04a779c..4c9bd05 100644
--- a/cekit/tools.py
+++ b/cekit/tools.py
@@ -158,7 +158,8 @@ class DependencyHandler(object):
             with open(os_release_path, 'r') as f:
                 content = f.readlines()
 
-            self.os_release = dict(l.strip().split('=') for l in content)
+            self.os_release = dict([l.strip().split('=')
+                                    for l in content if not l.isspace() and not l.strip().startswith('#')])
 
             # Remove the quote character, if it's there
             for key in self.os_release.keys():


Test patch:
diff --git a/tests/test_unit_tools.py b/tests/test_unit_tools.py
index b146a0e..859d5c5 100644
--- a/tests/test_unit_tools.py
+++ b/tests/test_unit_tools.py
@@ -9,6 +9,43 @@ from cekit.descriptor import Descriptor, Image, Module, Overrides, Run
 from cekit.errors import CekitError
 from cekit import tools
 
+rhel_7_os_release = '''NAME="Red Hat Enterprise Linux Server"
+VERSION="7.7 (Maipo)"
+ID="rhel"
+ID_LIKE="fedora"
+VARIANT="Server"
+VARIANT_ID="server"
+# Some comment
+VERSION_ID="7.7"
+PRETTY_NAME="Red Hat Enterprise Linux Server 7.7 Beta (Maipo)"
+ANSI_COLOR="0;31"
+CPE_NAME="cpe:/o:redhat:enterprise_linux:7.7:beta:server"
+HOME_URL="https://www.redhat.com/"
+BUG_REPORT_URL="https://bugzilla.redhat.com/"
+
+REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
+REDHAT_BUGZILLA_PRODUCT_VERSION=7.7
+REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
+REDHAT_SUPPORT_PRODUCT_VERSION="7.7 Beta"'''
+
+rhel_8_os_release = '''NAME="Red Hat Enterprise Linux"
+   # Poor comment
+VERSION="8.0 (Ootpa)"
+ID="rhel"
+ID_LIKE="fedora"
+VERSION_ID="8.0"
+PLATFORM_ID="platform:el8"
+PRETTY_NAME="Red Hat Enterprise Linux 8.0 (Ootpa)"
+ANSI_COLOR="0;31"
+CPE_NAME="cpe:/o:redhat:enterprise_linux:8.0:GA"
+HOME_URL="https://www.redhat.com/"
+BUG_REPORT_URL="https://bugzilla.redhat.com/"
+
+REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
+REDHAT_BUGZILLA_PRODUCT_VERSION=8.0
+REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
+REDHAT_SUPPORT_PRODUCT_VERSION="8.0"'''
+
 
 class MockedDescriptor(Descriptor):
     def __init__(self, descriptor):
@@ -52,39 +89,39 @@ def test_merging_description_override():
 
 def test_merging_plain_descriptors():
     desc1 = MockedDescriptor({'name': 'foo',
-                            'a': 1,
-                            'b': 2})
+                              'a': 1,
+                              'b': 2})
 
     desc2 = MockedDescriptor({'name': 'foo',
-                            'b': 5,
-                            'c': 3})
+                              'b': 5,
+                              'c': 3})
 
     expected = MockedDescriptor({'name': 'foo',
-                               'a': 1,
-                               'b': 2,
-                               'c': 3})
+                                 'a': 1,
+                                 'b': 2,
+                                 'c': 3})
     assert expected == _merge_descriptors(desc1, desc2)
     assert expected.items() == _merge_descriptors(desc1, desc2).items()
 
 
 def test_merging_emdedded_descriptors():
     desc1 = MockedDescriptor({'name': 'a',
-                            'a': 1,
-                            'b': {'name': 'b',
-                                  'b1': 10,
-                                  'b2': 20}})
+                              'a': 1,
+                              'b': {'name': 'b',
+                                    'b1': 10,
+                                    'b2': 20}})
     desc2 = MockedDescriptor({'b': {'name': 'b',
-                                  'b2': 50,
-                                  'b3': 30},
-                            'c': {'name': 'c'}})
+                                    'b2': 50,
+                                    'b3': 30},
+                              'c': {'name': 'c'}})
 
     expected = MockedDescriptor({'name': 'a',
-                               'a': 1,
-                               'b': {'name': 'b',
-                                     'b1': 10,
-                                     'b2': 20,
-                                     'b3': 30},
-                               'c': {'name': 'c'}})
+                                 'a': 1,
+                                 'b': {'name': 'b',
+                                       'b1': 10,
+                                       'b2': 20,
+                                       'b3': 30},
+                                 'c': {'name': 'c'}})
 
     assert expected == _merge_descriptors(desc1, desc2)
 
@@ -105,21 +142,21 @@ def test_merging_plain_list_of_list():
 
 def test_merging_list_of_descriptors():
     desc1 = [MockedDescriptor({'name': 1,
-                             'a': 1,
-                             'b': 2})]
+                               'a': 1,
+                               'b': 2})]
 
     desc2 = [MockedDescriptor({'name': 2,
-                             'a': 123}),
+                               'a': 123}),
              MockedDescriptor({'name': 1,
-                             'b': 3,
-                             'c': 3})]
+                               'b': 3,
+                               'c': 3})]
 
     expected = [MockedDescriptor({'name': 2,
-                                'a': 123}),
+                                  'a': 123}),
                 MockedDescriptor({'name': 1,
-                                'a': 1,
-                                'b': 2,
-                                'c': 3})]
+                                  'a': 1,
+                                  'b': 2,
+                                  'c': 3})]
 
     assert expected == _merge_lists(desc1, desc2)
 
@@ -223,6 +260,26 @@ def test_dependency_handler_init_on_unknown_env_with_os_release_file(mocker, cap
     assert "You are running CEKit on an unknown platform. External dependencies suggestions may not work!" in caplog.text
 
 
+# https://github.com/cekit/cekit/issues/450
+def test_dependency_handler_on_rhel_7(mocker, caplog):
+    caplog.set_level(logging.DEBUG, logger="cekit")
+
+    with mocked_dependency_handler(mocker, rhel_7_os_release):
+        pass
+
+    assert "You are running on known platform: Red Hat Enterprise Linux Server 7.7 (Maipo)" in caplog.text
+
+
+# https://github.com/cekit/cekit/issues/450
+def test_dependency_handler_on_rhel_8(mocker, caplog):
+    caplog.set_level(logging.DEBUG, logger="cekit")
+
+    with mocked_dependency_handler(mocker, rhel_8_os_release):
+        pass
+
+    assert "You are running on known platform: Red Hat Enterprise Linux 8.0 (Ootpa)" in caplog.text
+
+
 def test_dependency_handler_init_on_known_env(mocker, caplog):
     caplog.set_level(logging.DEBUG, logger="cekit")
 
@@ -347,8 +404,6 @@ def test_dependency_handler_handle_dependencies_with_platform_specific_package(m
         handler._check_for_executable.assert_called_once_with(
             'xyz', 'xyz-aaa', 'python-fedora-xyz-aaa')
 
-    print(caplog.text)
-
     assert "Checking if 'xyz' dependency is provided..." in caplog.text
     assert "All dependencies provided!" in caplog.text