aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-02-15 11:34:36 +0000
committerGerrit Code Review <review@openstack.org>2021-02-15 11:34:36 +0000
commit60bb16520c42c3cbe8d720cb90bf452223971adb (patch)
tree1f0dfbe42f8534a24df7e7c7e614c0a44e6c4734
parent12aae8ae9513c68e8a540541968b10316137dd6f (diff)
parent8e3027c5427ecfb89fe48ad38eb8189b1608d0fc (diff)
downloadkolla-60bb16520c42c3cbe8d720cb90bf452223971adb.tar.gz
kolla-60bb16520c42c3cbe8d720cb90bf452223971adb.zip
Merge "Make kolla_set_configs open files in binary mode"
-rw-r--r--docker/base/set_configs.py2
-rw-r--r--releasenotes/notes/bug-1913952-a23431cef137f9c7.yaml6
-rw-r--r--tests/test_set_config.py23
3 files changed, 30 insertions, 1 deletions
diff --git a/docker/base/set_configs.py b/docker/base/set_configs.py
index 572e4a001..0cb0e414c 100644
--- a/docker/base/set_configs.py
+++ b/docker/base/set_configs.py
@@ -164,7 +164,7 @@ class ConfigFile(object):
not os.path.exists(dest)):
return False
# check content
- with open(source) as f1, open(dest) as f2:
+ with open(source, 'rb') as f1, open(dest, 'rb') as f2:
if f1.read() != f2.read():
LOG.error('The content of source file(%s) and'
' dest file(%s) are not equal.', source, dest)
diff --git a/releasenotes/notes/bug-1913952-a23431cef137f9c7.yaml b/releasenotes/notes/bug-1913952-a23431cef137f9c7.yaml
new file mode 100644
index 000000000..c1987d38e
--- /dev/null
+++ b/releasenotes/notes/bug-1913952-a23431cef137f9c7.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+ - |
+ Fixes an issue with the ``kolla_set_configs --check`` command when
+ the compared files are non-Unicode.
+ `LP#1913952 <https://launchpad.net/bugs/1913952>`__
diff --git a/tests/test_set_config.py b/tests/test_set_config.py
index 115ccb2cd..ca3a6bb95 100644
--- a/tests/test_set_config.py
+++ b/tests/test_set_config.py
@@ -339,3 +339,26 @@ class ConfigFileTest(base.BaseTestCase):
mock_cmp_dir.assert_called_once_with(
'/var/lib/kolla/config_files/bar', '/foo')
mock_cmp_file.assert_not_called()
+
+ @mock.patch('grp.getgrgid', autospec=True)
+ @mock.patch('pwd.getpwuid', autospec=True)
+ @mock.patch('os.stat', autospec=True)
+ @mock.patch('builtins.open', new_callable=mock.mock_open)
+ @mock.patch('os.path.exists', autospec=True)
+ def test_cmp_file_opens_both_files_rb(self, mock_os_exists, mock_open,
+ mock_os_stat, mock_pwd_getpwuid,
+ mock_grp_getgrgid):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644')
+
+ mock_os_exists.return_value = True
+ mock_os_stat.return_value.st_mode = int('0o100644', 8)
+ mock_pwd_getpwuid.return_value.pw_name = 'user1'
+ mock_grp_getgrgid.return_value.gr_name = 'user1'
+
+ self.assertIs(True,
+ config_file._cmp_file('/fake/file1', '/fake/file2'))
+
+ self.assertEqual([mock.call('/fake/file1', 'rb'),
+ mock.call('/fake/file2', 'rb')],
+ mock_open.call_args_list)