Skip to content

Commit 0e1ee7c

Browse files
committed
Test move ioc
1 parent 139abe8 commit 0e1ee7c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

server/tests/docker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def setup_compose() -> DockerCompose:
4646
if LOG.level <= logging.DEBUG:
4747
fetch_containers_and_log_logs(compose)
4848
compose.stop()
49+
4950
return setup_compose
5051

5152

@@ -71,3 +72,22 @@ def start_container(
7172
if container_id:
7273
docker_client = DockerClient()
7374
docker_client.containers.get(container_id).start()
75+
76+
77+
def clone_container(
78+
compose: DockerCompose, new_host_name: str, host_name: Optional[str] = None, container_id: Optional[str] = None
79+
) -> str:
80+
container_id = container_id or compose.get_container(host_name).ID
81+
if container_id:
82+
docker_client = DockerClient()
83+
container = docker_client.containers.get(container_id)
84+
image = container.image
85+
network = container.attrs.network_name
86+
container.stop()
87+
container.remove()
88+
docker_client.containers.run(
89+
image, detach=True, environment={"IOC_NAME": host_name}, hostname=new_host_name, network=network
90+
)
91+
92+
return container_id
93+
raise Exception("Container not found")

server/tests/test_single_ioc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from .docker import (
1717
ComposeFixtureFactory,
18+
clone_container,
1819
restart_container,
1920
shutdown_container,
2021
start_container,
@@ -113,3 +114,16 @@ def test_status_property_works_between_cf_down(
113114
)
114115
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
115116
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
117+
118+
119+
class TestMoveIocHost:
120+
def test_move_ioc_host(
121+
self,
122+
setup_compose: DockerCompose, # noqa: F811
123+
cf_client: ChannelFinderClient,
124+
) -> None:
125+
channels_begin = cf_client.find(name="*")
126+
clone_container(setup_compose, "ioc1-1-new", host_name="ioc1-1")
127+
wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I"))
128+
channels_end = cf_client.find(name="*")
129+
assert len(channels_begin) == len(channels_end)

0 commit comments

Comments
 (0)