'Test create incremental backup.'

@decorators.idempotent_id('c810fe2c-cb40-43ab-96aa-471b74516a98')
def test_incremental_backup(self):

    volume = self.create_volume(size=CONF.volume.volume_size, imageRef=CONF.compute.image_ref)
    self.addCleanup(self.volumes_client.delete_volume, volume['id'])
    backup = self.backups_client.create_backup(volume_id=volume['id'])['backup']
    waiters.wait_for_volume_resource_status(self.backups_client, backup['id'], 'available')
    bd_map = [{'volume_id': volume['id'], 'delete_on_termination': '0'}]
    server_name = data_utils.rand_name('instance')
    server = self.create_server(name=server_name, block_device_mapping=bd_map, wait_until='ACTIVE')
    self.servers_client.delete_server(server['id'])
    waiters.wait_for_volume_resource_status(self.volumes_client, volume['id'], 'available')
    backup_incr = self.backups_client.create_backup(volume_id=volume['id'], incremental=True)['backup']
    waiters.wait_for_volume_resource_status(self.backups_client, backup_incr['id'], 'available')
    is_incremental = self.backups_client.show_backup(backup_incr['id'])['backup']['is_incremental']
    self.assertTrue(is_incremental)
    self.backups_client.delete_backup(backup_incr['id'])
    self.backups_client.wait_for_resource_deletion(backup_incr['id'])
    self.backups_client.delete_backup(backup['id'])
    self.backups_client.wait_for_resource_deletion(backup['id'])
