Esempio n. 1
0
 def test_guestfs_conn_mount_ro_umount_raises(self, mock_gfs, disk_path,
                                              disk_root):
     mock_gfs.return_value.umount.side_effect = RuntimeError()
     with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
         mock_rootfs.return_value = disk_path
         with pytest.raises(GuestFSError):
             with guestfs_tools.guestfs_conn_mount_ro(disk_path, disk_root):
                 pass
         assert mock_gfs.return_value.umount.call_count == 1
         assert mock_gfs.return_value.mount_ro.call_count == 1
Esempio n. 2
0
 def test_guestfs_conn_mount_ro(self, mock_gfs, disk_path, disk_root):
     with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
         mock_rootfs.return_value = disk_root
         with guestfs_tools.guestfs_conn_mount_ro(disk_path,
                                                  disk_root) as conn:
             assert call.mount_ro(disk_root, '/') in conn.mock_calls
             assert call.add_drive_ro(disk_path) in conn.mock_calls
             conn.mount_ro.assert_called_once()
             conn.add_drive_ro.assert_called_once()
             mock_rootfs.assert_called_once()
         mock_gfs.return_value.umount.assert_called_once()
Esempio n. 3
0
 def test_guestfs_conn_mount_ro_umount_raises(
     self, mock_gfs, disk_path, disk_root
 ):
     mock_gfs.return_value.umount.side_effect = RuntimeError()
     with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
         mock_rootfs.return_value = disk_path
         with pytest.raises(GuestFSError):
             with guestfs_tools.guestfs_conn_mount_ro(disk_path, disk_root):
                 pass
         assert mock_gfs.return_value.umount.call_count == 1
         assert mock_gfs.return_value.mount_ro.call_count == 1
Esempio n. 4
0
 def test_guestfs_conn_mount_ro(self, mock_gfs, disk_path, disk_root):
     with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
         mock_rootfs.return_value = disk_root
         with guestfs_tools.guestfs_conn_mount_ro(
             disk_path, disk_root
         ) as conn:
             assert call.mount_ro(disk_root, '/') in conn.mock_calls
             assert call.add_drive_ro(disk_path) in conn.mock_calls
             conn.mount_ro.assert_called_once()
             conn.add_drive_ro.assert_called_once()
             mock_rootfs.assert_called_once()
         mock_gfs.return_value.umount.assert_called_once()
Esempio n. 5
0
    def test_guestfs_conn_mount_ro_retries_raises(self, mock_gfs, disk_path,
                                                  disk_root, retries):
        side_effects = [RuntimeError()] * (retries)
        mock_gfs.return_value.mount_ro.side_effect = side_effects
        with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
            mock_rootfs.return_value = disk_root
            with pytest.raises(GuestFSError):
                with guestfs_tools.guestfs_conn_mount_ro(disk_path,
                                                         disk_root,
                                                         retries=retries,
                                                         wait=0):
                    pass

            assert mock_gfs.return_value.mount_ro.call_count == retries
            assert mock_gfs.return_value.umount.call_count == 0
            assert mock_gfs.return_value.add_drive_ro.call_count == retries
            assert mock_gfs.return_value.shutdown.call_count == retries
            assert mock_gfs.return_value.close.call_count == retries
Esempio n. 6
0
    def test_guestfs_conn_mount_ro_retries_raises(
        self, mock_gfs, disk_path, disk_root, retries
    ):
        side_effects = [RuntimeError()] * (retries)
        mock_gfs.return_value.mount_ro.side_effect = side_effects
        with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
            mock_rootfs.return_value = disk_root
            with pytest.raises(GuestFSError):
                with guestfs_tools.guestfs_conn_mount_ro(
                    disk_path, disk_root, retries=retries, wait=0
                ):
                    pass

            assert mock_gfs.return_value.mount_ro.call_count == retries
            assert mock_gfs.return_value.umount.call_count == 0
            assert mock_gfs.return_value.add_drive_ro.call_count == retries
            assert mock_gfs.return_value.shutdown.call_count == retries
            assert mock_gfs.return_value.close.call_count == retries
Esempio n. 7
0
    def test_guestfs_conn_mount_ro_retries(self, mock_gfs, disk_path,
                                           disk_root, retries):
        side_effects = [RuntimeError()] * (retries - 1)
        side_effects.append(None)
        mock_gfs.return_value.mount_ro.side_effect = side_effects
        with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
            mock_rootfs.return_value = disk_root
            with guestfs_tools.guestfs_conn_mount_ro(disk_path,
                                                     disk_root,
                                                     retries=retries,
                                                     wait=0) as conn:

                assert call.mount_ro(disk_root, '/') in conn.mock_calls
                assert call.add_drive_ro(disk_path) in conn.mock_calls
            assert conn.mount_ro.call_count == retries
            assert conn.umount.call_count == 1
            assert conn.add_drive_ro.call_count == retries
            assert conn.shutdown.call_count == retries
            assert conn.close.call_count == retries
Esempio n. 8
0
    def test_guestfs_conn_mount_ro_retries(
        self, mock_gfs, disk_path, disk_root, retries
    ):
        side_effects = [RuntimeError()] * (retries - 1)
        side_effects.append(None)
        mock_gfs.return_value.mount_ro.side_effect = side_effects
        with patch('lago.guestfs_tools.find_rootfs') as mock_rootfs:
            mock_rootfs.return_value = disk_root
            with guestfs_tools.guestfs_conn_mount_ro(
                disk_path, disk_root, retries=retries, wait=0
            ) as conn:

                assert call.mount_ro(disk_root, '/') in conn.mock_calls
                assert call.add_drive_ro(disk_path) in conn.mock_calls
            assert conn.mount_ro.call_count == retries
            assert conn.umount.call_count == 1
            assert conn.add_drive_ro.call_count == retries
            assert conn.shutdown.call_count == retries
            assert conn.close.call_count == retries