Explorar o código

Add test case for `_get_mounted_devices` method

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu hai 1 ano
pai
achega
676d6c9cdf
Modificáronse 1 ficheiros con 26 adicións e 0 borrados
  1. 26 0
      coriolis/tests/osmorphing/osmount/test_base.py

+ 26 - 0
coriolis/tests/osmorphing/osmount/test_base.py

@@ -602,6 +602,32 @@ class BaseLinuxOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
 
         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 = (