summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRadosław Piliszek <radoslaw.piliszek@gmail.com>2021-01-31 17:09:04 +0100
committerRadosław Piliszek <radoslaw.piliszek@gmail.com>2021-02-10 15:57:58 +0100
commit8e3027c5427ecfb89fe48ad38eb8189b1608d0fc (patch)
treea279fa01fc7c7f235af725e6281c135f6491e4c4 /tests
parent849b31303f4aad7d6fb190a80cf95514e8755279 (diff)
downloadkolla-8e3027c5427ecfb89fe48ad38eb8189b1608d0fc.tar.gz
kolla-8e3027c5427ecfb89fe48ad38eb8189b1608d0fc.zip
Make kolla_set_configs open files in binary mode
This fixes comparisons when files are not Unicode-encoded. A relevant unit test is included. It can be used as a base for other _cmp_file method unit tests if the need arises. Change-Id: Ic638516eb92d24ad247a7866fd1b5e2ac0400388 Closes-Bug: #1913952
Diffstat (limited to 'tests')
-rw-r--r--tests/test_set_config.py23
1 files changed, 23 insertions, 0 deletions
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)