def test_create_volume_backup(self, mock_connection):
        # Prepare the context for create snapshot operation
        self._prepare_context_for_operation(
            test_name='VolumeTestCase',
            ctx_operation_name='cloudify.interfaces.snapshot.create')

        # Set resource id as runtime properties for volume instance
        self._ctx.instance.runtime_properties['id'] = '1'

        snapshot_name = \
            get_snapshot_name('volume', 'test_volume_backup', False)

        volume_backup_instance = openstack.block_storage.v2.backup.Backup(
            **{
                'id': '1',
                'name': snapshot_name,
                'description': 'volume_backup_description',
                'availability_zone': 'test_availability_zone',
                'status': VOLUME_STATUS_CREATING
            })
        available_volume_backup = \
            openstack.block_storage.v2.backup.Backup(**{
                'id': '1',
                'name': snapshot_name,
                'description': 'volume_backup_description',
                'availability_zone': 'test_availability_zone',
                'status': VOLUME_STATUS_AVAILABLE
            })
        # Mock create volume backup response
        mock_connection().block_storage.create_backup = \
            mock.MagicMock(return_value=volume_backup_instance)

        # Mock get volume backup response
        mock_connection().block_storage.get_backup = \
            mock.MagicMock(return_value=available_volume_backup)

        snapshot_params = {
            'snapshot_name': 'test_volume_backup',
            'snapshot_incremental': False
        }

        # Call create backup volume volume
        volume.snapshot_create(**snapshot_params)

        for attr in [VOLUME_SNAPSHOT_TASK, VOLUME_BACKUP_ID]:
            self.assertNotIn(attr, self._ctx.instance.runtime_properties)
    def test_create_volume_snapshot_with_retry(self, mock_connection):
        # Prepare the context for create snapshot operation
        self._prepare_context_for_operation(
            test_name='VolumeTestCase',
            ctx_operation_name='cloudify.interfaces.snapshot.create')

        # Set resource id as runtime properties for volume instance
        self._ctx.instance.runtime_properties['id'] = '1'

        snapshot_name = \
            get_snapshot_name('volume', 'test_volume_snapshot', True)

        volume_snapshot_instance = \
            openstack.block_storage.v2.snapshot.Snapshot(**{
                'id': '1',
                'name': snapshot_name,
                'description': 'volume_snapshot_description',
                'status': VOLUME_STATUS_CREATING
            })
        # Mock create volume snapshot response
        mock_connection().block_storage.create_snapshot = \
            mock.MagicMock(return_value=volume_snapshot_instance)

        # Mock get volume snapshot response
        mock_connection().block_storage.get_snapshot = \
            mock.MagicMock(return_value=volume_snapshot_instance)

        snapshot_params = {
            'snapshot_name': 'test_volume_snapshot',
            'snapshot_type': 'Daily',
            'snapshot_incremental': True
        }

        # Call create snapshot volume volume
        with self.assertRaises(OperationRetry):
            volume.snapshot_create(**snapshot_params)