# Copyright (c) 2014 NetApp, Inc.
# Copyright (c) 2015 Mirantis, Inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""Unit tests for the Generic driver module."""

import os
import time

import ddt
import mock
from oslo_concurrency import processutils
from oslo_config import cfg
from six import moves

from manila.common import constants as const
from manila import compute
from manila import context
from manila import exception
import manila.share.configuration
from manila.share.drivers import generic
from manila.share import share_types
from manila import test
from manila.tests import fake_compute
from manila.tests import fake_service_instance
from manila.tests import fake_share
from manila.tests import fake_utils
from manila.tests import fake_volume
from manila import utils
from manila import volume


CONF = cfg.CONF


def get_fake_manage_share():
    return {
        'id': 'fake',
        'share_proto': 'NFS',
        'share_type_id': 'fake',
        'export_locations': [
            {'path': '10.0.0.1:/foo/fake/path'},
            {'path': '11.0.0.1:/bar/fake/path'},
        ],
    }


def get_fake_snap_dict():
    snap_dict = {
        'status': 'available',
        'project_id': '13c0be6290934bd98596cfa004650049',
        'user_id': 'a0314a441ca842019b0952224aa39192',
        'description': None,
        'deleted': '0',
        'created_at': '2015-08-10 00:05:58',
        'updated_at': '2015-08-10 00:05:58',
        'consistency_group_id': '4b04fdc3-00b9-4909-ba1a-06e9b3f88b67',
        'cgsnapshot_members': [
            {
                'status': 'available',
                'share_type_id': '1a9ed31e-ee70-483d-93ba-89690e028d7f',
                'share_id': 'e14b5174-e534-4f35-bc4f-fe81c1575d6f',
                'user_id': 'a0314a441ca842019b0952224aa39192',
                'deleted': 'False',
                'created_at': '2015-08-10 00:05:58',
                'share': {
                    'id': '03e2f06e-14f2-45a5-9631-0949d1937bd8',
                    'deleted': False,
                },
                'updated_at': '2015-08-10 00:05:58',
                'share_proto': 'NFS',
                'project_id': '13c0be6290934bd98596cfa004650049',
                'cgsnapshot_id': 'f6aa3b59-57eb-421e-965c-4e182538e36a',
                'deleted_at': None,
                'id': '03e2f06e-14f2-45a5-9631-0949d1937bd8',
                'size': 1,
            },
        ],
        'deleted_at': None,
        'id': 'f6aa3b59-57eb-421e-965c-4e182538e36a',
        'name': None,
    }
    return snap_dict


def get_fake_cg_dict():
    cg_dict = {
        'status': 'creating',
        'project_id': '13c0be6290934bd98596cfa004650049',
        'user_id': 'a0314a441ca842019b0952224aa39192',
        'description': None,
        'deleted': 'False',
        'created_at': '2015-08-10 00:07:58',
        'updated_at': None,
        'source_cgsnapshot_id': 'f6aa3b59-57eb-421e-965c-4e182538e36a',
        'host': 'openstack2@cmodeSSVMNFS',
        'deleted_at': None,
        'shares': [
            {
                'id': '02a32f06e-14f2-45a5-9631-7483f1937bd8',
                'deleted': False,
                'source_cgsnapshot_member_id':
                    '03e2f06e-14f2-45a5-9631-0949d1937bd8',
            },

        ],