Skip to content

Commit 0fc2d2b

Browse files
committed
Test move ioc
1 parent c80e3c6 commit 0fc2d2b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

server/tests/docker.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,22 @@ def start_container(
7272
if container_id:
7373
docker_client = DockerClient()
7474
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,
@@ -112,3 +113,16 @@ def test_status_property_works_between_cf_down(
112113
)
113114
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
114115
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
116+
117+
118+
class TestMoveIocHost:
119+
def test_move_ioc_host(
120+
self,
121+
setup_compose: DockerCompose, # noqa: F811
122+
cf_client: ChannelFinderClient,
123+
) -> None:
124+
channels_begin = cf_client.find(name="*")
125+
clone_container(setup_compose, "ioc1-1-new", host_name="ioc1-1")
126+
wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I"))
127+
channels_end = cf_client.find(name="*")
128+
assert len(channels_begin) == len(channels_end)

0 commit comments

Comments
 (0)