Skip to content

Commit 9cec021

Browse files
fabi200123Dany9966
authored andcommitted
Fix issue 'Permission denied' due to repo permissions on redhat linux
1 parent 6f3e392 commit 9cec021

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

coriolis/osmorphing/redhat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,12 @@ def _find_yum_repos(self, repos_to_enable=[]):
270270
installed_repos = []
271271
for file in repofiles:
272272
path = os.path.join(reposdir_path, file)
273-
content = self._read_file(path).decode()
273+
try:
274+
content = self._read_file_sudo(path).decode()
275+
except Exception as e:
276+
LOG.warning(
277+
"Could not read yum repository file %s: %s", path, e)
278+
continue
274279
for line in content.splitlines():
275280
m = re.match(r'^\[(.+)\]$', line)
276281
if m:

coriolis/tests/osmorphing/test_redhat.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,26 +453,27 @@ def test__yum_clean_all_path_not_exists(self, mock_test_path,
453453
mock_exec_cmd_chroot.assert_called_once_with("yum clean all")
454454

455455
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_list_dir')
456-
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_read_file')
457-
def test__find_yum_repos_found(self, mock_read_file, mock_list_dir):
456+
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_read_file_sudo')
457+
def test__find_yum_repos_found(self, mock_read_file_sudo, mock_list_dir):
458458
mock_list_dir.return_value = ['file1.repo', 'file2.repo']
459-
mock_read_file.return_value = b'[repo1]\n[repo2]'
459+
mock_read_file_sudo.return_value = b'[repo1]\n[repo2]'
460460
repos_to_enable = ['repo1']
461461

462462
result = self.morphing_tools._find_yum_repos(repos_to_enable)
463463

464-
mock_read_file.assert_has_calls([
464+
mock_read_file_sudo.assert_has_calls([
465465
mock.call('etc/yum.repos.d/file1.repo'),
466466
mock.call('etc/yum.repos.d/file2.repo')
467467
])
468468

469469
self.assertEqual(result, ['repo1'])
470470

471471
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_list_dir')
472-
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_read_file')
473-
def test__find_yum_repos_not_found(self, mock_read_file, mock_list_dir):
472+
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_read_file_sudo')
473+
def test__find_yum_repos_not_found(self, mock_read_file_sudo,
474+
mock_list_dir):
474475
mock_list_dir.return_value = ['file1.repo', 'file2.repo']
475-
mock_read_file.return_value = b'[repo1]\n[repo2]'
476+
mock_read_file_sudo.return_value = b'[repo1]\n[repo2]'
476477
repos_to_enable = ['repo3']
477478

478479
with self.assertLogs('coriolis.osmorphing.redhat', level=logging.WARN):

0 commit comments

Comments
 (0)