-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_host.py
75 lines (57 loc) · 2.58 KB
/
test_host.py
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
# 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 pytest
from adcm_aio_client.client import ADCMClient
from adcm_aio_client.errors import ObjectDoesNotExistError
from adcm_aio_client.objects import Cluster, Host, HostProvider
pytestmark = [pytest.mark.asyncio]
async def test_host(admin_client: ADCMClient, example_cluster: Cluster, example_hostprovider: HostProvider) -> None:
"""
Service (`client.hosts`) API Examples:
- creating a host
- retrieval with filtering / all hosts
- iteration through all hosts
- adding host to cluster
- turning on maintenance mode
- refreshing host's data
- host removal
"""
client = admin_client
cluster = example_cluster
hostprovider = example_hostprovider
# Create new host
host = await client.hosts.create(hostprovider=hostprovider, name="Example-host")
# Get all hosts
all_hosts: list[Host] = await client.hosts.all() # noqa: F841
# Iterate through all hosts
async for host in client.hosts.iter(): # noqa: B007
pass
# Get all hosts of hostprovider
hosts: list[Host] = await client.hosts.filter(hostprovider__eq=hostprovider)
name_not_exists = "Non-existent-host"
# Get host or `None` if no object is found
none_host: None = await client.hosts.get_or_none(name__eq=name_not_exists) # pyright: ignore[reportAssignmentType] # noqa: F841
# Get error trying to get non-existent host
with pytest.raises(ObjectDoesNotExistError, match="No objects found with the given filter."):
await client.hosts.get(name__eq=name_not_exists)
# Get all hosts, which name contains `host`
hosts: list[Host] = await client.hosts.filter(name__contains="host") # noqa: F841
# Add host to cluster with allowed maintenance mode
await cluster.hosts.add(host=host)
# Turn on host's maintenance mode
host_mm = await host.maintenance_mode
await host_mm.on()
# Sync host data with remote state
await host.refresh()
# Delete host after removing it from cluster
await cluster.hosts.remove(host=host)
await host.delete()