diff --git a/CHANGELOG.rst b/CHANGELOG.rst index eb1f455240..a6107c7374 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -84,15 +84,20 @@ Changed way to find out about this failure would be to inspect the ``st2rulesengine`` service logs. (improvement) #4231 +Fixed +~~~~~ + +* Fix an issue with ``AttributeError: module 'enum' has no attribute 'IntFlag'`` error which would + appear when using Python 3 for a particular pack virtual environment and running on RHEL / + CentOS. (bug fix) #4297 + Deprecated ~~~~~~~~~~ -* The CloudSlang runner is now deprecated. In StackStorm 3.1 it will be removed from the core StackStorm codebase. - The runner code will be moved to a separate repository, and no longer maintained by the core StackStorm team. - Users will still be able to install and use this runner, but it will require additional steps to install. - -Fixed -~~~~~ +* The CloudSlang runner is now deprecated. In StackStorm 3.1 it will be removed from the core + StackStorm codebase. The runner code will be moved to a separate repository, and no longer + maintained by the core StackStorm team. Users will still be able to install and use this runner, + but it will require additional steps to install. 2.8.1 - July 18, 2018 --------------------- diff --git a/st2common/st2common/util/sandboxing.py b/st2common/st2common/util/sandboxing.py index 8b1f388446..eea7fc8cbe 100644 --- a/st2common/st2common/util/sandboxing.py +++ b/st2common/st2common/util/sandboxing.py @@ -151,14 +151,19 @@ def get_sandbox_python_path_for_python_action(pack, inherit_from_parent=True, uses_python3 = False if uses_python3: - # Add Python 3 lib/site-packages directory infront of the system site packages - # This is important because we want Python 3 compatible libraries to be used from - # the pack virtual environment and not system ones + # Add Python 3 lib directory (lib/python3.x) in front of the PYTHONPATH. This way we avoid + # issues with scripts trying to use packages / modules from Python 2.7 site-packages + # directory instead of the versions from Python 3 stdlib. + python3_lib_directory = os.path.join(pack_virtualenv_lib_path, virtualenv_directories[0]) + + # Add Python 3 site-packages directory (lib/python3.x/site-packages) in front of the Python + # 2.7 system site-packages This is important because we want Python 3 compatible libraries + # to be used from the pack virtual environment and not system ones. python3_site_packages_directory = os.path.join(pack_virtualenv_lib_path, virtualenv_directories[0], 'site-packages') - sandbox_python_path = (python3_site_packages_directory + ':' + pack_actions_lib_paths + - ':' + sandbox_python_path) + sandbox_python_path = (python3_lib_directory + ':' + python3_site_packages_directory + ':' + + pack_actions_lib_paths + ':' + sandbox_python_path) return sandbox_python_path diff --git a/st2common/tests/unit/test_util_sandboxing.py b/st2common/tests/unit/test_util_sandboxing.py index 7e6bf8c42e..97477e235f 100644 --- a/st2common/tests/unit/test_util_sandboxing.py +++ b/st2common/tests/unit/test_util_sandboxing.py @@ -141,13 +141,16 @@ def test_get_sandbox_python_path_for_python_action_python3_used_for_venv(self, inherit_parent_virtualenv=False) split = python_path.strip(':').split(':') - self.assertEqual(len(split), 2) + self.assertEqual(len(split), 3) - # First entry should be python3 site-packages dir from venv - self.assertTrue('virtualenvs/dummy_pack/lib/python3.6/site-packages' in split[0]) + # First entry should be lib/python3 dir from venv + self.assertTrue('virtualenvs/dummy_pack/lib/python3.6' in split[0]) - # Second entry should be actions/lib dir from pack root directory - self.assertTrue('packs/dummy_pack/actions/lib/' in split[1]) + # Second entry should be python3 site-packages dir from venv + self.assertTrue('virtualenvs/dummy_pack/lib/python3.6/site-packages' in split[1]) + + # Third entry should be actions/lib dir from pack root directory + self.assertTrue('packs/dummy_pack/actions/lib/' in split[2]) # Inherit python path from current process # Mock the current process python path @@ -156,7 +159,8 @@ def test_get_sandbox_python_path_for_python_action_python3_used_for_venv(self, python_path = get_sandbox_python_path_for_python_action(pack='dummy_pack', inherit_from_parent=True, inherit_parent_virtualenv=False) - expected = ('/tmp/virtualenvs/dummy_pack/lib/python3.6/site-packages:' + expected = ('/tmp/virtualenvs/dummy_pack/lib/python3.6:' + '/tmp/virtualenvs/dummy_pack/lib/python3.6/site-packages:' '/tmp/packs/dummy_pack/actions/lib/::/data/test1:/data/test2') self.assertEqual(python_path, expected) @@ -174,7 +178,8 @@ def test_get_sandbox_python_path_for_python_action_python3_used_for_venv(self, inherit_from_parent=True, inherit_parent_virtualenv=True) - expected = ('/tmp/virtualenvs/dummy_pack/lib/python3.6/site-packages:' + expected = ('/tmp/virtualenvs/dummy_pack/lib/python3.6:' + '/tmp/virtualenvs/dummy_pack/lib/python3.6/site-packages:' '/tmp/packs/dummy_pack/actions/lib/::/data/test1:/data/test2:' '%s/virtualenvtest' % (sys.prefix)) self.assertEqual(python_path, expected)