def test_with_mount_and_with_check_file(self):
        """Test remount_if_needed when mount works and check file already exists."""
        self.mock.exists.return_value = True
        windows.remount_if_needed()

        self.assertEqual(0, self.mock.call.call_count)
        self.assertEqual(0, self.mock.check_call.call_count)
        self.assertEqual(0, self.mock.write_data_to_file.call_count)
    def test_without_mount_and_with_check_file_no_retry(self):
        """Test remount_if_needed when mount does not exist, but check file does and
    check file does not get recreated later on successful remount."""
        self.mock.exists.side_effect = [False, True]
        windows.remount_if_needed()

        self.mock.call.assert_called_once_with(['umount', '-f', 'X:\\'])
        self.mock.check_call.assert_called_once_with([
            'mount', '-o', 'anon', '-o', 'nolock', '-o', 'retry=10',
            'clusterfuzz-windows-0001:/cfvolume', 'X:\\'
        ])
        self.assertEqual(0, self.mock.write_data_to_file.call_count)
    def test_without_mount_and_without_check_file_retry(self):
        """Test remount_if_needed when check file does not exist and gets created
    later on second remount try."""
        self.mock.exists.side_effect = [False, False, False, False, True]
        windows.remount_if_needed()

        self.mock.call.assert_has_calls([mock.call(['umount', '-f', 'X:\\'])] *
                                        2)
        self.mock.check_call.assert_has_calls([
            mock.call([
                'mount', '-o', 'anon', '-o', 'nolock', '-o', 'retry=10',
                'clusterfuzz-windows-0001:/cfvolume', 'X:\\'
            ])
        ] * 2)
        self.mock.write_data_to_file.assert_called_once_with('ok', r'X:\check')
    def test_without_check_file_fail(self):
        """Test remount_if_needed when check file does not exist and does not get
    recreated due to remount failure."""
        self.mock.exists.side_effect = [False, False, False] * 6

        with self.assertRaises(Exception):
            windows.remount_if_needed()

        self.mock.call.assert_has_calls([mock.call(['umount', '-f', 'X:\\'])] *
                                        6)
        self.mock.check_call.assert_has_calls([
            mock.call([
                'mount', '-o', 'anon', '-o', 'nolock', '-o', 'retry=10',
                'clusterfuzz-windows-0001:/cfvolume', 'X:\\'
            ])
        ] * 6)
        self.mock.write_data_to_file.assert_has_calls(
            [mock.call('ok', r'X:\check')] * 6)