diff --git a/coriolis/osmorphing/osmount/base.py b/coriolis/osmorphing/osmount/base.py index e521ff6c..926342c9 100644 --- a/coriolis/osmorphing/osmount/base.py +++ b/coriolis/osmorphing/osmount/base.py @@ -384,6 +384,10 @@ def _get_mounted_devices(self): colls = line.split() if colls[0].startswith("/dev"): dev_name = self._get_symlink_target(colls[0]) + if not utils.test_ssh_path(self._ssh, dev_name): + LOG.warn( + "Device name %s not found, skipping mount.", dev_name) + continue ret.append(dev_name) mounted_device_numbers.append( self._exec_cmd(dev_nmb_cmd % dev_name).decode().rstrip()) diff --git a/coriolis/tests/osmorphing/osmount/test_base.py b/coriolis/tests/osmorphing/osmount/test_base.py index eb8c3caa..9f3e9343 100644 --- a/coriolis/tests/osmorphing/osmount/test_base.py +++ b/coriolis/tests/osmorphing/osmount/test_base.py @@ -602,6 +602,32 @@ def test__get_mounted_devices(self, mock_exec_cmd): self.assertEqual(result, ['/dev/sda1', '/dev/sda2']) + @mock.patch.object(base.BaseSSHOSMountTools, '_exec_cmd') + @mock.patch.object(base.utils, 'test_ssh_path') + def test__get_mounted_devices_not_found(self, mock_test_ssh_path, + mock_exec_cmd): + mock_exec_cmd.side_effect = [ + b"/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro)\n", + b"/dev/sda1", + b"" + ] + mock_test_ssh_path.return_value = False + + with self.assertLogs('coriolis.osmorphing.osmount.base', + level=logging.WARN): + result = self.base_os_mount_tools._get_mounted_devices() + self.assertEqual(result, []) + + mock_exec_cmd.assert_has_calls([ + mock.call("cat /proc/mounts"), + mock.call("readlink -en /dev/sda1"), + mock.call("ls -al /dev | grep ^b") + ]) + + mock_test_ssh_path.assert_called_once_with( + self.base_os_mount_tools._ssh, "/dev/sda1" + ) + @mock.patch.object(base.BaseSSHOSMountTools, '_exec_cmd') def test__get_mount_destinations(self, mock_exec_cmd): mock_exec_cmd.return_value = (