From 78b3d28f36cb7f85b633fcbe50d397262482af5c Mon Sep 17 00:00:00 2001 From: Javier Pena Date: Thu, 20 May 2021 11:24:30 +0200 Subject: [PATCH] Fix Python 2.7 compatibility for test_ansible.py [1] broke Python 2.7 compatibility, which is still maintained by the rest of the codebase (for CentOS 7 support). [1] - https://review.opendev.org/c/openstack/validations-libs/+/777100 Change-Id: Ia338ef0f1f83a6da4f9836deb7ecbce48634fdf8 --- validations_libs/tests/test_ansible.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/validations_libs/tests/test_ansible.py b/validations_libs/tests/test_ansible.py index 41943227..0b9d6804 100644 --- a/validations_libs/tests/test_ansible.py +++ b/validations_libs/tests/test_ansible.py @@ -30,6 +30,14 @@ try: except pkg_resources.DistributionNotFound: backward_compat = False +# NOTE(cloudnull): This is setting the FileExistsError for py2 environments. +# When we no longer support py2 (centos7) this should be +# removed. +try: + FileExistsError = FileExistsError +except NameError: + FileExistsError = OSError + class TestAnsible(TestCase): @@ -175,7 +183,7 @@ class TestAnsible(TestCase): self.assertEqual(extra_vars, self.run._get_extra_vars(extra_vars)) @mock.patch('yaml.safe_load', return_value={'fizz': 'buzz'}) - @mock.patch('builtins.open', spec=open) + @mock.patch('six.moves.builtins.open', spec=open) @mock.patch('os.path.exists', return_value=True) @mock.patch('os.path.isfile', return_value=True) def test_get_extra_vars_path(self, mock_isfile,