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


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

    scenario.variables["Password"] = "Z3VhbmxpeXVhbm1pbWExMjMhQCM="
    scenario.variables["SnapshotSysName"] = "snapshot-ARK-SYS-01"
    scenario.variables["SnapshotSysDesc"] = "snapshot-ARK-SYS-01-desc"
    scenario.variables["SnapDiskType"] = "LocalBoot"
    scenario.variables["SnapshotDataNameModify"] = "snapshot-ARK-DATA-01-modify"
    scenario.variables[
        "SnapshotDataDescModify"
    ] = "snapshot-ARK-DATA-01-desc-Modify"
    scenario.variables["UhostName"] = "uhost-snapshot-ARK-auto-api-1"
    scenario.variables["SnapshotDataName"] = "snapshot-ARK-DATA-01"
    scenario.variables["SnapshotDataDesc"] = "snapshot-ARK-DATA-01-desc"
    scenario.variables[
        "CreateFromTimeMachinePassword"
    ] = "Z3VhbmxpeXVhbm1pbWExMjMhQCM="
    scenario.variables["ImageID"] = "#{u_get_image_resource($Region,$Zone)}"

    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", "DescribeImageResponse"),
    ],
    action="DescribeImage",
)
def describe_image_00(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "Region": variables.get("Region"),
        "OsType": "Linux",
        "ImageType": "Base",
    }

    try:
        resp = client.uhost().describe_image(d)
    except exc.RetCodeException as e:
        resp = e.json()

    variables["ImageID"] = utest.value_at_path(resp, "ImageSet.0.ImageId")
    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [("str_eq", "RetCode", 0)],
    action="CreateUHostInstance",
)
def create_uhost_instance_01(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "TimemachineFeature": "no",
        "Region": variables.get("Region"),
        "Password": "VXFhNzg5VGVzdCFAIyQ7LA==",
        "Name": variables.get("UhostName"),
        "Memory": 1024,
        "LoginMode": "Password",
        "ImageId": variables.get("ImageID"),
        "HotplugFeature": False,
        "GPU": False,
        "DiskSpace": 10,
        "CPU": 1,
    }

    try:
        resp = client.uhost().create_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    variables["hostId"] = utest.value_at_path(resp, "UHostIds.0")
    return resp


@scenario.step(
    max_retries=100,
    retry_interval=30,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "UHostSet.0.State", "Running"),
        ("str_eq", "UHostSet.0.TimemachineFeature", "no"),
        ("str_eq", "UHostSet.0.BootDiskState", "Normal"),
    ],
    action="DescribeUHostInstance",
)
def describe_uhost_instance_02(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostIds": [variables.get("hostId")],
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().describe_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "StopUHostInstanceResponse"),
    ],
    action="StopUHostInstance",
)
def stop_uhost_instance_03(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().stop_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=10,
    retry_interval=10,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "UHostSet.0.State", "Stopped"),
    ],
    action="DescribeUHostInstance",
)
def describe_uhost_instance_04(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostIds": [variables.get("hostId")],
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().describe_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "UpgradeToArkUHostInstanceResponse"),
    ],
    action="UpgradeToArkUHostInstance",
)
def upgrade_to_ark_uhost_instance_05(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostIds": [variables.get("hostId")],
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().upgrade_to_ark_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=200,
    retry_interval=30,
    startup_delay=100,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "UHostSet.0.State", "Stopped"),
        ("str_eq", "UHostSet.0.TimemachineFeature", "yes"),
        ("str_eq", "UHostSet.0.BootDiskState", "Normal"),
        ("str_eq", "UHostSet.0.DiskSet.0.BackupType", "DATAARK"),
    ],
    action="DescribeUHostInstance",
)
def describe_uhost_instance_06(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostIds": [variables.get("hostId")],
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().describe_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "StartUHostInstanceResponse"),
    ],
    action="StartUHostInstance",
)
def start_uhost_instance_07(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().start_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=30,
    retry_interval=30,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "UHostSet.0.State", "Running"),
        ("str_eq", "UHostSet.0.TimemachineFeature", "yes"),
        ("str_eq", "UHostSet.0.DiskSet.0.BackupType", "DATAARK"),
    ],
    action="DescribeUHostInstance",
)
def describe_uhost_instance_08(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostIds": [variables.get("hostId")],
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().describe_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=60,
    retry_interval=60,
    startup_delay=100,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeUhostTmMetaResponse"),
        ("str_eq", "UtmStatus", "normal"),
    ],
    action="DescribeUhostTmMeta",
)
def describe_uhost_tm_meta_09(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UhostId": variables.get("hostId"),
        "Region": variables.get("Region"),
    }

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

    variables["VdiskIdSys"] = utest.value_at_path(resp, "DataSet.0.VdiskId")
    variables["VdiskIdData"] = utest.value_at_path(resp, "DataSet.1.VdiskId")
    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeVDiskTmListResponse"),
    ],
    action="DescribeVDiskTmList",
)
def describe_v_disk_tm_list_10(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "VDiskId": variables.get("VdiskIdSys"),
        "SnapshotType": "all",
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeVDiskTmListResponse"),
    ],
    action="DescribeVDiskTmList",
)
def describe_v_disk_tm_list_11(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "VDiskId": variables.get("VdiskIdData"),
        "SnapshotType": "all",
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "CreateUserVDiskSnapshotResponse"),
    ],
    action="CreateUserVDiskSnapshot",
)
def create_user_v_disk_snapshot_12(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "VDiskId": variables.get("VdiskIdSys"),
        "Region": variables.get("Region"),
        "Name": variables.get("SnapshotSysName"),
        "Comment": variables.get("SnapshotSysDesc"),
    }

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

    variables["VdiskSnapIDSys"] = utest.value_at_path(resp, "SnapshotId.0")
    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "CreateUserVDiskSnapshotResponse"),
    ],
    action="CreateUserVDiskSnapshot",
)
def create_user_v_disk_snapshot_13(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "VDiskId": variables.get("VdiskIdData"),
        "Region": variables.get("Region"),
        "Name": variables.get("SnapshotDataName"),
        "Comment": variables.get("SnapshotDataDesc"),
    }

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

    variables["VdiskSnapIDData"] = utest.value_at_path(resp, "SnapshotId.0")
    return resp


