#   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.
# import datetime
import random
import uuid

import mock

from openstackclient.tests.unit import utils
from otcextensions.tests.unit.osclient import test_base

from otcextensions.sdk.dcs.v1 import backup
from otcextensions.sdk.dcs.v1 import config
from otcextensions.sdk.dcs.v1 import instance
from otcextensions.sdk.dcs.v1 import restore
from otcextensions.sdk.dcs.v1 import statistic


class TestDCS(utils.TestCommand):

    def setUp(self):
        super(TestDCS, self).setUp()

        self.app.client_manager.dcs = mock.Mock()
        self.client = self.app.client_manager.dcs

        self.client.get_instance = mock.Mock()
        self.client.find_instance = mock.Mock()
        self.client.instances = mock.Mock()
        self.client.delete_instance = mock.Mock()
        self.client.update_instance = mock.Mock()
        self.client.create_instance = mock.Mock()
        self.client.extend_instance = mock.Mock()


class FakeInstance(test_base.Fake):
    """Fake one or more Instance"""

    @classmethod
    def generate(cls):
        object_info = {
            'name': 'group-' + uuid.uuid4().hex,
            'id': 'id-' + uuid.uuid4().hex,
            'description': 'SOME description',
            'status': random.choice(['CREATING', 'CREATEFILED',
                                     'RUNNING', 'ERROR', 'STARTING',
                                     'RESTARTING', 'CLOSING', 'CLOSED',
                                     'EXTENDING']),
            'engine': uuid.uuid4().hex,
            'capacity': random.randint(1, 100),
            'ip': uuid.uuid4().hex,
            'port': random.randint(1, 65535),
            'resource_spec_code': random.choice(['dcs.single_node',
                                                 'dcs.master_standby',
                                                 'dcs.cluster'
                                                 ]),
            'engine_version': uuid.uuid4().hex,
            'internal_version': uuid.uuid4().hex,
            'charging_mode': random.randint(0, 10),
            'vpc_id': uuid.uuid4().hex,
            'vpc_name': uuid.uuid4().hex,
            'subnet_id': uuid.uuid4().hex,
            'subnet_name': uuid.uuid4().hex,
            'subnet_cidr': uuid.uuid4().hex,
            'security_group_id': uuid.uuid4().hex,
            'security_group_name': uuid.uuid4().hex,
            'created_at': uuid.uuid4().hex,
            'error_code': uuid.uuid4().hex,
            'product_id': random.choice(['OTC_DCS_SINGLE',
                                         'OTC_DCS_MS',
                                         'OTC_DCS_CL']),
            'available_zones': uuid.uuid4().hex,
            'max_memory': random.randint(0, 10),
            'used_memory': random.randint(0, 10),
            'user_id': uuid.uuid4().hex,
            'user_name': uuid.uuid4().hex,
            'order_id': uuid.uuid4().hex,
            'maintain_begin': uuid.uuid4().hex,
            'maintain_end': uuid.uuid4().hex,
        }
        obj = instance.Instance.existing(**object_info)
        return obj


class FakeStatistic(test_base.Fake):
    """Fake one or more Statistic"""

    @classmethod
    def generate(cls):
        object_info = {
            'instance_id': 'instance_id-' + uuid.uuid4().hex,
            'max_memory': random.randint(1, 65535),
            'used_memory': random.randint(1, 65535),
            'cmd_get_count': random.randint(1, 65535),
            'cmd_set_count': random.randint(1, 65535),
            'used_cpu': 'cpu-' + uuid.uuid4().hex,
            'input_kbps': 'input-' + uuid.uuid4().hex,
            'output_kbps': 'output-' + uuid.uuid4().hex,

        }
        obj = statistic.Statistic.existing(**object_info)
        return obj


class FakeBackup(test_base.Fake):
    """Fake one or more Backup"""

    @classmethod
    def generate(cls):
        object_info = {
            'instance_id': 'instance_id-' + uuid.uuid4().hex,
            'id': 'id-' + uuid.uuid4().hex,
            'size': random.randint(1, 65535),
            'period': uuid.uuid4().hex,
            'description': uuid.uuid4().hex,
            'progress': uuid.uuid4().hex,
            'created_at': uuid.uuid4().hex,
            'updated_at': uuid.uuid4().hex,
            'type': uuid.uuid4().hex,
            'name': uuid.uuid4().hex,
            'error_code': uuid.uuid4().hex,
            'is_restorable': True,

        }
        obj = backup.Backup.existing(**object_info)
        return obj


