Skip to content

Commit 3f930ea

Browse files
committed
Test move ioc
1 parent 26f082f commit 3f930ea

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
@@ -63,3 +63,22 @@ def start_container(
6363
if container_id:
6464
docker_client = DockerClient()
6565
docker_client.containers.get(container_id).start()
66+
67+
68+
def clone_container(
69+
compose: DockerCompose, new_host_name: str, host_name: Optional[str] = None, container_id: Optional[str] = None
70+
) -> str:
71+
container_id = container_id or compose.get_container(host_name).ID
72+
if container_id:
73+
docker_client = DockerClient()
74+
container = docker_client.containers.get(container_id)
75+
image = container.image
76+
network = container.attrs.network_name
77+
container.stop()
78+
container.remove()
79+
docker_client.containers.run(
80+
image, detach=True, environment={"IOC_NAME": host_name}, hostname=new_host_name, network=network
81+
)
82+
83+
return container_id
84+
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
@@ -14,6 +14,7 @@
1414
wait_for_sync,
1515
)
1616
from .docker import (
17+
clone_container,
1718
restart_container,
1819
setup_compose,
1920
shutdown_container,
@@ -117,3 +118,16 @@ def test_status_property_works_between_cf_down(
117118
)
118119
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
119120
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
121+
122+
123+
class TestMoveIocHost:
124+
def test_move_ioc_host(
125+
self,
126+
setup_compose: DockerCompose, # noqa: F811
127+
cf_client: ChannelFinderClient,
128+
) -> None:
129+
channels_begin = cf_client.find(name="*")
130+
clone_container(setup_compose, "ioc1-1-new", host_name="ioc1-1")
131+
wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:Msg-I"))
132+
channels_end = cf_client.find(name="*")
133+
assert len(channels_begin) == len(channels_end)

0 commit comments

Comments
 (0)