mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Merge pull request #1270 from GNS3/replace-async-with-ensure-future
Replace asyncio.async with ensure_future because of deprecation, Fixe…
This commit is contained in:
commit
3c5ca9ce0e
@ -127,7 +127,7 @@ class BaseManager:
|
|||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
for node_id in self._nodes.keys():
|
for node_id in self._nodes.keys():
|
||||||
tasks.append(asyncio.async(self.close_node(node_id)))
|
tasks.append(asyncio.ensure_future(self.close_node(node_id)))
|
||||||
|
|
||||||
if tasks:
|
if tasks:
|
||||||
done, _ = yield from asyncio.wait(tasks)
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
|
@ -511,7 +511,7 @@ class DockerVM(BaseNode):
|
|||||||
|
|
||||||
output_stream.feed_data(self.name.encode() + b" console is now available... Press RETURN to get started.\r\n")
|
output_stream.feed_data(self.name.encode() + b" console is now available... Press RETURN to get started.\r\n")
|
||||||
|
|
||||||
asyncio.async(self._read_console_output(self._console_websocket, output_stream))
|
asyncio.ensure_future(self._read_console_output(self._console_websocket, output_stream))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _read_console_output(self, ws, out):
|
def _read_console_output(self, ws, out):
|
||||||
|
@ -172,7 +172,7 @@ class Dynamips(BaseManager):
|
|||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
for device in self._devices.values():
|
for device in self._devices.values():
|
||||||
tasks.append(asyncio.async(device.hypervisor.stop()))
|
tasks.append(asyncio.ensure_future(device.hypervisor.stop()))
|
||||||
|
|
||||||
if tasks:
|
if tasks:
|
||||||
done, _ = yield from asyncio.wait(tasks)
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
@ -196,7 +196,7 @@ class Dynamips(BaseManager):
|
|||||||
tasks = []
|
tasks = []
|
||||||
for device in self._devices.values():
|
for device in self._devices.values():
|
||||||
if device.project.id == project.id:
|
if device.project.id == project.id:
|
||||||
tasks.append(asyncio.async(device.delete()))
|
tasks.append(asyncio.ensure_future(device.delete()))
|
||||||
|
|
||||||
if tasks:
|
if tasks:
|
||||||
done, _ = yield from asyncio.wait(tasks)
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
|
@ -194,7 +194,7 @@ class Router(BaseNode):
|
|||||||
"""
|
"""
|
||||||
Called when the NVRAM file has changed
|
Called when the NVRAM file has changed
|
||||||
"""
|
"""
|
||||||
asyncio.async(self.save_configs())
|
asyncio.ensure_future(self.save_configs())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dynamips_id(self):
|
def dynamips_id(self):
|
||||||
|
@ -325,7 +325,7 @@ class Project:
|
|||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
for node in self._nodes:
|
for node in self._nodes:
|
||||||
tasks.append(asyncio.async(node.manager.close_node(node.id)))
|
tasks.append(asyncio.ensure_future(node.manager.close_node(node.id)))
|
||||||
|
|
||||||
if tasks:
|
if tasks:
|
||||||
done, _ = yield from asyncio.wait(tasks)
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
|
@ -738,4 +738,4 @@ if __name__ == '__main__':
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
vmware = VMware.instance()
|
vmware = VMware.instance()
|
||||||
print("=> Check version")
|
print("=> Check version")
|
||||||
loop.run_until_complete(asyncio.async(vmware.check_vmware_version()))
|
loop.run_until_complete(asyncio.ensure_future(vmware.check_vmware_version()))
|
||||||
|
@ -415,7 +415,7 @@ class Compute:
|
|||||||
if self._connection_failure == 5:
|
if self._connection_failure == 5:
|
||||||
log.warning("Cannot connect to compute '{}': {}".format(self._id, e))
|
log.warning("Cannot connect to compute '{}': {}".format(self._id, e))
|
||||||
yield from self._controller.close_compute_projects(self)
|
yield from self._controller.close_compute_projects(self)
|
||||||
asyncio.get_event_loop().call_later(2, lambda: asyncio.async(self._try_reconnect()))
|
asyncio.get_event_loop().call_later(2, lambda: asyncio.ensure_future(self._try_reconnect()))
|
||||||
return
|
return
|
||||||
except aiohttp.web.HTTPNotFound:
|
except aiohttp.web.HTTPNotFound:
|
||||||
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server or it's a 1.X server".format(self._id))
|
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server or it's a 1.X server".format(self._id))
|
||||||
@ -472,7 +472,7 @@ class Compute:
|
|||||||
|
|
||||||
# Try to reconnect after 1 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
# Try to reconnect after 1 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
||||||
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
||||||
asyncio.get_event_loop().call_later(1, lambda: asyncio.async(self.connect()))
|
asyncio.get_event_loop().call_later(1, lambda: asyncio.ensure_future(self.connect()))
|
||||||
self._ws = None
|
self._ws = None
|
||||||
self._cpu_usage_percent = None
|
self._cpu_usage_percent = None
|
||||||
self._memory_usage_percent = None
|
self._memory_usage_percent = None
|
||||||
|
@ -302,7 +302,7 @@ class GNS3VM:
|
|||||||
|
|
||||||
# check if the VM is in the same subnet as the local server, start 10 seconds later to give
|
# check if the VM is in the same subnet as the local server, start 10 seconds later to give
|
||||||
# some time for the compute in the VM to be ready for requests
|
# some time for the compute in the VM to be ready for requests
|
||||||
asyncio.get_event_loop().call_later(10, lambda: asyncio.async(self._check_network(compute)))
|
asyncio.get_event_loop().call_later(10, lambda: asyncio.ensure_future(self._check_network(compute)))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _check_network(self, compute):
|
def _check_network(self, compute):
|
||||||
|
@ -288,7 +288,7 @@ class Link:
|
|||||||
|
|
||||||
self._capturing = True
|
self._capturing = True
|
||||||
self._capture_file_name = capture_file_name
|
self._capture_file_name = capture_file_name
|
||||||
self._streaming_pcap = asyncio.async(self._start_streaming_pcap())
|
self._streaming_pcap = asyncio.ensure_future(self._start_streaming_pcap())
|
||||||
self._project.controller.notification.emit("link.updated", self.__json__())
|
self._project.controller.notification.emit("link.updated", self.__json__())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -867,7 +867,7 @@ class Project:
|
|||||||
# Start all in the background without waiting for completion
|
# Start all in the background without waiting for completion
|
||||||
# we ignore errors because we want to let the user open
|
# we ignore errors because we want to let the user open
|
||||||
# their project and fix it
|
# their project and fix it
|
||||||
asyncio.async(self.start_all())
|
asyncio.ensure_future(self.start_all())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def wait_loaded(self):
|
def wait_loaded(self):
|
||||||
|
@ -43,7 +43,7 @@ class NotificationHandler:
|
|||||||
ws = WebSocketResponse()
|
ws = WebSocketResponse()
|
||||||
yield from ws.prepare(request)
|
yield from ws.prepare(request)
|
||||||
|
|
||||||
asyncio.async(process_websocket(ws))
|
asyncio.ensure_future(process_websocket(ws))
|
||||||
|
|
||||||
with notifications.queue() as queue:
|
with notifications.queue() as queue:
|
||||||
while True:
|
while True:
|
||||||
|
@ -246,7 +246,7 @@ class ProjectHandler:
|
|||||||
ws = aiohttp.web.WebSocketResponse()
|
ws = aiohttp.web.WebSocketResponse()
|
||||||
yield from ws.prepare(request)
|
yield from ws.prepare(request)
|
||||||
|
|
||||||
asyncio.async(process_websocket(ws))
|
asyncio.ensure_future(process_websocket(ws))
|
||||||
|
|
||||||
with controller.notification.queue(project) as queue:
|
with controller.notification.queue(project) as queue:
|
||||||
while True:
|
while True:
|
||||||
|
@ -57,7 +57,7 @@ class ServerHandler:
|
|||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
for project in projects:
|
for project in projects:
|
||||||
tasks.append(asyncio.async(project.close()))
|
tasks.append(asyncio.ensure_future(project.close()))
|
||||||
|
|
||||||
if tasks:
|
if tasks:
|
||||||
done, _ = yield from asyncio.wait(tasks)
|
done, _ = yield from asyncio.wait(tasks)
|
||||||
@ -71,7 +71,7 @@ class ServerHandler:
|
|||||||
# then shutdown the server itself
|
# then shutdown the server itself
|
||||||
from gns3server.web.web_server import WebServer
|
from gns3server.web.web_server import WebServer
|
||||||
server = WebServer.instance()
|
server = WebServer.instance()
|
||||||
asyncio.async(server.shutdown_server())
|
asyncio.ensure_future(server.shutdown_server())
|
||||||
response.set_status(201)
|
response.set_status(201)
|
||||||
|
|
||||||
@Route.get(
|
@Route.get(
|
||||||
|
@ -223,9 +223,9 @@ def run():
|
|||||||
if server_config.getboolean("local"):
|
if server_config.getboolean("local"):
|
||||||
log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")
|
log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")
|
||||||
|
|
||||||
# we only support Python 3 version >= 3.4
|
# we only support Python 3 version >= 3.4.4
|
||||||
if sys.version_info < (3, 4):
|
if sys.version_info < (3, 4, 4):
|
||||||
raise SystemExit("Python 3.4 or higher is required")
|
raise SystemExit("Python 3.4.4 or higher is required")
|
||||||
|
|
||||||
user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
|
user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
|
||||||
major=sys.version_info[0], minor=sys.version_info[1],
|
major=sys.version_info[0], minor=sys.version_info[1],
|
||||||
|
@ -108,7 +108,7 @@ def _check_process(process, termination_callback):
|
|||||||
def monitor_process(process, termination_callback):
|
def monitor_process(process, termination_callback):
|
||||||
"""Call termination_callback when a process dies"""
|
"""Call termination_callback when a process dies"""
|
||||||
|
|
||||||
asyncio.async(_check_process(process, termination_callback))
|
asyncio.ensure_future(_check_process(process, termination_callback))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -69,8 +69,8 @@ class AsyncioRawCommandServer:
|
|||||||
else:
|
else:
|
||||||
replaces.append((replace[0], replace[1], ))
|
replaces.append((replace[0], replace[1], ))
|
||||||
|
|
||||||
network_read = asyncio.async(network_reader.read(READ_SIZE))
|
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
|
||||||
reader_read = asyncio.async(process_reader.read(READ_SIZE))
|
reader_read = asyncio.ensure_future(process_reader.read(READ_SIZE))
|
||||||
timeout = 30
|
timeout = 30
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -89,7 +89,7 @@ class AsyncioRawCommandServer:
|
|||||||
if network_reader.at_eof():
|
if network_reader.at_eof():
|
||||||
raise ConnectionResetError()
|
raise ConnectionResetError()
|
||||||
|
|
||||||
network_read = asyncio.async(network_reader.read(READ_SIZE))
|
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
|
||||||
|
|
||||||
process_writer.write(data)
|
process_writer.write(data)
|
||||||
yield from process_writer.drain()
|
yield from process_writer.drain()
|
||||||
@ -97,7 +97,7 @@ class AsyncioRawCommandServer:
|
|||||||
if process_reader.at_eof():
|
if process_reader.at_eof():
|
||||||
raise ConnectionResetError()
|
raise ConnectionResetError()
|
||||||
|
|
||||||
reader_read = asyncio.async(process_reader.read(READ_SIZE))
|
reader_read = asyncio.ensure_future(process_reader.read(READ_SIZE))
|
||||||
|
|
||||||
for replace in replaces:
|
for replace in replaces:
|
||||||
data = data.replace(replace[0], replace[1])
|
data = data.replace(replace[0], replace[1])
|
||||||
|
@ -229,13 +229,13 @@ class AsyncioTelnetServer:
|
|||||||
self._reader_process = network_reader
|
self._reader_process = network_reader
|
||||||
if self._reader:
|
if self._reader:
|
||||||
if self._reader_process == network_reader:
|
if self._reader_process == network_reader:
|
||||||
self._current_read = asyncio.async(self._reader.read(READ_SIZE))
|
self._current_read = asyncio.ensure_future(self._reader.read(READ_SIZE))
|
||||||
return self._current_read
|
return self._current_read
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _process(self, network_reader, network_writer, connection):
|
def _process(self, network_reader, network_writer, connection):
|
||||||
network_read = asyncio.async(network_reader.read(READ_SIZE))
|
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
|
||||||
reader_read = yield from self._get_reader(network_reader)
|
reader_read = yield from self._get_reader(network_reader)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -261,7 +261,7 @@ class AsyncioTelnetServer:
|
|||||||
if network_reader.at_eof():
|
if network_reader.at_eof():
|
||||||
raise ConnectionResetError()
|
raise ConnectionResetError()
|
||||||
|
|
||||||
network_read = asyncio.async(network_reader.read(READ_SIZE))
|
network_read = asyncio.ensure_future(network_reader.read(READ_SIZE))
|
||||||
|
|
||||||
if IAC in data:
|
if IAC in data:
|
||||||
data = yield from self._IAC_parser(data, network_reader, network_writer, connection)
|
data = yield from self._IAC_parser(data, network_reader, network_writer, connection)
|
||||||
@ -418,7 +418,7 @@ if __name__ == '__main__':
|
|||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
process = loop.run_until_complete(asyncio.async(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
|
process = loop.run_until_complete(asyncio.ensure_future(asyncio.subprocess.create_subprocess_exec("/bin/sh", "-i",
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.STDOUT,
|
stderr=asyncio.subprocess.STDOUT,
|
||||||
stdin=asyncio.subprocess.PIPE)))
|
stdin=asyncio.subprocess.PIPE)))
|
||||||
|
@ -136,7 +136,7 @@ class WebServer:
|
|||||||
|
|
||||||
def signal_handler(signame, *args):
|
def signal_handler(signame, *args):
|
||||||
log.warning("Server has got signal {}, exiting...".format(signame))
|
log.warning("Server has got signal {}, exiting...".format(signame))
|
||||||
asyncio.async(self.shutdown_server())
|
asyncio.ensure_future(self.shutdown_server())
|
||||||
|
|
||||||
signals = ["SIGTERM", "SIGINT"]
|
signals = ["SIGTERM", "SIGINT"]
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
@ -203,7 +203,7 @@ class WebServer:
|
|||||||
# Because with a large image collection
|
# Because with a large image collection
|
||||||
# without md5sum already computed we start the
|
# without md5sum already computed we start the
|
||||||
# computing with server start
|
# computing with server start
|
||||||
asyncio.async(Qemu.instance().list_images())
|
asyncio.ensure_future(Qemu.instance().list_images())
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
@ -283,7 +283,7 @@ class WebServer:
|
|||||||
self._exit_handling()
|
self._exit_handling()
|
||||||
|
|
||||||
if server_config.getboolean("shell"):
|
if server_config.getboolean("shell"):
|
||||||
asyncio.async(self.start_shell())
|
asyncio.ensure_future(self.start_shell())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._loop.run_forever()
|
self._loop.run_forever()
|
||||||
|
@ -45,7 +45,7 @@ def test_query_success(loop, vm):
|
|||||||
|
|
||||||
response.read.side_effect = read
|
response.read.side_effect = read
|
||||||
vm._session.request = AsyncioMagicMock(return_value=response)
|
vm._session.request = AsyncioMagicMock(return_value=response)
|
||||||
data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
|
data = loop.run_until_complete(asyncio.ensure_future(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
|
||||||
vm._session.request.assert_called_with('POST',
|
vm._session.request.assert_called_with('POST',
|
||||||
'http://docker/v1.25/test',
|
'http://docker/v1.25/test',
|
||||||
data='{"a": true}',
|
data='{"a": true}',
|
||||||
@ -68,7 +68,7 @@ def test_query_error(loop, vm):
|
|||||||
response.read.side_effect = read
|
response.read.side_effect = read
|
||||||
vm._session.request = AsyncioMagicMock(return_value=response)
|
vm._session.request = AsyncioMagicMock(return_value=response)
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
|
data = loop.run_until_complete(asyncio.ensure_future(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
|
||||||
vm._session.request.assert_called_with('POST',
|
vm._session.request.assert_called_with('POST',
|
||||||
'http://docker/v1.25/test',
|
'http://docker/v1.25/test',
|
||||||
data='{"a": true}',
|
data='{"a": true}',
|
||||||
@ -89,7 +89,7 @@ def test_query_error_json(loop, vm):
|
|||||||
response.read.side_effect = read
|
response.read.side_effect = read
|
||||||
vm._session.request = AsyncioMagicMock(return_value=response)
|
vm._session.request = AsyncioMagicMock(return_value=response)
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
data = loop.run_until_complete(asyncio.async(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
|
data = loop.run_until_complete(asyncio.ensure_future(vm.query("POST", "test", data={"a": True}, params={"b": 1})))
|
||||||
vm._session.request.assert_called_with('POST',
|
vm._session.request.assert_called_with('POST',
|
||||||
'http://docker/v1.25/test',
|
'http://docker/v1.25/test',
|
||||||
data='{"a": true}',
|
data='{"a": true}',
|
||||||
@ -126,7 +126,7 @@ def test_list_images(loop):
|
|||||||
]
|
]
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
images = loop.run_until_complete(asyncio.async(Docker.instance().list_images()))
|
images = loop.run_until_complete(asyncio.ensure_future(Docker.instance().list_images()))
|
||||||
mock.assert_called_with("GET", "images/json", params={"all": 0})
|
mock.assert_called_with("GET", "images/json", params={"all": 0})
|
||||||
assert len(images) == 5
|
assert len(images) == 5
|
||||||
assert {"image": "ubuntu:12.04"} in images
|
assert {"image": "ubuntu:12.04"} in images
|
||||||
@ -160,7 +160,7 @@ def test_pull_image(loop):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", side_effect=DockerHttp404Error("404")):
|
with asyncio_patch("gns3server.compute.docker.Docker.query", side_effect=DockerHttp404Error("404")):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||||
images = loop.run_until_complete(asyncio.async(Docker.instance().pull_image("ubuntu")))
|
images = loop.run_until_complete(asyncio.ensure_future(Docker.instance().pull_image("ubuntu")))
|
||||||
mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}, timeout=None)
|
mock.assert_called_with("POST", "images/create", params={"fromImage": "ubuntu"}, timeout=None)
|
||||||
|
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ def test_docker_check_connection_docker_minimum_version(vm, loop):
|
|||||||
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||||
vm._connected = False
|
vm._connected = False
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
loop.run_until_complete(asyncio.async(vm._check_connection()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_connection()))
|
||||||
|
|
||||||
|
|
||||||
def test_docker_check_connection_docker_preferred_version_against_newer(vm, loop):
|
def test_docker_check_connection_docker_preferred_version_against_newer(vm, loop):
|
||||||
@ -185,7 +185,7 @@ def test_docker_check_connection_docker_preferred_version_against_newer(vm, loop
|
|||||||
with patch("gns3server.compute.docker.Docker.connector"), \
|
with patch("gns3server.compute.docker.Docker.connector"), \
|
||||||
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||||
vm._connected = False
|
vm._connected = False
|
||||||
loop.run_until_complete(asyncio.async(vm._check_connection()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_connection()))
|
||||||
assert vm._api_version == DOCKER_PREFERRED_API_VERSION
|
assert vm._api_version == DOCKER_PREFERRED_API_VERSION
|
||||||
|
|
||||||
|
|
||||||
@ -197,5 +197,5 @@ def test_docker_check_connection_docker_preferred_version_against_older(vm, loop
|
|||||||
with patch("gns3server.compute.docker.Docker.connector"), \
|
with patch("gns3server.compute.docker.Docker.connector"), \
|
||||||
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response):
|
||||||
vm._connected = False
|
vm._connected = False
|
||||||
loop.run_until_complete(asyncio.async(vm._check_connection()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_connection()))
|
||||||
assert vm._api_version == DOCKER_MINIMUM_API_VERSION
|
assert vm._api_version == DOCKER_MINIMUM_API_VERSION
|
@ -86,7 +86,7 @@ def test_create(loop, project, manager):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
"OpenStdin": True,
|
"OpenStdin": True,
|
||||||
@ -125,7 +125,7 @@ def test_create_with_tag(loop, project, manager):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:16.04")
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:16.04")
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
"OpenStdin": True,
|
"OpenStdin": True,
|
||||||
@ -167,7 +167,7 @@ def test_create_vnc(loop, project, manager):
|
|||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc", console=5900)
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc", console=5900)
|
||||||
vm._start_vnc = MagicMock()
|
vm._start_vnc = MagicMock()
|
||||||
vm._display = 42
|
vm._display = 42
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
"OpenStdin": True,
|
"OpenStdin": True,
|
||||||
@ -212,7 +212,7 @@ def test_create_start_cmd(loop, project, manager):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
|
||||||
vm._start_command = "/bin/ls"
|
vm._start_command = "/bin/ls"
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
"OpenStdin": True,
|
"OpenStdin": True,
|
||||||
@ -256,7 +256,7 @@ def test_create_environment(loop, project, manager):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||||
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2"
|
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2"
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
"OpenStdin": True,
|
"OpenStdin": True,
|
||||||
@ -311,7 +311,7 @@ def test_create_image_not_available(loop, project, manager):
|
|||||||
vm._get_image_information.side_effect = information
|
vm._get_image_information.side_effect = information
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM.pull_image", return_value=True) as mock_pull:
|
with asyncio_patch("gns3server.compute.docker.DockerVM.pull_image", return_value=True) as mock_pull:
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
mock.assert_called_with("POST", "containers/create", data={
|
mock.assert_called_with("POST", "containers/create", data={
|
||||||
"Tty": True,
|
"Tty": True,
|
||||||
"OpenStdin": True,
|
"OpenStdin": True,
|
||||||
@ -357,17 +357,17 @@ def test_get_container_state(loop, vm):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "running"
|
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "running"
|
||||||
|
|
||||||
response["State"]["Running"] = False
|
response["State"]["Running"] = False
|
||||||
response["State"]["Paused"] = True
|
response["State"]["Paused"] = True
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "paused"
|
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "paused"
|
||||||
|
|
||||||
response["State"]["Running"] = False
|
response["State"]["Running"] = False
|
||||||
response["State"]["Paused"] = False
|
response["State"]["Paused"] = False
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "exited"
|
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "exited"
|
||||||
|
|
||||||
|
|
||||||
def test_is_running(loop, vm):
|
def test_is_running(loop, vm):
|
||||||
@ -378,17 +378,17 @@ def test_is_running(loop, vm):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
assert loop.run_until_complete(asyncio.async(vm.is_running())) is False
|
assert loop.run_until_complete(asyncio.ensure_future(vm.is_running())) is False
|
||||||
|
|
||||||
response["State"]["Running"] = True
|
response["State"]["Running"] = True
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
assert loop.run_until_complete(asyncio.async(vm.is_running())) is True
|
assert loop.run_until_complete(asyncio.ensure_future(vm.is_running())) is True
|
||||||
|
|
||||||
|
|
||||||
def test_pause(loop, vm):
|
def test_pause(loop, vm):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.pause()))
|
loop.run_until_complete(asyncio.ensure_future(vm.pause()))
|
||||||
|
|
||||||
mock.assert_called_with("POST", "containers/e90e34656842/pause")
|
mock.assert_called_with("POST", "containers/e90e34656842/pause")
|
||||||
assert vm.status == "suspended"
|
assert vm.status == "suspended"
|
||||||
@ -397,7 +397,7 @@ def test_pause(loop, vm):
|
|||||||
def test_unpause(loop, vm):
|
def test_unpause(loop, vm):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.unpause()))
|
loop.run_until_complete(asyncio.ensure_future(vm.unpause()))
|
||||||
|
|
||||||
mock.assert_called_with("POST", "containers/e90e34656842/unpause")
|
mock.assert_called_with("POST", "containers/e90e34656842/unpause")
|
||||||
|
|
||||||
@ -417,10 +417,10 @@ def test_start(loop, vm, manager, free_console_port):
|
|||||||
vm._start_console = AsyncioMagicMock()
|
vm._start_console = AsyncioMagicMock()
|
||||||
|
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
|
|
||||||
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
|
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
|
||||||
vm._add_ubridge_connection.assert_called_once_with(nio, 0)
|
vm._add_ubridge_connection.assert_called_once_with(nio, 0)
|
||||||
@ -436,7 +436,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
|
|||||||
vm.adapters = 1
|
vm.adapters = 1
|
||||||
|
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
@ -446,7 +446,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
|
|||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_log", return_value='Hello not available') as mock_log:
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_log", return_value='Hello not available') as mock_log:
|
||||||
|
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
|
|
||||||
mock_query.assert_any_call("POST", "containers/e90e34656842/start")
|
mock_query.assert_any_call("POST", "containers/e90e34656842/start")
|
||||||
mock_add_ubridge_connection.assert_called_once_with(nio, 0)
|
mock_add_ubridge_connection.assert_called_once_with(nio, 0)
|
||||||
@ -468,7 +468,7 @@ def test_start_without_nio(loop, vm, manager, free_console_port):
|
|||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_namespace", return_value=42) as mock_namespace:
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection:
|
with asyncio_patch("gns3server.compute.docker.DockerVM._add_ubridge_connection") as mock_add_ubridge_connection:
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._start_console") as mock_start_console:
|
with asyncio_patch("gns3server.compute.docker.DockerVM._start_console") as mock_start_console:
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
|
|
||||||
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
|
mock_query.assert_called_with("POST", "containers/e90e34656842/start")
|
||||||
assert mock_add_ubridge_connection.called
|
assert mock_add_ubridge_connection.called
|
||||||
@ -481,7 +481,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock:
|
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert vm.status == "started"
|
assert vm.status == "started"
|
||||||
|
|
||||||
@ -489,7 +489,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
|
|||||||
def test_restart(loop, vm):
|
def test_restart(loop, vm):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.restart()))
|
loop.run_until_complete(asyncio.ensure_future(vm.restart()))
|
||||||
|
|
||||||
mock.assert_called_with("POST", "containers/e90e34656842/restart")
|
mock.assert_called_with("POST", "containers/e90e34656842/restart")
|
||||||
|
|
||||||
@ -502,7 +502,7 @@ def test_stop(loop, vm):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
|
||||||
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
||||||
assert mock.stop.called
|
assert mock.stop.called
|
||||||
assert vm._ubridge_hypervisor is None
|
assert vm._ubridge_hypervisor is None
|
||||||
@ -514,7 +514,7 @@ def test_stop_paused_container(loop, vm):
|
|||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="paused"):
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause") as mock_unpause:
|
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause") as mock_unpause:
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
|
||||||
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
|
||||||
assert mock_unpause.called
|
assert mock_unpause.called
|
||||||
|
|
||||||
@ -532,7 +532,7 @@ def test_update(loop, vm):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.update()))
|
loop.run_until_complete(asyncio.ensure_future(vm.update()))
|
||||||
|
|
||||||
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
||||||
mock_query.assert_any_call("POST", "containers/create", data={
|
mock_query.assert_any_call("POST", "containers/create", data={
|
||||||
@ -582,7 +582,7 @@ def test_update_vnc(loop, vm):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.update()))
|
loop.run_until_complete(asyncio.ensure_future(vm.update()))
|
||||||
|
|
||||||
assert vm.console == original_console
|
assert vm.console == original_console
|
||||||
assert vm.aux == original_aux
|
assert vm.aux == original_aux
|
||||||
@ -601,7 +601,7 @@ def test_update_running(loop, vm):
|
|||||||
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.update()))
|
loop.run_until_complete(asyncio.ensure_future(vm.update()))
|
||||||
|
|
||||||
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
||||||
mock_query.assert_any_call("POST", "containers/create", data={
|
mock_query.assert_any_call("POST", "containers/create", data={
|
||||||
@ -639,7 +639,7 @@ def test_delete(loop, vm):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.delete()))
|
loop.run_until_complete(asyncio.ensure_future(vm.delete()))
|
||||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
||||||
|
|
||||||
|
|
||||||
@ -649,11 +649,11 @@ def test_close(loop, vm, port_manager):
|
|||||||
"rport": 4343,
|
"rport": 4343,
|
||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.close()))
|
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
||||||
|
|
||||||
assert vm._closed is True
|
assert vm._closed is True
|
||||||
@ -668,7 +668,7 @@ def test_close_vnc(loop, vm, port_manager):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="stopped"):
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
|
||||||
loop.run_until_complete(asyncio.async(vm.close()))
|
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||||
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
|
||||||
|
|
||||||
assert vm._closed is True
|
assert vm._closed is True
|
||||||
@ -682,7 +682,7 @@ def test_get_namespace(loop, vm):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
|
||||||
assert loop.run_until_complete(asyncio.async(vm._get_namespace())) == 42
|
assert loop.run_until_complete(asyncio.ensure_future(vm._get_namespace())) == 42
|
||||||
mock_query.assert_called_with("GET", "containers/e90e34656842/json")
|
mock_query.assert_called_with("GET", "containers/e90e34656842/json")
|
||||||
|
|
||||||
|
|
||||||
@ -697,7 +697,7 @@ def test_add_ubridge_connection(loop, vm):
|
|||||||
vm._ubridge_hypervisor = MagicMock()
|
vm._ubridge_hypervisor = MagicMock()
|
||||||
vm._namespace = 42
|
vm._namespace = 42
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
|
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0)))
|
||||||
|
|
||||||
calls = [
|
calls = [
|
||||||
call.send('bridge create bridge0'),
|
call.send('bridge create bridge0'),
|
||||||
@ -718,7 +718,7 @@ def test_add_ubridge_connection_none_nio(loop, vm):
|
|||||||
vm._ubridge_hypervisor = MagicMock()
|
vm._ubridge_hypervisor = MagicMock()
|
||||||
vm._namespace = 42
|
vm._namespace = 42
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
|
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0)))
|
||||||
|
|
||||||
calls = [
|
calls = [
|
||||||
call.send('bridge create bridge0'),
|
call.send('bridge create bridge0'),
|
||||||
@ -739,7 +739,7 @@ def test_add_ubridge_connection_invalid_adapter_number(loop, vm):
|
|||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 12)))
|
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 12)))
|
||||||
|
|
||||||
|
|
||||||
def test_add_ubridge_connection_no_free_interface(loop, vm):
|
def test_add_ubridge_connection_no_free_interface(loop, vm):
|
||||||
@ -755,7 +755,7 @@ def test_add_ubridge_connection_no_free_interface(loop, vm):
|
|||||||
interfaces = ["tap-gns3-e{}".format(index) for index in range(4096)]
|
interfaces = ["tap-gns3-e{}".format(index) for index in range(4096)]
|
||||||
|
|
||||||
with patch("psutil.net_if_addrs", return_value=interfaces):
|
with patch("psutil.net_if_addrs", return_value=interfaces):
|
||||||
loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
|
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0)))
|
||||||
|
|
||||||
|
|
||||||
def test_adapter_add_nio_binding(vm, loop):
|
def test_adapter_add_nio_binding(vm, loop):
|
||||||
@ -764,7 +764,7 @@ def test_adapter_add_nio_binding(vm, loop):
|
|||||||
"rport": 4343,
|
"rport": 4343,
|
||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0) == nio
|
assert vm._ethernet_adapters[0].get_nio(0) == nio
|
||||||
|
|
||||||
|
|
||||||
@ -779,9 +779,9 @@ def test_adapter_udpate_nio_binding(vm, loop):
|
|||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_update_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_update_nio_binding(0, nio)))
|
||||||
assert vm._ubridge_apply_filters.called
|
assert vm._ubridge_apply_filters.called
|
||||||
|
|
||||||
|
|
||||||
@ -793,9 +793,9 @@ def test_adapter_udpate_nio_binding_bridge_not_started(vm, loop):
|
|||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_update_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_update_nio_binding(0, nio)))
|
||||||
assert vm._ubridge_apply_filters.called is False
|
assert vm._ubridge_apply_filters.called is False
|
||||||
|
|
||||||
|
|
||||||
@ -806,7 +806,7 @@ def test_adapter_add_nio_binding_invalid_adapter(vm, loop):
|
|||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(12, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(12, nio)))
|
||||||
|
|
||||||
|
|
||||||
def test_adapter_remove_nio_binding(vm, loop):
|
def test_adapter_remove_nio_binding(vm, loop):
|
||||||
@ -818,10 +818,10 @@ def test_adapter_remove_nio_binding(vm, loop):
|
|||||||
"rport": 4343,
|
"rport": 4343,
|
||||||
"rhost": "127.0.0.1"}
|
"rhost": "127.0.0.1"}
|
||||||
nio = vm.manager.create_nio(nio)
|
nio = vm.manager.create_nio(nio)
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.DockerVM._ubridge_send") as delete_ubridge_mock:
|
with asyncio_patch("gns3server.compute.docker.DockerVM._ubridge_send") as delete_ubridge_mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(0)))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0) is None
|
assert vm._ethernet_adapters[0].get_nio(0) is None
|
||||||
delete_ubridge_mock.assert_any_call('bridge stop bridge0')
|
delete_ubridge_mock.assert_any_call('bridge stop bridge0')
|
||||||
delete_ubridge_mock.assert_any_call('bridge remove_nio_udp bridge0 4242 127.0.0.1 4343')
|
delete_ubridge_mock.assert_any_call('bridge remove_nio_udp bridge0 4242 127.0.0.1 4343')
|
||||||
@ -829,15 +829,15 @@ def test_adapter_remove_nio_binding(vm, loop):
|
|||||||
|
|
||||||
def test_adapter_remove_nio_binding_invalid_adapter(vm, loop):
|
def test_adapter_remove_nio_binding_invalid_adapter(vm, loop):
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(12)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(12)))
|
||||||
|
|
||||||
|
|
||||||
def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
|
def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
|
||||||
|
|
||||||
output_file = str(tmpdir / "test.pcap")
|
output_file = str(tmpdir / "test.pcap")
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
loop.run_until_complete(asyncio.async(vm.start_capture(0, output_file)))
|
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, output_file)))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
||||||
|
|
||||||
|
|
||||||
@ -845,10 +845,10 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
|
|||||||
|
|
||||||
output_file = str(tmpdir / "test.pcap")
|
output_file = str(tmpdir / "test.pcap")
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
loop.run_until_complete(vm.start_capture(0, output_file))
|
loop.run_until_complete(vm.start_capture(0, output_file))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
||||||
loop.run_until_complete(asyncio.async(vm.stop_capture(0)))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0)))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
|
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
|
||||||
|
|
||||||
|
|
||||||
@ -861,7 +861,7 @@ def test_get_log(loop, vm):
|
|||||||
mock_query.read = read
|
mock_query.read = read
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
|
||||||
images = loop.run_until_complete(asyncio.async(vm._get_log()))
|
images = loop.run_until_complete(asyncio.ensure_future(vm._get_log()))
|
||||||
mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={})
|
mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={})
|
||||||
|
|
||||||
|
|
||||||
@ -870,7 +870,7 @@ def test_get_image_informations(project, manager, loop):
|
|||||||
}
|
}
|
||||||
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
|
||||||
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
|
||||||
loop.run_until_complete(asyncio.async(vm._get_image_information()))
|
loop.run_until_complete(asyncio.ensure_future(vm._get_image_information()))
|
||||||
mock.assert_called_with("GET", "images/ubuntu:latest/json")
|
mock.assert_called_with("GET", "images/ubuntu:latest/json")
|
||||||
|
|
||||||
|
|
||||||
@ -900,7 +900,7 @@ def test_start_vnc(vm, loop):
|
|||||||
with patch("shutil.which", return_value="/bin/x"):
|
with patch("shutil.which", return_value="/bin/x"):
|
||||||
with asyncio_patch("gns3server.compute.docker.docker_vm.wait_for_file_creation") as mock_wait:
|
with asyncio_patch("gns3server.compute.docker.docker_vm.wait_for_file_creation") as mock_wait:
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec:
|
with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec:
|
||||||
loop.run_until_complete(asyncio.async(vm._start_vnc()))
|
loop.run_until_complete(asyncio.ensure_future(vm._start_vnc()))
|
||||||
assert vm._display is not None
|
assert vm._display is not None
|
||||||
mock_exec.assert_any_call("Xvfb", "-nolisten", "tcp", ":{}".format(vm._display), "-screen", "0", "1280x1024x16")
|
mock_exec.assert_any_call("Xvfb", "-nolisten", "tcp", ":{}".format(vm._display), "-screen", "0", "1280x1024x16")
|
||||||
mock_exec.assert_any_call("x11vnc", "-forever", "-nopw", "-shared", "-geometry", "1280x1024", "-display", "WAIT:{}".format(vm._display), "-rfbport", str(vm.console), "-rfbportv6", str(vm.console), "-noncache", "-listen", "127.0.0.1")
|
mock_exec.assert_any_call("x11vnc", "-forever", "-nopw", "-shared", "-geometry", "1280x1024", "-display", "WAIT:{}".format(vm._display), "-rfbport", str(vm.console), "-rfbportv6", str(vm.console), "-noncache", "-listen", "127.0.0.1")
|
||||||
@ -909,13 +909,13 @@ def test_start_vnc(vm, loop):
|
|||||||
|
|
||||||
def test_start_vnc_xvfb_missing(vm, loop):
|
def test_start_vnc_xvfb_missing(vm, loop):
|
||||||
with pytest.raises(DockerError):
|
with pytest.raises(DockerError):
|
||||||
loop.run_until_complete(asyncio.async(vm._start_vnc()))
|
loop.run_until_complete(asyncio.ensure_future(vm._start_vnc()))
|
||||||
|
|
||||||
|
|
||||||
def test_start_aux(vm, loop):
|
def test_start_aux(vm, loop):
|
||||||
|
|
||||||
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
|
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
|
||||||
loop.run_until_complete(asyncio.async(vm._start_aux()))
|
loop.run_until_complete(asyncio.ensure_future(vm._start_aux()))
|
||||||
mock_exec.assert_called_with('docker', 'exec', '-i', 'e90e34656842', '/gns3/bin/busybox', 'script', '-qfc', 'while true; do TERM=vt100 /gns3/bin/busybox sh; done', '/dev/null', stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
|
mock_exec.assert_called_with('docker', 'exec', '-i', 'e90e34656842', '/gns3/bin/busybox', 'script', '-qfc', 'while true; do TERM=vt100 /gns3/bin/busybox sh; done', '/dev/null', stderr=asyncio.subprocess.STDOUT, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
|
||||||
|
|
||||||
|
|
||||||
@ -977,5 +977,5 @@ def test_read_console_output_with_binary_mode(vm, loop):
|
|||||||
output_stream = MagicMock()
|
output_stream = MagicMock()
|
||||||
|
|
||||||
with asyncio_patch('gns3server.compute.docker.docker_vm.DockerVM.stop'):
|
with asyncio_patch('gns3server.compute.docker.docker_vm.DockerVM.stop'):
|
||||||
loop.run_until_complete(asyncio.async(vm._read_console_output(input_stream, output_stream)))
|
loop.run_until_complete(asyncio.ensure_future(vm._read_console_output(input_stream, output_stream)))
|
||||||
output_stream.feed_data.assert_called_once_with(b"test")
|
output_stream.feed_data.assert_called_once_with(b"test")
|
||||||
|
@ -70,6 +70,6 @@ def test_router_invalid_dynamips_path(project, manager, loop):
|
|||||||
|
|
||||||
with pytest.raises(DynamipsError):
|
with pytest.raises(DynamipsError):
|
||||||
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
||||||
loop.run_until_complete(asyncio.async(router.create()))
|
loop.run_until_complete(asyncio.ensure_future(router.create()))
|
||||||
assert router.name == "test"
|
assert router.name == "test"
|
||||||
assert router.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
assert router.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||||
|
@ -102,7 +102,7 @@ def test_start(loop, vm):
|
|||||||
|
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as mock_exec:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as mock_exec:
|
||||||
mock_process.returncode = None
|
mock_process.returncode = None
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
assert vm.command_line == ' '.join(mock_exec.call_args[0])
|
assert vm.command_line == ' '.join(mock_exec.call_args[0])
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ def test_start_with_iourc(loop, vm, tmpdir):
|
|||||||
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file}):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as exec_mock:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=mock_process) as exec_mock:
|
||||||
mock_process.returncode = None
|
mock_process.returncode = None
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
arsgs, kwargs = exec_mock.call_args
|
arsgs, kwargs = exec_mock.call_args
|
||||||
assert kwargs["env"]["IOURC"] == fake_file
|
assert kwargs["env"]["IOURC"] == fake_file
|
||||||
@ -168,10 +168,10 @@ def test_stop(loop, vm):
|
|||||||
|
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
process.returncode = None
|
process.returncode = None
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
process.terminate.assert_called_with()
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
@ -193,9 +193,9 @@ def test_reload(loop, vm, fake_iou_bin):
|
|||||||
|
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
loop.run_until_complete(asyncio.async(vm.reload()))
|
loop.run_until_complete(asyncio.ensure_future(vm.reload()))
|
||||||
assert vm.is_running() is True
|
assert vm.is_running() is True
|
||||||
process.terminate.assert_called_with()
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ def test_close(vm, port_manager, loop):
|
|||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||||
vm.start()
|
vm.start()
|
||||||
port = vm.console
|
port = vm.console
|
||||||
loop.run_until_complete(asyncio.async(vm.close()))
|
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||||
# Raise an exception if the port is not free
|
# Raise an exception if the port is not free
|
||||||
port_manager.reserve_tcp_port(port, vm.project)
|
port_manager.reserve_tcp_port(port, vm.project)
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
@ -250,7 +250,7 @@ def test_create_netmap_config(vm):
|
|||||||
|
|
||||||
def test_build_command(vm, loop):
|
def test_build_command(vm, loop):
|
||||||
|
|
||||||
assert loop.run_until_complete(asyncio.async(vm._build_command())) == [vm.path, str(vm.application_id)]
|
assert loop.run_until_complete(asyncio.ensure_future(vm._build_command())) == [vm.path, str(vm.application_id)]
|
||||||
|
|
||||||
|
|
||||||
def test_get_startup_config(vm):
|
def test_get_startup_config(vm):
|
||||||
@ -312,11 +312,11 @@ def test_library_check(loop, vm):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="") as mock:
|
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="") as mock:
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm._library_check()))
|
loop.run_until_complete(asyncio.ensure_future(vm._library_check()))
|
||||||
|
|
||||||
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="libssl => not found") as mock:
|
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="libssl => not found") as mock:
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
loop.run_until_complete(asyncio.async(vm._library_check()))
|
loop.run_until_complete(asyncio.ensure_future(vm._library_check()))
|
||||||
|
|
||||||
|
|
||||||
def test_enable_l1_keepalives(loop, vm):
|
def test_enable_l1_keepalives(loop, vm):
|
||||||
@ -324,14 +324,14 @@ def test_enable_l1_keepalives(loop, vm):
|
|||||||
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-l Enable Layer 1 keepalive messages\n-u <n> UDP port base for distributed networks\n") as mock:
|
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-l Enable Layer 1 keepalive messages\n-u <n> UDP port base for distributed networks\n") as mock:
|
||||||
|
|
||||||
command = ["test"]
|
command = ["test"]
|
||||||
loop.run_until_complete(asyncio.async(vm._enable_l1_keepalives(command)))
|
loop.run_until_complete(asyncio.ensure_future(vm._enable_l1_keepalives(command)))
|
||||||
assert command == ["test", "-l"]
|
assert command == ["test", "-l"]
|
||||||
|
|
||||||
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-u <n> UDP port base for distributed networks\n") as mock:
|
with asyncio_patch("gns3server.utils.asyncio.subprocess_check_output", return_value="***************************************************************\n\n-u <n> UDP port base for distributed networks\n") as mock:
|
||||||
|
|
||||||
command = ["test"]
|
command = ["test"]
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
loop.run_until_complete(asyncio.async(vm._enable_l1_keepalives(command)))
|
loop.run_until_complete(asyncio.ensure_future(vm._enable_l1_keepalives(command)))
|
||||||
assert command == ["test"]
|
assert command == ["test"]
|
||||||
|
|
||||||
|
|
||||||
@ -339,8 +339,8 @@ def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
|
|||||||
|
|
||||||
output_file = str(tmpdir / "test.pcap")
|
output_file = str(tmpdir / "test.pcap")
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, 0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, 0, nio)))
|
||||||
loop.run_until_complete(asyncio.async(vm.start_capture(0, 0, output_file)))
|
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, 0, output_file)))
|
||||||
assert vm._adapters[0].get_nio(0).capturing
|
assert vm._adapters[0].get_nio(0).capturing
|
||||||
|
|
||||||
|
|
||||||
@ -348,10 +348,10 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
|
|||||||
|
|
||||||
output_file = str(tmpdir / "test.pcap")
|
output_file = str(tmpdir / "test.pcap")
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, 0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, 0, nio)))
|
||||||
loop.run_until_complete(vm.start_capture(0, 0, output_file))
|
loop.run_until_complete(vm.start_capture(0, 0, output_file))
|
||||||
assert vm._adapters[0].get_nio(0).capturing
|
assert vm._adapters[0].get_nio(0).capturing
|
||||||
loop.run_until_complete(asyncio.async(vm.stop_capture(0, 0)))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0, 0)))
|
||||||
assert vm._adapters[0].get_nio(0).capturing is False
|
assert vm._adapters[0].get_nio(0).capturing is False
|
||||||
|
|
||||||
|
|
||||||
@ -364,42 +364,42 @@ def test_invalid_iou_file(loop, vm, iourc_file):
|
|||||||
|
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
# Missing ;
|
# Missing ;
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
with open(iourc_file, "w+") as f:
|
with open(iourc_file, "w+") as f:
|
||||||
f.write("[license]\n{} = aaaaaaaaaaaaaaaa".format(hostname))
|
f.write("[license]\n{} = aaaaaaaaaaaaaaaa".format(hostname))
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
# Key too short
|
# Key too short
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
with open(iourc_file, "w+") as f:
|
with open(iourc_file, "w+") as f:
|
||||||
f.write("[license]\n{} = aaaaaaaaaaaaaa;".format(hostname))
|
f.write("[license]\n{} = aaaaaaaaaaaaaa;".format(hostname))
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
# Invalid hostname
|
# Invalid hostname
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
with open(iourc_file, "w+") as f:
|
with open(iourc_file, "w+") as f:
|
||||||
f.write("[license]\nbla = aaaaaaaaaaaaaa;")
|
f.write("[license]\nbla = aaaaaaaaaaaaaa;")
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
# Missing licence section
|
# Missing licence section
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
with open(iourc_file, "w+") as f:
|
with open(iourc_file, "w+") as f:
|
||||||
f.write("[licensetest]\n{} = aaaaaaaaaaaaaaaa;")
|
f.write("[licensetest]\n{} = aaaaaaaaaaaaaaaa;")
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
# Broken config file
|
# Broken config file
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
with open(iourc_file, "w+") as f:
|
with open(iourc_file, "w+") as f:
|
||||||
f.write("[")
|
f.write("[")
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
# Missing file
|
# Missing file
|
||||||
with pytest.raises(IOUError):
|
with pytest.raises(IOUError):
|
||||||
os.remove(iourc_file)
|
os.remove(iourc_file)
|
||||||
loop.run_until_complete(asyncio.async(vm._check_iou_licence()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_iou_licence()))
|
||||||
|
|
||||||
|
|
||||||
def test_iourc_content(vm):
|
def test_iourc_content(vm):
|
||||||
|
@ -69,5 +69,5 @@ def test_rebase(tmpdir, loop):
|
|||||||
qcow2 = Qcow2(str(tmpdir / "linked.qcow2"))
|
qcow2 = Qcow2(str(tmpdir / "linked.qcow2"))
|
||||||
assert qcow2.version == 3
|
assert qcow2.version == 3
|
||||||
assert qcow2.backing_file == "empty8G.qcow2"
|
assert qcow2.backing_file == "empty8G.qcow2"
|
||||||
loop.run_until_complete(asyncio.async(qcow2.rebase(qemu_img(), str(tmpdir / "empty16G.qcow2"))))
|
loop.run_until_complete(asyncio.ensure_future(qcow2.rebase(qemu_img(), str(tmpdir / "empty16G.qcow2"))))
|
||||||
assert qcow2.backing_file == str(tmpdir / "empty16G.qcow2")
|
assert qcow2.backing_file == str(tmpdir / "empty16G.qcow2")
|
||||||
|
@ -41,7 +41,7 @@ def fake_qemu_img_binary(tmpdir):
|
|||||||
def test_get_qemu_version(loop):
|
def test_get_qemu_version(loop):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="QEMU emulator version 2.2.0, Copyright (c) 2003-2008 Fabrice Bellard") as mock:
|
||||||
version = loop.run_until_complete(asyncio.async(Qemu.get_qemu_version("/tmp/qemu-test")))
|
version = loop.run_until_complete(asyncio.ensure_future(Qemu.get_qemu_version("/tmp/qemu-test")))
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
assert version == ""
|
assert version == ""
|
||||||
else:
|
else:
|
||||||
@ -64,7 +64,7 @@ def test_binary_list(loop):
|
|||||||
else:
|
else:
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
|
||||||
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list()))
|
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.binary_list()))
|
||||||
|
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} in qemus
|
||||||
@ -72,14 +72,14 @@ def test_binary_list(loop):
|
|||||||
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86_64-spice"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86_64-spice"), "version": version} not in qemus
|
||||||
|
|
||||||
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list(["x86"])))
|
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.binary_list(["x86"])))
|
||||||
|
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x42"), "version": version} not in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "hello"), "version": version} not in qemus
|
||||||
|
|
||||||
qemus = loop.run_until_complete(asyncio.async(Qemu.binary_list(["x86", "x42"])))
|
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.binary_list(["x86", "x42"])))
|
||||||
|
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-system-x86"), "version": version} in qemus
|
||||||
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
|
assert {"path": os.path.join(os.environ["PATH"], "qemu-kvm"), "version": version} not in qemus
|
||||||
@ -98,7 +98,7 @@ def test_img_binary_list(loop):
|
|||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
|
with asyncio_patch("gns3server.compute.qemu.subprocess_check_output", return_value="qemu-img version 2.2.0, Copyright (c) 2004-2008 Fabrice Bellard") as mock:
|
||||||
qemus = loop.run_until_complete(asyncio.async(Qemu.img_binary_list()))
|
qemus = loop.run_until_complete(asyncio.ensure_future(Qemu.img_binary_list()))
|
||||||
|
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ def test_create_image_abs_path(loop, tmpdir, fake_qemu_img_binary):
|
|||||||
"size": 100
|
"size": 100
|
||||||
}
|
}
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, str(tmpdir / "hda.qcow2"), options)))
|
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(fake_qemu_img_binary, str(tmpdir / "hda.qcow2"), options)))
|
||||||
args, kwargs = process.call_args
|
args, kwargs = process.call_args
|
||||||
assert args == (
|
assert args == (
|
||||||
fake_qemu_img_binary,
|
fake_qemu_img_binary,
|
||||||
@ -152,7 +152,7 @@ def test_create_image_relative_path(loop, tmpdir, fake_qemu_img_binary):
|
|||||||
}
|
}
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
||||||
args, kwargs = process.call_args
|
args, kwargs = process.call_args
|
||||||
assert args == (
|
assert args == (
|
||||||
fake_qemu_img_binary,
|
fake_qemu_img_binary,
|
||||||
@ -174,7 +174,7 @@ def test_create_image_exist(loop, tmpdir, fake_qemu_img_binary):
|
|||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
with patch("gns3server.compute.qemu.Qemu.get_images_directory", return_value=str(tmpdir)):
|
||||||
with pytest.raises(QemuError):
|
with pytest.raises(QemuError):
|
||||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(fake_qemu_img_binary, "hda.qcow2", options)))
|
||||||
assert not process.called
|
assert not process.called
|
||||||
|
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ def test_create_image_with_not_supported_characters_by_filesystem(loop, tmpdir,
|
|||||||
patch("os.makedirs"):
|
patch("os.makedirs"):
|
||||||
|
|
||||||
with pytest.raises(QemuError):
|
with pytest.raises(QemuError):
|
||||||
loop.run_until_complete(asyncio.async(Qemu.instance().create_disk(
|
loop.run_until_complete(asyncio.ensure_future(Qemu.instance().create_disk(
|
||||||
fake_qemu_img_binary, "hda.qcow2", options)))
|
fake_qemu_img_binary, "hda.qcow2", options)))
|
||||||
assert not process.called
|
assert not process.called
|
||||||
|
|
||||||
@ -201,12 +201,12 @@ def test_create_image_with_not_supported_characters_by_filesystem(loop, tmpdir,
|
|||||||
def test_get_kvm_archs_kvm_ok(loop):
|
def test_get_kvm_archs_kvm_ok(loop):
|
||||||
|
|
||||||
with patch("os.path.exists", return_value=True):
|
with patch("os.path.exists", return_value=True):
|
||||||
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
|
archs = loop.run_until_complete(asyncio.ensure_future(Qemu.get_kvm_archs()))
|
||||||
if platform.machine() == 'x86_64':
|
if platform.machine() == 'x86_64':
|
||||||
assert archs == ['x86_64', 'i386']
|
assert archs == ['x86_64', 'i386']
|
||||||
else:
|
else:
|
||||||
assert archs == [platform.machine()]
|
assert archs == [platform.machine()]
|
||||||
|
|
||||||
with patch("os.path.exists", return_value=False):
|
with patch("os.path.exists", return_value=False):
|
||||||
archs = loop.run_until_complete(asyncio.async(Qemu.get_kvm_archs()))
|
archs = loop.run_until_complete(asyncio.ensure_future(Qemu.get_kvm_archs()))
|
||||||
assert archs == []
|
assert archs == []
|
||||||
|
@ -118,7 +118,7 @@ def test_is_running(vm, running_subprocess_mock):
|
|||||||
def test_start(loop, vm, running_subprocess_mock):
|
def test_start(loop, vm, running_subprocess_mock):
|
||||||
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
|
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock) as mock:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=running_subprocess_mock) as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
assert vm.command_line == ' '.join(mock.call_args[0])
|
assert vm.command_line == ' '.join(mock.call_args[0])
|
||||||
|
|
||||||
@ -135,9 +135,9 @@ def test_stop(loop, vm, running_subprocess_mock):
|
|||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
|
||||||
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||||
vm.adapter_add_nio_binding(0, nio)
|
vm.adapter_add_nio_binding(0, nio)
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
process.terminate.assert_called_with()
|
process.terminate.assert_called_with()
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ def test_termination_callback_error(vm, tmpdir, async_run):
|
|||||||
def test_reload(loop, vm):
|
def test_reload(loop, vm):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as mock:
|
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.reload()))
|
loop.run_until_complete(asyncio.ensure_future(vm.reload()))
|
||||||
assert mock.called_with("system_reset")
|
assert mock.called_with("system_reset")
|
||||||
|
|
||||||
|
|
||||||
@ -193,33 +193,33 @@ def test_suspend(loop, vm):
|
|||||||
control_vm_result = MagicMock()
|
control_vm_result = MagicMock()
|
||||||
control_vm_result.match.group.decode.return_value = "running"
|
control_vm_result.match.group.decode.return_value = "running"
|
||||||
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock:
|
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock:
|
||||||
loop.run_until_complete(asyncio.async(vm.suspend()))
|
loop.run_until_complete(asyncio.ensure_future(vm.suspend()))
|
||||||
assert mock.called_with("system_reset")
|
assert mock.called_with("system_reset")
|
||||||
|
|
||||||
|
|
||||||
def test_add_nio_binding_udp(vm, loop):
|
def test_add_nio_binding_udp(vm, loop):
|
||||||
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||||
assert nio.lport == 4242
|
assert nio.lport == 4242
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
assert nio.lport == 4242
|
assert nio.lport == 4242
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_port_remove_nio_binding(vm, loop):
|
def test_port_remove_nio_binding(vm, loop):
|
||||||
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
nio = Qemu.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(0)))
|
||||||
assert vm._ethernet_adapters[0].ports[0] is None
|
assert vm._ethernet_adapters[0].ports[0] is None
|
||||||
|
|
||||||
|
|
||||||
def test_close(vm, port_manager, loop):
|
def test_close(vm, port_manager, loop):
|
||||||
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
|
with asyncio_patch("gns3server.compute.qemu.QemuVM.start_wrap_console"):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
|
|
||||||
console_port = vm.console
|
console_port = vm.console
|
||||||
|
|
||||||
loop.run_until_complete(asyncio.async(vm.close()))
|
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||||
|
|
||||||
# Raise an exception if the port is not free
|
# Raise an exception if the port is not free
|
||||||
port_manager.reserve_tcp_port(console_port, vm.project)
|
port_manager.reserve_tcp_port(console_port, vm.project)
|
||||||
@ -328,7 +328,7 @@ def test_disk_options(vm, tmpdir, loop, fake_qemu_img_binary):
|
|||||||
open(vm._hda_disk_image, "w+").close()
|
open(vm._hda_disk_image, "w+").close()
|
||||||
|
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
options = loop.run_until_complete(asyncio.async(vm._disk_options()))
|
options = loop.run_until_complete(asyncio.ensure_future(vm._disk_options()))
|
||||||
assert process.called
|
assert process.called
|
||||||
args, kwargs = process.call_args
|
args, kwargs = process.call_args
|
||||||
assert args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hda_disk_image), "-f", "qcow2", os.path.join(vm.working_dir, "hda_disk.qcow2"))
|
assert args == (fake_qemu_img_binary, "create", "-o", "backing_file={}".format(vm._hda_disk_image), "-f", "qcow2", os.path.join(vm.working_dir, "hda_disk.qcow2"))
|
||||||
@ -341,7 +341,7 @@ def test_cdrom_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
|||||||
vm._cdrom_image = str(tmpdir / "test.iso")
|
vm._cdrom_image = str(tmpdir / "test.iso")
|
||||||
open(vm._cdrom_image, "w+").close()
|
open(vm._cdrom_image, "w+").close()
|
||||||
|
|
||||||
options = loop.run_until_complete(asyncio.async(vm._build_command()))
|
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
|
|
||||||
assert ' '.join(['-cdrom', str(tmpdir / "test.iso")]) in ' '.join(options)
|
assert ' '.join(['-cdrom', str(tmpdir / "test.iso")]) in ' '.join(options)
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ def test_bios_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
|||||||
vm._bios_image = str(tmpdir / "test.img")
|
vm._bios_image = str(tmpdir / "test.img")
|
||||||
open(vm._bios_image, "w+").close()
|
open(vm._bios_image, "w+").close()
|
||||||
|
|
||||||
options = loop.run_until_complete(asyncio.async(vm._build_command()))
|
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
|
|
||||||
assert ' '.join(['-bios', str(tmpdir / "test.img")]) in ' '.join(options)
|
assert ' '.join(['-bios', str(tmpdir / "test.img")]) in ' '.join(options)
|
||||||
|
|
||||||
@ -359,14 +359,14 @@ def test_bios_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
|||||||
def test_vnc_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
def test_vnc_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
||||||
vm._console_type = 'vnc'
|
vm._console_type = 'vnc'
|
||||||
vm._console = 5905
|
vm._console = 5905
|
||||||
options = loop.run_until_complete(asyncio.async(vm._build_command()))
|
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert '-vnc 127.0.0.1:5' in ' '.join(options)
|
assert '-vnc 127.0.0.1:5' in ' '.join(options)
|
||||||
|
|
||||||
|
|
||||||
def test_spice_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
def test_spice_option(vm, tmpdir, loop, fake_qemu_img_binary):
|
||||||
vm._console_type = 'spice'
|
vm._console_type = 'spice'
|
||||||
vm._console = 5905
|
vm._console = 5905
|
||||||
options = loop.run_until_complete(asyncio.async(vm._build_command()))
|
options = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert '-spice addr=127.0.0.1,port=5905,disable-ticketing' in ' '.join(options)
|
assert '-spice addr=127.0.0.1,port=5905,disable-ticketing' in ' '.join(options)
|
||||||
assert '-vga qxl' in ' '.join(options)
|
assert '-vga qxl' in ' '.join(options)
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ def test_disk_options_multiple_disk(vm, tmpdir, loop, fake_qemu_img_binary):
|
|||||||
open(vm._hdd_disk_image, "w+").close()
|
open(vm._hdd_disk_image, "w+").close()
|
||||||
|
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
options = loop.run_until_complete(asyncio.async(vm._disk_options()))
|
options = loop.run_until_complete(asyncio.ensure_future(vm._disk_options()))
|
||||||
|
|
||||||
assert options == [
|
assert options == [
|
||||||
'-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk',
|
'-drive', 'file=' + os.path.join(vm.working_dir, "hda_disk.qcow2") + ',if=ide,index=0,media=disk',
|
||||||
@ -400,7 +400,7 @@ def test_set_process_priority(vm, loop, fake_qemu_img_binary):
|
|||||||
vm._process = MagicMock()
|
vm._process = MagicMock()
|
||||||
vm._process.pid = 42
|
vm._process.pid = 42
|
||||||
vm._process_priority = "low"
|
vm._process_priority = "low"
|
||||||
loop.run_until_complete(asyncio.async(vm._set_process_priority()))
|
loop.run_until_complete(asyncio.ensure_future(vm._set_process_priority()))
|
||||||
assert process.called
|
assert process.called
|
||||||
args, kwargs = process.call_args
|
args, kwargs = process.call_args
|
||||||
assert args == ("renice", "-n", "5", "-p", "42")
|
assert args == ("renice", "-n", "5", "-p", "42")
|
||||||
@ -412,7 +412,7 @@ def test_set_process_priority_normal(vm, loop, fake_qemu_img_binary):
|
|||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
vm._process = MagicMock()
|
vm._process = MagicMock()
|
||||||
vm._process.pid = 42
|
vm._process.pid = 42
|
||||||
loop.run_until_complete(asyncio.async(vm._set_process_priority()))
|
loop.run_until_complete(asyncio.ensure_future(vm._set_process_priority()))
|
||||||
assert not process.called
|
assert not process.called
|
||||||
|
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ def test_control_vm(vm, loop):
|
|||||||
reader = MagicMock()
|
reader = MagicMock()
|
||||||
writer = MagicMock()
|
writer = MagicMock()
|
||||||
with asyncio_patch("asyncio.open_connection", return_value=(reader, writer)) as open_connect:
|
with asyncio_patch("asyncio.open_connection", return_value=(reader, writer)) as open_connect:
|
||||||
res = loop.run_until_complete(asyncio.async(vm._control_vm("test")))
|
res = loop.run_until_complete(asyncio.ensure_future(vm._control_vm("test")))
|
||||||
assert writer.write.called_with("test")
|
assert writer.write.called_with("test")
|
||||||
assert res is None
|
assert res is None
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ def test_control_vm_expect_text(vm, loop, running_subprocess_mock):
|
|||||||
reader.readline.return_value = future
|
reader.readline.return_value = future
|
||||||
|
|
||||||
vm._monitor = 4242
|
vm._monitor = 4242
|
||||||
res = loop.run_until_complete(asyncio.async(vm._control_vm("test", [b"epic"])))
|
res = loop.run_until_complete(asyncio.ensure_future(vm._control_vm("test", [b"epic"])))
|
||||||
assert writer.write.called_with("test")
|
assert writer.write.called_with("test")
|
||||||
|
|
||||||
assert res == "epic product"
|
assert res == "epic product"
|
||||||
@ -456,7 +456,7 @@ def test_build_command(vm, loop, fake_qemu_binary, port_manager):
|
|||||||
|
|
||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
nio = vm._local_udp_tunnels[0][0]
|
nio = vm._local_udp_tunnels[0][0]
|
||||||
assert cmd == [
|
assert cmd == [
|
||||||
fake_qemu_binary,
|
fake_qemu_binary,
|
||||||
@ -489,7 +489,7 @@ def test_build_command_manual_uuid(vm, loop, fake_qemu_binary, port_manager):
|
|||||||
vm.options = "-uuid e1c307a4-896f-11e6-81a5-3c07547807cc"
|
vm.options = "-uuid e1c307a4-896f-11e6-81a5-3c07547807cc"
|
||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert "e1c307a4-896f-11e6-81a5-3c07547807cc" in cmd
|
assert "e1c307a4-896f-11e6-81a5-3c07547807cc" in cmd
|
||||||
assert vm.id not in cmd
|
assert vm.id not in cmd
|
||||||
|
|
||||||
@ -502,7 +502,7 @@ def test_build_command_kvm(linux_platform, vm, loop, fake_qemu_binary, port_mana
|
|||||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.3.2")
|
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.3.2")
|
||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
nio = vm._local_udp_tunnels[0][0]
|
nio = vm._local_udp_tunnels[0][0]
|
||||||
assert cmd == [
|
assert cmd == [
|
||||||
fake_qemu_binary,
|
fake_qemu_binary,
|
||||||
@ -536,7 +536,7 @@ def test_build_command_kvm_2_4(linux_platform, vm, loop, fake_qemu_binary, port_
|
|||||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.4.2")
|
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.4.2")
|
||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
nio = vm._local_udp_tunnels[0][0]
|
nio = vm._local_udp_tunnels[0][0]
|
||||||
assert cmd == [
|
assert cmd == [
|
||||||
fake_qemu_binary,
|
fake_qemu_binary,
|
||||||
@ -569,7 +569,7 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary):
|
|||||||
|
|
||||||
os.environ["DISPLAY"] = ""
|
os.environ["DISPLAY"] = ""
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert "-nographic" in cmd
|
assert "-nographic" in cmd
|
||||||
|
|
||||||
|
|
||||||
@ -578,7 +578,7 @@ def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager):
|
|||||||
os.environ["DISPLAY"] = "0:0"
|
os.environ["DISPLAY"] = "0:0"
|
||||||
vm.adapters = 2
|
vm.adapters = 2
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
nio1 = vm._local_udp_tunnels[0][0]
|
nio1 = vm._local_udp_tunnels[0][0]
|
||||||
nio2 = vm._local_udp_tunnels[1][0]
|
nio2 = vm._local_udp_tunnels[1][0]
|
||||||
assert cmd == [
|
assert cmd == [
|
||||||
@ -619,7 +619,7 @@ def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port
|
|||||||
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
|
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
|
||||||
assert mac_0[:8] == "00:00:ab"
|
assert mac_0[:8] == "00:00:ab"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert "e1000,mac={},netdev=gns3-0".format(mac_0) in cmd
|
assert "e1000,mac={},netdev=gns3-0".format(mac_0) in cmd
|
||||||
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
|
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
|
||||||
|
|
||||||
@ -628,7 +628,7 @@ def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port
|
|||||||
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
|
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
|
||||||
assert mac_0[:8] == "00:42:ab"
|
assert mac_0[:8] == "00:42:ab"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
assert "e1000,mac={},netdev=gns3-0".format(mac_0) in cmd
|
assert "e1000,mac={},netdev=gns3-0".format(mac_0) in cmd
|
||||||
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
|
assert "e1000,mac={},netdev=gns3-1".format(mac_1) in cmd
|
||||||
|
|
||||||
@ -648,7 +648,7 @@ def test_build_command_large_number_of_adapters(vm, loop, fake_qemu_binary, port
|
|||||||
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
|
mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)
|
||||||
assert mac_0[:8] == "00:00:ab"
|
assert mac_0[:8] == "00:00:ab"
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
|
|
||||||
# Count if we have 100 e1000 adapters in the command
|
# Count if we have 100 e1000 adapters in the command
|
||||||
assert len([l for l in cmd if "e1000" in l ]) == 100
|
assert len([l for l in cmd if "e1000" in l ]) == 100
|
||||||
@ -672,10 +672,10 @@ def test_build_command_large_number_of_adapters(vm, loop, fake_qemu_binary, port
|
|||||||
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.0.0")
|
vm.manager.get_qemu_version = AsyncioMagicMock(return_value="2.0.0")
|
||||||
with pytest.raises(QemuError):
|
with pytest.raises(QemuError):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
vm.adapters = 5
|
vm.adapters = 5
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
|
|
||||||
# Windows accept this kind of mistake
|
# Windows accept this kind of mistake
|
||||||
|
|
||||||
@ -685,7 +685,7 @@ def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
|
|||||||
|
|
||||||
vm.options = "'test"
|
vm.options = "'test"
|
||||||
with pytest.raises(QemuError):
|
with pytest.raises(QemuError):
|
||||||
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
|
cmd = loop.run_until_complete(asyncio.ensure_future(vm._build_command()))
|
||||||
|
|
||||||
|
|
||||||
def test_hda_disk_image(vm, images_dir):
|
def test_hda_disk_image(vm, images_dir):
|
||||||
|
@ -83,7 +83,7 @@ def test_close(node, loop, port_manager):
|
|||||||
|
|
||||||
node.aux = aux
|
node.aux = aux
|
||||||
port = node.console
|
port = node.console
|
||||||
assert loop.run_until_complete(asyncio.async(node.close()))
|
assert loop.run_until_complete(asyncio.ensure_future(node.close()))
|
||||||
# Raise an exception if the port is not free
|
# Raise an exception if the port is not free
|
||||||
port_manager.reserve_tcp_port(port, node.project)
|
port_manager.reserve_tcp_port(port, node.project)
|
||||||
# Raise an exception if the port is not free
|
# Raise an exception if the port is not free
|
||||||
@ -92,7 +92,7 @@ def test_close(node, loop, port_manager):
|
|||||||
assert node.aux is None
|
assert node.aux is None
|
||||||
|
|
||||||
# Called twice closed should return False
|
# Called twice closed should return False
|
||||||
assert loop.run_until_complete(asyncio.async(node.close())) is False
|
assert loop.run_until_complete(asyncio.ensure_future(node.close())) is False
|
||||||
|
|
||||||
|
|
||||||
def test_aux(project, manager, port_manager):
|
def test_aux(project, manager, port_manager):
|
||||||
|
@ -43,7 +43,7 @@ def manager(port_manager):
|
|||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def node(project, manager, loop):
|
def node(project, manager, loop):
|
||||||
node = manager.create_node("test", project.id, "00010203-0405-0607-0809-0a0b0c0d0e0f")
|
node = manager.create_node("test", project.id, "00010203-0405-0607-0809-0a0b0c0d0e0f")
|
||||||
return loop.run_until_complete(asyncio.async(node))
|
return loop.run_until_complete(asyncio.ensure_future(node))
|
||||||
|
|
||||||
|
|
||||||
def test_affect_uuid():
|
def test_affect_uuid():
|
||||||
@ -120,7 +120,7 @@ def test_project_delete(loop):
|
|||||||
project = Project(project_id=str(uuid4()))
|
project = Project(project_id=str(uuid4()))
|
||||||
directory = project.path
|
directory = project.path
|
||||||
assert os.path.exists(directory)
|
assert os.path.exists(directory)
|
||||||
loop.run_until_complete(asyncio.async(project.delete()))
|
loop.run_until_complete(asyncio.ensure_future(project.delete()))
|
||||||
assert os.path.exists(directory) is False
|
assert os.path.exists(directory) is False
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ def test_project_delete_permission_issue(loop):
|
|||||||
assert os.path.exists(directory)
|
assert os.path.exists(directory)
|
||||||
os.chmod(directory, 0)
|
os.chmod(directory, 0)
|
||||||
with pytest.raises(aiohttp.web.HTTPInternalServerError):
|
with pytest.raises(aiohttp.web.HTTPInternalServerError):
|
||||||
loop.run_until_complete(asyncio.async(project.delete()))
|
loop.run_until_complete(asyncio.ensure_future(project.delete()))
|
||||||
os.chmod(directory, 700)
|
os.chmod(directory, 700)
|
||||||
|
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ def test_project_add_node(manager):
|
|||||||
def test_project_close(loop, node, project):
|
def test_project_close(loop, node, project):
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.close") as mock:
|
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.close") as mock:
|
||||||
loop.run_until_complete(asyncio.async(project.close()))
|
loop.run_until_complete(asyncio.ensure_future(project.close()))
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert node.id not in node.manager._nodes
|
assert node.id not in node.manager._nodes
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ def test_list_files(tmpdir, loop):
|
|||||||
with open(os.path.join(path, "test.txt"), "w+") as f:
|
with open(os.path.join(path, "test.txt"), "w+") as f:
|
||||||
f.write("test2")
|
f.write("test2")
|
||||||
|
|
||||||
files = loop.run_until_complete(asyncio.async(project.list_files()))
|
files = loop.run_until_complete(asyncio.ensure_future(project.list_files()))
|
||||||
|
|
||||||
assert files == [
|
assert files == [
|
||||||
{
|
{
|
||||||
|
@ -92,7 +92,7 @@ def test_list_vms(manager, loop):
|
|||||||
|
|
||||||
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute") as mock:
|
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute") as mock:
|
||||||
mock.side_effect = execute_mock
|
mock.side_effect = execute_mock
|
||||||
vms = loop.run_until_complete(asyncio.async(manager.list_vms()))
|
vms = loop.run_until_complete(asyncio.ensure_future(manager.list_vms()))
|
||||||
assert vms == [
|
assert vms == [
|
||||||
{"vmname": "Windows 8.1", "ram": 512},
|
{"vmname": "Windows 8.1", "ram": 512},
|
||||||
{"vmname": "Linux Microcore 4.7.1", "ram": 256}
|
{"vmname": "Linux Microcore 4.7.1", "ram": 256}
|
||||||
|
@ -75,20 +75,20 @@ def test_rename_vmname(project, manager, async_run):
|
|||||||
def test_vm_valid_virtualbox_api_version(loop, project, manager):
|
def test_vm_valid_virtualbox_api_version(loop, project, manager):
|
||||||
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]):
|
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_3"]):
|
||||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
|
|
||||||
|
|
||||||
def test_vm_invalid_virtualbox_api_version(loop, project, manager):
|
def test_vm_invalid_virtualbox_api_version(loop, project, manager):
|
||||||
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]):
|
with asyncio_patch("gns3server.compute.virtualbox.VirtualBox.execute", return_value=["API version: 4_2"]):
|
||||||
with pytest.raises(VirtualBoxError):
|
with pytest.raises(VirtualBoxError):
|
||||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.ensure_future(vm.create()))
|
||||||
|
|
||||||
|
|
||||||
def test_vm_adapter_add_nio_binding_adapter_not_exist(loop, vm, manager, free_console_port):
|
def test_vm_adapter_add_nio_binding_adapter_not_exist(loop, vm, manager, free_console_port):
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
with pytest.raises(VirtualBoxError):
|
with pytest.raises(VirtualBoxError):
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(15, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(15, nio)))
|
||||||
|
|
||||||
|
|
||||||
def test_json(vm, tmpdir, project):
|
def test_json(vm, tmpdir, project):
|
||||||
|
@ -56,8 +56,8 @@ def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
|
|||||||
output_file = str(tmpdir / "test.pcap")
|
output_file = str(tmpdir / "test.pcap")
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
vm.adapters = 1
|
vm.adapters = 1
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
loop.run_until_complete(asyncio.async(vm.start_capture(0, output_file)))
|
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, output_file)))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
||||||
|
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
|
|||||||
output_file = str(tmpdir / "test.pcap")
|
output_file = str(tmpdir / "test.pcap")
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.1"})
|
||||||
vm.adapters = 1
|
vm.adapters = 1
|
||||||
loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
|
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio)))
|
||||||
loop.run_until_complete(vm.start_capture(0, output_file))
|
loop.run_until_complete(vm.start_capture(0, output_file))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
assert vm._ethernet_adapters[0].get_nio(0).capturing
|
||||||
loop.run_until_complete(asyncio.async(vm.stop_capture(0)))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0)))
|
||||||
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
|
assert vm._ethernet_adapters[0].get_nio(0).capturing is False
|
||||||
|
@ -56,13 +56,13 @@ def test_vm(project, manager):
|
|||||||
|
|
||||||
def test_vm_check_vpcs_version(loop, vm, manager):
|
def test_vm_check_vpcs_version(loop, vm, manager):
|
||||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"):
|
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.9"):
|
||||||
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
|
||||||
assert vm._vpcs_version == parse_version("0.9")
|
assert vm._vpcs_version == parse_version("0.9")
|
||||||
|
|
||||||
|
|
||||||
def test_vm_check_vpcs_version_0_6_1(loop, vm, manager):
|
def test_vm_check_vpcs_version_0_6_1(loop, vm, manager):
|
||||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"):
|
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.subprocess_check_output", return_value="Welcome to Virtual PC Simulator, version 0.6.1"):
|
||||||
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
|
||||||
assert vm._vpcs_version == parse_version("0.6.1")
|
assert vm._vpcs_version == parse_version("0.6.1")
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ def test_vm_invalid_vpcs_version(loop, manager, vm):
|
|||||||
with pytest.raises(VPCSError):
|
with pytest.raises(VPCSError):
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
|
||||||
vm.port_add_nio_binding(0, nio)
|
vm.port_add_nio_binding(0, nio)
|
||||||
loop.run_until_complete(asyncio.async(vm._check_vpcs_version()))
|
loop.run_until_complete(asyncio.ensure_future(vm._check_vpcs_version()))
|
||||||
assert vm.name == "test"
|
assert vm.name == "test"
|
||||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ def test_vm_invalid_vpcs_path(vm, manager, loop):
|
|||||||
with pytest.raises(VPCSError):
|
with pytest.raises(VPCSError):
|
||||||
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||||
vm.port_add_nio_binding(0, nio)
|
vm.port_add_nio_binding(0, nio)
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert vm.name == "test"
|
assert vm.name == "test"
|
||||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ def test_start(loop, vm, async_run):
|
|||||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
|
||||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
|
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM.start_wrap_console"):
|
||||||
loop.run_until_complete(asyncio.async(vm.start()))
|
loop.run_until_complete(asyncio.ensure_future(vm.start()))
|
||||||
assert mock_exec.call_args[0] == (vm._vpcs_path(),
|
assert mock_exec.call_args[0] == (vm._vpcs_path(),
|
||||||
'-p',
|
'-p',
|
||||||
str(vm._internal_console_port),
|
str(vm._internal_console_port),
|
||||||
@ -169,7 +169,7 @@ def test_stop(loop, vm, async_run):
|
|||||||
assert vm.is_running()
|
assert vm.is_running()
|
||||||
|
|
||||||
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
|
||||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
loop.run_until_complete(asyncio.ensure_future(vm.stop()))
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
@ -300,5 +300,5 @@ def test_close(vm, port_manager, loop):
|
|||||||
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
with asyncio_patch("gns3server.compute.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True):
|
||||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||||
vm.start()
|
vm.start()
|
||||||
loop.run_until_complete(asyncio.async(vm.close()))
|
loop.run_until_complete(asyncio.ensure_future(vm.close()))
|
||||||
assert vm.is_running() is False
|
assert vm.is_running() is False
|
||||||
|
@ -314,7 +314,7 @@ def async_run(loop):
|
|||||||
"""
|
"""
|
||||||
Shortcut for running in asyncio loop
|
Shortcut for running in asyncio loop
|
||||||
"""
|
"""
|
||||||
return lambda x: loop.run_until_complete(asyncio.async(x))
|
return lambda x: loop.run_until_complete(asyncio.ensure_future(x))
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
|
@ -74,7 +74,7 @@ class Query:
|
|||||||
response = yield from self._session.ws_connect(self.get_url(path))
|
response = yield from self._session.ws_connect(self.get_url(path))
|
||||||
future.set_result(response)
|
future.set_result(response)
|
||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
asyncio.async(go_request(future))
|
asyncio.ensure_future(go_request(future))
|
||||||
self._loop.run_until_complete(future)
|
self._loop.run_until_complete(future)
|
||||||
return future.result()
|
return future.result()
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ class Query:
|
|||||||
- example if True the session is included inside documentation
|
- example if True the session is included inside documentation
|
||||||
- raw do not JSON encode the query
|
- raw do not JSON encode the query
|
||||||
"""
|
"""
|
||||||
return self._loop.run_until_complete(asyncio.async(self._async_fetch(method, path, body=body, **kwargs)))
|
return self._loop.run_until_complete(asyncio.ensure_future(self._async_fetch(method, path, body=body, **kwargs)))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _async_fetch(self, method, path, body=None, **kwargs):
|
def _async_fetch(self, method, path, body=None, **kwargs):
|
||||||
|
@ -356,7 +356,7 @@ def test_pcap(http_controller, tmpdir, project, compute, loop):
|
|||||||
project._links = {link.id: link}
|
project._links = {link.id: link}
|
||||||
|
|
||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
asyncio.async(go(future))
|
asyncio.ensure_future(go(future))
|
||||||
response = loop.run_until_complete(future)
|
response = loop.run_until_complete(future)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert b'hello' == response.body
|
assert b'hello' == response.body
|
||||||
|
@ -140,7 +140,7 @@ def test_notification(http_controller, project, controller, loop, async_run):
|
|||||||
response.close()
|
response.close()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
response = async_run(asyncio.async(go()))
|
response = async_run(asyncio.ensure_future(go()))
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
assert b'"action": "ping"' in response.body
|
assert b'"action": "ping"' in response.body
|
||||||
assert b'"cpu_usage_percent"' in response.body
|
assert b'"cpu_usage_percent"' in response.body
|
||||||
|
@ -31,7 +31,7 @@ def test_wait_run_in_executor(loop):
|
|||||||
return param
|
return param
|
||||||
|
|
||||||
exec = wait_run_in_executor(change_var, "test")
|
exec = wait_run_in_executor(change_var, "test")
|
||||||
result = loop.run_until_complete(asyncio.async(exec))
|
result = loop.run_until_complete(asyncio.ensure_future(exec))
|
||||||
assert result == "test"
|
assert result == "test"
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ def test_exception_wait_run_in_executor(loop):
|
|||||||
|
|
||||||
exec = wait_run_in_executor(raise_exception)
|
exec = wait_run_in_executor(raise_exception)
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
result = loop.run_until_complete(asyncio.async(exec))
|
result = loop.run_until_complete(asyncio.ensure_future(exec))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
|
||||||
@ -52,7 +52,7 @@ def test_subprocess_check_output(loop, tmpdir, restore_original_path):
|
|||||||
with open(path, "w+") as f:
|
with open(path, "w+") as f:
|
||||||
f.write("TEST")
|
f.write("TEST")
|
||||||
exec = subprocess_check_output("cat", path)
|
exec = subprocess_check_output("cat", path)
|
||||||
result = loop.run_until_complete(asyncio.async(exec))
|
result = loop.run_until_complete(asyncio.ensure_future(exec))
|
||||||
assert result == "TEST"
|
assert result == "TEST"
|
||||||
|
|
||||||
|
|
||||||
@ -64,13 +64,13 @@ def test_wait_for_process_termination(loop):
|
|||||||
process = MagicMock()
|
process = MagicMock()
|
||||||
process.returncode = 0
|
process.returncode = 0
|
||||||
exec = wait_for_process_termination(process)
|
exec = wait_for_process_termination(process)
|
||||||
loop.run_until_complete(asyncio.async(exec))
|
loop.run_until_complete(asyncio.ensure_future(exec))
|
||||||
|
|
||||||
process = MagicMock()
|
process = MagicMock()
|
||||||
process.returncode = None
|
process.returncode = None
|
||||||
exec = wait_for_process_termination(process, timeout=0.5)
|
exec = wait_for_process_termination(process, timeout=0.5)
|
||||||
with pytest.raises(asyncio.TimeoutError):
|
with pytest.raises(asyncio.TimeoutError):
|
||||||
loop.run_until_complete(asyncio.async(exec))
|
loop.run_until_complete(asyncio.ensure_future(exec))
|
||||||
|
|
||||||
|
|
||||||
def test_lock_decorator(loop):
|
def test_lock_decorator(loop):
|
||||||
|
Loading…
Reference in New Issue
Block a user