Skip to content

Commit

Permalink
ADCM-6282: Prepare an example of interaction with a hostprovider (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starovoitov authored Jan 22, 2025
1 parent 5b772ae commit b535a37
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 17 deletions.
9 changes: 9 additions & 0 deletions tests/integration/bundles/simple_hostprovider/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
name: simple_provider
version: 4

upgrade:
- name: simple_provider
display_name: "simple upgrade"
versions:
min: 1
max: 4
states:
available: any

actions: &actions
success: &job
display_name: I will survive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@
pytestmark = [pytest.mark.asyncio]


async def test_iteration_with_cluster(adcm: ADCMContainer) -> None:
async def test_cluster(adcm: ADCMContainer) -> None:
"""
Interaction with clusters: creating, deleting, getting a list of clusters using filtering,
configuring cluster configuration, launching actions on the cluster and updating the cluster.
"""
url = adcm.url

async with ADCMSession(url=url, credentials=CREDENTIALS, **REQUEST_KWARGS) as client:
clusters = await client.clusters.all()
assert len(clusters) == 0


async def test_interaction_with_cluster(adcm: ADCMContainer) -> None:
"""
Interaction with clusters: creating, deleting, getting a list of clusters using filtering,
configuring cluster configuration, launching actions on the cluster and updating the cluster.
Cluster (`client.clusters`) API Examples:
- upload from path
- retrieval with filtering / all clusters
- cluster removal
- change of mapping between hosts and components by cluster
- update of cluster config
- upgrade of cluster
- running of cluster action
"""
async with ADCMSession(url=adcm.url, credentials=CREDENTIALS, **REQUEST_KWARGS) as client:
simple_cluster = await client.clusters.create(
Expand Down
54 changes: 54 additions & 0 deletions tests/integration/examples/test_hostprovider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest

from adcm_aio_client import ADCMSession
from tests.integration.examples.conftest import CREDENTIALS, REQUEST_KWARGS
from tests.integration.setup_environment import ADCMContainer

pytestmark = [pytest.mark.asyncio]


async def test_hostprovider(adcm: ADCMContainer) -> None:
"""
Hostprovider (`client.hostproviders`) API Examples:
- upload from path
- retrieval with filtering / all hostproviders
- hostprovider removal
- creation of new hosts by hostprovider
- retrieval a list of hosts by hostprovider with filtering / all hosts
- upgrade of hostprovider
"""
async with ADCMSession(url=adcm.url, credentials=CREDENTIALS, **REQUEST_KWARGS) as client:
# adding new hostprovider
hostprovider = await client.hostproviders.create(
bundle=await client.bundles.get(name__eq="simple_provider"), name="first provider"
)
second_hostprovider = await client.hostproviders.create(
bundle=await client.bundles.get(name__eq="simple_provider"), name="second provider"
)

# getting full list of hostproviders
providers = await client.hostproviders.all()
assert len(providers) == 2

# getting filtered list of hostproviders
providers = await client.hostproviders.filter(name__contains="first")
assert len(providers) == 1

# deletion of hostprovider
await second_hostprovider.delete()

# adding new hosts by hostprovider
for i in range(3):
await client.hosts.create(hostprovider=hostprovider, name=f"host-{i}")

# getting full list of hosts
hosts = await hostprovider.hosts.all()
assert len(hosts) == 3

# getting filtered list of hosts:
hosts = await hostprovider.hosts.filter(name__contains="host-2")
assert len(hosts) == 1

# running upgrade of hostprovider
upgrade = await hostprovider.upgrades.get(name__eq="simple_provider")
await upgrade.run()
4 changes: 2 additions & 2 deletions tests/integration/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ async def _test_upgrade_with_mapping(context: Context) -> None:

async def _test_upgrade_filtering(context: Context, tmp_path: Path) -> None:
hostprovider = context.hostprovider
upgrades_simple = 40
upgrades_simple = 41
upgrades_action = 20
upgrades_total = upgrades_simple + upgrades_action

assert await hostprovider.upgrades.all() == []
assert await hostprovider.upgrades.all() == [await hostprovider.upgrades.get(name__eq="simple_provider")]

new_bundle = await upload_hp_bundle_with_50_plus_upgrades(adcm_client=context.client, workdir=tmp_path)

Expand Down

0 comments on commit b535a37

Please sign in to comment.