Skip to content

Fix chroot paths #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions coriolis/osmorphing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,22 @@ def get_update_grub2_command(self):
raise NotImplementedError()

def _test_path(self, chroot_path):
chroot_path = chroot_path.lstrip('/')
path = os.path.join(self._os_root_dir, chroot_path)
return utils.test_ssh_path(self._ssh, path)

def _read_file(self, chroot_path):
chroot_path = chroot_path.lstrip('/')
path = os.path.join(self._os_root_dir, chroot_path)
return utils.read_ssh_file(self._ssh, path)

def _write_file(self, chroot_path, content):
chroot_path = chroot_path.lstrip('/')
path = os.path.join(self._os_root_dir, chroot_path)
utils.write_ssh_file(self._ssh, path, content)

def _list_dir(self, chroot_path):
chroot_path = chroot_path.lstrip('/')
path = os.path.join(self._os_root_dir, chroot_path)
return utils.list_ssh_dir(self._ssh, path)

Expand Down Expand Up @@ -320,6 +324,7 @@ def _get_os_release(self):
return self._read_config_file("etc/os-release", check_exists=True)

def _read_config_file(self, chroot_path, check_exists=False):
chroot_path = chroot_path.lstrip('/')
full_path = os.path.join(self._os_root_dir, chroot_path)
return utils.read_ssh_ini_config_file(
self._ssh, full_path, check_exists=check_exists)
Expand Down
26 changes: 7 additions & 19 deletions coriolis/tests/osmorphing/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def setUp(self):
self.conn = mock.sentinel.conn
self.os_root_dir = '/root'
self.chroot_path = '/root/etc/resolv.conf'
self.joined_chroot_path = '/root/root/etc/resolv.conf'
self.os_root_device = mock.sentinel.os_root_device
self.hypervisor = mock.sentinel.hypervisor
self.event_manager = mock.MagicMock()
Expand Down Expand Up @@ -288,45 +289,33 @@ def test_get_update_grub2_command(self):
def test__test_path(self, mock_test_ssh_path):
result = self.os_morphing_tools._test_path(self.chroot_path)

mocked_full_path = os.path.join(
self.os_morphing_tools._os_root_dir, self.chroot_path)

mock_test_ssh_path.assert_called_once_with(
self.os_morphing_tools._ssh, mocked_full_path)
self.os_morphing_tools._ssh, self.joined_chroot_path)
self.assertEqual(result, mock_test_ssh_path.return_value)

@mock.patch.object(base.utils, 'read_ssh_file')
def test__read_file(self, mock_read_ssh_file):
result = self.os_morphing_tools._read_file(self.chroot_path)

mocked_full_path = os.path.join(
self.os_morphing_tools._os_root_dir, self.chroot_path)

mock_read_ssh_file.assert_called_once_with(
self.os_morphing_tools._ssh, mocked_full_path)
self.os_morphing_tools._ssh, self.joined_chroot_path)
self.assertEqual(result, mock_read_ssh_file.return_value)

@mock.patch.object(base.utils, 'write_ssh_file')
def test__write_file(self, mock_write_ssh_file):
self.os_morphing_tools._write_file(
self.chroot_path, mock.sentinel.content)

mocked_full_path = os.path.join(
self.os_morphing_tools._os_root_dir, self.chroot_path)

mock_write_ssh_file.assert_called_once_with(
self.os_morphing_tools._ssh, mocked_full_path,
self.os_morphing_tools._ssh, self.joined_chroot_path,
mock.sentinel.content)

@mock.patch.object(base.utils, 'list_ssh_dir')
def test__list_dir(self, mock_list_ssh_dir):
result = self.os_morphing_tools._list_dir(self.chroot_path)

mocked_full_path = os.path.join(
self.os_morphing_tools._os_root_dir, self.chroot_path)

mock_list_ssh_dir.assert_called_once_with(
self.os_morphing_tools._ssh, mocked_full_path)
self.os_morphing_tools._ssh, self.joined_chroot_path)
self.assertEqual(result, mock_list_ssh_dir.return_value)

@mock.patch.object(base.utils, 'exec_ssh_cmd')
Expand Down Expand Up @@ -464,10 +453,9 @@ def test__read_config_file(self, mock_read_ssh_ini):
result = self.os_morphing_tools._read_config_file(
self.chroot_path, check_exists=False)

mocked_full_path = os.path.join(
self.os_morphing_tools._os_root_dir, self.chroot_path)
mock_read_ssh_ini.assert_called_once_with(
self.os_morphing_tools._ssh, mocked_full_path, check_exists=False)
self.os_morphing_tools._ssh, self.joined_chroot_path,
check_exists=False)
self.assertEqual(result, mock_read_ssh_ini.return_value)

@mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path')
Expand Down