Skip to content

Commit 4d319f0

Browse files
committed
Add tests for opreate_stop
1 parent 11f0924 commit 4d319f0

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/supervisor/views/test_operator.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,82 @@ async def test_operator_confidential_initialize_already_running(aiohttp_client,
102102
}
103103

104104

105+
@pytest.mark.asyncio
106+
@pytest.mark.skip()
107+
async def test_operator_expire(aiohttp_client, mocker):
108+
"""Test that the expires endpoint work. SPOILER it doesn't"""
109+
110+
settings.ENABLE_QEMU_SUPPORT = True
111+
settings.ENABLE_CONFIDENTIAL_COMPUTING = True
112+
settings.setup()
113+
114+
vm_hash = ItemHash(settings.FAKE_INSTANCE_ID)
115+
instance_message = await get_message(ref=vm_hash)
116+
117+
fake_vm_pool = mocker.Mock(
118+
executions={
119+
vm_hash: mocker.Mock(
120+
vm_hash=vm_hash,
121+
message=instance_message.content,
122+
is_confidential=False,
123+
is_running=False,
124+
),
125+
},
126+
)
127+
128+
# Disable auth
129+
mocker.patch(
130+
"aleph.vm.orchestrator.views.authentication.authenticate_jwk",
131+
return_value=instance_message.sender,
132+
)
133+
app = setup_webapp()
134+
app["vm_pool"] = fake_vm_pool
135+
client: TestClient = await aiohttp_client(app)
136+
response = await client.post(
137+
f"/control/machine/{vm_hash}/expire",
138+
data={"timeout": 1},
139+
# json={"timeout": 1},
140+
)
141+
assert response.status == 200, await response.text()
142+
assert fake_vm_pool["executions"][vm_hash].expire.call_count == 1
143+
144+
145+
@pytest.mark.asyncio
146+
async def test_operator_stop(aiohttp_client, mocker):
147+
"""Test that the stop endpoint call the method on pool"""
148+
149+
settings.ENABLE_QEMU_SUPPORT = True
150+
settings.ENABLE_CONFIDENTIAL_COMPUTING = True
151+
settings.setup()
152+
153+
vm_hash = ItemHash(settings.FAKE_INSTANCE_ID)
154+
instance_message = await get_message(ref=vm_hash)
155+
156+
fake_vm_pool = mocker.AsyncMock(
157+
executions={
158+
vm_hash: mocker.AsyncMock(
159+
vm_hash=vm_hash,
160+
message=instance_message.content,
161+
is_running=True,
162+
),
163+
},
164+
)
165+
166+
# Disable auth
167+
mocker.patch(
168+
"aleph.vm.orchestrator.views.authentication.authenticate_jwk",
169+
return_value=instance_message.sender,
170+
)
171+
app = setup_webapp()
172+
app["vm_pool"] = fake_vm_pool
173+
client: TestClient = await aiohttp_client(app)
174+
response = await client.post(
175+
f"/control/machine/{vm_hash}/stop",
176+
)
177+
assert response.status == 200, await response.text()
178+
assert fake_vm_pool.stop_vm.call_count == 1
179+
180+
105181
@pytest.mark.asyncio
106182
async def test_operator_confidential_initialize_not_confidential(aiohttp_client, mocker):
107183
"""Test that the confidential initialize endpoint rejects if the VM is not confidential"""

0 commit comments

Comments
 (0)