""" Code is generated by ucloud-model, DO NOT EDIT IT. """

import pytest
import logging

from ucloud.core import exc
from ucloud.testing import env, funcs, op, utest

logger = logging.getLogger(__name__)


scenario = utest.Scenario(2117)


@pytest.mark.skipif(env.is_ut(), reason=env.get_skip_reason())
def test_set_2117(client: utest.Client, variables: dict):
    scenario.initial(variables)

    scenario.variables["ResourceType"] = "single"
    scenario.variables["ConfigId"] = "9a891891-c245-4b66-bce8-67e59430d67c"
    scenario.variables["Name"] = "single_memcache"
    scenario.variables["Protocol"] = "memcache"
    scenario.variables["Count"] = 1

    scenario.run(client)


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "CreateUMemcacheGroupResponse"),
    ],
    action="CreateUMemcacheGroup",
)
def create_umem_cache_group_00(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "Size": 1,
        "Region": variables.get("Region"),
        "Quantity": 1,
        "Name": variables.get("Name"),
        "ConfigId": variables.get("ConfigId"),
        "ChargeType": "Month",
    }

    try:
        resp = client.umem().create_umem_cache_group(d)
    except exc.RetCodeException as e:
        resp = e.json()

    variables["group_id"] = utest.value_at_path(resp, "GroupId")
    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "CheckUMemcacheAllowanceResponse"),
    ],
    action="CheckUMemcacheAllowance",
)
def check_umem_cache_allowance_01(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "Size": 1,
        "Region": variables.get("Region"),
        "Count": variables.get("Count"),
    }

    try:
        resp = client.invoke("CheckUMemcacheAllowance", d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=30,
    retry_interval=10,
    startup_delay=20,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "DataSet.0.State", "Running"),
    ],
    action="DescribeUMem",
)
def describe_umem_02(client: utest.Client, variables: dict):
    d = {
        "ResourceId": variables.get("group_id"),
        "Region": variables.get("Region"),
        "Protocol": variables.get("Protocol"),
        "Offset": 0,
        "Limit": 1000,
    }

    try:
        resp = client.invoke("DescribeUMem", d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=100,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeUMemcacheGroupResponse"),
    ],
    action="DescribeUMemcacheGroup",
)
def describe_umem_cache_group_03(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "Region": variables.get("Region"),
        "Offset": 0,
        "Limit": 100,
        "GroupId": variables.get("group_id"),
    }

    try:
        resp = client.umem().describe_umem_cache_group(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=0,
    retry_interval=0,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="ResizeUMemcacheGroup",
)
def resize_umem_cache_group_04(client: utest.Client, variables: dict):
    d = {
        "Size": 2,
        "Region": variables.get("Region"),
        "GroupId": variables.get("group_id"),
    }

    try:
        resp = client.invoke("ResizeUMemcacheGroup", d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=30,
    retry_interval=10,
    startup_delay=3,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "DataSet.0.State", "Running"),
    ],
    action="DescribeUMem",
)
def describe_umem_05(client: utest.Client, variables: dict):
    d = {
        "ResourceId": variables.get("group_id"),
        "Region": variables.get("Region"),
        "Protocol": variables.get("Protocol"),
        "Offset": 0,
        "Limit": 1000,
    }

    try:
        resp = client.invoke("DescribeUMem", d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=0,
    retry_interval=0,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="RestartUMemcacheGroup",
)
def restart_umem_cache_group_06(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "Region": variables.get("Region"),
        "GroupId": variables.get("group_id"),
    }

    try:
        resp = client.umem().restart_umem_cache_group(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=30,
    retry_interval=10,
    startup_delay=60,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "DataSet.0.State", "Running"),
    ],
    action="DescribeUMem",
)
def describe_umem_07(client: utest.Client, variables: dict):
    d = {
        "ResourceId": variables.get("group_id"),
        "Region": variables.get("Region"),
        "Protocol": variables.get("Protocol"),
        "Offset": 0,
        "Limit": 1000,
    }

    try:
        resp = client.invoke("DescribeUMem", d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=10,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DeleteUMemcacheGroupResponse"),
    ],
    action="DeleteUMemcacheGroup",
)
def delete_umem_cache_group_08(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "Region": variables.get("Region"),
        "GroupId": variables.get("group_id"),
    }

    try:
        resp = client.umem().delete_umem_cache_group(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=10,
    fast_fail=False,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeUMemResponse"),
        ("object_not_contains", "DataSet", variables.get("group_id")),
    ],
    action="DescribeUMem",
)
def describe_umem_09(client: utest.Client, variables: dict):
    d = {
        "ResourceId": variables.get("group_id"),
        "Region": variables.get("Region"),
        "Protocol": variables.get("Protocol"),
        "Offset": 0,
        "Limit": 100,
    }

    try:
        resp = client.invoke("DescribeUMem", d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp
