Ejemplo n.º 1
0
    def test_snapshot_mount_error_raises_Exception(self,
                                                   mock_create_dir,
                                                   mock_get_lvm_info,
                                                   mock_get_vol_fs_type,
                                                   mock_popen,
                                                   mock_lvm_snap_remove):
        mock_get_vol_fs_type.return_value = 'xfs'
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}
        mock_lvcreate_process, mock_mount_process = Mock(), Mock()

        mock_lvcreate_process.communicate.return_value = '', ''
        mock_lvcreate_process.returncode = 0

        mock_mount_process.communicate.return_value = '', 'mount error'
        mock_mount_process.returncode = 1

        mock_popen.side_effect = [mock_lvcreate_process, mock_mount_process]

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'ro'

        with self.assertRaises(Exception) as cm:
            lvm.lvm_snap(backup_opt)
        the_exception = cm.exception
        self.assertIn('lvm snapshot mounting error', the_exception.message)

        mock_lvm_snap_remove.assert_called_once_with(backup_opt)
Ejemplo n.º 2
0
    def test_mysql_mode_locks_unlocks_tables(self, mock_create_dir, mock_get_lvm_info, mock_get_vol_fs_type, mock_popen):
        mock_get_vol_fs_type.return_value = 'xfs'
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}
        mock_process = Mock()
        mock_process.communicate.return_value = '', ''
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'ro'
        backup_opt.mode = 'mysql'
        backup_opt.mysql_db_inst = Mock()
        mock_cursor = Mock()
        backup_opt.mysql_db_inst.cursor.return_value = mock_cursor

        self.assertTrue(lvm.lvm_snap(backup_opt))

        first_call = call('FLUSH TABLES WITH READ LOCK')
        second_call = call('UNLOCK TABLES')
        self.assertEquals(first_call, mock_cursor.execute.call_args_list[0])
        self.assertEquals(second_call, mock_cursor.execute.call_args_list[1])
Ejemplo n.º 3
0
    def test_with_auto_snap_param_path_mismatch_raises(self, mock_create_dir, mock_get_lvm_info, mock_validate_lvm_params):
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}

        backup_opt = Mock()
        backup_opt.snapshot = False
        backup_opt.lvm_auto_snap = '/just/a/path'
        backup_opt.path_to_backup = '/different'
        backup_opt.lvm_dirmount = '/var/mountpoint'

        self.assertRaises(Exception, lvm.lvm_snap, backup_opt)
Ejemplo n.º 4
0
    def test_with_snapshot_opt_simple_sets_correct_path_and_raises_on_perm(self, mock_create_dir, mock_get_lvm_info):
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'invalid_value'

        with self.assertRaises(Exception) as cm:
            lvm.lvm_snap(backup_opt)
        the_exception = cm.exception
        self.assertIn('Invalid value for option lvm-snap-perm', the_exception.message)
Ejemplo n.º 5
0
    def test_ok(self, mock_create_dir, mock_get_lvm_info, mock_get_vol_fs_type, mock_popen, mock_validate_lvm_params):
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}
        mock_process = Mock()
        mock_process.communicate.return_value = '', ''
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'ro'
        backup_opt.lvm_volgroup = ''
        backup_opt.lvm_srcvol = ''

        self.assertTrue(lvm.lvm_snap(backup_opt))
Ejemplo n.º 6
0
    def test_snapshot_fails(self, mock_create_dir, mock_get_lvm_info, mock_get_vol_fs_type, mock_popen, mock_validate_lvm_params):
        mock_get_lvm_info.return_value = {
            'volgroup': 'lvm_volgroup',
            'srcvol': 'lvm_device',
            'snap_path': 'snap_path'}
        mock_process = Mock()
        mock_process.communicate.return_value = '', ''
        mock_process.returncode = 1
        mock_popen.return_value = mock_process

        backup_opt = Mock()
        backup_opt.snapshot = True
        backup_opt.lvm_auto_snap = ''
        backup_opt.path_to_backup = '/just/a/path'
        backup_opt.lvm_dirmount = '/var/mountpoint'
        backup_opt.lvm_snapperm = 'ro'

        with self.assertRaises(Exception) as cm:
            lvm.lvm_snap(backup_opt)
        the_exception = cm.exception
        self.assertIn('lvm snapshot creation error', the_exception.message)
Ejemplo n.º 7
0
 def test_no_lvm_configured_returns_false(self, mock_validate_lvm_params):
     backup_opt = Mock()
     backup_opt.lvm_auto_snap = ''
     mock_validate_lvm_params.return_value = False
     backup_opt.snapshot = False
     self.assertFalse(lvm.lvm_snap(backup_opt))