21
21
import pytest_asyncio
22
22
import uuid
23
23
import os
24
+
25
+ from unittest .mock import patch
24
26
from tests .utils import asyncio_patch , AsyncioMagicMock
25
27
26
28
from gns3server .compute .ubridge .ubridge_error import UbridgeNamespaceError
@@ -1072,8 +1074,9 @@ async def test_start(vm, manager, free_console_port):
1072
1074
nio = manager .create_nio ({"type" : "nio_udp" , "lport" : free_console_port , "rport" : free_console_port , "rhost" : "127.0.0.1" })
1073
1075
await vm .adapter_add_nio_binding (0 , nio )
1074
1076
1075
- with asyncio_patch ("gns3server.compute.docker.Docker.query" ) as mock_query :
1076
- await vm .start ()
1077
+ with patch ("gns3server.compute.docker.Docker.install_busybox" ):
1078
+ with asyncio_patch ("gns3server.compute.docker.Docker.query" ) as mock_query :
1079
+ await vm .start ()
1077
1080
1078
1081
mock_query .assert_called_with ("POST" , "containers/e90e34656842/start" )
1079
1082
vm ._add_ubridge_connection .assert_called_once_with (nio , 0 )
@@ -1092,15 +1095,16 @@ async def test_start_namespace_failed(vm, manager, free_console_port):
1092
1095
nio = manager .create_nio ({"type" : "nio_udp" , "lport" : free_console_port , "rport" : free_console_port , "rhost" : "127.0.0.1" })
1093
1096
await vm .adapter_add_nio_binding (0 , nio )
1094
1097
1095
- with asyncio_patch ("gns3server.compute.docker.DockerVM._get_container_state" , return_value = "stopped" ):
1096
- with asyncio_patch ("gns3server.compute.docker.Docker.query" ) as mock_query :
1097
- with asyncio_patch ("gns3server.compute.docker.DockerVM._start_ubridge" ) as mock_start_ubridge :
1098
- with asyncio_patch ("gns3server.compute.docker.DockerVM._get_namespace" , return_value = 42 ) as mock_namespace :
1099
- with asyncio_patch ("gns3server.compute.docker.DockerVM._add_ubridge_connection" , side_effect = UbridgeNamespaceError ()) as mock_add_ubridge_connection :
1100
- with asyncio_patch ("gns3server.compute.docker.DockerVM._get_log" , return_value = 'Hello not available' ) as mock_log :
1098
+ with patch ("gns3server.compute.docker.Docker.install_busybox" ):
1099
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._get_container_state" , return_value = "stopped" ):
1100
+ with asyncio_patch ("gns3server.compute.docker.Docker.query" ) as mock_query :
1101
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._start_ubridge" ) as mock_start_ubridge :
1102
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._get_namespace" , return_value = 42 ) as mock_namespace :
1103
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._add_ubridge_connection" , side_effect = UbridgeNamespaceError ()) as mock_add_ubridge_connection :
1104
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._get_log" , return_value = 'Hello not available' ) as mock_log :
1101
1105
1102
- with pytest .raises (DockerError ):
1103
- await vm .start ()
1106
+ with pytest .raises (DockerError ):
1107
+ await vm .start ()
1104
1108
1105
1109
mock_query .assert_any_call ("POST" , "containers/e90e34656842/start" )
1106
1110
mock_add_ubridge_connection .assert_called_once_with (nio , 0 )
@@ -1117,13 +1121,14 @@ async def test_start_without_nio(vm):
1117
1121
assert vm .status != "started"
1118
1122
vm .adapters = 1
1119
1123
1120
- with asyncio_patch ("gns3server.compute.docker.DockerVM._get_container_state" , return_value = "stopped" ):
1121
- with asyncio_patch ("gns3server.compute.docker.Docker.query" ) as mock_query :
1122
- with asyncio_patch ("gns3server.compute.docker.DockerVM._start_ubridge" ) as mock_start_ubridge :
1123
- with asyncio_patch ("gns3server.compute.docker.DockerVM._get_namespace" , return_value = 42 ):
1124
- with asyncio_patch ("gns3server.compute.docker.DockerVM._add_ubridge_connection" ) as mock_add_ubridge_connection :
1125
- with asyncio_patch ("gns3server.compute.docker.DockerVM._start_console" ) as mock_start_console :
1126
- await vm .start ()
1124
+ with patch ("gns3server.compute.docker.Docker.install_busybox" ):
1125
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._get_container_state" , return_value = "stopped" ):
1126
+ with asyncio_patch ("gns3server.compute.docker.Docker.query" ) as mock_query :
1127
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._start_ubridge" ) as mock_start_ubridge :
1128
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._get_namespace" , return_value = 42 ):
1129
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._add_ubridge_connection" ) as mock_add_ubridge_connection :
1130
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._start_console" ) as mock_start_console :
1131
+ await vm .start ()
1127
1132
1128
1133
mock_query .assert_called_with ("POST" , "containers/e90e34656842/start" )
1129
1134
assert mock_add_ubridge_connection .called
@@ -1135,9 +1140,10 @@ async def test_start_without_nio(vm):
1135
1140
@pytest .mark .asyncio
1136
1141
async def test_start_unpause (vm ):
1137
1142
1138
- with asyncio_patch ("gns3server.compute.docker.DockerVM._get_container_state" , return_value = "paused" ):
1139
- with asyncio_patch ("gns3server.compute.docker.DockerVM.unpause" , return_value = "paused" ) as mock :
1140
- await vm .start ()
1143
+ with patch ("gns3server.compute.docker.Docker.install_busybox" ):
1144
+ with asyncio_patch ("gns3server.compute.docker.DockerVM._get_container_state" , return_value = "paused" ):
1145
+ with asyncio_patch ("gns3server.compute.docker.DockerVM.unpause" , return_value = "paused" ) as mock :
1146
+ await vm .start ()
1141
1147
assert mock .called
1142
1148
assert vm .status == "started"
1143
1149
0 commit comments