Skip to content

Commit

Permalink
ADCM-6247: fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBalalan committed Dec 27, 2024
1 parent 878fa1a commit 05f40ab
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/integration/test_cluster.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections.abc import Collection
from pathlib import Path
import asyncio
import random
import string
import asyncio

from httpx import AsyncClient
import pytest
Expand Down
98 changes: 82 additions & 16 deletions tests/integration/test_host.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import NamedTuple

import pytest
import pytest_asyncio
Expand All @@ -23,15 +24,26 @@
pytestmark = [pytest.mark.asyncio]


class Expected(NamedTuple):
name: str
description: str
provider_id: int
cluster_id: int | None
status: str = "down"
maintenance_mode: str = "off"


@pytest_asyncio.fixture()
async def cluster_bundle(adcm_client: ADCMClient, tmp_path: Path) -> Bundle:
bundle_path = pack_bundle(from_dir=BUNDLES / "complex_cluster", to=tmp_path)
return await adcm_client.bundles.create(source=bundle_path)


@pytest_asyncio.fixture()
async def cluster(adcm_client: ADCMClient, cluster_bundle: Bundle) -> Cluster:
return await adcm_client.clusters.create(bundle=cluster_bundle, name="Cluster", description="Cluster description")
async def cluster(adcm_client: ADCMClient, complex_cluster_bundle: Bundle) -> Cluster:
return await adcm_client.clusters.create(
bundle=complex_cluster_bundle, name="Cluster", description="Cluster description"
)


@pytest_asyncio.fixture()
Expand All @@ -54,8 +66,12 @@ async def test_host(adcm_client: ADCMClient, hostprovider: HostProvider, cluster
name=f"test-host-{i}",
)

await cluster.hosts.add(host=await adcm_client.hosts.get(name__eq="test-host-0"))
await _test_host_properties(adcm_client.hosts, hostprovider, cluster)
expected = Expected(name="test-host-0", description="", cluster_id=cluster.id, provider_id=hostprovider.id)
host = await adcm_client.hosts.get(name__eq=expected.name)
await cluster.hosts.add(host=host)
await host.refresh()

await _test_host_properties(host, expected)
await _test_host_accessors(adcm_client.hosts, cluster)
await _test_pagination(adcm_client.hosts)

Expand All @@ -79,25 +95,75 @@ async def test_host_in_host_group(adcm_client: ADCMClient, hostprovider: HostPro
await config_host_group.hosts.add(await cluster.hosts.filter(name__contains="test-host"))
await action_host_group.hosts.add(await cluster.hosts.filter(name__contains="test-host"))

await _test_host_properties(config_host_group.hosts, hostprovider, cluster)
await _test_host_properties(action_host_group.hosts, hostprovider, cluster)
expected = Expected(name="test-host-0", description="", cluster_id=cluster.id, provider_id=hostprovider.id)
await _test_host_properties(await config_host_group.hosts.get(name__eq=expected.name), expected)
await _test_host_properties(await action_host_group.hosts.get(name__eq=expected.name), expected)

assert len(await config_host_group.hosts.all()) == 80
assert len(await action_host_group.hosts.all()) == 80


async def _test_host_properties(
hosts_node: HostsInActionHostGroupNode | HostsInConfigHostGroupNode | HostsNode,
hostprovider: HostProvider,
cluster: Cluster,
async def test_host_objects(
adcm_client: ADCMClient, hostprovider_bundle: Bundle, complex_cluster_bundle: Bundle
) -> None:
host = await hosts_node.get(name__eq="test-host-0")
assert host.name == "test-host-0"
assert (await host.hostprovider).name == hostprovider.name
assert (await host.cluster).name == cluster.name # pyright: ignore[reportOptionalMemberAccess]
"""Testing similarity, accessibility of attributes of host objects got from different sources"""

host_name = "Target-test-host"
provider = await adcm_client.hostproviders.create(bundle=hostprovider_bundle, name="New provider")
await adcm_client.hosts.create(hostprovider=provider, name=host_name)
target_host = await adcm_client.hosts.get(name__eq=host_name)

cluster = await adcm_client.clusters.create(
bundle=complex_cluster_bundle, name="Cluster with hosts", description="descr"
)
service = (await cluster.services.add(Filter(attr="name", op="eq", value="example_1")))[0]
component = await service.components.get(name__eq="first")

await cluster.hosts.add(host=target_host)
await target_host.refresh()

mapping = await cluster.mapping
await mapping.add(component=component, host=target_host)
await mapping.save()

chg = await cluster.config_host_groups.create(name="chg", hosts=[target_host])
ahg = await cluster.action_host_groups.create(name="ahg", hosts=[target_host])

expected = Expected(name=host_name, description="", cluster_id=cluster.id, provider_id=provider.id)
from_chg = await chg.hosts.get(name__eq=expected.name)
await _test_host_properties(from_chg, expected)
from_ahg = await ahg.hosts.get(name__eq=expected.name)
await _test_host_properties(from_ahg, expected)
from_mapping = await mapping.hosts.get(name__eq=expected.name)
await _test_host_properties(from_mapping, expected)
from_cluster = await cluster.hosts.get(name__eq=expected.name)
await _test_host_properties(from_cluster, expected)
from_component = await component.hosts.get(name__eq=expected.name)
await _test_host_properties(from_component, expected)
from_provider = await provider.hosts.get(name__eq=expected.name)
await _test_host_properties(from_provider, expected)

assert (
target_host.id
== from_chg.id
== from_ahg.id
== from_mapping.id
== from_cluster.id
== from_component.id
== from_provider.id
)


async def _test_host_properties(host: Host, expected: Expected) -> None:
assert isinstance(host.id, int)
assert host.name == expected.name
assert isinstance(host_cluster := await host.cluster, Cluster)
assert host_cluster.id == expected.cluster_id
assert isinstance(host.actions, ActionsAccessor)
assert await host.get_status() == "down"
assert (await host.maintenance_mode).value == "off"
assert isinstance(await host.actions.all(), list)
assert await host.get_status() == expected.status
assert (await host.hostprovider).id == expected.provider_id
assert (await host.maintenance_mode).value == expected.maintenance_mode


async def _test_host_accessors(
Expand Down

0 comments on commit 05f40ab

Please sign in to comment.