@scenario.step(
    max_retries=30,
    retry_interval=30,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeSnapshotResponse"),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotId",
            variables.get("VdiskSnapIDSys"),
        ),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotName",
            variables.get("SnapshotSysName"),
        ),
        ("str_eq", "UHostSnapshotSet.0.DiskType", "LocalBoot"),
        (
            "str_eq",
            "UHostSnapshotSet.0.ResourceName",
            variables.get("UhostName"),
        ),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotDescription",
            variables.get("SnapshotSysDesc"),
        ),
        ("str_eq", "UHostSnapshotSet.0.State", "Normal"),
    ],
    action="DescribeSnapshot",
)
def describe_snapshot_14(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "SnapshotIds": [variables.get("VdiskSnapIDSys")],
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=30,
    retry_interval=10,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeSnapshotResponse"),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotId",
            variables.get("VdiskSnapIDData"),
        ),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotName",
            variables.get("SnapshotDataName"),
        ),
        ("str_eq", "UHostSnapshotSet.0.DiskType", "LocalData"),
        (
            "str_eq",
            "UHostSnapshotSet.0.ResourceName",
            variables.get("UhostName"),
        ),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotDescription",
            variables.get("SnapshotDataDesc"),
        ),
        ("str_eq", "UHostSnapshotSet.0.State", "Normal"),
    ],
    action="DescribeSnapshot",
)
def describe_snapshot_15(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "SnapshotIds": [variables.get("VdiskSnapIDData")],
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "ModifySnapshotResponse"),
    ],
    action="ModifySnapshot",
)
def modify_snapshot_16(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "SnapshotName": variables.get("SnapshotDataNameModify"),
        "SnapshotId": variables.get("VdiskSnapIDData"),
        "SnapshotDescription": variables.get("SnapshotDataDescModify"),
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=10,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeSnapshotResponse"),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotId",
            variables.get("VdiskSnapIDData"),
        ),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotName",
            variables.get("SnapshotDataNameModify"),
        ),
        ("str_eq", "UHostSnapshotSet.0.DiskType", "LocalData"),
        (
            "str_eq",
            "UHostSnapshotSet.0.ResourceName",
            variables.get("UhostName"),
        ),
        (
            "str_eq",
            "UHostSnapshotSet.0.SnapshotDescription",
            variables.get("SnapshotDataDescModify"),
        ),
        ("str_eq", "UHostSnapshotSet.0.State", "Normal"),
    ],
    action="DescribeSnapshot",
)
def describe_snapshot_17(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "SnapshotIds": [variables.get("VdiskSnapIDData")],
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DeleteSnapshotResponse"),
    ],
    action="DeleteSnapshot",
)
def delete_snapshot_18(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "SnapshotId": variables.get("VdiskSnapIDSys"),
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DeleteSnapshotResponse"),
    ],
    action="DeleteSnapshot",
)
def delete_snapshot_19(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "SnapshotId": variables.get("VdiskSnapIDData"),
        "Region": variables.get("Region"),
    }

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=30,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "DescribeSnapshotResponse"),
        (
            "object_not_contains",
            "UHostSnapshotSet",
            variables.get("VdiskSnapIDSys"),
        ),
        (
            "object_not_contains",
            "UHostSnapshotSet",
            variables.get("VdiskSnapIDData"),
        ),
    ],
    action="DescribeSnapshot",
)
def describe_snapshot_20(client: utest.Client, variables: dict):
    d = {"Zone": variables.get("Zone"), "Region": variables.get("Region")}

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

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "StopUHostInstanceResponse"),
    ],
    action="StopUHostInstance",
)
def stop_uhost_instance_21(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().stop_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=30,
    retry_interval=10,
    startup_delay=10,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "UHostSet.0.State", "Stopped"),
    ],
    action="DescribeUHostInstance",
)
def describe_uhost_instance_22(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostIds": [variables.get("hostId")],
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().describe_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp


@scenario.step(
    max_retries=3,
    retry_interval=1,
    startup_delay=0,
    fast_fail=True,
    validators=lambda variables: [
        ("str_eq", "RetCode", 0),
        ("str_eq", "Action", "TerminateUHostInstanceResponse"),
    ],
    action="TerminateUHostInstance",
)
def terminate_uhost_instance_23(client: utest.Client, variables: dict):
    d = {
        "Zone": variables.get("Zone"),
        "UHostId": variables.get("hostId"),
        "Region": variables.get("Region"),
    }

    try:
        resp = client.uhost().terminate_uhost_instance(d)
    except exc.RetCodeException as e:
        resp = e.json()

    return resp
