-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_host_groups.py
More file actions
115 lines (97 loc) · 4.87 KB
/
test_host_groups.py
File metadata and controls
115 lines (97 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import pytest
from adcm_aio_client import ADCMSession, Filter
from adcm_aio_client.config import ParameterHG
from adcm_aio_client.objects import ActionHostGroup, ConfigHostGroup
from tests.integration.examples.conftest import CREDENTIALS, REQUEST_KWARGS
from tests.integration.setup_environment import ADCMContainer
pytestmark = [pytest.mark.asyncio]
async def test_config_host_group(adcm: ADCMContainer) -> None:
"""
Config Host Group API Examples:
- creation
- deletion
- hosts management
- various retrieval approaches
- config basic interaction
"""
async with ADCMSession(url=adcm.url, credentials=CREDENTIALS, **REQUEST_KWARGS) as client:
bundle = await client.bundles.get(name__eq="simple_provider")
hostprovider = await client.hostproviders.create(bundle=bundle, name="For Hosts")
bundle = await client.bundles.get(name__icontains="Some cluste", version__eq="1")
cluster = await client.clusters.create(bundle=bundle, name="For CHG")
hosts = await asyncio.gather(
*(
client.hosts.create(hostprovider=hostprovider, name=f"host-for-group-{i}", cluster=cluster)
for i in range(3)
)
)
# Config host groups exist for Cluster, Service, Component and HostProvider.
# Not all hosts can be added to groups, only "related":
# refer to documentation for more info.
group: ConfigHostGroup = await cluster.config_host_groups.create(name="Cluster Group", hosts=hosts)
config = await group.config
config["string_field", ParameterHG].set("chanded value")
await config.save()
assert (await group.config_history[-1]).id == config.id
assert len(await group.hosts.all()) == 3
one_of_hosts, *_ = await group.hosts.filter(name__in=["host-for-group-1", "host-for-group-0"])
await group.hosts.remove(host=one_of_hosts)
assert len(await group.hosts.all()) == 2
assert len(await cluster.hosts.all()) == 3
await group.hosts.add(host=Filter(attr="name", op="eq", value=one_of_hosts.name))
# Since it's there's only one group, get without parameters will work,
# yet avoid using it like that.
group_ = await cluster.config_host_groups.get()
assert group_.id == group.id
await group.delete()
assert len(await cluster.config_host_groups.all()) == 0
async def test_action_host_group(adcm: ADCMContainer) -> None:
"""
Action Host Group API Examples:
- creation
- deletion
- hosts management
- various retrieval approaches
- action basic interaction
"""
async with ADCMSession(url=adcm.url, credentials=CREDENTIALS, **REQUEST_KWARGS) as client:
bundle = await client.bundles.get(name__eq="simple_provider")
hostprovider = await client.hostproviders.create(bundle=bundle, name="For Hosts")
bundle = await client.bundles.get(name__icontains="Some cluste", version__eq="1")
cluster = await client.clusters.create(bundle=bundle, name="For AHG")
hosts = await asyncio.gather(
*(
client.hosts.create(hostprovider=hostprovider, name=f"host-for-group-{i}", cluster=cluster)
for i in range(3)
)
)
group: ActionHostGroup = await cluster.action_host_groups.create(name="Cluster Group")
await group.hosts.add(host=hosts)
# Complex actions may have own `config` and `mapping` node as all actions do
action = await group.actions.get(display_name__contains="I will survive")
task = await action.run()
await task.wait(timeout=50)
assert len(await group.hosts.all()) == 3
one_of_hosts, *_ = await group.hosts.filter(name__in=["host-for-group-1", "host-for-group-0"])
await group.hosts.remove(host=one_of_hosts)
assert len(await group.hosts.all()) == 2
assert len(await cluster.hosts.all()) == 3
await group.hosts.add(host=Filter(attr="name", op="eq", value=one_of_hosts.name))
# Since it's there's only one group, get without parameters will work,
# yet avoid using it like that.
group_ = await cluster.action_host_groups.get()
assert group_.id == group.id
await group.delete()
assert len(await cluster.action_host_groups.all()) == 0