class FakeRestore(test_base.Fake):
    """Fake one or more Restore"""

    @classmethod
    def generate(cls):
        object_info = {
            'instance_id': 'instance_id-' + uuid.uuid4().hex,
            'max_memory': random.randint(1, 65535),
            'used_memory': random.randint(1, 65535),
            'cmd_get_count': random.randint(1, 65535),
            'cmd_set_count': random.randint(1, 65535),
            'used_cpu': 'cpu-' + uuid.uuid4().hex,
            'input_kbps': 'input-' + uuid.uuid4().hex,
            'output_kbps': 'output-' + uuid.uuid4().hex
        }
        obj = restore.Restore.existing(**object_info)
        return obj


class FakeConfig(test_base.Fake):
    """Fake one or more Config"""

    @classmethod
    def generate(cls):
        object_info = {
            'instance_id': 'instance_id-' + uuid.uuid4().hex,
            'id': uuid.uuid4().hex,
            'name': uuid.uuid4().hex,
            'value': uuid.uuid4().hex,
            'value_type': uuid.uuid4().hex,
            'value_range': uuid.uuid4().hex,
            'default_value': uuid.uuid4().hex,
            'description': uuid.uuid4().hex
        }
        obj = config.Config.existing(**object_info)
        return obj

[((1083, 1094), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1092, 1094), False, 'import mock\n'), ((1181, 1192), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1190, 1192), False, 'import mock\n'), ((1229, 1240), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1238, 1240), False, 'import mock\n'), ((1273, 1284), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1282, 1284), False, 'import mock\n'), ((1323, 1334), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1332, 1334), False, 'import mock\n'), ((1373, 1384), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1382, 1384), False, 'import mock\n'), ((1423, 1434), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1432, 1434), False, 'import mock\n'), ((1473, 1484), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (1482, 1484), False, 'import mock\n'), ((3566, 3607), 'otcextensions.sdk.dcs.v1.instance.Instance.existing', 'instance.Instance.existing', ([], {}), '(**object_info)\n', (3592, 3607), False, 'from otcextensions.sdk.dcs.v1 import instance\n'), ((4233, 4276), 'otcextensions.sdk.dcs.v1.statistic.Statistic.existing', 'statistic.Statistic.existing', ([], {}), '(**object_info)\n', (4261, 4276), False, 'from otcextensions.sdk.dcs.v1 import statistic\n'), ((4978, 5015), 'otcextensions.sdk.dcs.v1.backup.Backup.existing', 'backup.Backup.existing', ([], {}), '(**object_info)\n', (5000, 5015), False, 'from otcextensions.sdk.dcs.v1 import backup\n'), ((5635, 5674), 'otcextensions.sdk.dcs.v1.restore.Restore.existing', 'restore.Restore.existing', ([], {}), '(**object_info)\n', (5659, 5674), False, 'from otcextensions.sdk.dcs.v1 import restore\n'), ((6208, 6245), 'otcextensions.sdk.dcs.v1.config.Config.existing', 'config.Config.existing', ([], {}), '(**object_info)\n', (6230, 6245), False, 'from otcextensions.sdk.dcs.v1 import config\n'), ((1786, 1912), 'random.choice', 'random.choice', (["['CREATING', 'CREATEFILED', 'RUNNING', 'ERROR', 'STARTING', 'RESTARTING',\n    'CLOSING', 'CLOSED', 'EXTENDING']"], {}), "(['CREATING', 'CREATEFILED', 'RUNNING', 'ERROR', 'STARTING',\n    'RESTARTING', 'CLOSING', 'CLOSED', 'EXTENDING'])\n", (1799, 1912), False, 'import random\n'), ((2085, 2107), 'random.randint', 'random.randint', (['(1)', '(100)'], {}), '(1, 100)\n', (2099, 2107), False, 'import random\n'), ((2165, 2189), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (2179, 2189), False, 'import random\n'), ((2225, 2296), 'random.choice', 'random.choice', (["['dcs.single_node', 'dcs.master_standby', 'dcs.cluster']"], {}), "(['dcs.single_node', 'dcs.master_standby', 'dcs.cluster'])\n", (2238, 2296), False, 'import random\n'), ((2573, 2594), 'random.randint', 'random.randint', (['(0)', '(10)'], {}), '(0, 10)\n', (2587, 2594), False, 'import random\n'), ((3029, 3090), 'random.choice', 'random.choice', (["['OTC_DCS_SINGLE', 'OTC_DCS_MS', 'OTC_DCS_CL']"], {}), "(['OTC_DCS_SINGLE', 'OTC_DCS_MS', 'OTC_DCS_CL'])\n", (3042, 3090), False, 'import random\n'), ((3249, 3270), 'random.randint', 'random.randint', (['(0)', '(10)'], {}), '(0, 10)\n', (3263, 3270), False, 'import random\n'), ((3299, 3320), 'random.randint', 'random.randint', (['(0)', '(10)'], {}), '(0, 10)\n', (3313, 3320), False, 'import random\n'), ((3856, 3880), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (3870, 3880), False, 'import random\n'), ((3909, 3933), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (3923, 3933), False, 'import random\n'), ((3964, 3988), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (3978, 3988), False, 'import random\n'), ((4019, 4043), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (4033, 4043), False, 'import random\n'), ((4557, 4581), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (4571, 4581), False, 'import random\n'), ((5260, 5284), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (5274, 5284), False, 'import random\n'), ((5313, 5337), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (5327, 5337), False, 'import random\n'), ((5368, 5392), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (5382, 5392), False, 'import random\n'), ((5423, 5447), 'random.randint', 'random.randint', (['(1)', '(65535)'], {}), '(1, 65535)\n', (5437, 5447), False, 'import random\n'), ((2043, 2055), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2053, 2055), False, 'import uuid\n'), ((2127, 2139), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2137, 2139), False, 'import uuid\n'), ((2476, 2488), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2486, 2488), False, 'import uuid\n'), ((2526, 2538), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2536, 2538), False, 'import uuid\n'), ((2618, 2630), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2628, 2630), False, 'import uuid\n'), ((2660, 2672), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2670, 2672), False, 'import uuid\n'), ((2703, 2715), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2713, 2715), False, 'import uuid\n'), ((2748, 2760), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2758, 2760), False, 'import uuid\n'), ((2793, 2805), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2803, 2805), False, 'import uuid\n'), ((2844, 2856), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2854, 2856), False, 'import uuid\n'), ((2897, 2909), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2907, 2909), False, 'import uuid\n'), ((2941, 2953), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2951, 2953), False, 'import uuid\n'), ((2985, 2997), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (2995, 2997), False, 'import uuid\n'), ((3205, 3217), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3215, 3217), False, 'import uuid\n'), ((3345, 3357), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3355, 3357), False, 'import uuid\n'), ((3388, 3400), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3398, 3400), False, 'import uuid\n'), ((3430, 3442), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3440, 3442), False, 'import uuid\n'), ((3478, 3490), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3488, 3490), False, 'import uuid\n'), ((3524, 3536), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3534, 3536), False, 'import uuid\n'), ((4605, 4617), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4615, 4617), False, 'import uuid\n'), ((4650, 4662), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4660, 4662), False, 'import uuid\n'), ((4692, 4704), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4702, 4704), False, 'import uuid\n'), ((4736, 4748), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4746, 4748), False, 'import uuid\n'), ((4780, 4792), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4790, 4792), False, 'import uuid\n'), ((4818, 4830), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4828, 4830), False, 'import uuid\n'), ((4856, 4868), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4866, 4868), False, 'import uuid\n'), ((4900, 4912), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4910, 4912), False, 'import uuid\n'), ((5909, 5921), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5919, 5921), False, 'import uuid\n'), ((5947, 5959), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5957, 5959), False, 'import uuid\n'), ((5986, 5998), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5996, 5998), False, 'import uuid\n'), ((6030, 6042), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (6040, 6042), False, 'import uuid\n'), ((6075, 6087), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (6085, 6087), False, 'import uuid\n'), ((6122, 6134), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (6132, 6134), False, 'import uuid\n'), ((6167, 6179), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (6177, 6179), False, 'import uuid\n'), ((1655, 1667), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (1665, 1667), False, 'import uuid\n'), ((1699, 1711), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (1709, 1711), False, 'import uuid\n'), ((3812, 3824), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (3822, 3824), False, 'import uuid\n'), ((4078, 4090), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4088, 4090), False, 'import uuid\n'), ((4133, 4145), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4143, 4145), False, 'import uuid\n'), ((4190, 4202), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4200, 4202), False, 'import uuid\n'), ((4475, 4487), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4485, 4487), False, 'import uuid\n'), ((4519, 4531), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4529, 4531), False, 'import uuid\n'), ((5216, 5228), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5226, 5228), False, 'import uuid\n'), ((5482, 5494), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5492, 5494), False, 'import uuid\n'), ((5537, 5549), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5547, 5549), False, 'import uuid\n'), ((5594, 5606), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5604, 5606), False, 'import uuid\n'), ((5873, 5885), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5883, 5885), False, 'import uuid\n')]