def test_create(self): instance = mock(Instance) when(BuiltInstance).load(any(), any()).thenReturn(instance) when(instance).validate_can_perform_action().thenReturn(None) when(api.API).create_backup(any()).thenReturn(None) expire_at = int(time.time()) bu = models.Backup.create(self.context, self.instance_id, BACKUP_NAME, BACKUP_DESC, group_id=GROUP_ID,backup_type=BACKUP_TYPE, expire_at=expire_at) db_record = models.DBBackup.find_by(id=bu.id,deleted=False) db_record.data() print "-----> %s" % (db_record.data()) self.assertEqual(bu.id, db_record['id']) self.assertEqual(BACKUP_NAME, db_record['name']) self.assertEqual(BACKUP_DESC, db_record['description']) self.assertEqual(self.instance_id, db_record['instance_id']) self.assertEqual(models.BackupState.NEW, db_record['state']) self.assertEqual(GROUP_ID,db_record["group_id"]) self.assertEqual(expire_at,db_record['expire_at']) self.assertEqual(BACKUP_TYPE,db_record.type)
def test_create_instance_not_active(self): instance = mock(Instance) when(BuiltInstance).load(any(), any()).thenReturn(instance) when(instance).validate_can_perform_action().thenRaise( exception.UnprocessableEntity) self.assertRaises(exception.UnprocessableEntity, models.Backup.create, self.context, self.instance_id, BACKUP_NAME, BACKUP_DESC, group_id=GROUP_ID,backup_type=TYPE)
def _create_backup_strategy(self): instance = mock(Instance) when(BuiltInstance).load(any(), any()).thenReturn(instance) when(instance).validate_can_perform_action().thenReturn(None) process = fake() process.pid = "pid" def _terminate(): pass process.terminate = _terminate print process.pid bu = models.Backup.create(self.context, self.instance_id, BACKUP_NAME, BACKUP_DESC, group_id=GROUP_ID, backup_type=BACKUP_TYPE,expire_at=1000) from trove.guestagent.backup import backupagent backup_strategy = backupagent.get_backup_strategy("InnoBackupEx_master", "trove.patch.guestagent.strategies.backup.impl") print backup_strategy mysql_dir = CONF.mount_point backup_dir = CONF.ebs_backup_path _bk = backup_strategy(filename=bu.id, mysql_dir=mysql_dir, backup_dir=backup_dir,parallel=4,compress_thread=4) print _bk.command SUCCESS_FLAG = "completed OK" return _bk, process, SUCCESS_FLAG
def test_delete_backup_is_running(self): backup = mock() backup.is_running = True when(models.Backup).get_by_id(any(), any()).thenReturn(backup) self.assertRaises(exception.UnprocessableEntity, models.Backup.delete, self.context, 'backup_id')