""" 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(227)


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

    scenario.run(client)


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="CreateULB",
)
def create_ulb_00(client: utest.Client, variables: dict):
    d = {
        "ULBName": "测试",
        "Tag": "Default",
        "Region": variables.get("Region"),
        "OuterMode": "Yes",
        "InnerMode": "No",
    }

    try:
        resp = client.ulb().create_ulb(d)
    except exc.RetCodeException as e:
        resp = e.json()

    variables["ULBId_outer"] = utest.value_at_path(resp, "ULBId")
    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=5,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 4107)],
    action="CreateVServer",
)
def create_vserver_01(client: utest.Client, variables: dict):
    d = {
        "VServerName": "vserver-http",
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
        "Protocol": "HTTP",
        "PersistenceType": "ServerInsert",
        "Method": "Roundrobin",
        "ListenType": "RequestProxy",
        "FrontendPort": 80,
    }

    try:
        resp = client.ulb().create_vserver(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="DescribeVServer",
)
def describe_vserver_02(client: utest.Client, variables: dict):
    d = {
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.ulb().describe_vserver(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=10,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 4107)],
    action="CreateVServer",
)
def create_vserver_03(client: utest.Client, variables: dict):
    d = {
        "VServerName": "vserver-https",
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
        "Protocol": "HTTPS",
        "PersistenceType": "UserDefined",
        "PersistenceInfo": "huangchao",
        "Method": "Source",
        "ListenType": "RequestProxy",
        "FrontendPort": 443,
        "ClientTimeout": 60,
    }

    try:
        resp = client.ulb().create_vserver(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="DescribeVServer",
)
def describe_vserver_04(client: utest.Client, variables: dict):
    d = {
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.ulb().describe_vserver(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=20,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 4107)],
    action="CreateVServer",
)
def create_vserver_05(client: utest.Client, variables: dict):
    d = {
        "VServerName": "vserver-https",
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
        "Protocol": "TCP",
        "PersistenceType": "None",
        "Method": "Source",
        "ListenType": "RequestProxy",
        "FrontendPort": 1024,
    }

    try:
        resp = client.ulb().create_vserver(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=0,
    fast_fail=False,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="DescribeVServer",
)
def describe_vserver_06(client: utest.Client, variables: dict):
    d = {
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.ulb().describe_vserver(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=10,
    fast_fail=False,
    action="DeleteULB",
)
def delete_ulb_07(client: utest.Client, variables: dict):
    d = {
        "ULBId": variables.get("ULBId_outer"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.ulb().delete_ulb(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp
